ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHParameterInterface.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHParameterInterface.cc
1 #include "PHParameterInterface.h"
2 #include "PHParameters.h"
3 
5 #include <phool/PHDataNode.h>
6 
7 #include <TSystem.h>
8 
9 #include <iostream>
10 #include <utility>
11 
13  : m_Params(new PHParameters(name))
14 {
15 }
16 
17 void PHParameterInterface::set_paramname(const std::string &name)
18 {
19  m_Params->set_name(name);
20 }
21 
22 void PHParameterInterface::set_default_double_param(const std::string &name, const double dval)
23 {
24  if (m_DefaultDoubleParMap.find(name) == m_DefaultDoubleParMap.end())
25  {
27  }
28  else
29  {
30  std::cout << "trying to overwrite default double " << name << " "
31  << m_DefaultDoubleParMap[name] << " with " << dval << std::endl;
32  gSystem->Exit(1);
33  }
34  return;
35 }
36 
37 void PHParameterInterface::set_default_int_param(const std::string &name, const int ival)
38 {
39  if (m_DefaultIntParMap.find(name) == m_DefaultIntParMap.end())
40  {
41  m_DefaultIntParMap[name] = ival;
42  }
43  else
44  {
45  std::cout << "trying to overwrite default int " << name << " "
46  << m_DefaultIntParMap[name] << " with " << ival << std::endl;
47  gSystem->Exit(1);
48  }
49  return;
50 }
51 
52 void PHParameterInterface::set_default_string_param(const std::string &name, const std::string &sval)
53 {
54  if (m_DefaultStringParMap.find(name) == m_DefaultStringParMap.end())
55  {
57  }
58  else
59  {
60  std::cout << "trying to overwrite default string " << name << " "
61  << m_DefaultStringParMap[name] << " with " << sval << std::endl;
62  gSystem->Exit(1);
63  }
64  return;
65 }
66 void PHParameterInterface::set_double_param(const std::string &name, const double dval)
67 {
68  if (m_DefaultDoubleParMap.find(name) == m_DefaultDoubleParMap.end())
69  {
70  std::cout << "double parameter " << name << " not implemented" << std::endl;
71  std::cout << "implemented double parameters are:" << std::endl;
72  for (std::map<const std::string, double>::const_iterator iter = m_DefaultDoubleParMap.begin(); iter != m_DefaultDoubleParMap.end(); ++iter)
73  {
74  std::cout << iter->first << std::endl;
75  }
76  return;
77  }
78  m_DoubleParMap[name] = dval;
79 }
80 
81 double
83 {
84  return m_Params->get_double_param(name);
85 }
86 
87 void PHParameterInterface::set_int_param(const std::string &name, const int ival)
88 {
89  if (m_DefaultIntParMap.find(name) == m_DefaultIntParMap.end())
90  {
91  std::cout << "integer parameter " << name << " not implemented" << std::endl;
92  std::cout << "implemented integer parameters are:" << std::endl;
93  for (std::map<const std::string, int>::const_iterator iter = m_DefaultIntParMap.begin(); iter != m_DefaultIntParMap.end(); ++iter)
94  {
95  std::cout << iter->first << std::endl;
96  }
97  return;
98  }
99  m_IntParMap[name] = ival;
100 }
101 
102 int PHParameterInterface::get_int_param(const std::string &name) const
103 {
104  return m_Params->get_int_param(name);
105 }
106 
107 void PHParameterInterface::set_string_param(const std::string &name, const std::string &sval)
108 {
109  if (m_DefaultStringParMap.find(name) == m_DefaultStringParMap.end())
110  {
111  std::cout << "string parameter " << name << " not implemented" << std::endl;
112  std::cout << "implemented string parameters are:" << std::endl;
113  for (std::map<const std::string, std::string>::const_iterator iter = m_DefaultStringParMap.begin(); iter != m_DefaultStringParMap.end(); ++iter)
114  {
115  std::cout << iter->first << std::endl;
116  }
117  return;
118  }
119  m_StringParMap[name] = sval;
120 }
121 
122 std::string
124 {
125  return m_Params->get_string_param(name);
126 }
127 
129 {
130  for (std::map<const std::string, double>::const_iterator iter = m_DoubleParMap.begin(); iter != m_DoubleParMap.end(); ++iter)
131  {
132  m_Params->set_double_param(iter->first, iter->second);
133  }
134  for (std::map<const std::string, int>::const_iterator iter = m_IntParMap.begin(); iter != m_IntParMap.end(); ++iter)
135  {
136  m_Params->set_int_param(iter->first, iter->second);
137  }
138  for (std::map<const std::string, std::string>::const_iterator iter = m_StringParMap.begin(); iter != m_StringParMap.end(); ++iter)
139  {
140  m_Params->set_string_param(iter->first, iter->second);
141  }
142  return;
143 }
144 
145 void PHParameterInterface::SaveToNodeTree(PHCompositeNode *runNode, const std::string &nodename)
146 {
147  m_Params->SaveToNodeTree(runNode, nodename);
148  return;
149 }
150 
151 void PHParameterInterface::PutOnParNode(PHCompositeNode *parNode, const std::string &nodename)
152 {
153  parNode->addNode(new PHDataNode<PHParameters>(m_Params, nodename));
154 }
155 
157 {
158  SetDefaultParameters(); // call method from specific subsystem
159  // now load those parameters to our params class
160  for (std::map<const std::string, double>::const_iterator iter = m_DefaultDoubleParMap.begin(); iter != m_DefaultDoubleParMap.end(); ++iter)
161  {
162  m_Params->set_double_param(iter->first, iter->second);
163  }
164  for (std::map<const std::string, int>::const_iterator iter = m_DefaultIntParMap.begin(); iter != m_DefaultIntParMap.end(); ++iter)
165  {
166  m_Params->set_int_param(iter->first, iter->second);
167  }
168  for (std::map<const std::string, std::string>::const_iterator iter = m_DefaultStringParMap.begin(); iter != m_DefaultStringParMap.end(); ++iter)
169  {
170  m_Params->set_string_param(iter->first, iter->second);
171  }
172 }