Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlagSavev1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FlagSavev1.cc
1 #include "FlagSavev1.h"
2 
3 #include <phool/PHFlag.h>
4 
5 #include <cstdint> // for uint64_t
6 #include <utility> // for pair
7 
8 class PHObject;
9 
10 PHObject *
12 {
13  FlagSavev1 *ret = new FlagSavev1();
14 
15  ret->intflag = this->intflag;
17  ret->doubleflag = this->doubleflag;
18  ret->floatflag = this->floatflag;
19  ret->stringflag = this->stringflag;
20 
21  return ret;
22 }
23 
25 {
26  if (intflag.empty() &&
27  doubleflag.empty() &&
28  floatflag.empty() &&
29  stringflag.empty() &&
30  m_uint64flag_map.empty())
31  {
32  return 0;
33  }
34  return 1;
35 }
36 
37 void FlagSavev1::identify(std::ostream &out) const
38 {
39  out << "identify yourself: I am an FlagSavev1 Object" << std::endl;
40  PrintIntFlag(out);
41  Printuint64Flag(out);
42  PrintDoubleFlag(out);
43  PrintFloatFlag(out);
44  PrintStringFlag(out);
45  return;
46 }
47 
48 int FlagSavev1::FillFromPHFlag(const PHFlag *flags, const bool clearold)
49 {
50  if (clearold)
51  {
52  ClearAll();
53  }
54  int iret = FillIntFromPHFlag(flags);
55  iret += Filluint64FromPHFlag(flags);
56  iret += FillDoubleFromPHFlag(flags);
57  iret += FillFloatFromPHFlag(flags);
58  iret += FillStringFromPHFlag(flags);
59  return iret;
60 }
61 
62 int FlagSavev1::PutFlagsBack(PHFlag *flags, const bool overwrite)
63 {
64  int iret = PutIntToPHFlag(flags, overwrite);
65  iret += Putuint64ToPHFlag(flags, overwrite);
66  iret += PutDoubleToPHFlag(flags, overwrite);
67  iret += PutFloatToPHFlag(flags, overwrite);
68  iret += PutStringToPHFlag(flags, overwrite);
69  return iret;
70 }
71 
73 {
74  std::map<std::string, int>::const_iterator iter;
75  const std::map<std::string, int> *intm = flags->IntMap();
76  for (iter = intm->begin(); iter != intm->end(); ++iter)
77  {
78  intflag[iter->first] = iter->second;
79  }
80  return 0;
81 }
82 
84 {
85  std::map<std::string, uint64_t>::const_iterator iter;
86  const std::map<std::string, uint64_t> *intm = flags->uint64Map();
87  for (iter = intm->begin(); iter != intm->end(); ++iter)
88  {
89  m_uint64flag_map[iter->first] = iter->second;
90  }
91  return 0;
92 }
93 
95 {
96  std::map<std::string, double>::const_iterator iter;
97  const std::map<std::string, double> *intm = flags->DoubleMap();
98  for (iter = intm->begin(); iter != intm->end(); ++iter)
99  {
100  doubleflag[iter->first] = iter->second;
101  }
102  return 0;
103 }
104 
106 {
107  std::map<std::string, float>::const_iterator iter;
108  const std::map<std::string, float> *intm = flags->FloatMap();
109  for (iter = intm->begin(); iter != intm->end(); ++iter)
110  {
111  floatflag[iter->first] = iter->second;
112  }
113  return 0;
114 }
115 
117 {
118  std::map<std::string, std::string>::const_iterator iter;
119  const std::map<std::string, std::string> *intm = flags->StringMap();
120  for (iter = intm->begin(); iter != intm->end(); ++iter)
121  {
122  std::string input(iter->second);
123  stringflag[iter->first] = input;
124  }
125  return 0;
126 }
127 // general procedure, if overwrite is set, just set the flag
128 // if overwrite is false, call get flag with initialization which is used if it does not exist
129 int FlagSavev1::PutIntToPHFlag(PHFlag *flags, const bool overwrite)
130 {
131  std::map<std::string, int>::const_iterator iter;
132  for (iter = intflag.begin(); iter != intflag.end(); ++iter)
133  {
134  if (overwrite)
135  {
136  flags->set_IntFlag(iter->first, iter->second);
137  }
138  else
139  {
140  flags->get_IntFlag(iter->first, iter->second);
141  }
142  }
143  return 0;
144 }
145 
146 int FlagSavev1::Putuint64ToPHFlag(PHFlag *flags, const bool overwrite)
147 {
148  std::map<std::string, uint64_t>::const_iterator iter;
149  for (iter = m_uint64flag_map.begin(); iter != m_uint64flag_map.end(); ++iter)
150  {
151  if (overwrite)
152  {
153  flags->set_uint64Flag(iter->first, iter->second);
154  }
155  else
156  {
157  flags->get_uint64Flag(iter->first, iter->second);
158  }
159  }
160  return 0;
161 }
162 
163 int FlagSavev1::PutDoubleToPHFlag(PHFlag *flags, const bool overwrite)
164 {
165  std::map<std::string, double>::const_iterator iter;
166  for (iter = doubleflag.begin(); iter != doubleflag.end(); ++iter)
167  {
168  if (overwrite)
169  {
170  flags->set_DoubleFlag(iter->first, iter->second);
171  }
172  else
173  {
174  flags->get_DoubleFlag(iter->first, iter->second);
175  }
176  }
177  return 0;
178 }
179 
180 int FlagSavev1::PutFloatToPHFlag(PHFlag *flags, const bool overwrite)
181 {
182  std::map<std::string, float>::const_iterator iter;
183  for (iter = floatflag.begin(); iter != floatflag.end(); ++iter)
184  {
185  if (overwrite)
186  {
187  flags->set_FloatFlag(iter->first, iter->second);
188  }
189  else
190  {
191  flags->get_FloatFlag(iter->first, iter->second);
192  }
193  }
194  return 0;
195 }
196 
197 int FlagSavev1::PutStringToPHFlag(PHFlag *flags, const bool overwrite)
198 {
199  std::map<std::string, std::string>::const_iterator iter;
200  for (iter = stringflag.begin(); iter != stringflag.end(); ++iter)
201  {
202  if (overwrite)
203  {
204  flags->set_StringFlag(iter->first, iter->second);
205  }
206  else
207  {
208  flags->get_StringFlag(iter->first, iter->second);
209  }
210  }
211  return 0;
212 }
213 
214 void FlagSavev1::PrintIntFlag(std::ostream &os) const
215 {
216  if (intflag.empty())
217  {
218  return;
219  }
220  std::map<std::string, int>::const_iterator iter;
221  os << "Int Flags: " << std::endl;
222  for (iter = intflag.begin(); iter != intflag.end(); ++iter)
223  {
224  os << iter->first << ": " << iter->second << std::endl;
225  }
226  return;
227 }
228 
229 void FlagSavev1::Printuint64Flag(std::ostream &os) const
230 {
231  if (m_uint64flag_map.empty())
232  {
233  return;
234  }
235  std::map<std::string, uint64_t>::const_iterator iter;
236  os << "UInt64 Flags: " << std::endl;
237  for (iter = m_uint64flag_map.begin(); iter != m_uint64flag_map.end(); ++iter)
238  {
239  os << iter->first << ": " << iter->second << std::endl;
240  }
241  return;
242 }
243 
244 void FlagSavev1::PrintDoubleFlag(std::ostream &os) const
245 {
246  if (doubleflag.empty())
247  {
248  return;
249  }
250  std::map<std::string, double>::const_iterator iter;
251  os << "Double Flags: " << std::endl;
252  for (iter = doubleflag.begin(); iter != doubleflag.end(); ++iter)
253  {
254  os << iter->first << ": " << iter->second << std::endl;
255  }
256  return;
257 }
258 
259 void FlagSavev1::PrintFloatFlag(std::ostream &os) const
260 {
261  if (floatflag.empty())
262  {
263  return;
264  }
265  std::map<std::string, float>::const_iterator iter;
266  os << "Float Flags: " << std::endl;
267  for (iter = floatflag.begin(); iter != floatflag.end(); ++iter)
268  {
269  os << iter->first << ": " << iter->second << std::endl;
270  }
271  return;
272 }
273 
274 void FlagSavev1::PrintStringFlag(std::ostream &os) const
275 {
276  if (stringflag.empty())
277  {
278  return;
279  }
280  std::map<std::string, std::string>::const_iterator iter;
281  os << "String Flags: " << std::endl;
282  for (iter = stringflag.begin(); iter != stringflag.end(); ++iter)
283  {
284  os << iter->first << ": " << iter->second << std::endl;
285  }
286  return;
287 }
288 
290 {
291  intflag.clear();
292  doubleflag.clear();
293  floatflag.clear();
294  stringflag.clear();
295  m_uint64flag_map.clear();
296 }