Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CDBTTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CDBTTree.cc
1 #include "CDBTTree.h"
2 
3 #include <phool/phool.h>
4 
5 #include <TBranch.h> // for TBranch
6 #include <TCollection.h> // for TIter
7 #include <TDirectory.h> // for TDirectoryAtomicAdapter, TDirectory, gDirec...
8 #include <TFile.h>
9 #include <TLeaf.h> // for TLeaf
10 #include <TObjArray.h> // for TObjArray
11 #include <TROOT.h>
12 #include <TSystem.h>
13 #include <TTree.h>
14 
15 #include <climits>
16 #include <cmath> // for NAN, isfinite
17 #include <cstdint> // for uint64_t
18 #include <iostream>
19 #include <limits> // for numeric_limits, numeric_limits<>::max_digits10
20 #include <set> // for set
21 #include <utility> // for pair, make_pair
22 
24  : m_Filename(fname)
25 {
26 }
27 
29 {
30  m_FloatEntryMap.clear();
31  m_SingleFloatEntryMap.clear();
32 }
33 
35 {
36  if (name == "ID")
37  {
38  std::cout << "Sorry ID is reserved as fieldname, pick anything else" << std::endl;
39  gSystem->Exit(1);
40  }
41  std::string fieldname = "F" + name;
43  {
44  std::cout << "Trying to add field " << name << " after another entry was committed" << std::endl;
45  std::cout << "That does not work, restructure your code" << std::endl;
46  gSystem->Exit(1);
47  }
48  m_FloatEntryMap[channel].insert(std::make_pair(fieldname, value));
49 }
50 
52 {
53  if (name == "ID")
54  {
55  std::cout << "Sorry ID is reserved as fieldname, pick anything else" << std::endl;
56  gSystem->Exit(1);
57  }
58  std::string fieldname = "D" + name;
60  {
61  std::cout << "Trying to add field " << name << " after another entry was committed" << std::endl;
62  std::cout << "That does not work, restructure your code" << std::endl;
63  gSystem->Exit(1);
64  }
65  m_DoubleEntryMap[channel].insert(std::make_pair(fieldname, value));
66 }
67 
69 {
70  if (name == "ID")
71  {
72  std::cout << "Sorry ID is reserved as fieldname, pick anything else" << std::endl;
73  gSystem->Exit(1);
74  }
75  std::string fieldname = "I" + name;
77  {
78  std::cout << "Trying to add field " << name << " after another entry was committed" << std::endl;
79  std::cout << "That does not work, restructure your code" << std::endl;
80  gSystem->Exit(1);
81  }
82  m_IntEntryMap[channel].insert(std::make_pair(fieldname, value));
83 }
84 
86 {
87  if (name == "ID")
88  {
89  std::cout << "Sorry ID is reserved as fieldname, pick anything else" << std::endl;
90  gSystem->Exit(1);
91  }
92  std::string fieldname = "g" + name;
94  {
95  std::cout << "Trying to add field " << name << " after another entry was committed" << std::endl;
96  std::cout << "That does not work, restructure your code" << std::endl;
97  gSystem->Exit(1);
98  }
99  m_UInt64EntryMap[channel].insert(std::make_pair(fieldname, value));
100 }
101 
103 {
104  m_Locked[MultipleEntries] = true;
105 }
106 
108 {
110  std::set<int> id_set;
111  std::map<std::string, float> floatmap;
112  std::map<std::string, double> doublemap;
113  std::map<std::string, int> intmap;
114  std::map<std::string, uint64_t> uint64map;
115  intmap.insert(std::make_pair("IID", std::numeric_limits<int>::min()));
116  for (auto &f_entry : m_FloatEntryMap)
117  {
118  id_set.insert(f_entry.first);
119  for (auto &f_val : f_entry.second)
120  {
121  floatmap.insert(std::make_pair(f_val.first, std::numeric_limits<float>::quiet_NaN()));
122  }
123  }
124  for (auto &f_val : floatmap)
125  {
126  std::string fielddescriptor = f_val.first + "/F";
127  m_TTree[MultipleEntries]->Branch(f_val.first.c_str(), &f_val.second, fielddescriptor.c_str());
128  }
129 
130  for (auto &f_entry : m_DoubleEntryMap)
131  {
132  id_set.insert(f_entry.first);
133  for (auto &f_val : f_entry.second)
134  {
135  doublemap.insert(std::make_pair(f_val.first, std::numeric_limits<double>::quiet_NaN()));
136  }
137  }
138  for (auto &f_val : doublemap)
139  {
140  std::string fielddescriptor = f_val.first + "/D";
141  m_TTree[MultipleEntries]->Branch(f_val.first.c_str(), &f_val.second, fielddescriptor.c_str());
142  }
143 
144  for (auto &i_entry : m_IntEntryMap)
145  {
146  id_set.insert(i_entry.first);
147  for (auto &i_val : i_entry.second)
148  {
149  intmap.insert(std::make_pair(i_val.first, std::numeric_limits<int>::min()));
150  }
151  }
152  for (auto &i_val : intmap)
153  {
154  std::string fielddescriptor = i_val.first + "/I";
155  m_TTree[MultipleEntries]->Branch(i_val.first.c_str(), &i_val.second, fielddescriptor.c_str());
156  }
157 
158  for (auto &i_entry : m_UInt64EntryMap)
159  {
160  id_set.insert(i_entry.first);
161  for (auto &i_val : i_entry.second)
162  {
163  uint64map.insert(std::make_pair(i_val.first, std::numeric_limits<uint64_t>::max()));
164  }
165  }
166  for (auto &i_val : uint64map)
167  {
168  std::string fielddescriptor = i_val.first + "/g";
169  m_TTree[MultipleEntries]->Branch(i_val.first.c_str(), &i_val.second, fielddescriptor.c_str());
170  }
171  // fill ttree
172  for (auto ids : id_set)
173  {
174  intmap["IID"] = ids;
175  auto fmapiter = m_FloatEntryMap.find(ids);
176  if (fmapiter != m_FloatEntryMap.end())
177  {
178  for (auto &f_val : fmapiter->second)
179  {
180  floatmap[f_val.first] = f_val.second;
181  }
182  }
183  auto dmapiter = m_DoubleEntryMap.find(ids);
184  if (dmapiter != m_DoubleEntryMap.end())
185  {
186  for (auto &d_val : dmapiter->second)
187  {
188  doublemap[d_val.first] = d_val.second;
189  }
190  }
191  auto imapiter = m_IntEntryMap.find(ids);
192  if (imapiter != m_IntEntryMap.end())
193  {
194  for (auto &i_val : imapiter->second)
195  {
196  intmap[i_val.first] = i_val.second;
197  }
198  }
199  auto uint64mapiter = m_UInt64EntryMap.find(ids);
200  if (uint64mapiter != m_UInt64EntryMap.end())
201  {
202  for (auto &uint64_val : uint64mapiter->second)
203  {
204  uint64map[uint64_val.first] = uint64_val.second;
205  }
206  }
207  m_TTree[MultipleEntries]->Fill();
208  for (auto &f_val : floatmap)
209  {
210  f_val.second = std::numeric_limits<float>::quiet_NaN();
211  }
212  for (auto &f_val : doublemap)
213  {
214  f_val.second = std::numeric_limits<double>::quiet_NaN();
215  }
216  for (auto &i_val : intmap)
217  {
218  i_val.second = std::numeric_limits<int>::min();
219  }
220  for (auto &i_val : uint64map)
221  {
222  i_val.second = std::numeric_limits<uint64_t>::max();
223  }
224  }
225  return;
226 }
227 
229 {
230  std::string fieldname = "F" + name;
231  if (m_SingleFloatEntryMap.find(fieldname) == m_SingleFloatEntryMap.end())
232  {
233  if (m_Locked[SingleEntries])
234  {
235  std::cout << "Trying to add field " << name << " after another entry was committed" << std::endl;
236  std::cout << "That does not work, restructure your code" << std::endl;
237  gSystem->Exit(1);
238  }
239  m_SingleFloatEntryMap.insert(std::make_pair(fieldname, value));
240  return;
241  }
242  m_SingleFloatEntryMap[fieldname] = value;
243 }
244 
246 {
247  std::string fieldname = "D" + name;
248  if (m_SingleDoubleEntryMap.find(fieldname) == m_SingleDoubleEntryMap.end())
249  {
250  if (m_Locked[SingleEntries])
251  {
252  std::cout << "Trying to add field " << name << " after another entry was committed" << std::endl;
253  std::cout << "That does not work, restructure your code" << std::endl;
254  gSystem->Exit(1);
255  }
256  m_SingleDoubleEntryMap.insert(std::make_pair(fieldname, value));
257  return;
258  }
259  m_SingleDoubleEntryMap[fieldname] = value;
260 }
261 
263 {
264  std::string fieldname = "I" + name;
265  if (m_SingleIntEntryMap.find(fieldname) == m_SingleIntEntryMap.end())
266  {
267  if (m_Locked[SingleEntries])
268  {
269  std::cout << "Trying to add field " << name << " after another entry was committed" << std::endl;
270  std::cout << "That does not work, restructure your code" << std::endl;
271  gSystem->Exit(1);
272  }
273  m_SingleIntEntryMap.insert(std::make_pair(fieldname, value));
274  return;
275  }
276  m_SingleIntEntryMap[fieldname] = value;
277 }
278 
280 {
281  std::string fieldname = "g" + name;
282  if (m_SingleUInt64EntryMap.find(fieldname) == m_SingleUInt64EntryMap.end())
283  {
284  if (m_Locked[SingleEntries])
285  {
286  std::cout << "Trying to add field " << name << " after another entry was committed" << std::endl;
287  std::cout << "That does not work, restructure your code" << std::endl;
288  gSystem->Exit(1);
289  }
290  m_SingleUInt64EntryMap.insert(std::make_pair(fieldname, value));
291  return;
292  }
293  m_SingleUInt64EntryMap[fieldname] = value;
294 }
295 
297 {
298  m_Locked[SingleEntries] = true;
299  return;
300 }
301 
303 {
304  m_TTree[SingleEntries] = new TTree(m_TTreeName[SingleEntries].c_str(), m_TTreeName[SingleEntries].c_str());
305  for (auto &field : m_SingleFloatEntryMap)
306  {
307  std::string fielddescriptor = field.first + "/F";
308  m_TTree[SingleEntries]->Branch(field.first.c_str(), &field.second, fielddescriptor.c_str());
309  }
310  for (auto &field : m_SingleDoubleEntryMap)
311  {
312  std::string fielddescriptor = field.first + "/D";
313  m_TTree[SingleEntries]->Branch(field.first.c_str(), &field.second, fielddescriptor.c_str());
314  }
315  for (auto &field : m_SingleIntEntryMap)
316  {
317  std::string fielddescriptor = field.first + "/I";
318  m_TTree[SingleEntries]->Branch(field.first.c_str(), &field.second, fielddescriptor.c_str());
319  }
320  for (auto &field : m_SingleUInt64EntryMap)
321  {
322  std::string fielddescriptor = field.first + "/g";
323  m_TTree[SingleEntries]->Branch(field.first.c_str(), &field.second, fielddescriptor.c_str());
324  }
325 
326  m_TTree[SingleEntries]->Fill();
327  return;
328 }
329 
331 {
332  if (!m_FloatEntryMap.empty())
333  {
334  std::cout << "Number of float entries: " << m_FloatEntryMap.size() << std::endl;
335  for (auto &field : m_FloatEntryMap)
336  {
337  std::cout << "ID: " << field.first << std::endl;
338  for (auto &calibs : field.second)
339  {
340  std::string tmpstring = calibs.first;
341  tmpstring.erase(0, 1);
342  std::cout << "name " << tmpstring << " value: " << calibs.second << std::endl;
343  }
344  }
345  std::cout << "--------------------------------------------------" << std::endl
346  << std::endl;
347  }
348  if (!m_DoubleEntryMap.empty())
349  {
350  std::cout << "Number of double entries: " << m_DoubleEntryMap.size() << std::endl;
351  for (auto &field : m_DoubleEntryMap)
352  {
353  std::cout << "ID: " << field.first << std::endl;
354  for (auto &calibs : field.second)
355  {
356  std::string tmpstring = calibs.first;
357  tmpstring.erase(0, 1);
358  std::cout << "name " << tmpstring << " value: " << calibs.second << std::endl;
359  }
360  }
361  std::cout << "--------------------------------------------------" << std::endl
362  << std::endl;
363  }
364  if (!m_IntEntryMap.empty())
365  {
366  std::cout << "Number of int entries: " << m_IntEntryMap.size() << std::endl;
367  for (auto &field : m_IntEntryMap)
368  {
369  std::cout << "ID: " << field.first << std::endl;
370  for (auto &calibs : field.second)
371  {
372  std::string tmpstring = calibs.first;
373  tmpstring.erase(0, 1);
374  std::cout << "name " << tmpstring << " value: " << calibs.second << std::endl;
375  }
376  }
377  }
378  if (!m_UInt64EntryMap.empty())
379  {
380  std::cout << "Number of uint64 entries: " << m_UInt64EntryMap.size() << std::endl;
381  for (auto &field : m_UInt64EntryMap)
382  {
383  std::cout << "ID: " << field.first << std::endl;
384  for (auto &calibs : field.second)
385  {
386  std::string tmpstring = calibs.first;
387  tmpstring.erase(0, 1);
388  std::cout << "name " << tmpstring << " value: " << calibs.second << std::endl;
389  }
390  }
391  }
392 
393  if (!m_SingleFloatEntryMap.empty())
394  {
395  std::cout << "Number of single float fields: " << m_SingleFloatEntryMap.size() << std::endl;
396  for (auto &field : m_SingleFloatEntryMap)
397  {
398  std::string tmpstring = field.first;
399  tmpstring.erase(0, 1);
400  std::cout << tmpstring << " value " << field.second << std::endl;
401  }
402  }
403  if (!m_SingleDoubleEntryMap.empty())
404  {
405  std::cout << "Number of single double fields: " << m_SingleDoubleEntryMap.size() << std::endl;
406  // some acrobatics to restore the old state of cout after changing the precision for double printout
407  std::ios oldState(nullptr);
408  oldState.copyfmt(std::cout);
409  std::cout.precision(std::numeric_limits<double>::max_digits10);
410  for (auto &field : m_SingleDoubleEntryMap)
411  {
412  std::string tmpstring = field.first;
413  tmpstring.erase(0, 1);
414  std::cout << tmpstring << " value " << field.second << std::endl;
415  }
416  std::cout.copyfmt(oldState);
417  }
418  if (!m_SingleIntEntryMap.empty())
419  {
420  std::cout << "Number of single int fields: " << m_SingleIntEntryMap.size() << std::endl;
421  for (auto &field : m_SingleIntEntryMap)
422  {
423  std::string tmpstring = field.first;
424  tmpstring.erase(0, 1);
425  std::cout << tmpstring << " value " << field.second << std::endl;
426  }
427  }
428  if (!m_SingleUInt64EntryMap.empty())
429  {
430  std::cout << "Number of single uint64 fields: " << m_SingleUInt64EntryMap.size() << std::endl;
431  for (auto &field : m_SingleUInt64EntryMap)
432  {
433  std::string tmpstring = field.first;
434  tmpstring.erase(0, 1);
435  std::cout << tmpstring << " value " << field.second << std::endl;
436  }
437  }
438 }
439 
441 {
442  bool empty_single = m_SingleFloatEntryMap.empty() && m_SingleDoubleEntryMap.empty() &&
443  m_SingleIntEntryMap.empty() && m_SingleUInt64EntryMap.empty();
444  if (!empty_single && !m_Locked[SingleEntries])
445  {
446  std::cout << "You need to call CDBTTree::CommitSingle() before writing" << std::endl;
447  return;
448  }
449  bool empty_multiple = m_FloatEntryMap.empty() && m_DoubleEntryMap.empty() &&
450  m_IntEntryMap.empty() && m_UInt64EntryMap.empty();
451  if (!empty_multiple && !m_Locked[MultipleEntries])
452  {
453  std::cout << "You need to call CDBTTree::Commit() before writing" << std::endl;
454  return;
455  }
456  if (empty_single && empty_multiple)
457  {
458  std::cout << "no values to be saved" << std::endl;
459  return;
460  }
461 
462  std::string currdir = gDirectory->GetPath();
463 
464  TFile *f = TFile::Open(m_Filename.c_str(), "RECREATE");
465  if (!empty_single)
466  {
468  m_TTree[SingleEntries]->Write();
469  }
470  if (!empty_multiple)
471  {
473  m_TTree[MultipleEntries]->Write();
474  }
475  f->Close();
476 
477  gROOT->cd(currdir.c_str()); // restore previous directory
478 }
479 
481 {
482  std::string currdir = gDirectory->GetPath();
483 
484  TFile *f = TFile::Open(m_Filename.c_str());
485  f->GetObject(m_TTreeName[SingleEntries].c_str(), m_TTree[SingleEntries]);
486  f->GetObject(m_TTreeName[MultipleEntries].c_str(), m_TTree[MultipleEntries]);
487  if (m_TTree[SingleEntries] != nullptr)
488  {
489  TObjArray *branches = m_TTree[SingleEntries]->GetListOfBranches();
490  TIter iter(branches);
491  while (TBranch *thisbranch = static_cast<TBranch *>(iter.Next()))
492  {
493  // this convoluted expression returns the data type of a split branch
494  std::string DataType = thisbranch->GetLeaf(thisbranch->GetName())->GetTypeName();
495  if (DataType == "Float_t")
496  {
497  auto itermap = m_SingleFloatEntryMap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<float>::quiet_NaN()));
498  m_TTree[SingleEntries]->SetBranchAddress(thisbranch->GetName(), &(itermap.first)->second);
499  }
500  else if (DataType == "Double_t")
501  {
502  auto itermap = m_SingleDoubleEntryMap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<double>::quiet_NaN()));
503  m_TTree[SingleEntries]->SetBranchAddress(thisbranch->GetName(), &(itermap.first)->second);
504  }
505  else if (DataType == "Int_t")
506  {
507  auto itermap = m_SingleIntEntryMap.insert(std::make_pair(thisbranch->GetName(), -99999));
508  m_TTree[SingleEntries]->SetBranchAddress(thisbranch->GetName(), &(itermap.first)->second);
509  }
510  else if (DataType == "ULong_t")
511  {
512  auto itermap = m_SingleUInt64EntryMap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<uint64_t>::max()));
513  m_TTree[SingleEntries]->SetBranchAddress(thisbranch->GetName(), &(itermap.first)->second);
514  }
515  else
516  {
517  std::cout << __PRETTY_FUNCTION__ << " data type " << DataType
518  << " in " << m_TTree[SingleEntries]->GetName()
519  << " from " << f->GetName()
520  << " not implemented" << std::endl;
521  gSystem->Exit(1);
522  }
523  }
524  m_TTree[SingleEntries]->GetEntry(0);
525  }
526  if (m_TTree[MultipleEntries] != nullptr)
527  {
528  TObjArray *branches = m_TTree[MultipleEntries]->GetListOfBranches();
529  TIter iter(branches);
530  std::map<std::string, float> floatvalmap;
531  std::map<std::string, double> doublevalmap;
532  std::map<std::string, int> intvalmap;
533  std::map<std::string, uint64_t> uint64valmap;
534  while (TBranch *thisbranch = static_cast<TBranch *>(iter.Next()))
535  {
536  // this convoluted expression returns the data type of a split branch
537  std::string DataType = thisbranch->GetLeaf(thisbranch->GetName())->GetTypeName();
538  if (DataType == "Float_t")
539  {
540  auto itermap = floatvalmap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<float>::quiet_NaN()));
541  m_TTree[MultipleEntries]->SetBranchAddress(thisbranch->GetName(), &(itermap.first)->second);
542  }
543  if (DataType == "Double_t")
544  {
545  auto itermap = doublevalmap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<double>::quiet_NaN()));
546  m_TTree[MultipleEntries]->SetBranchAddress(thisbranch->GetName(), &(itermap.first)->second);
547  }
548  if (DataType == "Int_t")
549  {
550  auto itermap = intvalmap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<int>::min()));
551  m_TTree[MultipleEntries]->SetBranchAddress(thisbranch->GetName(), &(itermap.first)->second);
552  }
553  if (DataType == "ULong_t")
554  {
555  auto itermap = uint64valmap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<uint64_t>::max()));
556  m_TTree[MultipleEntries]->SetBranchAddress(thisbranch->GetName(), &(itermap.first)->second);
557  }
558  }
559  for (auto entry = 0; entry < m_TTree[MultipleEntries]->GetEntries(); ++entry)
560  {
561  for (auto &field : floatvalmap)
562  {
563  field.second = std::numeric_limits<float>::quiet_NaN();
564  }
565  for (auto &field : doublevalmap)
566  {
567  field.second = std::numeric_limits<double>::quiet_NaN();
568  }
569  for (auto &field : intvalmap)
570  {
572  }
573  for (auto &field : uint64valmap)
574  {
575  field.second = std::numeric_limits<uint64_t>::max();
576  }
577  m_TTree[MultipleEntries]->GetEntry(entry);
578  int ID = intvalmap.find("IID")->second;
579  std::map<std::string, float> tmp_floatvalmap;
580  for (auto &field : floatvalmap)
581  {
582  if (std::isfinite(field.second))
583  {
584  tmp_floatvalmap.insert(std::make_pair(field.first, field.second));
585  }
586  }
587  if (!tmp_floatvalmap.empty())
588  {
589  m_FloatEntryMap.insert(std::make_pair(ID, tmp_floatvalmap));
590  }
591 
592  std::map<std::string, double> tmp_doublevalmap;
593  for (auto &field : doublevalmap)
594  {
595  if (std::isfinite(field.second))
596  {
597  tmp_doublevalmap.insert(std::make_pair(field.first, field.second));
598  }
599  }
600  if (!tmp_doublevalmap.empty())
601  {
602  m_DoubleEntryMap.insert(std::make_pair(ID, tmp_doublevalmap));
603  }
604 
605  std::map<std::string, int> tmp_intvalmap;
606  for (auto &field : intvalmap)
607  {
608  if (field.second != std::numeric_limits<int>::min() && field.first != "IID")
609  {
610  tmp_intvalmap.insert(std::make_pair(field.first, field.second));
611  }
612  }
613  if (!tmp_intvalmap.empty())
614  {
615  m_IntEntryMap.insert(std::make_pair(ID, tmp_intvalmap));
616  }
617 
618  std::map<std::string, uint64_t> tmp_uint64valmap;
619  for (auto &field : uint64valmap)
620  {
621  if (field.second != std::numeric_limits<uint64_t>::max())
622  {
623  tmp_uint64valmap.insert(std::make_pair(field.first, field.second));
624  }
625  }
626  if (!tmp_uint64valmap.empty())
627  {
628  m_UInt64EntryMap.insert(std::make_pair(ID, tmp_uint64valmap));
629  }
630  }
631  }
632  for (auto ttree : m_TTree)
633  {
634  delete ttree;
635  ttree = nullptr;
636  }
637  f->Close();
638  gROOT->cd(currdir.c_str()); // restore previous directory
639 }
640 
642 {
643  if (m_SingleFloatEntryMap.empty())
644  {
646  }
647  std::string fieldname = "F" + name;
648  auto singleiter = m_SingleFloatEntryMap.find(fieldname);
649  if (singleiter == m_SingleFloatEntryMap.end())
650  {
651  if (verbose > 0)
652  {
653  std::cout << "Could not find " << name << " in single float calibrations" << std::endl;
654  std::cout << "Existing values:" << std::endl;
655  for (auto &eiter : m_SingleFloatEntryMap)
656  {
657  std::string tmpstring = eiter.first;
658  tmpstring.erase(0, 1);
659  std::cout << "name : " << tmpstring << ", value " << eiter.second
660  << std::endl;
661  }
662  }
663  return std::numeric_limits<float>::quiet_NaN();
664  }
665  return singleiter->second;
666 }
667 
669 {
670  if (m_FloatEntryMap.empty())
671  {
673  }
674  auto channelmapiter = m_FloatEntryMap.find(channel);
675  if (channelmapiter == m_FloatEntryMap.end())
676  {
677  if (verbose > 0)
678  {
679  std::cout << PHWHERE << " Could not find channel " << channel
680  << " for " << name << " in float calibrations" << std::endl;
681  }
682  return std::numeric_limits<float>::quiet_NaN();
683  }
684  std::string fieldname = "F" + name;
685  auto calibiter = channelmapiter->second.find(fieldname);
686  if (calibiter == channelmapiter->second.end())
687  {
688  if (verbose > 0)
689  {
690  std::cout << "Could not find " << name << " among float calibrations of channel " << channel << std::endl;
691  }
692  return std::numeric_limits<float>::quiet_NaN();
693  }
694  return calibiter->second;
695 }
696 
698 {
699  if (m_SingleDoubleEntryMap.empty())
700  {
702  }
703  std::string fieldname = "D" + name;
704  auto singleiter = m_SingleDoubleEntryMap.find(fieldname);
705  if (singleiter == m_SingleDoubleEntryMap.end())
706  {
707  if (verbose > 0)
708  {
709  std::cout << "Could not find " << name << " in single double calibrations" << std::endl;
710  std::cout << "Existing values:" << std::endl;
711  for (auto &eiter : m_SingleDoubleEntryMap)
712  {
713  std::string tmpstring = eiter.first;
714  tmpstring.erase(0, 1);
715  std::cout << "name : " << tmpstring << ", value " << eiter.second
716  << std::endl;
717  }
718  }
719  return std::numeric_limits<double>::quiet_NaN();
720  }
721  return singleiter->second;
722 }
723 
725 {
726  if (m_DoubleEntryMap.empty())
727  {
729  }
730  auto channelmapiter = m_DoubleEntryMap.find(channel);
731  if (channelmapiter == m_DoubleEntryMap.end())
732  {
733  if (verbose > 0)
734  {
735  std::cout << PHWHERE << " Could not find channel " << channel
736  << " for " << name << " in double calibrations" << std::endl;
737  }
738  return std::numeric_limits<double>::quiet_NaN();
739  }
740  std::string fieldname = "D" + name;
741  auto calibiter = channelmapiter->second.find(fieldname);
742  if (calibiter == channelmapiter->second.end())
743  {
744  if (verbose > 0)
745  {
746  std::cout << "Could not find " << name << " among double calibrations for channel " << channel << std::endl;
747  }
748  return std::numeric_limits<double>::quiet_NaN();
749  }
750  return calibiter->second;
751 }
752 
754 {
755  if (m_SingleIntEntryMap.empty())
756  {
758  }
759  std::string fieldname = "I" + name;
760  auto singleiter = m_SingleIntEntryMap.find(fieldname);
761  if (singleiter == m_SingleIntEntryMap.end())
762  {
763  if (verbose > 0)
764  {
765  std::cout << "Could not find " << name << " in single int calibrations" << std::endl;
766  std::cout << "Existing values:" << std::endl;
767  for (auto &eiter : m_SingleIntEntryMap)
768  {
769  std::string tmpstring = eiter.first;
770  tmpstring.erase(0, 1);
771  std::cout << "name : " << tmpstring << ", value " << eiter.second
772  << std::endl;
773  }
774  }
776  }
777  return singleiter->second;
778 }
779 
781 {
782  if (m_IntEntryMap.empty())
783  {
785  }
786  auto channelmapiter = m_IntEntryMap.find(channel);
787  if (channelmapiter == m_IntEntryMap.end())
788  {
789  if (verbose > 0)
790  {
791  std::cout << PHWHERE << " Could not find channel " << channel
792  << " for " << name << " in int calibrations" << std::endl;
793  }
795  }
796  std::string fieldname = "I" + name;
797  auto calibiter = channelmapiter->second.find(fieldname);
798  if (calibiter == channelmapiter->second.end())
799  {
800  if (verbose > 0)
801  {
802  std::cout << "Could not find " << name << " among int calibrations for channel " << channel << std::endl;
803  }
805  }
806  return calibiter->second;
807 }
808 
810 {
811  if (m_SingleUInt64EntryMap.empty())
812  {
814  }
815  std::string fieldname = "g" + name;
816  auto singleiter = m_SingleUInt64EntryMap.find(fieldname);
817  if (singleiter == m_SingleUInt64EntryMap.end())
818  {
819  if (verbose > 0)
820  {
821  std::cout << "Could not find " << name << " in single uint64 calibrations" << std::endl;
822  std::cout << "Existing values:" << std::endl;
823  for (auto &eiter : m_SingleUInt64EntryMap)
824  {
825  std::string tmpstring = eiter.first;
826  tmpstring.erase(0, 1);
827  std::cout << "name : " << tmpstring << ", value " << eiter.second
828  << std::endl;
829  }
830  }
831  return std::numeric_limits<uint64_t>::max();
832  }
833  return singleiter->second;
834 }
835 
837 {
838  if (m_UInt64EntryMap.empty())
839  {
841  }
842  auto channelmapiter = m_UInt64EntryMap.find(channel);
843  if (channelmapiter == m_UInt64EntryMap.end())
844  {
845  if (verbose > 0)
846  {
847  std::cout << "Could not find channel " << channel << " in unint64 calibrations" << std::endl;
848  }
849  return std::numeric_limits<uint64_t>::max();
850  }
851  std::string fieldname = "g" + name;
852  auto calibiter = channelmapiter->second.find(fieldname);
853  if (calibiter == channelmapiter->second.end())
854  {
855  if (verbose > 0)
856  {
857  std::cout << PHWHERE << " Could not find channel " << channel
858  << " for " << name << " in uint64_t calibrations" << std::endl;
859  }
860  return std::numeric_limits<uint64_t>::max();
861  }
862  return calibiter->second;
863 }