ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHParameterContainerInterface.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHParameterContainerInterface.cc
2 #include "PHParameters.h"
4 
6 #include <phool/PHDataNode.h>
7 
8 #include <TSystem.h>
9 
10 #include <cmath>
11 #include <iostream>
12 #include <sstream>
13 #include <utility>
14 
16  : paramscontainer(new PHParametersContainer(name))
17 {
18  std::string pname(name);
19  pname += "_default";
20  defaultparams = new PHParameters(pname);
21 }
22 
24 {
25  delete paramscontainer;
26  delete defaultparams;
27  while (macroparams.begin() != macroparams.end())
28  {
29  delete macroparams.begin()->second;
30  macroparams.erase(macroparams.begin());
31  }
32  return;
33 }
34 
36 {
38 }
39 
40 void PHParameterContainerInterface::set_default_double_param(const std::string &name, const double dval)
41 {
43  {
44  std::cout << "trying to overwrite default double " << name << " "
45  << defaultparams->get_double_param(name) << " with " << dval << std::endl;
46  gSystem->Exit(1);
47  }
48  defaultparams->set_double_param(name, dval);
49  return;
50 }
51 
52 void PHParameterContainerInterface::set_default_int_param(const std::string &name, const int ival)
53 {
54  if (defaultparams->exist_int_param(name))
55  {
56  std::cout << "trying to overwrite default double " << name << " "
57  << defaultparams->get_int_param(name) << " with " << ival << std::endl;
58  gSystem->Exit(1);
59  }
60  defaultparams->set_int_param(name, ival);
61  return;
62 }
63 
64 void PHParameterContainerInterface::set_default_string_param(const std::string &name, const std::string &sval)
65 {
67  {
68  std::cout << "trying to overwrite default double " << name << " "
69  << defaultparams->get_string_param(name) << " with " << sval << std::endl;
70  gSystem->Exit(1);
71  }
72  defaultparams->set_string_param(name, sval);
73  return;
74 }
75 
76 void PHParameterContainerInterface::set_double_param(const int detid, const std::string &name, const double dval)
77 {
79  {
80  std::cout << "double parameter " << name << " not implemented" << std::endl;
81  std::cout << "implemented double parameters are:" << std::endl;
83  gSystem->Exit(1);
84  return;
85  }
86  std::map<int, PHParameters *>::iterator iter = macroparams.find(detid);
87  PHParameters *params = nullptr;
88  if (iter != macroparams.end())
89  {
90  params = iter->second;
91  }
92  else
93  {
94  std::ostringstream paramname;
95  paramname << paramscontainer->Name() << "_" << detid;
96  params = new PHParameters(paramname.str());
97  macroparams[detid] = params;
98  }
99  params->set_double_param(name, dval);
100 }
101 
102 double
103 PHParameterContainerInterface::get_double_param(const int detid, const std::string &name) const
104 {
105  const PHParameters *params = paramscontainer->GetParameters(detid);
106  if (params)
107  {
108  return params->get_double_param(name);
109  }
110  std::cout << "no parameters for detid " << detid << " in "
111  << paramscontainer->Name() << " found" << std::endl;
112  return NAN;
113 }
114 
115 void PHParameterContainerInterface::set_int_param(const int detid, const std::string &name, const int ival)
116 {
117  if (!defaultparams->exist_int_param(name))
118  {
119  std::cout << "integer parameter " << name << " not implemented" << std::endl;
120  std::cout << "implemented integer parameters are:" << std::endl;
122  gSystem->Exit(1);
123  return;
124  }
125  std::map<int, PHParameters *>::iterator iter = macroparams.find(detid);
126  PHParameters *params = nullptr;
127  if (iter != macroparams.end())
128  {
129  params = iter->second;
130  }
131  else
132  {
133  std::ostringstream paramname;
134  paramname << paramscontainer->Name() << "_" << detid;
135  params = new PHParameters(paramname.str());
136  paramscontainer->AddPHParameters(detid, params);
137  }
138  params->set_int_param(name, ival);
139 }
140 
141 int PHParameterContainerInterface::get_int_param(const int detid, const std::string &name) const
142 {
143  const PHParameters *params = paramscontainer->GetParameters(detid);
144  if (params)
145  {
146  return params->get_int_param(name);
147  }
148  std::cout << "no parameters for detid " << detid << " in "
149  << paramscontainer->Name() << " found" << std::endl;
150  return (~0x0);
151 }
152 
153 void PHParameterContainerInterface::set_string_param(const int detid, const std::string &name, const std::string &sval)
154 {
155  if (!defaultparams->exist_string_param(name))
156  {
157  std::cout << "string parameter " << name << " not implemented" << std::endl;
158  std::cout << "implemented string parameters are:" << std::endl;
160  gSystem->Exit(1);
161  return;
162  }
163 
164  std::map<int, PHParameters *>::iterator iter = macroparams.find(detid);
165  PHParameters *params = nullptr;
166  if (iter != macroparams.end())
167  {
168  params = iter->second;
169  }
170  else
171  {
172  std::ostringstream paramname;
173  paramname << paramscontainer->Name() << "_" << detid;
174  params = new PHParameters(paramname.str());
175  paramscontainer->AddPHParameters(detid, params);
176  }
177  params->set_string_param(name, sval);
178 }
179 
180 std::string
181 PHParameterContainerInterface::get_string_param(const int detid, const std::string &name) const
182 {
183  const PHParameters *params = paramscontainer->GetParameters(detid);
184  if (params)
185  {
186  return params->get_string_param(name);
187  }
188  std::cout << "no parameters for detid " << detid << " in "
189  << paramscontainer->Name() << " found" << std::endl;
190  return "";
191 }
192 
194 {
195  std::map<int, PHParameters *>::const_iterator iter;
196  for (iter = macroparams.begin(); iter != macroparams.end(); ++iter)
197  {
198  CreateInitialize(iter->first);
199 
200  PHParameters *params = paramscontainer->GetParametersToModify(iter->first);
201  std::pair<PHParameters::dIter, PHParameters::dIter> double_begin_end = iter->second->get_all_double_params();
202  for (PHParameters::dIter diter = double_begin_end.first; diter != double_begin_end.second; ++diter)
203  {
204  params->set_double_param(diter->first, diter->second);
205  }
206 
207  std::pair<PHParameters::iIter, PHParameters::iIter> int_begin_end = iter->second->get_all_int_params();
208  for (PHParameters::iIter iiter = int_begin_end.first; iiter != int_begin_end.second; ++iiter)
209  {
210  params->set_int_param(iiter->first, iiter->second);
211  }
212 
213  std::pair<PHParameters::strIter, PHParameters::strIter> string_begin_end = iter->second->get_all_string_params();
214  for (PHParameters::strIter striter = string_begin_end.first; striter != string_begin_end.second; ++striter)
215  {
216  params->set_string_param(striter->first, striter->second);
217  }
218  }
219  return;
220 }
221 
222 void PHParameterContainerInterface::SaveToNodeTree(PHCompositeNode *runNode, const std::string &nodename)
223 {
224  paramscontainer->SaveToNodeTree(runNode, nodename);
225  return;
226 }
227 
228 void PHParameterContainerInterface::PutOnParNode(PHCompositeNode *parNode, const std::string &nodename)
229 {
231 }
232 
234 {
235  SetDefaultParameters(); // call method from specific subsystem
236 }
237 
239 {
241  if (!params)
242  {
243  std::ostringstream paramname;
244  paramname << paramscontainer->Name() << "_" << detid;
245  params = new PHParameters(*defaultparams, paramname.str());
246  paramscontainer->AddPHParameters(detid, params);
247  }
248  return;
249 }
250 
252 {
253  return paramscontainer->ExistDetid(detid);
254 }