ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHParameters.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHParameters.h
1 // Tell emacs that this is a C++ source
2 // -*- C++ -*-.
3 #ifndef PHPARAMETER_PHPARAMETERS_H
4 #define PHPARAMETER_PHPARAMETERS_H
5 
6 #include <phool/PHObject.h>
7 
8 #include <cstddef>
9 #include <map>
10 #include <string>
11 #include <utility>
12 
13 class PdbParameterMap;
15 class PHCompositeNode;
16 
17 // contains parameters in our units,
18 // convert to G4 units inside get access methods
19 
20 class PHParameters : public PHObject
21 {
22  public:
23  typedef std::map<const std::string, double> dMap;
24  typedef dMap::const_iterator dIter;
25  typedef std::map<const std::string, int> iMap;
26  typedef iMap::const_iterator iIter;
27  typedef std::map<const std::string, std::string> strMap;
28  typedef std::map<const std::string, std::string>::const_iterator strIter;
29 
30  explicit PHParameters(const std::string &name)
31  : m_Detector(name)
32  {
33  }
34  PHParameters(const PHParameters &params, const std::string &name);
35 
36  ~PHParameters() override;
37 
38  void Print(Option_t *option = "") const override;
39 
41  size_t get_hash() const;
42 
43  void set_int_param(const std::string &name, const int ival);
44  int get_int_param(const std::string &name) const;
45  bool exist_int_param(const std::string &name) const;
46  std::pair<std::map<const std::string, int>::const_iterator, std::map<const std::string, int>::const_iterator> get_all_int_params() { return std::make_pair(m_IntParMap.begin(), m_IntParMap.end()); }
47 
48  void set_double_param(const std::string &name, const double dval);
49  double get_double_param(const std::string &name) const;
50  bool exist_double_param(const std::string &name) const;
51  std::pair<std::map<const std::string, double>::const_iterator, std::map<const std::string, double>::const_iterator> get_all_double_params() { return std::make_pair(m_DoubleParMap.begin(), m_DoubleParMap.end()); }
52 
53  void set_string_param(const std::string &name, const std::string &str);
54  std::string get_string_param(const std::string &name) const;
55  bool exist_string_param(const std::string &name) const;
56  std::pair<std::map<const std::string, std::string>::const_iterator, std::map<const std::string, std::string>::const_iterator> get_all_string_params() { return std::make_pair(m_StringParMap.begin(), m_StringParMap.end()); }
57 
58  void set_name(const std::string &name) { m_Detector = name; }
59  std::string Name() const { return m_Detector; }
60 
61  void FillFrom(const PdbParameterMap *saveparams);
62  void FillFrom(const PdbParameterMapContainer *saveparamcontainer, const int layer);
63  void FillFrom(const PHParameters *saveparams);
64  // save parameters on node tree
65  void SaveToNodeTree(PHCompositeNode *topNode, const std::string &nodename);
66  // save parameters in container on node tree
67  void SaveToNodeTree(PHCompositeNode *topNode, const std::string &nodename, const int layer);
68 
69  // update parameters on node tree (in case the subsystem modified them)
70  void UpdateNodeTree(PHCompositeNode *topNode, const std::string &nodename);
71  void UpdateNodeTree(PHCompositeNode *topNode, const std::string &nodename, const int layer);
72 
73  int WriteToDB();
74  int ReadFromDB();
75  int ReadFromDB(const std::string &name, const int layer);
76  int WriteToFile(const std::string &extension, const std::string &dir = ".");
77 
79  inline int ReadFromFile(const std::string &name, const std::string &extension, const std::string &dir = ".")
80  {
81  return ReadFromFile(name, extension, 0, 0, dir);
82  }
83 
85  int ReadFromFile(const std::string &name, const std::string &extension, const int layer, const int issuper, const std::string &dir = ".");
87 
88  void printint() const;
89  void printdouble() const;
90  void printstring() const;
91 
92  private:
93  unsigned int ConvertStringToUint(const std::string &str) const;
94  std::string m_Detector;
98 
99  //No Class Def since this class is not intended to be persistent
100 };
101 
102 #endif // PHPARAMETER_PHPARAMETERS_H