CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes
edm::CmsRunParser Class Reference

#include <CmsRunParser.h>

Public Types

using MapOrExit = std::variant< boost::program_options::variables_map, int >
 

Public Member Functions

 CmsRunParser (const char *name)
 
MapOrExit parse (int argc, const char *argv[]) const
 

Static Public Member Functions

static int getExit (const MapOrExit &output)
 
static boost::program_options::variables_map getVM (const MapOrExit &output)
 
static bool hasExit (const MapOrExit &output)
 
static bool hasVM (const MapOrExit &output)
 

Static Public Attributes

static const char *const kCmdCommandOpt = "command,c"
 
static const char *const kCmdOpt = "command"
 
static const char *const kEnableJobreportCommandOpt = "enablejobreport,e"
 
static const char *const kEnableJobreportOpt = "enablejobreport"
 
static const char *const kHelpCommandOpt = "help,h"
 
static const char *const kHelpOpt = "help"
 
static const char *const kJobModeCommandOpt = "mode,m"
 
static const char *const kJobModeOpt = "mode"
 
static const char *const kJobreportCommandOpt = "jobreport,j"
 
static const char *const kJobreportOpt = "jobreport"
 
static const char *const kNumberOfThreadsCommandOpt = "numThreads,n"
 
static const char *const kNumberOfThreadsOpt = "numThreads"
 
static const char *const kParameterSetOpt = "parameter-set"
 
static const char *const kPythonOpt = "pythonOptions"
 
static const char *const kPythonOptDefault = "CMSRUN_PYTHONOPT_DEFAULT"
 
static const char *const kSizeOfStackForThreadCommandOpt = "sizeOfStackForThreadsInKB,s"
 
static const char *const kSizeOfStackForThreadOpt = "sizeOfStackForThreadsInKB"
 
static const char *const kStrictOpt = "strict"
 

Private Attributes

boost::program_options::options_description all_options_
 
boost::program_options::options_description desc_
 
boost::program_options::positional_options_description pos_options_
 

Detailed Description

Definition at line 9 of file CmsRunParser.h.

Member Typedef Documentation

◆ MapOrExit

using edm::CmsRunParser::MapOrExit = std::variant<boost::program_options::variables_map, int>

Definition at line 11 of file CmsRunParser.h.

Constructor & Destructor Documentation

◆ CmsRunParser()

edm::CmsRunParser::CmsRunParser ( const char *  name)

Definition at line 53 of file CmsRunParser.cc.

References all_options_, desc_, kCmdCommandOpt, kEnableJobreportCommandOpt, kHelpCommandOpt, kJobModeCommandOpt, kJobreportCommandOpt, kNumberOfThreadsCommandOpt, kParameterSetOpt, kPythonOpt, kSizeOfStackForThreadCommandOpt, kStrictOpt, pos_options_, and relativeConstraints::value.

54  : desc_(std::string(name) + " [options] [--] config_file [python options]\nAllowed options"),
55  all_options_("All Options") {
56  // clang-format off
57  desc_.add_options()(kHelpCommandOpt, "produce help message")(
59  boost::program_options::value<std::string>(),
60  "file name to use for a job report file: default extension is .xml")(
61  kEnableJobreportCommandOpt, "enable job report files (if any) specified in configuration file")(
63  boost::program_options::value<std::string>(),
64  "Job Mode for MessageLogger defaults - default mode is grid")(
66  boost::program_options::value<unsigned int>(),
67  "Number of threads to use in job (0 is use all CPUs)")(
69  boost::program_options::value<unsigned int>(),
70  "Size of stack in KB to use for extra threads (0 is use system default size)")(kStrictOpt, "strict parsing")(
71  kCmdCommandOpt, boost::program_options::value<std::string>(), "config passed in as string (cannot be used with config_file)");
72  // clang-format on
73 
74  // anything at the end will be ignored, and sent to python
75  pos_options_.add(kParameterSetOpt, 1).add(kPythonOpt, -1);
76 
77  // This --fwk option is not used anymore, but I'm leaving it around as
78  // it might be useful again in the future for code development
79  // purposes. We originally used it when implementing the boost
80  // state machine code.
81  boost::program_options::options_description hidden("hidden options");
82  hidden.add_options()("fwk", "For use only by Framework Developers")(
83  kParameterSetOpt, boost::program_options::value<std::string>(), "configuration file")(
84  kPythonOpt,
85  boost::program_options::value<std::vector<std::string>>(),
86  "options at the end to be passed to python");
87 
88  all_options_.add(desc_).add(hidden);
89  }
static const char *const kEnableJobreportCommandOpt
Definition: CmsRunParser.h:38
boost::program_options::options_description desc_
Definition: CmsRunParser.h:25
static const char *const kJobModeCommandOpt
Definition: CmsRunParser.h:40
static const char *const kStrictOpt
Definition: CmsRunParser.h:48
boost::program_options::positional_options_description pos_options_
Definition: CmsRunParser.h:27
static const char *const kParameterSetOpt
Definition: CmsRunParser.h:31
static const char *const kHelpCommandOpt
Definition: CmsRunParser.h:47
static const char *const kCmdCommandOpt
Definition: CmsRunParser.h:34
static const char *const kSizeOfStackForThreadCommandOpt
Definition: CmsRunParser.h:44
boost::program_options::options_description all_options_
Definition: CmsRunParser.h:26
static const char *const kPythonOpt
Definition: CmsRunParser.h:32
static const char *const kJobreportCommandOpt
Definition: CmsRunParser.h:36
static const char *const kNumberOfThreadsCommandOpt
Definition: CmsRunParser.h:42

Member Function Documentation

◆ getExit()

static int edm::CmsRunParser::getExit ( const MapOrExit output)
inlinestatic

Definition at line 22 of file CmsRunParser.h.

References convertSQLitetoXML_cfg::output.

22 { return std::get<int>(output); }

◆ getVM()

static boost::program_options::variables_map edm::CmsRunParser::getVM ( const MapOrExit output)
inlinestatic

Definition at line 18 of file CmsRunParser.h.

References convertSQLitetoXML_cfg::output.

18  {
19  return std::get<boost::program_options::variables_map>(output);
20  }

◆ hasExit()

static bool edm::CmsRunParser::hasExit ( const MapOrExit output)
inlinestatic

Definition at line 21 of file CmsRunParser.h.

References convertSQLitetoXML_cfg::output.

21 { return std::holds_alternative<int>(output); }

◆ hasVM()

static bool edm::CmsRunParser::hasVM ( const MapOrExit output)
inlinestatic

Definition at line 15 of file CmsRunParser.h.

References convertSQLitetoXML_cfg::output.

15  {
16  return std::holds_alternative<boost::program_options::variables_map>(output);
17  }

◆ parse()

CmsRunParser::MapOrExit edm::CmsRunParser::parse ( int  argc,
const char *  argv[] 
) const

Definition at line 90 of file CmsRunParser.cc.

References all_options_, dir2webdir::argc, GCPpyPlots::argv, edm::errors::CommandLineProcessing, gather_cfg::cout, desc_, relativeConstraints::error, edm::HaltMessageLogging(), kHelpOpt, kPythonOpt, kPythonOptDefault, AlcaSiPixelAliHarvester0T_cff::options, pos_options_, and writedatasetfile::run.

90  {
91  boost::program_options::variables_map vm;
92  try {
93  store(boost::program_options::command_line_parser(argc, argv)
94  .extra_style_parser(final_opts_parser)
96  .positional(pos_options_)
97  .run(),
98  vm);
99  notify(vm);
100  } catch (boost::program_options::error const& iException) {
101  edm::LogAbsolute("CommandLineProcessing")
102  << "cmsRun: Error while trying to process command line arguments:\n"
103  << iException.what() << "\nFor usage and an options list, please do 'cmsRun --help'.";
105  }
106 
107  if (vm.count(kHelpOpt)) {
108  std::cout << desc_ << std::endl;
110  return MapOrExit(0);
111  }
112 
113  //special handling of python options
114  if (vm.count(kPythonOpt)) {
115  const auto& pythonOptValues = vm[kPythonOpt].as<std::vector<std::string>>();
116  //omit default arg
117  if (pythonOptValues.size() == 1 and pythonOptValues[0] == kPythonOptDefault)
118  vm.erase(kPythonOpt);
119  }
120 
121  return MapOrExit(vm);
122  }
boost::program_options::options_description desc_
Definition: CmsRunParser.h:25
void HaltMessageLogging()
boost::program_options::positional_options_description pos_options_
Definition: CmsRunParser.h:27
static const char *const kHelpOpt
Definition: CmsRunParser.h:46
std::variant< boost::program_options::variables_map, int > MapOrExit
Definition: CmsRunParser.h:11
boost::program_options::options_description all_options_
Definition: CmsRunParser.h:26
static const char *const kPythonOpt
Definition: CmsRunParser.h:32
Log< level::System, true > LogAbsolute
static const char *const kPythonOptDefault
Definition: CmsRunParser.h:33

Member Data Documentation

◆ all_options_

boost::program_options::options_description edm::CmsRunParser::all_options_
private

Definition at line 26 of file CmsRunParser.h.

Referenced by CmsRunParser(), and parse().

◆ desc_

boost::program_options::options_description edm::CmsRunParser::desc_
private

Definition at line 25 of file CmsRunParser.h.

Referenced by CmsRunParser(), and parse().

◆ kCmdCommandOpt

const char* const edm::CmsRunParser::kCmdCommandOpt = "command,c"
inlinestatic

Definition at line 34 of file CmsRunParser.h.

Referenced by CmsRunParser().

◆ kCmdOpt

const char* const edm::CmsRunParser::kCmdOpt = "command"
inlinestatic

Definition at line 35 of file CmsRunParser.h.

◆ kEnableJobreportCommandOpt

const char* const edm::CmsRunParser::kEnableJobreportCommandOpt = "enablejobreport,e"
inlinestatic

Definition at line 38 of file CmsRunParser.h.

Referenced by CmsRunParser().

◆ kEnableJobreportOpt

const char* const edm::CmsRunParser::kEnableJobreportOpt = "enablejobreport"
inlinestatic

Definition at line 39 of file CmsRunParser.h.

◆ kHelpCommandOpt

const char* const edm::CmsRunParser::kHelpCommandOpt = "help,h"
inlinestatic

Definition at line 47 of file CmsRunParser.h.

Referenced by CmsRunParser().

◆ kHelpOpt

const char* const edm::CmsRunParser::kHelpOpt = "help"
inlinestatic

Definition at line 46 of file CmsRunParser.h.

Referenced by parse().

◆ kJobModeCommandOpt

const char* const edm::CmsRunParser::kJobModeCommandOpt = "mode,m"
inlinestatic

Definition at line 40 of file CmsRunParser.h.

Referenced by CmsRunParser().

◆ kJobModeOpt

const char* const edm::CmsRunParser::kJobModeOpt = "mode"
inlinestatic

Definition at line 41 of file CmsRunParser.h.

◆ kJobreportCommandOpt

const char* const edm::CmsRunParser::kJobreportCommandOpt = "jobreport,j"
inlinestatic

Definition at line 36 of file CmsRunParser.h.

Referenced by CmsRunParser().

◆ kJobreportOpt

const char* const edm::CmsRunParser::kJobreportOpt = "jobreport"
inlinestatic

Definition at line 37 of file CmsRunParser.h.

◆ kNumberOfThreadsCommandOpt

const char* const edm::CmsRunParser::kNumberOfThreadsCommandOpt = "numThreads,n"
inlinestatic

Definition at line 42 of file CmsRunParser.h.

Referenced by CmsRunParser().

◆ kNumberOfThreadsOpt

const char* const edm::CmsRunParser::kNumberOfThreadsOpt = "numThreads"
inlinestatic

Definition at line 43 of file CmsRunParser.h.

◆ kParameterSetOpt

const char* const edm::CmsRunParser::kParameterSetOpt = "parameter-set"
inlinestatic

Definition at line 31 of file CmsRunParser.h.

Referenced by CmsRunParser().

◆ kPythonOpt

const char* const edm::CmsRunParser::kPythonOpt = "pythonOptions"
inlinestatic

Definition at line 32 of file CmsRunParser.h.

Referenced by CmsRunParser(), and parse().

◆ kPythonOptDefault

const char* const edm::CmsRunParser::kPythonOptDefault = "CMSRUN_PYTHONOPT_DEFAULT"
inlinestatic

Definition at line 33 of file CmsRunParser.h.

Referenced by parse().

◆ kSizeOfStackForThreadCommandOpt

const char* const edm::CmsRunParser::kSizeOfStackForThreadCommandOpt = "sizeOfStackForThreadsInKB,s"
inlinestatic

Definition at line 44 of file CmsRunParser.h.

Referenced by CmsRunParser().

◆ kSizeOfStackForThreadOpt

const char* const edm::CmsRunParser::kSizeOfStackForThreadOpt = "sizeOfStackForThreadsInKB"
inlinestatic

Definition at line 45 of file CmsRunParser.h.

◆ kStrictOpt

const char* const edm::CmsRunParser::kStrictOpt = "strict"
inlinestatic

Definition at line 48 of file CmsRunParser.h.

Referenced by CmsRunParser().

◆ pos_options_

boost::program_options::positional_options_description edm::CmsRunParser::pos_options_
private

Definition at line 27 of file CmsRunParser.h.

Referenced by CmsRunParser(), and parse().