LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
BasicSourceOptionsHandler.cc
Go to the documentation of this file.
2 
5 #include "cetlib/container_algorithms.h"
6 #include "fhiclcpp/coding.h"
9 #include "fhiclcpp/parse.h"
10 
11 #include <fstream>
12 #include <iostream>
13 #include <string>
14 
16  bpo::options_description& desc)
17 {
18  bpo::options_description source_options{"Source options"};
19  auto options = source_options.add_options();
20  add_opt(options,
21  "source,s",
22  bpo::value<std::vector<std::string>>()->composing(),
23  "Source data file (multiple OK); precludes -S.");
24  add_opt(options,
25  "source-list,S",
26  bpo::value<std::string>(),
27  "file containing a list of source files to read, one per line; "
28  "precludes -s.");
29  add_opt(options,
30  "estart,e",
31  bpo::value<unsigned long>(),
32  "Event # of first event to process.");
33  add_opt(
34  options, "nevts,n", bpo::value<int>(), "Number of events to process.");
35  add_opt(
36  options, "nskip", bpo::value<unsigned long>(), "Number of events to skip.");
37  desc.add(source_options);
38 }
39 
40 int
42 {
43  return 0;
44 }
45 
46 int
48  bpo::variables_map const& vm,
49  fhicl::intermediate_table& raw_config)
50 {
51  std::vector<std::string> source_list;
52  if (vm.count("source")) {
53  cet::copy_all(vm["source"].as<std::vector<std::string>>(),
54  std::back_inserter(source_list));
55  }
56  auto have_source_list_file = processSourceListArg_(vm, source_list);
57  // Post-process the config.
58  if (source_list.size() > 0 || have_source_list_file) {
59  // Empty source list file will override non-empty FHiCL spec.
60  raw_config.put("source.fileNames", source_list);
61  }
62  if (vm.count("nevts")) {
63  raw_config.put("source.maxEvents", vm["nevts"].as<int>());
64  }
65  if (vm.count("estart")) {
66  raw_config.put("source.firstEvent", vm["estart"].as<unsigned long>());
67  }
68  if (vm.count("nskip")) {
69  raw_config.put("source.skipEvents", vm["nskip"].as<unsigned long>());
70  }
71  return 0;
72 }
73 
74 bool
76  bpo::variables_map const& vm,
77  std::vector<std::string>& source_list)
78 {
79  bool result = !!vm.count("source-list");
80  if (result) {
81  if (source_list.size()) {
83  << "--source-list (-S) and --source (-s) or non-option arguments are "
84  << "incompatible due to ordering ambiguities.\n";
85  }
86  std::ifstream flist(vm["source-list"].as<std::string>().c_str());
87  if (!flist) {
89  << "Specified source-list file \""
90  << vm["source-list"].as<std::string>() << "\" cannot be read.\n";
91  }
92  art::detail::fillSourceList(flist, source_list);
93  }
94  return result;
95 }
void add_opt(T &t, Args &&...args)
void fillSourceList(std::istream &ifs, std::vector< std::string > &source_list)
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
std::string value(boost::any const &)
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
bool processSourceListArg_(bpo::variables_map const &vm, std::vector< std::string > &source_list)