5 #ifndef AthenaMonitoringKernel_HistogramFiller_HistogramFillerTree_h
6 #define AthenaMonitoringKernel_HistogramFiller_HistogramFillerTree_h
11 #include <boost/algorithm/string.hpp>
15 template <>
void scalarFillerFunc<std::string>(TBranch*
branch,
const IMonitoredVariable&
var);
17 template <>
void vectorFillerFunc<std::string>(TBranch*
branch,
const IMonitoredVariable&
var);
32 if (cutMaskValuePair.first == 0) {
return 0; }
35 log << MSG::WARNING <<
"HistogramFillerTree (" <<
m_histDef->alias
36 <<
") does not support more than a single entry being filled at a time\n"
37 <<
"so a cut mask with > 1 entry doesn't make sense. Using first entry only." <<
endmsg;
38 if (! cutMaskValuePair.second(0)) {
return 0; }
43 log << MSG::ERROR <<
"Mismatch of passed variables and expected variables for " <<
m_histDef->alias
48 auto cutMaskAccessor = cutMaskValuePair.second;
50 auto tree = this->histogram<TTree>();
51 if (
tree->GetListOfBranches()->GetEntries() == 0) {
54 auto branchList =
tree->GetListOfBranches();
56 size_t idx = 0, idxgood = 0;
61 TBranch*
branch =
static_cast<TBranch*
>(branchList->At(idxgood));
65 for (Int_t
i = 0;
i < branchList->GetEntries(); ++
i) {
69 tree->SetEntries(
tree->GetEntries() + 1);
78 std::vector<std::string> tokenized;
80 for (
const auto& token : tokenized) {
81 auto ipart = token.find(
'/');
82 if (ipart == std::string::npos) {
84 log << MSG::ERROR <<
"Tree " <<
m_histDef->alias <<
": Badly formed variable definition " << token
88 auto branch = token.substr(0, ipart);
89 auto type = token.substr(ipart+1);
92 if (
type ==
"B") fillerFunc = scalarFillerFunc<Char_t>;
93 else if (
type ==
"b") fillerFunc = scalarFillerFunc<UChar_t>;
94 else if (
type ==
"S") fillerFunc = scalarFillerFunc<Short_t>;
95 else if (
type ==
"s") fillerFunc = scalarFillerFunc<UShort_t>;
96 else if (
type ==
"I") fillerFunc = scalarFillerFunc<Int_t>;
97 else if (
type ==
"i") fillerFunc = scalarFillerFunc<UInt_t>;
98 else if (
type ==
"F") fillerFunc = scalarFillerFunc<Float_t>;
99 else if (
type ==
"f") fillerFunc = scalarFillerFunc<Float16_t>;
100 else if (
type ==
"D") fillerFunc = scalarFillerFunc<Double_t>;
101 else if (
type ==
"d") fillerFunc = scalarFillerFunc<Double32_t>;
102 else if (
type ==
"L") fillerFunc = scalarFillerFunc<Long64_t>;
103 else if (
type ==
"l") fillerFunc = scalarFillerFunc<ULong64_t>;
104 else if (
type ==
"O") fillerFunc = scalarFillerFunc<Bool_t>;
105 else if (
type ==
"string") fillerFunc = scalarFillerFunc<std::string>;
106 else if (
type ==
"vector<char>") fillerFunc = vectorFillerFunc<char>;
107 else if (
type ==
"vector<unsigned char>") fillerFunc = vectorFillerFunc<unsigned char>;
108 else if (
type ==
"vector<int>") fillerFunc = vectorFillerFunc<int>;
109 else if (
type ==
"vector<unsigned int>") fillerFunc = vectorFillerFunc<unsigned int>;
110 else if (
type ==
"vector<float>") fillerFunc = vectorFillerFunc<float>;
111 else if (
type ==
"vector<double>") fillerFunc = vectorFillerFunc<double>;
112 else if (
type ==
"vector<long>") fillerFunc = vectorFillerFunc<long>;
113 else if (
type ==
"vector<unsigned long>") fillerFunc = vectorFillerFunc<unsigned long>;
114 else if (
type ==
"vector<string>") fillerFunc = vectorFillerFunc<std::string>;
115 else if (
type ==
"C") {
117 log << MSG::ERROR <<
"Tree " <<
m_histDef->alias <<
": Branch type \"C\" not supported for branch" <<
branch
118 <<
"; please use \"string\"" <<
endmsg;
122 log << MSG::ERROR <<
"Tree " <<
m_histDef->alias <<
": Unrecognized branch type " <<
type <<
" for branch " <<
branch
123 <<
"; ignoring branch " <<
endmsg;
131 template <
typename T>
133 std::vector<T>
dummy;
134 std::vector<T>* dummyptr = &
dummy;
136 tree->Branch(brdef.first.c_str(), &dummyptr);
141 if (brdef.second ==
"vector<char>") branchHelper<char>(
tree, brdef);
142 else if (brdef.second ==
"vector<unsigned char>") branchHelper<unsigned char>(
tree, brdef);
143 else if (brdef.second ==
"vector<int>") branchHelper<int>(
tree, brdef);
144 else if (brdef.second ==
"vector<unsigned int>") branchHelper<unsigned int>(
tree, brdef);
145 else if (brdef.second ==
"vector<float>") branchHelper<float>(
tree, brdef);
146 else if (brdef.second ==
"vector<double>") branchHelper<double>(
tree, brdef);
147 else if (brdef.second ==
"vector<long>") branchHelper<long>(
tree, brdef);
148 else if (brdef.second ==
"vector<unsigned long>") branchHelper<unsigned long>(
tree, brdef);
149 else if (brdef.second ==
"vector<string>") branchHelper<std::string>(
tree, brdef);
150 else if (brdef.second ==
"string") {
152 }
else if (brdef.second !=
"IGNORE") {
153 tree->Branch(brdef.first.c_str(), (
void*)
nullptr, (brdef.first+
"/"+brdef.second).c_str());
160 template <
typename T>
164 log << MSG::WARNING <<
"Tree " <<
branch->GetTree()->GetName() <<
": Empty value passed to scalar branch fill for"
168 T tofill =
var.get(0);
179 log << MSG::WARNING <<
"Tree " <<
branch->GetTree()->GetName() <<
": Empty value passed to scalar branch fill for"
183 std::string tofill{
var.getString(0)};
184 branch->SetObject(&tofill);
189 template <
typename T>
191 std::vector<T> tofill;
192 tofill.reserve(
var.size());
193 for (
size_t i = 0;
i <
var.size();
i++) {
194 tofill.push_back(
var.get(
i));
196 std::vector<T>* tofillptr = &tofill;
197 branch->SetAddress(&tofillptr);
204 std::vector<std::string> tofill;
205 tofill.reserve(
var.size());
206 for (
size_t i = 0;
i <
var.size();
i++) {
207 tofill.push_back(
var.getString(
i));
209 auto* tofillptr = &tofill;
210 branch->SetAddress(&tofillptr);
215 #endif // AthenaMonitoringKernel_HistogramFiller_HistogramFillerTree_h