10 #include <TProfile2D.h>
25 return StatusCode::SUCCESS;
29 if ( not m_explicitBooking ) {
33 return StatusCode::SUCCESS;
37 m_alwaysCreateFillers.clear();
39 if (m_registerHandler) {
41 SmartIF<IIncidentSvc> incSvc{service(
"IncidentSvc")};
43 incSvc->removeListener(
this, IncidentType::BeginEvent);
45 return StatusCode::SUCCESS;
49 for (
const auto& filler : m_alwaysCreateFillers) {
57 if (m_histoPath.empty()) {
58 auto named =
dynamic_cast<const INamedInterface*
>(
parent());
59 m_histoPath = named ? named->name() :
name();
63 std::replace( m_histoPath.begin(), m_histoPath.end(),
'.',
'/' );
65 ATH_MSG_DEBUG(
"Booking histograms in path: " << m_histoPath.value());
69 for (
const std::string&
item : m_histograms) {
78 std::shared_ptr<HistogramFiller> filler(factory.
create(def));
82 if (m_registerHandler) {
83 m_alwaysCreateFillers.push_back(filler);
88 m_fillers.push_back(std::move(filler));
94 return StatusCode::FAILURE;
99 if ( m_fillers.empty() && m_failOnEmpty ) {
101 for (
const auto &
h : m_histograms)
hists += (
h+
",");
102 ATH_MSG_ERROR(
"No monitored variables created based on histogram definition: [" <<
hists <<
103 "] Remove this monitoring tool or check its configuration.");
104 return StatusCode::FAILURE;
109 if (! m_alwaysCreateFillers.empty() && m_registerHandler) {
111 SmartIF<IIncidentSvc> incSvc{service(
"IncidentSvc")};
113 incSvc->addListener(
this, IncidentType::BeginEvent);
116 return StatusCode::SUCCESS;
120 std::ostream&
operator<< ( std::ostream&
os,
const std::reference_wrapper<Monitored::IMonitoredVariable>& rmv ) {
121 std::string
s = rmv.get().name();
127 void invokeFillersDebug(MsgStream&
log,
129 const std::shared_ptr<Monitored::HistogramFiller>& filler,
130 const std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>>& monitoredVariables) {
131 bool reasonFound =
false;
134 log <<
MSG::DEBUG <<
"Filler weight not found in monitoredVariables:"
136 <<
"\n Asked to fill from mon. tl_vars: " << monitoredVariables <<
endmsg;
140 log <<
MSG::DEBUG <<
"Filler cut mask not found in monitoredVariables:"
142 <<
"\n Asked to fill from mon. tl_vars: " << monitoredVariables <<
endmsg;
144 if ( not reasonFound ) {
145 log <<
MSG::DEBUG <<
"Filler has different variables than monitoredVariables:"
147 <<
"\n Asked to fill from mon. tl_vars: " << monitoredVariables
148 <<
"\n Selected monitored variables: " << vars.
names() <<
endmsg;
157 std::string fillerKey(
const std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>>&
v) {
159 for (
const auto&
m :
v)
r.append(
m.get().name());
167 const std::vector<std::shared_ptr<Monitored::HistogramFiller>>* fillerList{&m_fillers};
169 std::vector<std::shared_ptr<Monitored::HistogramFiller>>* matchedFillerList{
nullptr};
171 const auto match = m_fillerCacheMap.find(fillerKey(monitoredVariables));
172 if (
match != m_fillerCacheMap.end()) {
173 fillerList = &
match->second;
176 matchedFillerList =
new std::vector<std::shared_ptr<Monitored::HistogramFiller>>;
180 for (
auto filler: *fillerList ) {
183 if ( fillerCardinality == 1 ) {
184 for (
auto&
var: monitoredVariables ) {
190 if (matchedFillerList) {
191 matchedFillerList->push_back(std::move(filler));
197 int matchesCount = 0;
199 for (
const auto&
var: monitoredVariables ) {
201 for (
unsigned fillerVarIndex = 0; fillerVarIndex < filler->
histogramVariablesNames().size(); ++fillerVarIndex ) {
203 vars.
set(fillerVarIndex, &
var.get());
209 if ( matchesCount == fillerCardinality )
break;
219 if ( matchesCount == fillerCardinality )
break;
221 if ( matchesCount == fillerCardinality ) {
224 filler->
fill( vars );
226 if (matchedFillerList) {
227 matchedFillerList->push_back(std::move(filler));
230 invokeFillersDebug(
msg(), vars, filler, monitoredVariables);
235 if (matchedFillerList) {
238 m_fillerCacheMap.emplace(fillerKey(monitoredVariables), std::move(*matchedFillerList));
243 return Gaudi::Hive::currentContext().eventID().run_number();
247 return Gaudi::Hive::currentContext().eventID().lumi_block();