Class Reference for E1039 Core & Analysis Software
PHG4ParameterContainerInterface.cc
Go to the documentation of this file.
3 #include "PHG4Parameters.h"
4 
6 #include <phool/PHDataNode.h>
7 
8 #include <TSystem.h>
9 
10 #include <sstream>
11 
12 using namespace std;
13 
15  paramscontainer(new PHG4ParametersContainer(name)),
16  defaultparams(nullptr)
17 {
18  string pname(name);
19  pname += "_default";
20  defaultparams = new PHG4Parameters(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 
35 
36 void
38 {
39  paramscontainer->set_name(name);
40 }
41 
42 void
43 PHG4ParameterContainerInterface::set_default_double_param( const std::string &name, const double dval)
44 {
45  if (defaultparams->exist_double_param(name))
46  {
47  cout << "trying to overwrite default double " << name << " "
48  << defaultparams->get_double_param(name) << " with " << dval << endl;
49  gSystem->Exit(1);
50  }
51  defaultparams->set_double_param(name,dval);
52  return;
53 }
54 
55 void
56 PHG4ParameterContainerInterface::set_default_int_param( const std::string &name, const int ival)
57 {
58  if (defaultparams->exist_int_param(name))
59  {
60  cout << "trying to overwrite default double " << name << " "
61  << defaultparams->get_int_param(name) << " with " << ival << endl;
62  gSystem->Exit(1);
63  }
64  defaultparams->set_int_param(name,ival);
65  return;
66 }
67 
68 void
69 PHG4ParameterContainerInterface::set_default_string_param( const std::string &name, const string &sval)
70 {
71  if (defaultparams->exist_string_param(name))
72  {
73  cout << "trying to overwrite default double " << name << " "
74  << defaultparams->get_string_param(name) << " with " << sval << endl;
75  gSystem->Exit(1);
76  }
77  defaultparams->set_string_param(name,sval);
78  return;
79 }
80 
81 void
82 PHG4ParameterContainerInterface::set_double_param(const int detid, const std::string &name, const double dval)
83 {
84  if (! defaultparams->exist_double_param(name))
85  {
86  cout << "double parameter " << name << " not implemented" << endl;
87  cout << "implemented double parameters are:" << endl;
88  defaultparams->printdouble();
89  gSystem->Exit(1);
90  return;
91  }
92  map<int, PHG4Parameters *>::iterator iter = macroparams.find(detid);
93  PHG4Parameters *params = nullptr;
94  if (iter != macroparams.end())
95  {
96  params = iter->second;
97  }
98  else
99  {
100  ostringstream paramname;
101  paramname << paramscontainer->Name() << "_" << detid;
102  params = new PHG4Parameters(paramname.str());
103  macroparams[detid] = params;
104  }
105  params->set_double_param(name,dval);
106 }
107 
108 double
109 PHG4ParameterContainerInterface::get_double_param(const int detid, const std::string &name) const
110 {
111  const PHG4Parameters *params = paramscontainer->GetParameters(detid);
112  if (params)
113  {
114  return params->get_double_param(name);
115  }
116  cout << "no parameters for detid " << detid << " in "
117  << paramscontainer->Name() << " found" << endl;
118  return NAN;
119 }
120 
121 void
122 PHG4ParameterContainerInterface::set_int_param(const int detid, const std::string &name, const int ival)
123 {
124  if (! defaultparams->exist_int_param(name))
125  {
126  cout << "integer parameter " << name << " not implemented" << endl;
127  cout << "implemented integer parameters are:" << endl;
128  defaultparams->printint();
129  gSystem->Exit(1);
130  return;
131  }
132  map<int, PHG4Parameters *>::iterator iter = macroparams.find(detid);
133  PHG4Parameters *params = nullptr;
134  if (iter != macroparams.end())
135  {
136  params = iter->second;
137  }
138  else
139  {
140  ostringstream paramname;
141  paramname << paramscontainer->Name() << "_" << detid;
142  params = new PHG4Parameters(paramname.str());
143  paramscontainer->AddPHG4Parameters(detid,params);
144  }
145  params->set_int_param(name,ival);
146 }
147 
148 int
149 PHG4ParameterContainerInterface::get_int_param(const int detid, const std::string &name) const
150 {
151  const PHG4Parameters *params = paramscontainer->GetParameters(detid);
152  if (params)
153  {
154  return params->get_int_param(name);
155  }
156  cout << "no parameters for detid " << detid << " in "
157  << paramscontainer->Name() << " found" << endl;
158  return (~0x0);
159 }
160 
161 void
162 PHG4ParameterContainerInterface::set_string_param(const int detid, const std::string &name, const string &sval)
163 {
164  if (! defaultparams->exist_string_param(name))
165  {
166  cout << "string parameter " << name << " not implemented" << endl;
167  cout << "implemented string parameters are:" << endl;
168  defaultparams->printstring();
169  gSystem->Exit(1);
170  return;
171  }
172 
173  map<int, PHG4Parameters *>::iterator iter = macroparams.find(detid);
174  PHG4Parameters *params = nullptr;
175  if (iter != macroparams.end())
176  {
177  params = iter->second;
178  }
179  else
180  {
181  ostringstream paramname;
182  paramname << paramscontainer->Name() << "_" << detid;
183  params = new PHG4Parameters(paramname.str());
184  paramscontainer->AddPHG4Parameters(detid,params);
185  }
186  params->set_string_param(name,sval);
187 }
188 
189 string
190 PHG4ParameterContainerInterface::get_string_param(const int detid, const std::string &name) const
191 {
192  const PHG4Parameters *params = paramscontainer->GetParameters(detid);
193  if (params)
194  {
195  return params->get_string_param(name);
196  }
197  cout << "no parameters for detid " << detid << " in "
198  << paramscontainer->Name() << " found" << endl;
199  return "";
200 }
201 
202 void
204 {
205  map<int, PHG4Parameters *>::const_iterator iter;
206  for (iter = macroparams.begin(); iter != macroparams.end(); ++iter)
207  {
208  CreateInitialize(iter->first);
209 
210  PHG4Parameters *params = paramscontainer->GetParametersToModify(iter->first);
211  std::pair< PHG4Parameters::dIter, PHG4Parameters::dIter> double_begin_end = iter->second->get_all_double_params();
212  for (PHG4Parameters::dIter diter = double_begin_end.first; diter != double_begin_end.second; ++diter)
213  {
214  params->set_double_param(diter->first,diter->second);
215  }
216 
217  std::pair< PHG4Parameters::iIter, PHG4Parameters::iIter> int_begin_end = iter->second->get_all_int_params();
218  for (PHG4Parameters::iIter iiter = int_begin_end.first; iiter != int_begin_end.second; ++iiter)
219  {
220  params->set_int_param(iiter->first,iiter->second);
221  }
222 
223  std::pair< PHG4Parameters::strIter, PHG4Parameters::strIter> string_begin_end = iter->second->get_all_string_params();
224  for (PHG4Parameters::strIter striter = string_begin_end.first; striter != string_begin_end.second; ++striter)
225  {
226  params->set_string_param(striter->first,striter->second);
227  }
228  }
229  return;
230 }
231 
232 void
234 {
235  paramscontainer->SaveToNodeTree(runNode, nodename);
236  return;
237 }
238 
239 void
241 {
242  parNode->addNode(new PHDataNode<PHG4ParametersContainer>(paramscontainer,nodename));
243 }
244 
245 void
247 {
248  SetDefaultParameters(); // call method from specific subsystem
249 }
250 
251 void
253 {
254  PHG4Parameters *params = paramscontainer->GetParametersToModify(detid);
255  if (! params)
256  {
257  ostringstream paramname;
258  paramname << paramscontainer->Name() << "_" << detid;
259  params = new PHG4Parameters(*defaultparams,paramname.str());
260  paramscontainer->AddPHG4Parameters(detid,params);
261  }
262  return;
263 }
264 
265 int
267 {
268  return paramscontainer->ExistDetid(detid);
269 }
PHBoolean addNode(PHNode *)
std::string get_string_param(const int id, const std::string &name) const
void set_default_int_param(const std::string &name, const int ival)
void set_int_param(const int id, const std::string &name, const int ival)
void set_default_double_param(const std::string &name, const double dval)
double get_double_param(const int id, const std::string &name) const
void SaveToNodeTree(PHCompositeNode *runNode, const std::string &nodename)
int get_int_param(const int id, const std::string &name) const
void set_default_string_param(const std::string &name, const std::string &sval)
PHG4ParameterContainerInterface(const std::string &name)
void set_double_param(const int id, const std::string &name, const double dval)
void PutOnParNode(PHCompositeNode *parNode, const std::string &nodename)
void set_string_param(const int id, const std::string &name, const std::string &sval)
virtual void SetDefaultParameters()=0
void set_name(const std::string &name)
void AddPHG4Parameters(const int layer, PHG4Parameters *params)
int ExistDetid(const int detid) const
const PHG4Parameters * GetParameters(const int layer) const
void SaveToNodeTree(PHCompositeNode *topNode, const std::string &nodename)
PHG4Parameters * GetParametersToModify(const int layer)
void printstring() const
void set_double_param(const std::string &name, const double dval)
bool exist_string_param(const std::string &name) const
dMap::const_iterator dIter
std::string get_string_param(const std::string &name) const
void set_int_param(const std::string &name, const int ival)
double get_double_param(const std::string &name) const
iMap::const_iterator iIter
bool exist_int_param(const std::string &name) const
std::map< const std::string, std::string >::const_iterator strIter
void set_string_param(const std::string &name, const std::string &str)
bool exist_double_param(const std::string &name) const
int get_int_param(const std::string &name) const
void printint() const
void printdouble() const
std::pair< std::map< const std::string, double >::const_iterator, std::map< const std::string, double >::const_iterator > get_all_double_params()