CMS 3D CMS Logo

CommandLineParser.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 #if !defined(CommandLineParser_H)
4 #define CommandLineParser_H
5 
7 
8 namespace optutl {
9 
11  public:
13  // Public Constants //
15 
16  static const std::string kSpaces;
17 
18  enum { kEventContOpt = 1 << 0 };
19 
21  // friends //
23  // tells particle data how to print itself out
24  friend std::ostream &operator<<(std::ostream &o_stream, const CommandLineParser &rhs);
25 
27  // _ //
28  // |\/| |_ //
29  // | |EMBER | UNCTIONS //
30  // //
32 
34  // Constructors and Destructor //
36  CommandLineParser(const std::string &usage, unsigned int optionsType = kEventContOpt);
37 
39  // One Liners //
41 
42  // turn on (true) or off (false) printing of options by default
44 
45  // return vector calling arguments
46  const SVec argVec() const { return m_fullArgVec; }
47 
49  // Regular Member Functions //
51 
52  // parse the command line arguments. If 'returnArgs' is true, then
53  // any non-assignments and non-options will be returned.
54  void parseArguments(int argc, char **argv, bool allowArgs = false);
55 
56  // prints out '--help' screen, then exits.
57  void help();
58 
59  // print out all of the variables hooked up
60  void printOptionValues();
61 
62  // Not called by users anymore. Finish evaluating default options.
63  // Pass in 'tag' if you want to modify the output name based on
64  // options the user has passed in. 'tag' is not passed by const
65  // reference because it may be modified.
67 
69  // Static Member Functions //
71 
72  // remove an ending (e.g., '.root') from a string
73  static std::string removeEnding(const std::string &input, const std::string &ending);
74 
75  // splits a line into words
76  static void split(SVec &retval, std::string line, std::string match = " \t", bool ignoreComments = true);
77 
78  // removes '# ....' comment
79  static void removeComment(std::string &line);
80 
81  // removes leading and trailing spaces
83 
84  // given a line, finds first non-space word and rest of line
86 
87  private:
89  // Private Member Functions //
91 
92  // Sets a variable 'varname' to a 'value' from a string
93  // 'varname=value'. If 'dontOverrideChange' is set true, then the
94  // function will NOT set a variable that has been already set.
95  // This will allow you to read in a file to set most variables and
96  // still be allowed to make changes from the command line. If you
97  // want to ignore the first 'n' characters, simply set 'offset=n'.
98  bool _setVariableFromString(const std::string &arg, bool dontOverrideChange = false, int offset = 0);
99 
100  // sets variable options from file where lines are formatted as
101  // - var=value
103 
104  // runs command embedded in arg
106 
107  // given a section number (1..N) and totalsection (N), fills output
108  // list with correct files.
109  void _getSectionFiles(const SVec &inputList, SVec &outputList, int section, int totalSection);
110 
112  // Private Member Data //
118  unsigned int m_optionsType;
119  };
120 
121 } // namespace optutl
122 
123 #endif // CommandLineParser_H
cmsBatch.argv
argv
Definition: cmsBatch.py:279
input
static const std::string input
Definition: EdmProvDump.cc:48
optutl::CommandLineParser::findCommand
static void findCommand(const std::string &line, std::string &command, std::string &rest)
Definition: CommandLineParser.cc:184
dir2webdir.argc
argc
Definition: dir2webdir.py:39
optutl::CommandLineParser::_getSectionFiles
void _getSectionFiles(const SVec &inputList, SVec &outputList, int section, int totalSection)
Definition: CommandLineParser.cc:545
VariableMapCont.h
optutl::CommandLineParser::m_optionsType
unsigned int m_optionsType
Definition: CommandLineParser.h:118
optutl::CommandLineParser::removeEnding
static std::string removeEnding(const std::string &input, const std::string &ending)
Definition: CommandLineParser.cc:174
optutl::CommandLineParser::CommandLineParser
CommandLineParser(const std::string &usage, unsigned int optionsType=kEventContOpt)
Definition: CommandLineParser.cc:19
mps_check.command
list command
Definition: mps_check.py:25
optutl::CommandLineParser::operator<<
friend std::ostream & operator<<(std::ostream &o_stream, const CommandLineParser &rhs)
optutl::CommandLineParser::m_printOptions
bool m_printOptions
Definition: CommandLineParser.h:117
optutl::CommandLineParser::_runVariableCommandFromString
bool _runVariableCommandFromString(const std::string &arg)
Definition: CommandLineParser.cc:461
optutl::CommandLineParser::_setVariablesFromFile
bool _setVariablesFromFile(const std::string &filename)
Definition: CommandLineParser.cc:413
optutl::CommandLineParser::m_fullArgVec
SVec m_fullArgVec
Definition: CommandLineParser.h:114
optutl::CommandLineParser::argVec
const SVec argVec() const
Definition: CommandLineParser.h:46
optutl::CommandLineParser::m_usageString
std::string m_usageString
Definition: CommandLineParser.h:116
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
optutl::CommandLineParser::help
void help()
Definition: CommandLineParser.cc:104
optutl::CommandLineParser::kEventContOpt
Definition: CommandLineParser.h:18
optutl::CommandLineParser::printOptionValues
void printOptionValues()
Definition: CommandLineParser.cc:202
optutl::CommandLineParser::setPrintOptoins
void setPrintOptoins(bool print)
Definition: CommandLineParser.h:43
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
optutl::CommandLineParser::m_argv0
std::string m_argv0
Definition: CommandLineParser.h:115
optutl::CommandLineParser::split
static void split(SVec &retval, std::string line, std::string match=" \t", bool ignoreComments=true)
Definition: CommandLineParser.cc:115
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
optutl::CommandLineParser::removeComment
static void removeComment(std::string &line)
Definition: CommandLineParser.cc:149
optutl::CommandLineParser::_setVariableFromString
bool _setVariableFromString(const std::string &arg, bool dontOverrideChange=false, int offset=0)
Definition: CommandLineParser.cc:313
optutl::CommandLineParser::_finishDefaultOptions
void _finishDefaultOptions(std::string tag="")
Definition: CommandLineParser.cc:583
optutl::CommandLineParser::removeLeadingAndTrailingSpaces
static void removeLeadingAndTrailingSpaces(std::string &line)
Definition: CommandLineParser.cc:157
mergeAndRegister.rest
rest
Definition: mergeAndRegister.py:121
usage
void usage()
Definition: array2xmlEB.cc:14
optutl::VariableMapCont::SVec
std::vector< std::string > SVec
Definition: VariableMapCont.h:21
hgcalPlots.section
section
Definition: hgcalPlots.py:2670
funct::arg
A arg
Definition: Factorize.h:31
submitPVResolutionJobs.outputList
outputList
Definition: submitPVResolutionJobs.py:86
optutl::CommandLineParser::parseArguments
void parseArguments(int argc, char **argv, bool allowArgs=false)
Definition: CommandLineParser.cc:45
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
mps_splice.line
line
Definition: mps_splice.py:76
optutl
Definition: CommandLineParser.h:8
optutl::VariableMapCont
Definition: VariableMapCont.h:12
optutl::CommandLineParser::kSpaces
static const std::string kSpaces
Definition: CommandLineParser.h:16
optutl::CommandLineParser
Definition: CommandLineParser.h:10