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