LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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)
 
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 15 of file BasicOptionsHandler.h.

Constructor & Destructor Documentation

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

Definition at line 31 of file BasicOptionsHandler.cc.

References art::add_opt(), art::getReleaseVersion(), maker_, art::Suffixes::print(), s, and fhicl::detail::atom::value().

33  : help_desc_{desc}, maker_{maker}
34 {
35  auto options = desc.add_options();
36  add_opt(options, "help,h", "produce help message");
37  add_opt(
38  options,
39  "version",
40  ("Print art version (" + pretty_version(art::getReleaseVersion()) + ")")
41  .c_str());
42  add_opt(
43  options, "config,c", bpo::value<std::string>(), "Configuration file.");
44  add_opt(
45  options, "process-name", bpo::value<std::string>(), "art process name.");
46  add_opt(
47  options,
48  "print-available",
49  bpo::value<std::string>(),
50  ("List all available plugins with the provided suffix. Choose from:"s +
52  .c_str());
53  add_opt(options,
54  "print-available-modules",
55  "List all available modules that can be invoked in a FHiCL file.");
56  add_opt(options,
57  "print-available-services",
58  "List all available services that can be invoked in a FHiCL file.");
59  add_opt(options,
60  "print-description",
61  bpo::value<std::vector<std::string>>()->multitoken(),
62  "Print description of specified module, service, source, or other "
63  "plugin (multiple OK). Argument can be a regular expression used "
64  "to match the plugin specification. To narrow the search to "
65  "plugins with a particular suffix, preface the regular expression"
66  "with the suffix (e.g. service:TFileService).");
67  add_opt(options,
68  "status-bar",
69  "Provide status bar that reports the progress of retrieving "
70  "plugin information for a 'print-available' command.");
71 }
Float_t s
Definition: plot.C:23
void add_opt(T &t, Args &&...args)
static std::string print()
std::string const & getReleaseVersion()
bpo::options_description const & help_desc_
std::string value(boost::any const &)
cet::filepath_maker & maker_

Member Function Documentation

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

Definition at line 51 of file OptionsHandler.cc.

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 74 of file BasicOptionsHandler.cc.

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

75 {
76  // Technically the "help" and "print*" options are processing steps,
77  // but we want to short-circuit.
78  if (vm.count("help")) {
79  // Could simply do cout << help_desc_, but the boost-provided
80  // printout does not add any left-hand padding. Will add a
81  // 2-space tab by hand.
82  std::stringstream ss;
83  ss << help_desc_; // Note NOT our own desc_.
84  for (std::string s; std::getline(ss, s);)
85  std::cout << std::string(2, ' ') << s << '\n';
86  std::cout << '\n';
87  return detail::info_success();
88  }
89  bool const status_bar = vm.count("status-bar") > 0;
90  if (vm.count("print-available")) {
92  Suffixes::get(vm["print-available"].as<std::string>()), status_bar);
93  return detail::info_success();
94  }
95  if (vm.count("print-available-modules")) {
97  return detail::info_success();
98  }
99  if (vm.count("print-available-services")) {
101  return detail::info_success();
102  }
103  if (status_bar) {
105  << "The '--status-bar' option can be used only with the "
106  "'--print-available*' program options.\n";
107  }
108 
109  if (vm.count("print-description")) {
111  vm["print-description"].as<std::vector<std::string>>());
112  return detail::info_success();
113  }
114  if (vm.count("version")) {
115  std::cout << "art " << pretty_version(getReleaseVersion()) << '\n';
116  return detail::info_success();
117  }
118 
119  if (!vm.count("config")) {
120  throw Exception(errors::Configuration) << "No configuration file given.\n";
121  }
122  return 0;
123 }
Float_t s
Definition: plot.C:23
Float_t ss
Definition: plot.C:23
std::string const & getReleaseVersion()
void print_available_plugins(suffix_type st, bool const verbose, std::string const &spec)
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 & get(suffix_type st)
constexpr int info_success()
Definition: info_success.h:9
int art::BasicOptionsHandler::doProcessOptions ( bpo::variables_map const &  vm,
fhicl::intermediate_table raw_config 
)
overrideprivatevirtual

Implements art::OptionsHandler.

Definition at line 126 of file BasicOptionsHandler.cc.

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

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

Definition at line 60 of file OptionsHandler.cc.

Referenced by art::run_art_string_config().

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 28 of file BasicOptionsHandler.h.

Referenced by doCheckOptions().

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

Definition at line 29 of file BasicOptionsHandler.h.

Referenced by BasicOptionsHandler(), and doProcessOptions().


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