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
bool _runVariableCommandFromString(const std::string &arg)
void _getSectionFiles(const SVec &inputList, SVec &outputList, int section, int totalSection)
void _finishDefaultOptions(std::string tag="")
bool _setVariablesFromFile(const std::string &filename)
static std::string removeEnding(const std::string &input, const std::string &ending)
static void split(SVec &retval, std::string line, std::string match=" \, bool ignoreComments=true)
friend std::ostream & operator<<(std::ostream &o_stream, const CommandLineParser &rhs)
CommandLineParser(const std::string &usage, unsigned int optionsType=kEventContOpt)
void parseArguments(int argc, char **argv, bool allowArgs=false)
static void removeLeadingAndTrailingSpaces(std::string &line)
std::vector< std::string > SVec
void setPrintOptoins(bool print)
A arg
Definition: Factorize.h:31
static std::string const input
Definition: EdmProvDump.cc:50
static const std::string kSpaces
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
string inputList
Definition: crabTemplate.py:6
bool _setVariableFromString(const std::string &arg, bool dontOverrideChange=false, int offset=0)
static void removeComment(std::string &line)
list command
Definition: mps_check.py:25
static void findCommand(const std::string &line, std::string &command, std::string &rest)
void usage()
Definition: array2xmlEB.cc:14
const SVec argVec() const