LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::BasicOptionsHandler Class Reference

#include "BasicOptionsHandler.h"

Inheritance diagram for art::BasicOptionsHandler:
art::OptionsHandler

Public Member Functions

 BasicOptionsHandler (bpo::options_description &desc, cet::filepath_maker &maker, bool report_unused)
 
int checkOptions (bpo::variables_map const &vm)
 
int processOptions (bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)
 

Private Member Functions

int doCheckOptions (bpo::variables_map const &vm) override
 
int doProcessOptions (bpo::variables_map const &vm, fhicl::intermediate_table &raw_config) override
 

Private Attributes

bpo::options_description const & help_desc_
 
cet::filepath_maker & maker_
 

Detailed Description

Definition at line 13 of file BasicOptionsHandler.h.

Constructor & Destructor Documentation

art::BasicOptionsHandler::BasicOptionsHandler ( bpo::options_description &  desc,
cet::filepath_maker &  maker,
bool  report_unused 
)

Definition at line 28 of file BasicOptionsHandler.cc.

References art::getReleaseVersion(), maker_, art::Suffixes::print(), art::to_string(), and value.

31  : help_desc_{desc}, maker_{maker}
32 {
33  // clang-format off
34  desc.add_options()
35  ("help,h", "produce help message")
36  ("version", ("Print art version (" + getReleaseVersion() + ")").c_str())
37  ("config,c", bpo::value<std::string>(), "Configuration file.")
38  ("process-name", bpo::value<std::string>(), "art process name.")
39  ("prune-config",
40  bpo::value<bool>()->default_value(true, to_string(true)),
41  "Remove unused modules and paths from the fully-processed configuration.")
42  ("report-unused",
43  bpo::value<bool>()->default_value(report_unused, to_string(report_unused)),
44  "If 'true', the list of unused modules and paths will be printed to STDERR.")
45  ("print-available",
46  bpo::value<std::string>(),
47  ("List all available plugins with the provided suffix. Choose from:"s +
48  Suffixes::print()).c_str())
49  ("print-available-modules",
50  "List all available modules that can be invoked in a FHiCL file.")
51  ("print-available-services",
52  "List all available services that can be invoked in a FHiCL file.")
53  ("print-description",
54  bpo::value<std::vector<std::string>>()->multitoken(),
55  "Print description of specified module, service, source, or other "
56  "plugin (multiple OK). Argument can be a regular expression used "
57  "to match the plugin specification. To narrow the search to "
58  "plugins with a particular suffix, preface the regular expression"
59  "with the suffix (e.g. service:TFileService).")
60  ("status-bar",
61  "Provide status bar that reports the progress of retrieving "
62  "plugin information for a 'print-available' command.");
63  // clang-format on
64 }
static std::string print()
std::string const & getReleaseVersion()
double value
Definition: spectrum.C:18
bpo::options_description const & help_desc_
cet::filepath_maker & maker_
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34

Member Function Documentation

int art::OptionsHandler::checkOptions ( bpo::variables_map const &  vm)
inherited

Definition at line 51 of file OptionsHandler.cc.

References art::OptionsHandler::doCheckOptions().

52 {
53  std::string const thisClass(cet::demangle_symbol(typeid(*this).name()));
54  return exceptionCatcher([&vm, this] { return doCheckOptions(vm); },
55  thisClass + "::doCheckOptions()",
56  89);
57 }
virtual int doCheckOptions(bpo::variables_map const &vm)=0
int art::BasicOptionsHandler::doCheckOptions ( bpo::variables_map const &  vm)
overrideprivatevirtual

Implements art::OptionsHandler.

Definition at line 67 of file BasicOptionsHandler.cc.

References art::errors::Configuration, art::getReleaseVersion(), help_desc_, art::detail::info_success(), art::Suffixes::module(), art::detail::print_available_plugins(), art::detail::print_descriptions(), and art::Suffixes::service().

68 {
69  // Technically the "help" and "print*" options are processing steps,
70  // but we want to short-circuit.
71  if (vm.count("help")) {
72  // Could simply do cout << help_desc_, but the boost-provided
73  // printout does not add any left-hand padding. Will add a
74  // 2-space tab by hand.
75  std::stringstream ss;
76  ss << help_desc_; // Note NOT our own desc_.
77  for (std::string s; std::getline(ss, s);)
78  std::cout << std::string(2, ' ') << s << '\n';
79  std::cout << '\n';
80  return detail::info_success();
81  }
82  bool const status_bar = vm.count("status-bar") > 0;
83  if (vm.count("print-available")) {
84  detail::print_available_plugins(vm["print-available"].as<std::string>(),
85  status_bar);
86  return detail::info_success();
87  }
88  if (vm.count("print-available-modules")) {
90  return detail::info_success();
91  }
92  if (vm.count("print-available-services")) {
94  return detail::info_success();
95  }
96  if (status_bar) {
98  << "The '--status-bar' option can be used only with the "
99  "'--print-available*' program options.\n";
100  }
101 
102  if (vm.count("print-description")) {
104  vm["print-description"].as<std::vector<std::string>>());
105  return detail::info_success();
106  }
107  if (vm.count("version")) {
108  std::cout << "art " << getReleaseVersion() << '\n';
109  return detail::info_success();
110  }
111 
112  if (!vm.count("config")) {
113  throw Exception(errors::Configuration) << "No configuration file given.\n";
114  }
115  return 0;
116 }
void print_available_plugins(std::string const &suffix, std::string const &spec, bool verbose)
std::string const & getReleaseVersion()
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bpo::options_description const & help_desc_
void print_descriptions(std::vector< std::string > const &plugins)
static std::string const & service()
constexpr int info_success()
Definition: info_success.h:8
static std::string const & module()
int art::BasicOptionsHandler::doProcessOptions ( bpo::variables_map const &  vm,
fhicl::intermediate_table raw_config 
)
overrideprivatevirtual

Implements art::OptionsHandler.

Definition at line 119 of file BasicOptionsHandler.cc.

References e, fhicl::intermediate_table::empty(), maker_, fhicl::parse_document(), and fhicl::intermediate_table::put().

122 {
123  try {
124  raw_config = fhicl::parse_document(vm["config"].as<std::string>(), maker_);
125  }
126  catch (cet::exception& e) {
127  std::cerr << "Failed to parse the configuration file '"
128  << vm["config"].as<std::string>() << "' with exception\n"
129  << e.what() << '\n';
130  return 90;
131  }
132  if (raw_config.empty()) {
133  std::cerr << "INFO: provided configuration file '"
134  << vm["config"].as<std::string>() << "' is empty: \n"
135  << "using minimal defaults and command-line options.\n";
136  }
137  if (vm.count("process-name")) {
138  raw_config.put("process_name", vm["process-name"].as<std::string>());
139  }
140  if (vm.count("prune-config")) {
141  raw_config.put("services.scheduler.pruneConfig",
142  vm["prune-config"].as<bool>());
143  }
144  if (vm.count("report-unused")) {
145  raw_config.put("services.scheduler.reportUnused",
146  vm["report-unused"].as<bool>());
147  }
148  return 0;
149 }
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:709
cet::filepath_maker & maker_
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int art::OptionsHandler::processOptions ( bpo::variables_map const &  vm,
fhicl::intermediate_table raw_config 
)
inherited

Definition at line 60 of file OptionsHandler.cc.

References art::OptionsHandler::doProcessOptions().

62 {
63  std::string const thisClass(cet::demangle_symbol(typeid(*this).name()));
64  return exceptionCatcher(
65  [&, this] { return doProcessOptions(vm, raw_config); },
66  thisClass + "::doProcessOptions()",
67  90);
68 }
virtual int doProcessOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)=0

Member Data Documentation

bpo::options_description const& art::BasicOptionsHandler::help_desc_
private

Definition at line 27 of file BasicOptionsHandler.h.

Referenced by doCheckOptions().

cet::filepath_maker& art::BasicOptionsHandler::maker_
private

Definition at line 28 of file BasicOptionsHandler.h.

Referenced by BasicOptionsHandler(), and doProcessOptions().


The documentation for this class was generated from the following files: