CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
10 
12 {
13  public:
15  // Public Constants //
17 
18  static const std::string kSpaces;
19 
20  enum
21  {
22  kEventContOpt = 1 << 0
23  };
24 
26  // friends //
28  // tells particle data how to print itself out
29  friend std::ostream& operator<< (std::ostream& o_stream,
30  const CommandLineParser &rhs);
31 
33  // _ //
34  // |\/| |_ //
35  // | |EMBER | UNCTIONS //
36  // //
38 
40  // Constructors and Destructor //
42  CommandLineParser (const std::string &usage,
43  unsigned int optionsType = kEventContOpt);
44 
46  // One Liners //
48 
49  // turn on (true) or off (false) printing of options by default
51 
52  // return vector calling arguments
53  const SVec argVec() const { return m_fullArgVec; }
54 
56  // Regular Member Functions //
58 
59  // parse the command line arguments. If 'returnArgs' is true, then
60  // any non-assignments and non-options will be returned.
61  void parseArguments (int argc, char** argv, bool allowArgs = false);
62 
63  // prints out '--help' screen, then exits.
64  void help();
65 
66  // print out all of the variables hooked up
67  void printOptionValues();
68 
69  // Not called by users anymore. Finish evaluating default options.
70  // Pass in 'tag' if you want to modify the output name based on
71  // options the user has passed in. 'tag' is not passed by const
72  // reference because it may be modified.
73  void _finishDefaultOptions (std::string tag = "");
74 
76  // Static Member Functions //
78 
79  // remove an ending (e.g., '.root') from a string
80  static std::string removeEnding (const std::string &input,
81  const std::string &ending);
82 
83  // splits a line into words
84  static void split (SVec &retval, std::string line,
85  std::string match = " \t",
86  bool ignoreComments = true);
87 
88  // removes '# ....' comment
89  static void removeComment (std::string &line);
90 
91  // removes leading and trailing spaces
92  static void removeLeadingAndTrailingSpaces (std::string &line);
93 
94  // given a line, finds first non-space word and rest of line
95  static void findCommand (const std::string &line,
96  std::string &command,
97  std::string &rest);
98 
99 
100  private:
102  // Private Member Functions //
104 
105  // Sets a variable 'varname' to a 'value' from a string
106  // 'varname=value'. If 'dontOverrideChange' is set true, then the
107  // function will NOT set a variable that has been already set.
108  // This will allow you to read in a file to set most variables and
109  // still be allowed to make changes from the command line. If you
110  // want to ignore the first 'n' characters, simply set 'offset=n'.
111  bool _setVariableFromString (const std::string &arg,
112  bool dontOverrideChange = false,
113  int offset = 0);
114 
115  // sets variable options from file where lines are formatted as
116  // - var=value
117  bool _setVariablesFromFile (const std::string &filename);
118 
119  // runs command embedded in arg
120  bool _runVariableCommandFromString (const std::string &arg);
121 
122 
123  // given a section number (1..N) and totalsection (N), fills output
124  // list with correct files.
125  void _getSectionFiles (const SVec &inputList, SVec &outputList,
126  int section, int totalSection);
127 
129  // Private Member Data //
132  std::string m_argv0;
133  std::string m_usageString;
135  unsigned int m_optionsType;
136 
137 };
138 
139 }
140 
141 #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)
std::vector< std::string > SVec
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)
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
static void removeLeadingAndTrailingSpaces(std::string &line)
static void split(SVec &retval, std::string line, std::string match=" \t", bool ignoreComments=true)
outputList
All other commands ##.
Definition: compareJSON.py:62
void setPrintOptoins(bool print)
A arg
Definition: Factorize.h:36
static const std::string kSpaces
unsigned int offset(bool)
bool _setVariableFromString(const std::string &arg, bool dontOverrideChange=false, int offset=0)
tuple input
Definition: collect_tpl.py:10
static void removeComment(std::string &line)
const SVec argVec() const
static void findCommand(const std::string &line, std::string &command, std::string &rest)
tuple filename
Definition: lut2db_cfg.py:20
void usage()
Definition: array2xmlEB.cc:14
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6