CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Attributes
AllInOneConfig::Options Class Reference

#include <Options.h>

Public Member Functions

void helper (int argc, char *argv[])
 
 Options (bool getter=false)
 
void parser (int argc, char *argv[])
 

Public Attributes

std::string config
 
bool dry
 
std::string key
 

Private Attributes

boost::program_options::options_description desc
 
boost::program_options::options_description env
 
boost::program_options::options_description help
 
boost::program_options::options_description hide
 
boost::program_options::positional_options_description pos_hide
 

Detailed Description

Definition at line 8 of file Options.h.

Constructor & Destructor Documentation

◆ Options()

AllInOneConfig::Options::Options ( bool  getter = false)

Constructor for PO:

  • contains a parser for the help itself
  • contains a parser for the options (unless help was displayed)
  • and contains a hidden/position option to get the JSON config file

Definition at line 40 of file Options.cc.

40  : help{"Helper"}, desc{"Options"}, hide{"Hidden"} {
41  // define all options
42  help.add_options()("help,h", "Help screen")("example,e", "Print example of config in JSON format")(
43  "tutorial,t", "Explain how to use the command");
44 
45  // then (except for getJSON) the running options
46  if (!getter)
47  desc.add_options()(
48  "dry,d", po::bool_switch(&dry)->default_value(false), "Set up everything, but don't run anything")(
49  "verbose,v", po::bool_switch()->default_value(false)->notifier(set_verbose), "Enable standard output stream")(
50  "silent,s", po::bool_switch()->default_value(false)->notifier(set_silent), "Disable standard error stream");
51 
52  // and finally / most importantly, the config file as apositional argument
53  hide.add_options()("config,c", po::value<string>(&config)->required()->notifier(check_file), "JSON config file");
54  pos_hide.add("config", 1); // 1 means one (positional) argument
55  if (getter) {
56  // in case of getIMFO, adding a second positional argument for the key
57  hide.add_options()("key,k", po::value<string>(&key)->required(), "key");
58  pos_hide.add("key", 1);
59  }
60  }
void check_file(string file)
Definition: Options.cc:17
std::string config
Definition: Options.h:13
void set_verbose(bool flag)
Definition: Options.cc:25
boost::program_options::options_description hide
Definition: Options.h:9
boost::program_options::options_description help
Definition: Options.h:9
boost::program_options::options_description desc
Definition: Options.h:9
void set_silent(bool flag)
Definition: Options.cc:30
std::string key
Definition: Options.h:13
boost::program_options::positional_options_description pos_hide
Definition: Options.h:10

Member Function Documentation

◆ helper()

void AllInOneConfig::Options::helper ( int  argc,
char *  argv[] 
)

Definition at line 62 of file Options.cc.

References dir2webdir::argc, GCPpyPlots::argv, bold, gather_cfg::cout, desc, beamvalidation::exit(), help, normal, AlcaSiPixelAliHarvester0T_cff::options, and EnsembleCalibrationLA_cfg::path.

62  {
63  po::options_description options;
64  options.add(help).add(desc);
65 
66  po::command_line_parser parser_helper{argc, argv};
67  parser_helper
68  .options(help) // don't parse required options before parsing help
69  .allow_unregistered(); // ignore unregistered options,
70 
71  // defines actions
72  po::variables_map vm;
73  po::store(parser_helper.run(), vm);
74  po::notify(vm); // necessary for config to be given the value from the cmd line
75 
76  if (vm.count("help")) {
77  fs::path executable = argv[0];
78  cout << "Basic syntax:\n " << executable.filename().string() << " config.JSON\n"
79  << options << '\n'
80  << "Boost " << BOOST_LIB_VERSION << endl;
81  exit(EXIT_SUCCESS);
82  }
83 
84  if (vm.count("example")) {
85  static const char *bold = "\e[1m", *normal = "\e[0m";
86  cout << bold << "Example of HTC condor config:" << normal << '\n' << endl;
87  system("cat $CMSSW_BASE/src/Alignment/OfflineValidation/bin/.default.sub");
88  cout << '\n' << bold << "Example of JSON config (for `validateAlignment` only):" << normal << '\n' << endl;
89  system("cat $CMSSW_BASE/src/Alignment/OfflineValidation/bin/.example.JSON");
90  cout << '\n'
91  << bold << "NB: " << normal
92  << " for examples of inputs to GCPs, DMRs, etc., just make a dry run of the example" << endl;
93  exit(EXIT_SUCCESS);
94  }
95  // TODO: make examples for each executables? (could be examples used in release validation...)
96 
97  if (vm.count("tutorial")) {
98  cout << " ______________________\n"
99  << " < Oops! not ready yet! >\n"
100  << " ----------------------\n"
101  << " \\ ^__^\n"
102  << " \\ (oo)\\_______\n"
103  << " (__)\\ )\\/\\\n"
104  << " ||----w |\n"
105  << " || ||\n"
106  << flush;
107  exit(EXIT_SUCCESS);
108  }
109  }
static const char * normal
Definition: DMRtrends.cc:35
boost::program_options::options_description help
Definition: Options.h:9
boost::program_options::options_description desc
Definition: Options.h:9
static const char * bold
Definition: DMRtrends.cc:35
def exit(msg="")

◆ parser()

void AllInOneConfig::Options::parser ( int  argc,
char *  argv[] 
)

Definition at line 111 of file Options.cc.

References dir2webdir::argc, GCPpyPlots::argv, desc, hide, and pos_hide.

111  {
112  po::options_description cmd_line;
113  cmd_line.add(desc).add(hide);
114 
115  po::command_line_parser parser{argc, argv};
116  parser.options(cmd_line).positional(pos_hide);
117 
118  po::variables_map vm;
119  po::store(parser.run(), vm);
120  po::notify(vm); // necessary for config to be given the value from the cmd line
121  }
boost::program_options::options_description hide
Definition: Options.h:9
boost::program_options::options_description desc
Definition: Options.h:9
void parser(int argc, char *argv[])
Definition: Options.cc:111
boost::program_options::positional_options_description pos_hide
Definition: Options.h:10

Member Data Documentation

◆ config

std::string AllInOneConfig::Options::config

◆ desc

boost::program_options::options_description AllInOneConfig::Options::desc
private

Definition at line 9 of file Options.h.

Referenced by helper(), and parser().

◆ dry

bool AllInOneConfig::Options::dry

Definition at line 14 of file Options.h.

Referenced by ValidationMatrix_v2.ReleaseComparison::compare().

◆ env

boost::program_options::options_description AllInOneConfig::Options::env
private

Definition at line 9 of file Options.h.

◆ help

boost::program_options::options_description AllInOneConfig::Options::help
private

◆ hide

boost::program_options::options_description AllInOneConfig::Options::hide
private

Definition at line 9 of file Options.h.

Referenced by parser().

◆ key

std::string AllInOneConfig::Options::key

◆ pos_hide

boost::program_options::positional_options_description AllInOneConfig::Options::pos_hide
private

Definition at line 10 of file Options.h.

Referenced by parser().