6 #include <TCollection.h>
7 #include <TDirectory.h>
10 #include <TObjArray.h>
38 std::cout <<
"Sorry ID is reserved as fieldname, pick anything else" << std::endl;
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;
55 std::cout <<
"Sorry ID is reserved as fieldname, pick anything else" << std::endl;
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;
72 std::cout <<
"Sorry ID is reserved as fieldname, pick anything else" << std::endl;
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;
89 std::cout <<
"Sorry ID is reserved as fieldname, pick anything else" << std::endl;
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;
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;
118 id_set.insert(f_entry.first);
119 for (
auto &f_val : f_entry.second)
121 floatmap.insert(std::make_pair(f_val.first, std::numeric_limits<float>::quiet_NaN()));
124 for (
auto &f_val : floatmap)
132 id_set.insert(f_entry.first);
133 for (
auto &f_val : f_entry.second)
135 doublemap.insert(std::make_pair(f_val.first, std::numeric_limits<double>::quiet_NaN()));
138 for (
auto &f_val : doublemap)
146 id_set.insert(i_entry.first);
147 for (
auto &i_val : i_entry.second)
152 for (
auto &i_val : intmap)
160 id_set.insert(i_entry.first);
161 for (
auto &i_val : i_entry.second)
163 uint64map.insert(std::make_pair(i_val.first, std::numeric_limits<uint64_t>::max()));
166 for (
auto &i_val : uint64map)
172 for (
auto ids : id_set)
175 auto fmapiter = m_FloatEntryMap.find(
ids);
176 if (fmapiter != m_FloatEntryMap.end())
178 for (
auto &f_val : fmapiter->second)
180 floatmap[f_val.first] = f_val.second;
183 auto dmapiter = m_DoubleEntryMap.find(
ids);
184 if (dmapiter != m_DoubleEntryMap.end())
186 for (
auto &d_val : dmapiter->second)
188 doublemap[d_val.first] = d_val.second;
191 auto imapiter = m_IntEntryMap.find(
ids);
192 if (imapiter != m_IntEntryMap.end())
194 for (
auto &i_val : imapiter->second)
196 intmap[i_val.first] = i_val.second;
199 auto uint64mapiter = m_UInt64EntryMap.find(
ids);
200 if (uint64mapiter != m_UInt64EntryMap.end())
202 for (
auto &uint64_val : uint64mapiter->second)
204 uint64map[uint64_val.first] = uint64_val.second;
208 for (
auto &f_val : floatmap)
210 f_val.second = std::numeric_limits<float>::quiet_NaN();
212 for (
auto &f_val : doublemap)
214 f_val.second = std::numeric_limits<double>::quiet_NaN();
216 for (
auto &i_val : intmap)
220 for (
auto &i_val : uint64map)
222 i_val.second = std::numeric_limits<uint64_t>::max();
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;
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;
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;
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;
334 std::cout <<
"Number of float entries: " <<
m_FloatEntryMap.size() << std::endl;
337 std::cout <<
"ID: " <<
field.first << std::endl;
338 for (
auto &calibs :
field.second)
341 tmpstring.erase(0, 1);
342 std::cout <<
"name " << tmpstring <<
" value: " << calibs.second << std::endl;
345 std::cout <<
"--------------------------------------------------" << std::endl
350 std::cout <<
"Number of double entries: " <<
m_DoubleEntryMap.size() << std::endl;
353 std::cout <<
"ID: " <<
field.first << std::endl;
354 for (
auto &calibs :
field.second)
357 tmpstring.erase(0, 1);
358 std::cout <<
"name " << tmpstring <<
" value: " << calibs.second << std::endl;
361 std::cout <<
"--------------------------------------------------" << std::endl
366 std::cout <<
"Number of int entries: " <<
m_IntEntryMap.size() << std::endl;
369 std::cout <<
"ID: " <<
field.first << std::endl;
370 for (
auto &calibs :
field.second)
373 tmpstring.erase(0, 1);
374 std::cout <<
"name " << tmpstring <<
" value: " << calibs.second << std::endl;
380 std::cout <<
"Number of uint64 entries: " <<
m_UInt64EntryMap.size() << std::endl;
383 std::cout <<
"ID: " <<
field.first << std::endl;
384 for (
auto &calibs :
field.second)
387 tmpstring.erase(0, 1);
388 std::cout <<
"name " << tmpstring <<
" value: " << calibs.second << std::endl;
399 tmpstring.erase(0, 1);
400 std::cout << tmpstring <<
" value " <<
field.second << std::endl;
407 std::ios oldState(
nullptr);
408 oldState.copyfmt(std::cout);
409 std::cout.precision(std::numeric_limits<double>::max_digits10);
413 tmpstring.erase(0, 1);
414 std::cout << tmpstring <<
" value " <<
field.second << std::endl;
416 std::cout.copyfmt(oldState);
424 tmpstring.erase(0, 1);
425 std::cout << tmpstring <<
" value " <<
field.second << std::endl;
434 tmpstring.erase(0, 1);
435 std::cout << tmpstring <<
" value " <<
field.second << std::endl;
446 std::cout <<
"You need to call CDBTTree::CommitSingle() before writing" << std::endl;
453 std::cout <<
"You need to call CDBTTree::Commit() before writing" << std::endl;
456 if (empty_single && empty_multiple)
458 std::cout <<
"no values to be saved" << std::endl;
464 TFile *
f = TFile::Open(
m_Filename.c_str(),
"RECREATE");
477 gROOT->cd(currdir.c_str());
487 if (
m_TTree[SingleEntries] !=
nullptr)
490 TIter iter(branches);
491 while (TBranch *thisbranch = static_cast<TBranch *>(iter.Next()))
495 if (DataType ==
"Float_t")
497 auto itermap =
m_SingleFloatEntryMap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<float>::quiet_NaN()));
500 else if (DataType ==
"Double_t")
502 auto itermap =
m_SingleDoubleEntryMap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<double>::quiet_NaN()));
505 else if (DataType ==
"Int_t")
510 else if (DataType ==
"ULong_t")
512 auto itermap =
m_SingleUInt64EntryMap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<uint64_t>::max()));
517 std::cout << __PRETTY_FUNCTION__ <<
" data type " << DataType
519 <<
" from " << f->GetName()
520 <<
" not implemented" << std::endl;
526 if (
m_TTree[MultipleEntries] !=
nullptr)
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()))
538 if (DataType ==
"Float_t")
540 auto itermap = floatvalmap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<float>::quiet_NaN()));
543 if (DataType ==
"Double_t")
545 auto itermap = doublevalmap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<double>::quiet_NaN()));
548 if (DataType ==
"Int_t")
553 if (DataType ==
"ULong_t")
555 auto itermap = uint64valmap.insert(std::make_pair(thisbranch->GetName(), std::numeric_limits<uint64_t>::max()));
561 for (
auto &
field : floatvalmap)
563 field.second = std::numeric_limits<float>::quiet_NaN();
565 for (
auto &
field : doublevalmap)
567 field.second = std::numeric_limits<double>::quiet_NaN();
569 for (
auto &
field : intvalmap)
573 for (
auto &
field : uint64valmap)
575 field.second = std::numeric_limits<uint64_t>::max();
578 int ID = intvalmap.find(
"IID")->second;
579 std::map<std::string, float> tmp_floatvalmap;
580 for (
auto &
field : floatvalmap)
582 if (std::isfinite(
field.second))
584 tmp_floatvalmap.insert(std::make_pair(
field.first,
field.second));
587 if (!tmp_floatvalmap.empty())
592 std::map<std::string, double> tmp_doublevalmap;
593 for (
auto &
field : doublevalmap)
595 if (std::isfinite(
field.second))
597 tmp_doublevalmap.insert(std::make_pair(
field.first,
field.second));
600 if (!tmp_doublevalmap.empty())
605 std::map<std::string, int> tmp_intvalmap;
606 for (
auto &
field : intvalmap)
610 tmp_intvalmap.insert(std::make_pair(
field.first,
field.second));
613 if (!tmp_intvalmap.empty())
618 std::map<std::string, uint64_t> tmp_uint64valmap;
619 for (
auto &
field : uint64valmap)
621 if (
field.second != std::numeric_limits<uint64_t>::max())
623 tmp_uint64valmap.insert(std::make_pair(
field.first,
field.second));
626 if (!tmp_uint64valmap.empty())
638 gROOT->cd(currdir.c_str());
653 std::cout <<
"Could not find " << name <<
" in single float calibrations" << std::endl;
654 std::cout <<
"Existing values:" << std::endl;
658 tmpstring.erase(0, 1);
659 std::cout <<
"name : " << tmpstring <<
", value " << eiter.second
663 return std::numeric_limits<float>::quiet_NaN();
665 return singleiter->second;
679 std::cout <<
PHWHERE <<
" Could not find channel " << channel
680 <<
" for " << name <<
" in float calibrations" << std::endl;
682 return std::numeric_limits<float>::quiet_NaN();
685 auto calibiter = channelmapiter->second.find(fieldname);
686 if (calibiter == channelmapiter->second.end())
690 std::cout <<
"Could not find " << name <<
" among float calibrations of channel " << channel << std::endl;
692 return std::numeric_limits<float>::quiet_NaN();
694 return calibiter->second;
709 std::cout <<
"Could not find " << name <<
" in single double calibrations" << std::endl;
710 std::cout <<
"Existing values:" << std::endl;
714 tmpstring.erase(0, 1);
715 std::cout <<
"name : " << tmpstring <<
", value " << eiter.second
719 return std::numeric_limits<double>::quiet_NaN();
721 return singleiter->second;
735 std::cout <<
PHWHERE <<
" Could not find channel " << channel
736 <<
" for " << name <<
" in double calibrations" << std::endl;
738 return std::numeric_limits<double>::quiet_NaN();
741 auto calibiter = channelmapiter->second.find(fieldname);
742 if (calibiter == channelmapiter->second.end())
746 std::cout <<
"Could not find " << name <<
" among double calibrations for channel " << channel << std::endl;
748 return std::numeric_limits<double>::quiet_NaN();
750 return calibiter->second;
765 std::cout <<
"Could not find " << name <<
" in single int calibrations" << std::endl;
766 std::cout <<
"Existing values:" << std::endl;
770 tmpstring.erase(0, 1);
771 std::cout <<
"name : " << tmpstring <<
", value " << eiter.second
777 return singleiter->second;
791 std::cout <<
PHWHERE <<
" Could not find channel " << channel
792 <<
" for " << name <<
" in int calibrations" << std::endl;
797 auto calibiter = channelmapiter->second.find(fieldname);
798 if (calibiter == channelmapiter->second.end())
802 std::cout <<
"Could not find " << name <<
" among int calibrations for channel " << channel << std::endl;
806 return calibiter->second;
821 std::cout <<
"Could not find " << name <<
" in single uint64 calibrations" << std::endl;
822 std::cout <<
"Existing values:" << std::endl;
826 tmpstring.erase(0, 1);
827 std::cout <<
"name : " << tmpstring <<
", value " << eiter.second
831 return std::numeric_limits<uint64_t>::max();
833 return singleiter->second;
847 std::cout <<
"Could not find channel " << channel <<
" in unint64 calibrations" << std::endl;
849 return std::numeric_limits<uint64_t>::max();
852 auto calibiter = channelmapiter->second.find(fieldname);
853 if (calibiter == channelmapiter->second.end())
857 std::cout <<
PHWHERE <<
" Could not find channel " << channel
858 <<
" for " << name <<
" in uint64_t calibrations" << std::endl;
860 return std::numeric_limits<uint64_t>::max();
862 return calibiter->second;