ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoredRange.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TrigCostAnalysis.h"
6#include "MonitoredRange.h"
7#include "MonitorBase.h"
8
9#include "TProfile.h"
10
11MonitoredRange::MonitoredRange(const std::string& name, TrigCostAnalysis* parent) :
12 m_name(name),
13 m_parent(parent),
15 m_monitors(),
16 m_seenLB()
17{
18 std::string hisSvcName = getName() + "_walltime";
19 std::unique_ptr<TProfile> hist = std::make_unique<TProfile>(hisSvcName.c_str(), "Walltime;;Seconds", 5000, 0, 5000);
20 m_cachedLifetimeHistPtr = bookGetPointer(hist.release()); // Now owned by HistSvc
21}
22
23
24const std::string& MonitoredRange::getName() const {
25 return m_name;
26}
27
28
30 return m_parent;
31}
32
33
34TH1* MonitoredRange::bookGetPointer(TH1* hist, const std::string& tDir) const {
35 std::string dir = getName();
36 if (tDir != "") {
37 dir += "/";
38 dir += tDir;
39 }
40 return getParent()->bookGetPointer(hist, dir);
41}
42
43
44std::set< std::unique_ptr<MonitorBase> >& MonitoredRange::getMonitors() {
45 return m_monitors;
46}
47
48
49StatusCode MonitoredRange::addMonitor(std::unique_ptr<MonitorBase> monitor) {
50 m_monitors.insert( std::move(monitor) );
51 return StatusCode::SUCCESS;
52}
53
54
55StatusCode MonitoredRange::newEvent(const CostData& data, const float weight, const bool skipMonitoringThisEvent) {
56 if (not skipMonitoringThisEvent) {
57 for (auto& monitor : getMonitors()) {
58 ATH_CHECK(monitor->newEvent(data, weight));
59 ATH_CHECK(monitor->endEvent(weight));
60 }
61 }
63 const bool isNewLB = m_seenLB.insert( data.lb() ).second; // .second is true if a new element was inserted
64 if (data.liveTimeIsPerEvent() or isNewLB) {
65 // We have two modes of operation. Either we process an EnhancedBias file where we know exactly how many events to expect
66 // and can hence fill a per-event live time (meaning that the normalisation is correct, even if we do not run over all events).
67 // For this case we increment this bin for event event this monitor sees.
68 // Or, we can process P1 data where we only know the LB length and must assume that all events are collected and processed,
69 // otherwise the normalisation will be off. For this case we increment this one for every unique LB this monitor sees.
70 m_cachedLifetimeHistPtr->Fill(data.lb(), data.liveTime());
71 }
72
73 return StatusCode::SUCCESS;
74}
#define ATH_CHECK
Evaluate an expression and check for errors.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Caches and propagates event data to be used by monitoring algorithms.
Definition CostData.h:26
StatusCode addMonitor(std::unique_ptr< MonitorBase > monitor)
Adds a new Monitor into this Range.
const TrigCostAnalysis * getParent() const
Return cached non-owning ptr to this Monitor's parent TrigCostAnalysis Athena algorithm.
std::set< std::unique_ptr< MonitorBase > > m_monitors
Storage of Range's Monitors.
TrigCostAnalysis * m_parent
Cached ptr to the parent Athena algorithm.
const std::string m_name
Name of the Monitored Range.
std::set< std::unique_ptr< MonitorBase > > & getMonitors()
Getter for Range's owned Monitors.
std::set< uint32_t > m_seenLB
Luminosity blocks for which we have seen at least one event.
TH1 * m_cachedLifetimeHistPtr
Cached histogram ptr used to store normalisation quantities.
const std::string & getName() const
Getter for Range's name.
MonitoredRange()=delete
Forbid default constructor.
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Appends Range's name (to histogram path) and forwards histogram book request to parent Athena algorit...
StatusCode newEvent(const CostData &data, const float weight=1., const bool skipMonitoringThisEvent=false)
Interface called by TrigCostAnalysis algorithm to instruct this Range to trigger all its Monitors.
Athena algorithm used to process Trigger cost monitoring data in Run 3 and above.
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Public method forwarded to this class' AthHistogramAlgorithm::bookGetPointer base.