Analysis Software
Documentation for sPHENIX simulation 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 #include <phool/phool.h>
7 
8 #include <TSystem.h>
9 
10 #include <iostream>
11 #include <utility>
12 
14  : m_Params(new PHParameters(name))
15 {
16 }
17 
19 {
20  delete m_Params;
21 }
22 
24 {
25  m_Params->set_name(name);
26 }
27 
29 {
30  if (m_DefaultDoubleParMap.find(name) == m_DefaultDoubleParMap.end())
31  {
33  }
34  else
35  {
36  std::cout << "trying to overwrite default double " << name << " "
37  << m_DefaultDoubleParMap[name] << " with " << dval << std::endl;
38  gSystem->Exit(1);
39  }
40  return;
41 }
42 
44 {
45  if (m_DefaultIntParMap.find(name) == m_DefaultIntParMap.end())
46  {
47  m_DefaultIntParMap[name] = ival;
48  }
49  else
50  {
51  std::cout << "trying to overwrite default int " << name << " "
52  << m_DefaultIntParMap[name] << " with " << ival << std::endl;
53  gSystem->Exit(1);
54  }
55  return;
56 }
57 
59 {
60  if (m_DefaultStringParMap.find(name) == m_DefaultStringParMap.end())
61  {
63  }
64  else
65  {
66  std::cout << "trying to overwrite default string " << name << " "
67  << m_DefaultStringParMap[name] << " with " << sval << std::endl;
68  gSystem->Exit(1);
69  }
70  return;
71 }
73 {
74  if (m_Locked)
75  {
76  std::cout << PHWHERE << " PHParameterInterface is locked, no modifictions allowd" << std::endl;
77  gSystem->Exit(1);
78  }
79  if (m_DefaultDoubleParMap.find(name) == m_DefaultDoubleParMap.end())
80  {
81  std::cout << "double parameter " << name << " not implemented" << std::endl;
82  std::cout << "implemented double parameters are:" << std::endl;
83  for (std::map<const std::string, double>::const_iterator iter = m_DefaultDoubleParMap.begin(); iter != m_DefaultDoubleParMap.end(); ++iter)
84  {
85  std::cout << iter->first << std::endl;
86  }
87  return;
88  }
89  m_DoubleParMap[name] = dval;
90 }
91 
92 double
94 {
95  return m_Params->get_double_param(name);
96 }
97 
99 {
100  if (m_Locked)
101  {
102  std::cout << PHWHERE << " PHParameterInterface is locked, no modifictions allowd" << std::endl;
103  gSystem->Exit(1);
104  }
105  if (m_DefaultIntParMap.find(name) == m_DefaultIntParMap.end())
106  {
107  std::cout << "integer parameter " << name << " not implemented" << std::endl;
108  std::cout << "implemented integer parameters are:" << std::endl;
109  for (std::map<const std::string, int>::const_iterator iter = m_DefaultIntParMap.begin(); iter != m_DefaultIntParMap.end(); ++iter)
110  {
111  std::cout << iter->first << std::endl;
112  }
113  return;
114  }
115  m_IntParMap[name] = ival;
116 }
117 
119 {
120  return m_Params->get_int_param(name);
121 }
122 
124 {
125  if (m_Locked)
126  {
127  std::cout << PHWHERE << " PHParameterInterface is locked, no modifictions allowd" << std::endl;
128  gSystem->Exit(1);
129  }
130  if (m_DefaultStringParMap.find(name) == m_DefaultStringParMap.end())
131  {
132  std::cout << "string parameter " << name << " not implemented" << std::endl;
133  std::cout << "implemented string parameters are:" << std::endl;
134  for (std::map<const std::string, std::string>::const_iterator iter = m_DefaultStringParMap.begin(); iter != m_DefaultStringParMap.end(); ++iter)
135  {
136  std::cout << iter->first << std::endl;
137  }
138  return;
139  }
140  m_StringParMap[name] = sval;
141 }
142 
145 {
146  return m_Params->get_string_param(name);
147 }
148 
150 {
151  for (std::map<const std::string, double>::const_iterator iter = m_DoubleParMap.begin(); iter != m_DoubleParMap.end(); ++iter)
152  {
153  m_Params->set_double_param(iter->first, iter->second);
154  }
155  for (std::map<const std::string, int>::const_iterator iter = m_IntParMap.begin(); iter != m_IntParMap.end(); ++iter)
156  {
157  m_Params->set_int_param(iter->first, iter->second);
158  }
159  for (std::map<const std::string, std::string>::const_iterator iter = m_StringParMap.begin(); iter != m_StringParMap.end(); ++iter)
160  {
161  m_Params->set_string_param(iter->first, iter->second);
162  }
163  return;
164 }
165 
167 {
168  m_Locked = true; // no more modifications after it it on the node tree
169  m_Params->SaveToNodeTree(runNode, nodename);
170  return;
171 }
172 
174 {
175  m_Locked = true; // no more modifications after it it on the node tree
176  PHParameters *newparams = new PHParameters(*m_Params,m_Params->Name());
177  parNode->addNode(new PHDataNode<PHParameters>(newparams, nodename));
178 }
179 
181 {
182  SetDefaultParameters(); // call method from specific subsystem
183  // now load those parameters to our params class
184  for (std::map<const std::string, double>::const_iterator iter = m_DefaultDoubleParMap.begin(); iter != m_DefaultDoubleParMap.end(); ++iter)
185  {
186  m_Params->set_double_param(iter->first, iter->second);
187  }
188  for (std::map<const std::string, int>::const_iterator iter = m_DefaultIntParMap.begin(); iter != m_DefaultIntParMap.end(); ++iter)
189  {
190  m_Params->set_int_param(iter->first, iter->second);
191  }
192  for (std::map<const std::string, std::string>::const_iterator iter = m_DefaultStringParMap.begin(); iter != m_DefaultStringParMap.end(); ++iter)
193  {
194  m_Params->set_string_param(iter->first, iter->second);
195  }
196 }
197 
199 {
200  if (m_Params)
201  {
202  m_Params->Print();
203  }
204 }