11#include <TProfile2D.h>
26 return StatusCode::SUCCESS;
34 return StatusCode::SUCCESS;
42 SmartIF<IIncidentSvc> incSvc{service(
"IncidentSvc")};
44 incSvc->removeListener(
this, IncidentType::BeginEvent);
46 return StatusCode::SUCCESS;
59 auto named =
dynamic_cast<const INamedInterface*
>(parent());
79 std::shared_ptr<HistogramFiller> filler(factory.
create(def));
95 return StatusCode::FAILURE;
103 ATH_MSG_ERROR(
"No monitored variables created based on histogram definition: [" << hists <<
104 "] Remove this monitoring tool or check its configuration.");
105 return StatusCode::FAILURE;
112 SmartIF<IIncidentSvc> incSvc{service(
"IncidentSvc")};
114 incSvc->addListener(
this, IncidentType::BeginEvent);
117 return StatusCode::SUCCESS;
121 std::ostream&
operator<< ( std::ostream& os,
const std::reference_wrapper<Monitored::IMonitoredVariable>& rmv ) {
122 std::string s = rmv.get().name();
128 void invokeFillersDebug(MsgStream& log,
130 const std::shared_ptr<Monitored::HistogramFiller>& filler,
131 const std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>>& monitoredVariables) {
132 bool reasonFound =
false;
135 log << MSG::DEBUG <<
"Filler weight not found in monitoredVariables:"
136 <<
"\n Filler weight : " << filler->histogramWeightName()
137 <<
"\n Asked to fill from mon. tl_vars: " << monitoredVariables <<
endmsg;
139 if (
ATH_UNLIKELY(!filler->histogramCutMaskName().empty() && !vars.
cut)) {
141 log << MSG::DEBUG <<
"Filler cut mask not found in monitoredVariables:"
142 <<
"\n Filler cut mask : " << filler->histogramCutMaskName()
143 <<
"\n Asked to fill from mon. tl_vars: " << monitoredVariables <<
endmsg;
145 if ( not reasonFound ) {
146 log << MSG::DEBUG <<
"Filler has different variables than monitoredVariables:"
147 <<
"\n Filler variables : " << filler->histogramVariablesNames()
148 <<
"\n Asked to fill from mon. tl_vars: " << monitoredVariables
149 <<
"\n Selected monitored variables: " << vars.
names() <<
endmsg;
158 std::string fillerKey(
const std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>>& v) {
160 for (
const auto& m : v)
r.append(
m.get().name());
168 const std::vector<std::shared_ptr<Monitored::HistogramFiller>>* fillerList{&
m_fillers};
170 std::optional<std::vector<std::shared_ptr<Monitored::HistogramFiller>> > matchedFillerList;
172 const auto match = m_fillerCacheMap.find(fillerKey(monitoredVariables));
173 if (
match != m_fillerCacheMap.end()) {
174 fillerList = &
match->second;
177 matchedFillerList.emplace();
181 for (
auto filler: *fillerList ) {
182 const int fillerCardinality = filler->histogramVariablesNames().size() + (filler->histogramWeightName().
empty() ? 0: 1) + (filler->histogramCutMaskName().
empty() ? 0 : 1);
184 if ( fillerCardinality == 1 ) {
185 for (
auto& var: monitoredVariables ) {
186 if ( var.get().name().compare( filler->histogramVariablesNames()[0] ) == 0 ) {
188 auto guard{filler->getLock()};
189 filler->fill({&var.get()});
191 if (matchedFillerList) {
192 matchedFillerList->push_back(std::move(filler));
198 int matchesCount = 0;
200 for (
const auto& var: monitoredVariables ) {
201 bool matched =
false;
202 for (
unsigned fillerVarIndex = 0; fillerVarIndex < filler->histogramVariablesNames().size(); ++fillerVarIndex ) {
203 if ( var.get().name().compare( filler->histogramVariablesNames()[fillerVarIndex] ) == 0 ) {
204 vars.
set(fillerVarIndex, &var.get());
210 if ( matchesCount == fillerCardinality )
break;
212 if ( var.get().name().compare( filler->histogramWeightName() ) == 0 ) {
215 }
else if ( var.get().name().compare( filler->histogramCutMaskName() ) == 0 ) {
216 vars.
cut = &var.get();
220 if ( matchesCount == fillerCardinality )
break;
222 if ( matchesCount == fillerCardinality ) {
224 auto guard{filler->getLock()};
225 filler->fill( vars );
227 if (matchedFillerList) {
228 matchedFillerList->push_back(std::move(filler));
230 }
else if (
ATH_UNLIKELY( msgLvl(MSG::DEBUG) && matchesCount != 0 ) ) {
231 invokeFillersDebug(
msg(), vars, filler, monitoredVariables);
236 if (matchedFillerList) {
239 m_fillerCacheMap.emplace(fillerKey(monitoredVariables), std::move(*matchedFillerList));
244 return Gaudi::Hive::currentContext().eventID().run_number();
248 return Gaudi::Hive::currentContext().eventID().lumi_block();
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
static const Attributes_t empty
Factory of the histogram fillers.
HistogramFiller * create(const HistogramDef &def)
Creates HistogramFiller instance for given definition.
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Generic monitoring tool for athena components.
std::ostream & operator<<(std::ostream &os, const std::reference_wrapper< Monitored::IMonitoredVariable > &rmv)
the internal class used to keep parsed Filler properties
bool kAlwaysCreate
always create this histogram, even if never filled
static const HistogramDef parse(const std::string &histogramDefinition)
Parses histogram defintion from json data.
bool ok
good declaration: parsing or copying successful
std::vector< std::string > name
names of monitored variables
helper class to pass variables to fillers
const Monitored::IMonitoredVariable * cut
pointer to cut mask variable, typically absent
std::vector< std::string > names() const
names of all variables stored
void set(unsigned index, const IMonitoredVariable *ptr)
sets monitored variable at the index (may need to resize vector of variables)
const Monitored::IMonitoredVariable * weight
pointer to weight variable, typically absent