12 #include <TProfile2D.h>
27 return StatusCode::SUCCESS;
31 if ( not m_explicitBooking ) {
35 return StatusCode::SUCCESS;
39 m_alwaysCreateFillers.clear();
41 if (m_registerHandler) {
43 SmartIF<IIncidentSvc> incSvc{service(
"IncidentSvc")};
45 incSvc->removeListener(
this, IncidentType::BeginEvent);
47 return StatusCode::SUCCESS;
51 for (
const auto& filler : m_alwaysCreateFillers) {
59 if (m_histoPath.empty()) {
60 auto named =
dynamic_cast<const INamedInterface*
>(
parent());
61 m_histoPath = named ? named->name() :
name();
65 std::replace( m_histoPath.begin(), m_histoPath.end(),
'.',
'/' );
67 ATH_MSG_DEBUG(
"Booking histograms in path: " << m_histoPath.value());
71 for (
const std::string&
item : m_histograms) {
80 std::shared_ptr<HistogramFiller> filler(factory.
create(def));
84 if (m_registerHandler) {
85 m_alwaysCreateFillers.push_back(filler);
90 m_fillers.push_back(filler);
96 return StatusCode::FAILURE;
101 if ( m_fillers.empty() && m_failOnEmpty ) {
103 for (
const auto &
h : m_histograms)
hists += (
h+
",");
104 ATH_MSG_ERROR(
"No monitored variables created based on histogram definition: [" <<
hists <<
105 "] Remove this monitoring tool or check its configuration.");
106 return StatusCode::FAILURE;
111 if (! m_alwaysCreateFillers.empty() && m_registerHandler) {
113 SmartIF<IIncidentSvc> incSvc{service(
"IncidentSvc")};
115 incSvc->addListener(
this, IncidentType::BeginEvent);
118 return StatusCode::SUCCESS;
122 std::ostream&
operator<< ( std::ostream&
os,
const std::reference_wrapper<Monitored::IMonitoredVariable>& rmv ) {
123 std::string
s = rmv.get().name();
133 bool operator<(
const std::string&
a,
const std::reference_wrapper<Monitored::IMonitoredVariable>&
b) {
134 return a <
b.get().name();
136 bool operator<(
const std::reference_wrapper<Monitored::IMonitoredVariable>&
a,
const std::string&
b) {
137 return a.get().name() <
b;
142 const std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>>& rhs) {
143 return std::lexicographical_compare(lhs.begin(), lhs.end(),
144 rhs.begin(), rhs.end());
146 bool operator<(
const std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>>& lhs,
147 const std::vector<std::string>& rhs) {
148 return std::lexicographical_compare(lhs.begin(), lhs.end(),
149 rhs.begin(), rhs.end());
167 const std::vector<std::shared_ptr<Monitored::HistogramFiller>>* fillerList{
nullptr};
169 bool makeCache =
false;
171 std::unique_ptr<std::vector<std::shared_ptr<Monitored::HistogramFiller>>> matchedFillerList;
174 std::scoped_lock cacheguard(m_cacheMutex);
175 const auto match = m_fillerCacheMap.find(monitoredVariables);
176 if (
match != m_fillerCacheMap.end()) {
177 fillerList =
match->second.get();
179 fillerList = &m_fillers;
180 matchedFillerList = std::make_unique<std::vector<std::shared_ptr<Monitored::HistogramFiller>>>();
184 fillerList = &m_fillers;
187 for (
auto filler: *fillerList ) {
189 const int fillerCardinality = filler->histogramVariablesNames().size() + (filler->histogramWeightName().empty() ? 0: 1) + (filler->histogramCutMaskName().empty() ? 0 : 1);
191 if ( fillerCardinality == 1 ) {
192 for (
auto&
var: monitoredVariables ) {
193 if (
var.get().name().compare( filler->histogramVariablesNames()[0] ) == 0 ) {
194 tl_vars.var[0] = &
var.get();
196 auto guard{filler->getLock()};
197 filler->fill( tl_vars );
200 matchedFillerList->push_back(filler);
206 int matchesCount = 0;
207 for (
const auto&
var: monitoredVariables ) {
209 for (
unsigned fillerVarIndex = 0; fillerVarIndex < filler->histogramVariablesNames().size(); ++fillerVarIndex ) {
210 if (
var.get().name().compare( filler->histogramVariablesNames()[fillerVarIndex] ) == 0 ) {
211 tl_vars.set(fillerVarIndex, &
var.get());
217 if ( matchesCount == fillerCardinality )
break;
219 if (
var.get().name().compare( filler->histogramWeightName() ) == 0 ) {
220 tl_vars.weight = &
var.get();
222 }
else if (
var.get().name().compare( filler->histogramCutMaskName() ) == 0 ) {
223 tl_vars.cut = &
var.get();
227 if ( matchesCount == fillerCardinality )
break;
229 if ( matchesCount == fillerCardinality ) {
231 auto guard{filler->getLock()};
232 filler->fill( tl_vars );
235 matchedFillerList->push_back(filler);
238 invokeFillersDebug(filler, monitoredVariables);
246 std::scoped_lock cacheguard(m_cacheMutex);
247 const auto match = m_fillerCacheMap.find(monitoredVariables);
248 if (
match == m_fillerCacheMap.end()) {
249 std::vector<std::string>
key;
250 key.reserve(monitoredVariables.size());
251 for (
const auto& mv : monitoredVariables) {
252 key.push_back(mv.get().name());
254 m_fillerCacheMap[
key].swap(matchedFillerList);
260 const std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>>& monitoredVariables)
const {
261 bool reasonFound =
false;
264 ATH_MSG_DEBUG(
"Filler weight not found in monitoredVariables:"
266 <<
"\n Asked to fill from mon. tl_vars: " << monitoredVariables);
270 ATH_MSG_DEBUG(
"Filler cut mask not found in monitoredVariables:"
272 <<
"\n Asked to fill from mon. tl_vars: " << monitoredVariables);
274 if ( not reasonFound ) {
275 ATH_MSG_DEBUG(
"Filler has different variables than monitoredVariables:"
277 <<
"\n Asked to fill from mon. tl_vars: " << monitoredVariables
278 <<
"\n Selected monitored variables: " << tl_vars.names() );
283 return Gaudi::Hive::currentContext().eventID().run_number();
287 return Gaudi::Hive::currentContext().eventID().lumi_block();