BasicSourceOptionsHandler.cc
Go to the documentation of this file.
2 
8 
9 #include <fstream>
10 #include <string>
11 
13  bpo::options_description& desc)
14 {
15  bpo::options_description source_options{"Source options"};
16  // clang-format off
17  source_options.add_options()
18  ("source,s",
19  bpo::value<std::vector<std::string>>()->composing(),
20  "Source data file (multiple OK); precludes -S.")
21  ("source-list,S",
22  bpo::value<std::string>(),
23  "file containing a list of source files to read, one per line; "
24  "precludes -s.")
25  ("estart,e",
26  bpo::value<std::string>(),
27  "EventID of first event to process (e.g. '1:2:4' starts event "
28  "processing at run 1, subrun2, event 4).")
29  ("nevts,n", bpo::value<int>(), "Number of events to process.")
30  ("nskip", bpo::value<unsigned long>(), "Number of events to skip.");
31  // clang-format on
32  desc.add(source_options);
33 }
34 
35 int
37 {
38  return 0;
39 }
40 
41 int
43  bpo::variables_map const& vm,
44  fhicl::intermediate_table& raw_config)
45 {
46  std::vector<std::string> source_list;
47  if (vm.count("source")) {
48  source_list = vm["source"].as<std::vector<std::string>>();
49  }
50  auto have_source_list_file = processSourceListArg_(vm, source_list);
51  // Post-process the config.
52  if (source_list.size() > 0 || have_source_list_file) {
53  // Empty source list file will override non-empty FHiCL spec.
54  raw_config.put("source.fileNames", source_list);
55  }
56  if (vm.count("nevts")) {
57  raw_config.put("source.maxEvents", vm["nevts"].as<int>());
58  }
59  if (vm.count("estart")) {
60  auto const [run, subRun, event] =
61  detail::event_start(vm["estart"].as<std::string>());
62  raw_config.put("source.firstRun", run);
63  raw_config.put("source.firstSubRun", subRun);
64  raw_config.put("source.firstEvent", event);
65  }
66  if (vm.count("nskip")) {
67  raw_config.put("source.skipEvents", vm["nskip"].as<unsigned long>());
68  }
69  return 0;
70 }
71 
72 bool
74  bpo::variables_map const& vm,
75  std::vector<std::string>& source_list)
76 {
77  bool result = !!vm.count("source-list");
78  if (result) {
79  if (!source_list.empty()) {
81  << "--source-list (-S) and --source (-s) or non-option arguments are "
82  << "incompatible due to ordering ambiguities.\n";
83  }
84  auto const filename = vm["source-list"].as<std::string>();
85  std::ifstream flist{filename};
86  if (!flist) {
88  << "Specified source-list file \"" << filename
89  << "\" cannot be read.\n";
90  }
91  art::detail::fillSourceList(flist, source_list);
92  }
93  return result;
94 }
static QCString result
std::string string
Definition: nybbler.cc:12
void fillSourceList(std::istream &ifs, std::vector< std::string > &source_list)
string filename
Definition: train.py:213
std::tuple< RunNumber_t, SubRunNumber_t, EventNumber_t > event_start(std::string const &str_num)
Definition: event_start.cc:72
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
BasicSourceOptionsHandler(bpo::options_description &desc)
int doProcessOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config) override
int doCheckOptions(bpo::variables_map const &vm) override
Event finding and building.
bool processSourceListArg_(bpo::variables_map const &vm, std::vector< std::string > &source_list)