5#ifndef AthenaMonitoringKernel_HistogramFiller_HistogramFillerTree_h
6#define AthenaMonitoringKernel_HistogramFiller_HistogramFillerTree_h
11#include <boost/algorithm/string.hpp>
32 const size_t maskSize = vars.
cut->
size();
34 if (maskSize == 0 || (maskSize == 1 && !vars.
cut->
get(0))) {
return 0; }
38 log << MSG::WARNING <<
"HistogramFillerTree (" <<
m_histDef->alias
39 <<
") does not support more than a single entry being filled at a time\n"
40 <<
"so a cut mask with > 1 entry doesn't make sense. Using first entry only." <<
endmsg;
41 if (!vars.
cut->
get(0)) {
return 0; }
47 log << MSG::ERROR <<
"Mismatch of passed variables and expected variables for " <<
m_histDef->alias
53 if (
tree->GetListOfBranches()->GetEntries() == 0) {
56 auto branchList =
tree->GetListOfBranches();
58 size_t idx = 0, idxgood = 0;
63 TBranch* branch =
static_cast<TBranch*
>(branchList->At(idxgood));
67 for (Int_t i = 0; i < branchList->GetEntries(); ++i) {
71 tree->SetEntries(
tree->GetEntries() + 1);
80 std::vector<std::string> tokenized;
81 boost::split(tokenized,
m_histDef->treeDef, [](
char c){ return c ==
':'; });
82 for (
const auto& token : tokenized) {
83 auto ipart = token.find(
'/');
84 if (ipart == std::string::npos) {
86 log << MSG::ERROR <<
"Tree " <<
m_histDef->alias <<
": Badly formed variable definition " << token
90 auto branch = token.substr(0, ipart);
91 auto type = token.substr(ipart+1);
117 else if (
type ==
"C") {
119 log << MSG::ERROR <<
"Tree " <<
m_histDef->alias <<
": Branch type \"C\" not supported for branch" << branch
120 <<
"; please use \"string\"" <<
endmsg;
124 log << MSG::ERROR <<
"Tree " <<
m_histDef->alias <<
": Unrecognized branch type " <<
type <<
" for branch " << branch
125 <<
"; ignoring branch " <<
endmsg;
133 template <
typename T>
135 std::vector<T> dummy;
136 std::vector<T>* dummyptr = &dummy;
138 tree->Branch(brdef.first.c_str(), &dummyptr);
152 else if (brdef.second ==
"string") {
153 std::string dummy;
tree->Branch(brdef.first.c_str(), &dummy);
154 }
else if (brdef.second !=
"IGNORE") {
155 tree->Branch(brdef.first.c_str(), (
void*)
nullptr, (brdef.first+
"/"+brdef.second).c_str());
162 template <
typename T>
166 log << MSG::WARNING <<
"Tree " << branch->GetTree()->GetName() <<
": Empty value passed to scalar branch fill for"
167 << branch->GetName() <<
endmsg;
170 T tofill = var.get(0);
172 branch->SetAddress(ptr);
181 log << MSG::WARNING <<
"Tree " << branch->GetTree()->GetName() <<
": Empty value passed to scalar branch fill for"
182 << branch->GetName() <<
endmsg;
185 std::string tofill{var.getString(0)};
186 branch->SetObject(&tofill);
191 template <
typename T>
193 std::vector<T> tofill;
194 tofill.reserve(var.size());
195 for (
size_t i = 0; i < var.size(); i++) {
196 tofill.push_back(var.get(i));
198 std::vector<T>* tofillptr = &tofill;
199 branch->SetAddress(&tofillptr);
206 std::vector<std::string> tofill;
207 tofill.reserve(var.size());
208 for (
size_t i = 0; i < var.size(); i++) {
209 tofill.push_back(var.getString(i));
211 auto* tofillptr = &tofill;
212 branch->SetAddress(&tofillptr);
std::vector< std::function< void(TBranch *, const IMonitoredVariable &)> > m_fillerFunctions
std::vector< std::pair< std::string, std::string > > m_branchDefs
virtual unsigned fill(const HistogramFiller::VariablesPack &vars) const override
Method that actually fills the ROOT object.
HistogramFillerTree(const HistogramDef &definition, std::shared_ptr< IHistogramProvider > provider)
void branchHelper(TTree *tree, const std::pair< std::string, std::string > &brdef) const
void createBranches(TTree *tree) const
HistogramFiller(const HistogramDef &histDef, std::shared_ptr< IHistogramProvider > histogramProvider)
Default constructor.
std::shared_ptr< HistogramDef > m_histDef
virtual double get(size_t) const =0
virtual size_t size() const =0
gives size of vector representation
IMessageSvc * getMessageSvc(bool quiet=false)
Generic monitoring tool for athena components.
void vectorFillerFunc< std::string >(TBranch *branch, const IMonitoredVariable &var)
void scalarFillerFunc< std::string >(TBranch *branch, const IMonitoredVariable &var)
void vectorFillerFunc(TBranch *branch, const IMonitoredVariable &var)
void scalarFillerFunc(TBranch *branch, const IMonitoredVariable &var)
the internal class used to keep parsed Filler properties
helper class to pass variables to fillers
const Monitored::IMonitoredVariable * cut
pointer to cut mask variable, typically absent
size_t size() const
number of variables in the pack ( not counting the weight and mask )