ATLAS Offline Software
LumiblockHistogramProvider.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 
18 namespace Monitored {
26  public:
35  std::shared_ptr<HistogramFactory> factory,
36  const HistogramDef& histDef)
38  , m_gmTool(gmTool)
39  , m_factory(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
75  HistogramDef def = m_histDef;
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;
119  };
120 }
121 
122 #endif /* AthenaMonitoringKernel_HistogramFiller_LumiblockHistogramProvider_h */
IHistogramProvider.h
Monitored::LumiblockHistogramProvider::m_histDef
const HistogramDef m_histDef
Definition: LumiblockHistogramProvider.h:100
Monitored::IHistogramProvider
Interface of the source of ROOT objects for HistogramFillers.
Definition: IHistogramProvider.h:14
Monitored::LumiblockHistogramProvider::m_mutex
std::mutex m_mutex
! mutex for the map
Definition: LumiblockHistogramProvider.h:118
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
Monitored::LumiblockHistogramProvider
Implementation of IHistogramProvider for lumi block based histograms.
Definition: LumiblockHistogramProvider.h:25
HistogramDef.h
plotmaker.hist
hist
Definition: plotmaker.py:148
Monitored::LumiblockHistogramProvider::m_hists
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...
Definition: LumiblockHistogramProvider.h:117
GenericMonitoringTool::lumiBlock
virtual uint32_t lumiBlock()
Definition: GenericMonitoringTool.cxx:286
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Monitored::HistogramException
Represents error occurred during accessing histograms objects.
Definition: HistogramException.h:14
Monitored::HistogramDef
the internal class used to keep parsed Filler properties
Definition: HistogramDef.h:15
Monitored::LumiblockHistogramProvider::s_deregDelay
static const unsigned s_deregDelay
Number of lumiblocks before histogram gets deregistered/deleted.
Definition: LumiblockHistogramProvider.h:108
Monitored::LumiblockHistogramProvider::histogram
TNamed * histogram() override
Getter of ROOT object.
Definition: LumiblockHistogramProvider.h:51
GenericMonitoringTool.h
Monitored::HistogramDef::path
std::string path
booking path
Definition: HistogramDef.h:19
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
Monitored::HistogramDef::alias
std::string alias
unique alias for THistSvc
Definition: HistogramDef.h:17
GenericMonitoringTool
Definition: GenericMonitoringTool.py:1
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Monitored::LumiblockHistogramProvider::m_gmTool
GenericMonitoringTool *const m_gmTool
Definition: LumiblockHistogramProvider.h:98
HistogramFactory.h
Monitored::LumiblockHistogramProvider::LumiblockHistogramProvider
LumiblockHistogramProvider(GenericMonitoringTool *const gmTool, std::shared_ptr< HistogramFactory > factory, const HistogramDef &histDef)
Constructor.
Definition: LumiblockHistogramProvider.h:34
Monitored::LumiblockHistogramProvider::m_factory
std::shared_ptr< HistogramFactory > m_factory
Definition: LumiblockHistogramProvider.h:99
Monitored::HistogramDef::kLBNHistoryDepth
int kLBNHistoryDepth
length of lb history
Definition: HistogramDef.h:44
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327