travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProgramOptions.h
Go to the documentation of this file.
1 #ifndef tvx_ProgramOptions_h
2 #define tvx_ProgramOptions_h
3 
4 #include <set>
5 #include <string>
6 
7 #include <boost/program_options/options_description.hpp>
8 #include <boost/program_options/variables_map.hpp>
9 #include <boost/program_options/parsers.hpp>
10 
11 
12 namespace tvx {
13 
14 // A shorthand for a long namespace
15 namespace po = boost::program_options;
16 
17 
22 {
23 public:
24 
25  ProgramOptions(int argc, char **argv);
26 
27  std::string PathToInputFile() const { return fInFilePath; }
28  unsigned int GetMaxEventsUser() const { return fMaxEventsUser; }
29  float GetSparsity() const { return fSparsity; }
30  bool SaveGraphics() const { return fSaveGraphics; }
31  std::string GetOutPrefix() const { return fOutPrefix; }
32  std::string GetOutFileName(std::string suffix="hist") const;
33 
34  void ProcessOptions();
35  void Print() const;
36 
37 protected:
38 
40  void VerifyOptions();
41 
42  int fArgc;
43  char** fArgv;
44  po::options_description fOptions;
45  po::variables_map fOptionsValues;
46 
49  std::string fInFilePath;
50 
52  std::string fOutPrefix;
53 
55  unsigned int fMaxEventsUser;
56 
58  float fSparsity;
59 
62 };
63 
64 
68 template<class T>
69 bool out_to_stream(std::ostream& os, const boost::any& any_value)
70 {
71  try {
72  os << boost::any_cast<T>(any_value);
73  return true;
74  } catch(boost:: bad_any_cast& e) {
75  return false;
76  }
77 }
78 
79 std::ostream& operator<<(std::ostream& os, const boost::any& any_value);
80 
81 }
82 
83 #endif
void Print() const
Prints the options and their values.
float fSparsity
An approximate fraction of events to read and process.
std::string fInFilePath
Full path to either a root file with event tree or a text file with a list of such root files...
unsigned int fMaxEventsUser
The maximum number of input events to process.
bool SaveGraphics() const
po::variables_map fOptionsValues
Definition: Event.h:12
Processes and controls user options provided in the command line.
std::string GetOutPrefix() const
void ProcessOptions()
Takes the standard command line arguments and parses them with the boost program_options utility...
bool fSaveGraphics
This flag controls whether to produce images for created histograms.
unsigned int GetMaxEventsUser() const
std::string PathToInputFile() const
ProgramOptions(int argc, char **argv)
bool out_to_stream(std::ostream &os, const boost::any &any_value)
A helper function to print values of boost's any type.
po::options_description fOptions
std::string fOutPrefix
A prefix to specify the location of the output files.
std::string GetOutFileName(std::string suffix="hist") const
Form the name of the output file from the input file name by appending a suffix to it...
std::ostream & operator<<(std::ostream &os, const boost::any &any_value)
float GetSparsity() const
void VerifyOptions()
Verifies user submitted values.