SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Globals.hh
1 #ifndef GLOBALS_HH
2 #define GLOBALS_HH
3 
4 // Cpp includes
5 #include <iostream>
6 #include <iomanip>
7 #include <string>
8 #include <fstream>
9 #include <sstream>
10 #include <map>
11 #include <cstdlib>
12 #include <regex>
13 #include <getopt.h>
14 
15 // ROOT includes
16 #include "TSystem.h"
17 #include "TStyle.h"
18 #include "TVector3.h"
19 #include "TColor.h"
20 
21 // Other includes
22 #include "Exception.hh"
23 #include "Pitch.hh"
24 #include "GeometryHandler.hh"
25 
28 class Global {
29  public:
30 
32  Global() : _val(""), _des("") {}
33 
35  Global(const std::string& val): _val(val), _des("") {}
36 
38  Global(const Global& global) { *this = global; }
39 
41  Global& operator=(const Global& global) { _val = global._val;
42  _des = global._des;
43  return *this; }
45  ~Global() {}
46 
48  friend std::ostream& operator<<(std::ostream& os, const Global& global)
49  { os << global._val; return os; }
50 
52  bool AsBool() const { return (bool)strtol(&_val[0], NULL, 10); }
53 
55  int AsInt() const { return (int)strtol(&_val[0], NULL, 10); }
56 
58  long int AsLongInt() const { return strtol(&_val[0], NULL, 10); }
59 
61  long int AsBase(int base) const { return strtol(&_val[0], NULL, base); }
62 
64  float AsFloat() const { return strtof(&_val[0], NULL); }
65 
67  double AsDouble() const { return strtod(&_val[0], NULL); }
68 
70  void SetDescription(const std::string& des) { _des = des; }
71 
73  const std::string& Description() const { return _des; }
74 
76  const std::string& AsString() const { return _val; };
77 
79  bool operator !() const { return !AsBool(); }
80 
82  operator bool() const { return AsBool(); }
83 
85  operator int() const { return AsInt(); }
86 
88  operator long int() const { return AsLongInt(); }
89 
91  operator size_t() const { return (size_t)AsLongInt(); }
92 
94  operator float() const { return AsFloat(); }
95 
97  operator double() const { return AsDouble(); }
98 
100  operator std::string() const { return _val; }
101 
102  private:
103 
104  std::string _val;
105  std::string _des;
106 };
107 
116 class Globals {
117  public:
118 
124  static Globals& GetInstance(int argc = 0,
125  char** argv = NULL);
126 
128  const std::vector<std::string>& GetDataFiles() const { return _data_files; }
129 
131  const GeometryHandler& GetGeometryHandler() const { return _geoh; }
132 
134  const Global& operator()(const std::string& var) const;
135 
137  const Global& operator[](const std::string& var) const;
138 
140  void Print(Pitch::errorLevel level=Pitch::info) const;
141 
142  private:
143 
149  Globals(int argc,
150  char** argv);
151 
153  Globals(const Globals& globals);
154 
156  Globals& operator=(const Globals& globals);
157 
159  ~Globals();
160 
162  void LoadFile(std::string filename);
163 
169  void LoadCommandLine(int argc,
170  char** argv);
171 
173  void LoadGeometry();
174 
176  void SetDefaultStyle();
177 
178  std::map<std::string, Global> _globals;
179  std::vector<std::string> _data_files;
181 };
182 
183 #endif
void SetDefaultStyle()
Sets the default style of the ROOT plots.
Definition: Globals.cc:199
const Global & operator[](const std::string &var) const
Returns the requested global variable.
Definition: Globals.cc:42
std::vector< std::string > _data_files
List of runs (remaining arguments)
Definition: Globals.hh:179
bool operator!() const
Overload the unary ! operator.
Definition: Globals.hh:79
double AsDouble() const
Returns the variable as a double.
Definition: Globals.hh:67
Global()
Default constructor, initializes everything to 0.
Definition: Globals.hh:32
std::string _des
Description of the global variable.
Definition: Globals.hh:105
const std::string & AsString() const
Returns the variable as an std::string.
Definition: Globals.hh:76
Globals & operator=(const Globals &globals)
Equality operator, not implemented for singleton.
Global(const std::string &val)
Proper constructor.
Definition: Globals.hh:35
int AsInt() const
Returns the variable as an int.
Definition: Globals.hh:55
Imports, stores and manages the global variables.
Definition: Globals.hh:116
friend std::ostream & operator<<(std::ostream &os, const Global &global)
Overloads the ostream operator.
Definition: Globals.hh:48
Stores the positions of all the requested MICE detectors.
Definition: GeometryHandler.hh:109
const GeometryHandler & GetGeometryHandler() const
Returns the geometry handelr.
Definition: Globals.hh:131
const Global & operator()(const std::string &var) const
Returns the requested global variable.
Definition: Globals.cc:31
bool AsBool() const
Returns the variable as a bool.
Definition: Globals.hh:52
Global & operator=(const Global &global)
Equality operator.
Definition: Globals.hh:41
std::string _val
Global variable stored as an std::string.
Definition: Globals.hh:104
GeometryHandler _geoh
Geometry handler.
Definition: Globals.hh:180
long int AsBase(int base) const
Returns the variable as an int in the requested base.
Definition: Globals.hh:61
const std::vector< std::string > & GetDataFiles() const
Returns the list of data files.
Definition: Globals.hh:128
void LoadGeometry()
Loads the geometry handler.
Definition: Globals.cc:180
static Globals & GetInstance(int argc=0, char **argv=NULL)
Returns the single instance of the class, initialize if not yet done.
Definition: Globals.cc:3
Global(const Global &global)
Copy constructor.
Definition: Globals.hh:38
void LoadCommandLine(int argc, char **argv)
Load the extra arguments from the command line arguments.
Definition: Globals.cc:102
std::map< std::string, Global > _globals
Dictionary of global variables.
Definition: Globals.hh:178
Globals(int argc, char **argv)
Command line construct, takes extra arguments from the command line.
Definition: Globals.cc:10
float AsFloat() const
Returns the variable as a float.
Definition: Globals.hh:64
void SetDescription(const std::string &des)
Sets the decription of the varibale.
Definition: Globals.hh:70
long int AsLongInt() const
Returns the variable as a long int.
Definition: Globals.hh:58
~Globals()
Destructor.
Definition: Globals.cc:29
void Print(Pitch::errorLevel level=Pitch::info) const
Print the list of datacards and their value.
Definition: Globals.cc:53
Represents a single global variable and defines the methods to read it.
Definition: Globals.hh:28
errorLevel
Error level that determines where the output goes.
Definition: Pitch.hh:43
void LoadFile(std::string filename)
Loads the global constants from a datacards file.
Definition: Globals.cc:67
~Global()
Destructor.
Definition: Globals.hh:45
const std::string & Description() const
Returns the decription of the varibale.
Definition: Globals.hh:73