Class Reference for E1039 Core & Analysis Software
PHParameterInterface.cc
Go to the documentation of this file.
1 #include "PHParameterInterface.h"
2 #include "PHParameters.h"
3 
5 #include <phool/PHDataNode.h>
6 
7 #include <TSystem.h>
8 
9 using namespace std;
10 
12 params(new PHParameters(name))
13 {}
14 
15 void
17 {
18  params->set_name(name);
19 }
20 
21 void
22 PHParameterInterface::set_default_double_param( const std::string &name, const double dval)
23 {
24  if (default_double.find(name) == default_double.end())
25  {
26  default_double[name] = dval;
27  }
28  else
29  {
30  cout << "trying to overwrite default double " << name << " "
31  << default_double[name] << " with " << dval << endl;
32  gSystem->Exit(1);
33  }
34  return;
35 }
36 
37 void
38 PHParameterInterface::set_default_int_param( const std::string &name, const int ival)
39 {
40  if (default_int.find(name) == default_int.end())
41  {
42  default_int[name] = ival;
43  }
44  else
45  {
46  cout << "trying to overwrite default int " << name << " "
47  << default_int[name] << " with " << ival << endl;
48  gSystem->Exit(1);
49  }
50  return;
51 }
52 
53 void
54 PHParameterInterface::set_default_string_param( const std::string &name, const string &sval)
55 {
56  if (default_string.find(name) == default_string.end())
57  {
58  default_string[name] = sval;
59  }
60  else
61  {
62  cout << "trying to overwrite default string " << name << " "
63  << default_string[name] << " with " << sval << endl;
64  gSystem->Exit(1);
65  }
66  return;
67 }
68 void
69 PHParameterInterface::set_double_param(const std::string &name, const double dval)
70 {
71  if (default_double.find(name) == default_double.end())
72  {
73  cout << "double parameter " << name << " not implemented" << endl;
74  cout << "implemented double parameters are:" << endl;
75  for (map<const string, double>::const_iterator iter = default_double.begin(); iter != default_double.end(); ++iter)
76  {
77  cout << iter->first << endl;
78  }
79  return;
80  }
81  dparams[name] = dval;
82 }
83 
84 double
85 PHParameterInterface::get_double_param(const std::string &name) const
86 {
87  return params->get_double_param(name);
88 }
89 
90 void
91 PHParameterInterface::set_int_param(const std::string &name, const int ival)
92 {
93  if (default_int.find(name) == default_int.end())
94  {
95  cout << "integer parameter " << name << " not implemented" << endl;
96  cout << "implemented integer parameters are:" << endl;
97  for (map<const string, int>::const_iterator iter = default_int.begin(); iter != default_int.end(); ++iter)
98  {
99  cout << iter->first << endl;
100  }
101  return;
102  }
103  iparams[name] = ival;
104 }
105 
106 int
107 PHParameterInterface::get_int_param(const std::string &name) const
108 {
109  return params->get_int_param(name);
110 }
111 
112 void
113 PHParameterInterface::set_string_param(const std::string &name, const string &sval)
114 {
115  if (default_string.find(name) == default_string.end())
116  {
117  cout << "string parameter " << name << " not implemented" << endl;
118  cout << "implemented string parameters are:" << endl;
119  for (map<const string, string>::const_iterator iter = default_string.begin(); iter != default_string.end(); ++iter)
120  {
121  cout << iter->first << endl;
122  }
123  return;
124  }
125  cparams[name] = sval;
126 }
127 
128 string
129 PHParameterInterface::get_string_param(const std::string &name) const
130 {
131  return params->get_string_param(name);
132 }
133 
134 void
136 {
137  for (map<const string,double>::const_iterator iter = dparams.begin(); iter != dparams.end(); ++iter)
138  {
139  params->set_double_param(iter->first,iter->second);
140  }
141  for (map<const string,int>::const_iterator iter = iparams.begin(); iter != iparams.end(); ++iter)
142  {
143  params->set_int_param(iter->first,iter->second);
144  }
145  for (map<const string,string>::const_iterator iter = cparams.begin(); iter != cparams.end(); ++iter)
146  {
147  params->set_string_param(iter->first,iter->second);
148  }
149  return;
150 }
151 
152 void
153 PHParameterInterface::SaveToNodeTree(PHCompositeNode *runNode, const string &nodename)
154 {
155  params->SaveToNodeTree(runNode, nodename);
156  return;
157 }
158 
159 void
160 PHParameterInterface::PutOnParNode(PHCompositeNode *parNode, const string &nodename)
161 {
162  parNode->addNode(new PHDataNode<PHParameters>(params,nodename));
163 }
164 
165 void
167 {
168  SetDefaultParameters(); // call method from specific subsystem
169  // now load those parameters to our params class
170  for (map<const string,double>::const_iterator iter = default_double.begin(); iter != default_double.end(); ++iter)
171  {
172  params->set_double_param(iter->first,iter->second);
173  }
174  for (map<const string,int>::const_iterator iter = default_int.begin(); iter != default_int.end(); ++iter)
175  {
176  params->set_int_param(iter->first,iter->second);
177  }
178  for (map<const string,string>::const_iterator iter = default_string.begin(); iter != default_string.end(); ++iter)
179  {
180  params->set_string_param(iter->first,iter->second);
181  }
182 }
PHBoolean addNode(PHNode *)
void set_double_param(const std::string &name, const double dval)
void set_paramname(const std::string &name)
virtual void SetDefaultParameters()=0
void set_string_param(const std::string &name, const std::string &sval)
std::string get_string_param(const std::string &name) const
PHParameterInterface(const std::string &name)
void PutOnParNode(PHCompositeNode *parNode, const std::string &nodename)
void set_default_double_param(const std::string &name, const double dval)
void set_int_param(const std::string &name, const int ival)
double get_double_param(const std::string &name) const
void SaveToNodeTree(PHCompositeNode *runNode, const std::string &nodename)
void set_default_string_param(const std::string &name, const std::string &sval)
void set_default_int_param(const std::string &name, const int ival)
int get_int_param(const std::string &name) const
void set_string_param(const std::string &name, const std::string &str)
double get_double_param(const std::string &name) const
void set_name(const std::string &name)
Definition: PHParameters.h:62
int get_int_param(const std::string &name) const
Definition: PHParameters.cc:60
void set_int_param(const std::string &name, const int ival)
Definition: PHParameters.cc:54
void set_double_param(const std::string &name, const double dval)
Definition: PHParameters.cc:95
void SaveToNodeTree(PHCompositeNode *topNode, const std::string &nodename)
std::string get_string_param(const std::string &name) const