ATLAS Offline Software
Loading...
Searching...
No Matches
LumiblockHistogramProvider.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef AthenaMonitoringKernel_HistogramFiller_LumiblockHistogramProvider_h
6#define AthenaMonitoringKernel_HistogramFiller_LumiblockHistogramProvider_h
7
8#include <map>
9#include <memory>
10#include <utility>
11
15
16#include "HistogramFactory.h"
17
18namespace Monitored {
26 public:
35 std::shared_ptr<HistogramFactory> factory,
36 const HistogramDef& histDef)
38 , m_gmTool(gmTool)
39 , m_factory(std::move(factory))
40 , m_histDef(histDef)
41 {}
42
51 TNamed* histogram() override {
52
53 const unsigned lumiBlock = m_gmTool->lumiBlock();
54 std::scoped_lock lock(m_mutex); // access to m_hists
55
56 /* Find existing histogram. In the unlikely case of a very old lumiblock
57 being processed, it would be filled into the oldest histogram. */
58 const auto it = m_hists.lower_bound(lumiBlock);
59 if (it!=m_hists.end() && it->second.second!=nullptr) {
60 return it->second.second;
61 }
62
63 if (m_histDef.kLBNHistoryDepth <= 0) {
64 throw HistogramException("Histogram >"+ m_histDef.path + "< has invalid kLBNHistoryDepth.");
65 }
66
67 const int historyDepth = m_histDef.kLBNHistoryDepth;
68 const unsigned lumiPage = lumiBlock/historyDepth;
69
70 // Helpers to calculate min/max lumiblock for a given "page" (histogram)
71 auto minLumiBlock = [=](unsigned lumiPage) { return lumiPage * historyDepth; };
72 auto maxLumiBlock = [=](unsigned lumiPage) { return (lumiPage+1) * historyDepth - 1; };
73
74 // create new histogram definition with updated alias
76 def.alias += "_LB" + std::to_string(minLumiBlock(lumiPage));
77 if (historyDepth > 1) {
78 def.alias += "_" + std::to_string(maxLumiBlock(lumiPage));
79 }
80
81 TNamed* hist = m_factory->create(def);
82 m_hists.emplace(maxLumiBlock(lumiPage), std::make_pair(std::move(def), hist));
83
84 // deregister old histograms
85 for (auto it = m_hists.begin(); it!=m_hists.end();) {
86 const unsigned maxLB = it->first;
87 if (maxLB + s_deregDelay <= lumiBlock) {
88 m_factory->remove(it->second.first);
89 it = m_hists.erase(it); // this advances iterator by one
90 }
91 else break; // don't need to search further as std::map is sorted
92 }
93
94 return hist;
95 }
96
97 private:
99 std::shared_ptr<HistogramFactory> m_factory;
101
108 static const unsigned s_deregDelay{5};
109
117 std::map<unsigned, std::pair<HistogramDef, TNamed*>> m_hists;
118 std::mutex m_mutex;
119 };
120}
121
122#endif /* AthenaMonitoringKernel_HistogramFiller_LumiblockHistogramProvider_h */
Interface of the source of ROOT objects for HistogramFillers.
std::map< unsigned, std::pair< HistogramDef, TNamed * > > m_hists
Map storing upper end of lumi page (or lumiblock if depth==1) with the corresponding histogram defini...
static const unsigned s_deregDelay
Number of lumiblocks before histogram gets deregistered/deleted.
std::shared_ptr< HistogramFactory > m_factory
TNamed * histogram() override
Getter of ROOT object.
LumiblockHistogramProvider(GenericMonitoringTool *const gmTool, std::shared_ptr< HistogramFactory > factory, const HistogramDef &histDef)
Constructor.
Generic monitoring tool for athena components.
STL namespace.
the internal class used to keep parsed Filler properties
std::string alias
unique alias for THistSvc
Represents error occurred during accessing histograms objects.