Analysis Software
Documentation for sPHENIX simulation 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 
35  PHParameters(const PHParameters &params, const std::string &name);
36 
37  ~PHParameters() override;
38 
39  void Reset() override;
40 
41  void Print(Option_t *option = "") const override;
42 
44  size_t get_hash() const;
45 
46  void set_int_param(const std::string &name, const int ival);
47  int get_int_param(const std::string &name) const;
48  bool exist_int_param(const std::string &name) const;
49  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()); }
50 
51  void set_double_param(const std::string &name, const double dval);
52  double get_double_param(const std::string &name) const;
53  bool exist_double_param(const std::string &name) const;
54  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()); }
55 
56  void set_string_param(const std::string &name, const std::string &str);
58  bool exist_string_param(const std::string &name) const;
59  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()); }
60 
61  void set_name(const std::string &name) { m_Detector = name; }
62  std::string Name() const { return m_Detector; }
63 
64  void FillFrom(const PdbParameterMap *saveparams);
65  void FillFrom(const PdbParameterMapContainer *saveparamcontainer, const int layer);
66  void FillFrom(const PHParameters *saveparams);
67  // save parameters on node tree
68  void SaveToNodeTree(PHCompositeNode *topNode, const std::string &nodename);
69  // save parameters in container on node tree
70  void SaveToNodeTree(PHCompositeNode *topNode, const std::string &nodename, const int layer);
71 
72  // update parameters on node tree (in case the subsystem modified them)
73  void UpdateNodeTree(PHCompositeNode *topNode, const std::string &nodename);
74  void UpdateNodeTree(PHCompositeNode *topNode, const std::string &nodename, const int layer);
75 
76  int WriteToDB();
77  int ReadFromDB();
78  int ReadFromCDB(const std::string &domain);
79  int ReadFromDB(const std::string &name, const int layer);
81  int WriteToFile(const std::string &extension, const std::string &dir = ".");
82 
84  inline int ReadFromFile(const std::string &name, const std::string &extension, const std::string &dir = ".")
85  {
86  return ReadFromFile(name, extension, 0, 0, dir);
87  }
88  int ReadFromCDBFile(const std::string &name);
90  int ReadFromFile(const std::string &name, const std::string &extension, const int layer, const int issuper, const std::string &dir = ".");
92 
93  void printint() const;
94  void printdouble() const;
95  void printstring() const;
96 
97  private:
98  unsigned int ConvertStringToUint(const std::string &str) const;
103 
104  //No Class Def since this class is not intended to be persistent
105 };
106 
107 #endif // PHPARAMETER_PHPARAMETERS_H