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 tree = this->histogram<TTree>();
49 if (
tree->GetListOfBranches()->GetEntries() == 0) {
52 auto branchList =
tree->GetListOfBranches();
54 size_t idx = 0, idxgood = 0;
59 TBranch*
branch =
static_cast<TBranch*
>(branchList->At(idxgood));
63 for (Int_t
i = 0;
i < branchList->GetEntries(); ++
i) {
67 tree->SetEntries(
tree->GetEntries() + 1);
76 std::vector<std::string> tokenized;
78 for (
const auto& token : tokenized) {
79 auto ipart = token.find(
'/');
80 if (ipart == std::string::npos) {
82 log << MSG::ERROR <<
"Tree " <<
m_histDef->alias <<
": Badly formed variable definition " << token
86 auto branch = token.substr(0, ipart);
87 auto type = token.substr(ipart+1);
90 if (
type ==
"B") fillerFunc = scalarFillerFunc<Char_t>;
91 else if (
type ==
"b") fillerFunc = scalarFillerFunc<UChar_t>;
92 else if (
type ==
"S") fillerFunc = scalarFillerFunc<Short_t>;
93 else if (
type ==
"s") fillerFunc = scalarFillerFunc<UShort_t>;
94 else if (
type ==
"I") fillerFunc = scalarFillerFunc<Int_t>;
95 else if (
type ==
"i") fillerFunc = scalarFillerFunc<UInt_t>;
96 else if (
type ==
"F") fillerFunc = scalarFillerFunc<Float_t>;
97 else if (
type ==
"f") fillerFunc = scalarFillerFunc<Float16_t>;
98 else if (
type ==
"D") fillerFunc = scalarFillerFunc<Double_t>;
99 else if (
type ==
"d") fillerFunc = scalarFillerFunc<Double32_t>;
100 else if (
type ==
"L") fillerFunc = scalarFillerFunc<Long64_t>;
101 else if (
type ==
"l") fillerFunc = scalarFillerFunc<ULong64_t>;
102 else if (
type ==
"O") fillerFunc = scalarFillerFunc<Bool_t>;
103 else if (
type ==
"string") fillerFunc = scalarFillerFunc<std::string>;
104 else if (
type ==
"vector<char>") fillerFunc = vectorFillerFunc<char>;
105 else if (
type ==
"vector<unsigned char>") fillerFunc = vectorFillerFunc<unsigned char>;
106 else if (
type ==
"vector<int>") fillerFunc = vectorFillerFunc<int>;
107 else if (
type ==
"vector<unsigned int>") fillerFunc = vectorFillerFunc<unsigned int>;
108 else if (
type ==
"vector<float>") fillerFunc = vectorFillerFunc<float>;
109 else if (
type ==
"vector<double>") fillerFunc = vectorFillerFunc<double>;
110 else if (
type ==
"vector<long>") fillerFunc = vectorFillerFunc<long>;
111 else if (
type ==
"vector<unsigned long>") fillerFunc = vectorFillerFunc<unsigned long>;
112 else if (
type ==
"vector<string>") fillerFunc = vectorFillerFunc<std::string>;
113 else if (
type ==
"C") {
115 log << MSG::ERROR <<
"Tree " <<
m_histDef->alias <<
": Branch type \"C\" not supported for branch" <<
branch
116 <<
"; please use \"string\"" <<
endmsg;
120 log << MSG::ERROR <<
"Tree " <<
m_histDef->alias <<
": Unrecognized branch type " <<
type <<
" for branch " <<
branch
121 <<
"; ignoring branch " <<
endmsg;
129 template <
typename T>
131 std::vector<T>
dummy;
132 std::vector<T>* dummyptr = &
dummy;
134 tree->Branch(brdef.first.c_str(), &dummyptr);
139 if (brdef.second ==
"vector<char>") branchHelper<char>(
tree, brdef);
140 else if (brdef.second ==
"vector<unsigned char>") branchHelper<unsigned char>(
tree, brdef);
141 else if (brdef.second ==
"vector<int>") branchHelper<int>(
tree, brdef);
142 else if (brdef.second ==
"vector<unsigned int>") branchHelper<unsigned int>(
tree, brdef);
143 else if (brdef.second ==
"vector<float>") branchHelper<float>(
tree, brdef);
144 else if (brdef.second ==
"vector<double>") branchHelper<double>(
tree, brdef);
145 else if (brdef.second ==
"vector<long>") branchHelper<long>(
tree, brdef);
146 else if (brdef.second ==
"vector<unsigned long>") branchHelper<unsigned long>(
tree, brdef);
147 else if (brdef.second ==
"vector<string>") branchHelper<std::string>(
tree, brdef);
148 else if (brdef.second ==
"string") {
150 }
else if (brdef.second !=
"IGNORE") {
151 tree->Branch(brdef.first.c_str(), (
void*)
nullptr, (brdef.first+
"/"+brdef.second).c_str());
158 template <
typename T>
162 log << MSG::WARNING <<
"Tree " <<
branch->GetTree()->GetName() <<
": Empty value passed to scalar branch fill for"
166 T tofill =
var.get(0);
177 log << MSG::WARNING <<
"Tree " <<
branch->GetTree()->GetName() <<
": Empty value passed to scalar branch fill for"
181 std::string tofill{
var.getString(0)};
182 branch->SetObject(&tofill);
187 template <
typename T>
189 std::vector<T> tofill;
190 tofill.reserve(
var.size());
191 for (
size_t i = 0;
i <
var.size();
i++) {
192 tofill.push_back(
var.get(
i));
194 std::vector<T>* tofillptr = &tofill;
195 branch->SetAddress(&tofillptr);
202 std::vector<std::string> tofill;
203 tofill.reserve(
var.size());
204 for (
size_t i = 0;
i <
var.size();
i++) {
205 tofill.push_back(
var.getString(
i));
207 auto* tofillptr = &tofill;
208 branch->SetAddress(&tofillptr);
213 #endif // AthenaMonitoringKernel_HistogramFiller_HistogramFillerTree_h