ATLAS Offline Software
Loading...
Searching...
No Matches
CounterAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include "CounterAlgorithm.h"
9
10CounterAlgorithm::CounterAlgorithm(const std::string& name, const MonitorBase* parent, const bool skipHistograms)
11 : CounterBase(name, parent)
12{
13 if (!skipHistograms){
14 regHistogram("Time_perCall", "CPU Time/Call;Time [ms];Calls", VariableType::kPerCall, kLog, 0.01, 100000);
15 regHistogram("FirstTime_perEvent", "First Call CPU Time;Time [ms];Events", VariableType::kPerCall, kLog, 0.01, 100000);
16 regHistogram("Time_perEvent", "CPU Time/Event;Time [ms];Events", VariableType::kPerEvent);
17 regHistogram("Time_perEventFractional", "CPU Time/Event CPU Time;Fractional Time;Events", VariableType::kPerEvent, kLinear, 0., 1.);
18 regHistogram("AlgCalls_perEvent", "Calls/Event;Calls;Events", VariableType::kPerEvent, kLinear, -0.5, 499.5, 500);
19 regHistogram("InEventView_perCall", "In Event View;Yes or No;Calls", VariableType::kPerCall, kLinear, -0.5, 1.5, 2);
20 regHistogram("RoIID_perCall", "RoI ID;RoI ID;Calls", VariableType::kPerCall, kLinear, -1.5, 20.5, 22);
21 regHistogram("Request_perEvent", "Number of requests/Event;Number of requests;Events", VariableType::kPerEvent, LogType::kLinear, -0.5, 299.5, 300);
22 }
23}
24
25
26StatusCode CounterAlgorithm::newEvent(const CostData& data, size_t index, const float weight) {
27 const xAOD::TrigComposite* alg = data.costCollection().at(index);
28
29 const uint64_t start = alg->getDetail<uint64_t>("start"); // in mus
30 const uint64_t stop = alg->getDetail<uint64_t>("stop"); // in mus
31 const float cpuTime = timeToMilliSec(start, stop);
32
33 ATH_CHECK( fill("Time_perCall", cpuTime, weight) );
34
35 ATH_CHECK( fill("Time_perEvent", cpuTime, weight) );
36
37 Variable& firstTime_perEvent = getVariable("FirstTime_perEvent");
38 if (firstTime_perEvent.getCalls() == 0) {
39 ATH_CHECK( firstTime_perEvent.fill(cpuTime, weight) );
40 }
41
42 ATH_CHECK( setDenominator("Time_perEventFractional", data.algTotalTimeMilliSec()) );
43 ATH_CHECK( fill("Time_perEventFractional", cpuTime, weight) );
44
45 ATH_CHECK( increment("AlgCalls_perEvent", weight) );
46
47 const bool globalScope = (TrigConf::HLTUtils::hash2string( alg->getDetail<TrigConf::HLTHash>("store"), "STORE").find("StoreGateSvc") != std::string::npos);
48 ATH_CHECK( fill("InEventView_perCall", (globalScope ? 0.0 : 1.0), weight) );
49
50 ATH_CHECK( fill("RoIID_perCall", alg->getDetail<int32_t>("roi"), weight) );
51
52 return StatusCode::SUCCESS;
53}
#define ATH_CHECK
Evaluate an expression and check for errors.
@ kPerEvent
Variable should buffer fill calls in an accumulator and fill the underlying histogram once at the end...
Definition Variable.h:21
@ kPerCall
Variable should fill underlying histogram on each fill.
Definition Variable.h:20
@ kLinear
Linear x-binning.
Definition Variable.h:29
@ kLog
Logarithmic x-binning.
Definition Variable.h:30
Caches and propagates event data to be used by monitoring algorithms.
Definition CostData.h:26
virtual StatusCode newEvent(const CostData &data, size_t index, const float weight=1.) override
Concrete implimentation.
CounterAlgorithm()=delete
Forbid default constructor.
float timeToMilliSec(const uint64_t start, const uint64_t stop) const
Helper function.
CounterBase()=delete
Forbid default constructor.
StatusCode increment(std::string_view name, float weight=1.0)
Convenience function.
void regHistogram(const std::string &name, const std::string &title, const VariableType type=VariableType::kPerCall, const LogType xaxis=kLog, const float min=0.1, const float max=1000000., const size_t bins=70)
Book a histogram for this Counter, to be filled in per-event monitoring.
Variable & getVariable(std::string_view name)
Returns a mutable reference to a named Variable.
StatusCode fill(std::string_view name, float value, float weight=1.0)
Fill (for per-Call) or accumulate in a buffer (for per-Event) a quantity histogrammed by a named Vari...
StatusCode setDenominator(const std::string &name, float value)
Optional for per-Event Variables.
static const std::string hash2string(HLTHash, const std::string &category=s_defaultCategory)
hash function translating identifiers into names (via internal dictionary)
Wrapper around a histogram which allows for some additional filling patterns and data manipulation.
Definition Variable.h:41
StatusCode fill(float value, float weight=1.0)
Fill histogram (per-Call Variable), or add value to internal accumulator (per-Event Variable) to be f...
Definition Variable.cxx:50
size_t getCalls() const
Getter for how many times fill() has already been called on this Variable in this event.
Definition Variable.cxx:30
Definition index.py:1
TrigComposite_v1 TrigComposite
Declare the latest version of the class.