ATLAS Offline Software
Loading...
Searching...
No Matches
CounterChain.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include "CounterChain.h"
9
10
11CounterChain::CounterChain(const std::string& name, const MonitorBase* parent)
12 : CounterBase(name, parent), m_isInitialized(false)
13{
14 regHistogram("Group_perCall", "Chain group/Call;Group;Calls", VariableType::kPerCall, kLinear, -0.5, 9.5, 10);
15 regHistogram("Chain_perEvent", "Chain calls/Event;Chain call;Events", VariableType::kPerEvent, kLinear, -0.5, 49.5);
16 regHistogram("AlgCalls_perEvent", "Algorithm Calls/Event;Calls;Events", VariableType::kPerEvent, kLinear, -0.5, 999.5, 100);
17 regHistogram("Time_perCall", "CPU Time/Call;Time [ms];Calls", VariableType::kPerCall, kLog, 0.01, 100000);
18 regHistogram("Time_perEvent", "CPU Time/Event;Time [ms];Events", VariableType::kPerEvent);
19 regHistogram("UniqueTime_perCall", "Unique CPU Time/Call;Time [ms];Calls", VariableType::kPerCall, kLog, 0.01, 100000);
20 regHistogram("ChainPassed_perEvent", "Passed chain/Event;Passsed;Events", VariableType::kPerEvent, kLinear, -0.5, 1.5, 2);
21 regHistogram("Request_perEvent", "Number of requests/Event;Number of requests;Events", VariableType::kPerEvent, LogType::kLinear, -0.5, 299.5, 300);
22 regHistogram("NetworkRequest_perEvent", "Number of network requests/Event;Number of requests;Events", VariableType::kPerEvent, LogType::kLinear, -0.5, 149.5, 150);
23 regHistogram("CachedROBSize_perEvent", "Cached ROB Size/Event;ROB size;Events", VariableType::kPerEvent, LogType::kLinear, 0, 1024, 50);
24 regHistogram("NetworkROBSize_perEvent", "Network ROB Size/Event;ROB size;Events", VariableType::kPerEvent, LogType::kLinear, 0, 1024, 50);
25 regHistogram("RequestTime_perEvent", "ROB Elapsed Time/Event;Elapsed Time [ms];Events", VariableType::kPerEvent);
26}
27
28CounterChain::CounterChain(const std::string& name, unsigned nRos, const MonitorBase* parent)
29 : CounterChain(name, parent)
30{
31 regTProfile("ROSRequests_perEvent", "Number of ROS requests;ROS names;Numer of requests to ROS per event", VariableType::kPerCall, LogType::kLinear, 0, nRos, nRos);
32 regTProfile("NetworkROSRequests_perEvent", "Number of network ROS requests;ROS names;Numer of requests to ROS over the network per event", VariableType::kPerCall, LogType::kLinear, 0, nRos, nRos);
33 regTProfile("ROBRequestsPerROS_perEvent", "Number of ROBs per ROS requests;ROS names;Numer of ROBs requested per request", VariableType::kPerCall, LogType::kLinear, 0, nRos, nRos);
34 regTProfile("ROBRequestsPerROSPerEvent_perEvent", "Number of ROBs per ROS requests per event;ROS names;Numer of ROBs requested by ROS per event", VariableType::kPerCall, LogType::kLinear, 0, nRos, nRos);
35}
36
37
38StatusCode CounterChain::newEvent(const CostData& data, size_t index, const float weight) {
39
40 ATH_CHECK( increment("Chain_perEvent", weight) );
41
42 if (!m_isInitialized && variableExists("ROSRequests_perEvent")) {
43 // Set histograms labels
44 for (const auto& rosToRobPair : data.costROSData().getROStoROBMap()) {
45 int binForROS = data.costROSData().getBinForROS(rosToRobPair.first) + 1;
46 ATH_CHECK( getVariable("ROSRequests_perEvent").setBinLabel(binForROS, rosToRobPair.first));
47 ATH_CHECK( getVariable("NetworkROSRequests_perEvent").setBinLabel(binForROS, rosToRobPair.first));
48 ATH_CHECK( getVariable("ROBRequestsPerROS_perEvent").setBinLabel(binForROS, rosToRobPair.first));
49 ATH_CHECK( getVariable("ROBRequestsPerROSPerEvent_perEvent").setBinLabel(binForROS, rosToRobPair.first));
50 }
51
52 // Fill the bins with groups and add the labels
53 int bin = 1;
54 for (const std::string& group : data.seededChains()[index].groups){
55 ATH_CHECK( getVariable("Group_perCall").setBinLabel(bin, group) );
56 ATH_CHECK( getVariable("Group_perCall").fill(group, weight) );
57 ++bin;
58 }
59
60 m_isInitialized = true;
61 }
62
63 if (data.seededChains()[index].isPassRaw){
64 ATH_CHECK( increment("ChainPassed_perEvent", weight) );
65 }
66
67 // Monitor algorithms associated with chain name
68 if (!data.chainToAlgMap().count(getName())) return StatusCode::SUCCESS;
69
70 std::map<std::string, int> nRosPerEvent; // Accumulate how many times ROS was requested in a request per this event
71 std::map<std::string, int> nNetworkRosPerEvent; // Accumulate how many times ROS was requested in a request per this event
72 std::map<std::string, int> nRobsPerRosPerEvent; // Accumulate how many ROBs ROS requested per this event
73 for (const size_t algIndex : data.chainToAlgMap().at(getName())){
74 const xAOD::TrigComposite* alg = data.costCollection().at(algIndex);
75 const uint32_t slot = alg->getDetail<uint32_t>("slot");
76 if (slot != data.onlineSlot()) {
77 continue; // When monitoring the master slot, this Monitor ignores algs running in different slots
78 }
79
80 ATH_CHECK( increment("AlgCalls_perEvent", weight) );
81
82 const uint64_t start = alg->getDetail<uint64_t>("start"); // in mus
83 const uint64_t stop = alg->getDetail<uint64_t>("stop"); // in mus
84 const float cpuTime = timeToMilliSec(start, stop);
85 ATH_CHECK( fill("Time_perEvent", cpuTime, weight) );
86 ATH_CHECK( fill("Time_perCall", cpuTime, weight) );
87
88 // Monitor data requests
89 if (!data.algToRequestMap().count(algIndex)) continue;
90
91 for (size_t requestIdx : data.algToRequestMap().at(algIndex)) {
92 const xAOD::TrigComposite* request = data.rosCollection().at(requestIdx);
93 const std::vector<uint32_t> robIdsPerRequest = request->getDetail<std::vector<uint32_t>>("robs_id");
94 const std::vector<unsigned> robs_history = request->getDetail<std::vector<unsigned>>("robs_history");
95 const std::vector<uint32_t> robs_size = request->getDetail<std::vector<uint32_t>>("robs_size");
96
97 std::map<std::string, int> nRobsPerRosPerRequest; // Accumulate how many ROBs ROS requested per request
98
99 bool networkRequestIncremented = false;
100 std::set<std::string> requestedROSes;
101 std::set<std::string> requestedNetworkROSes;
102 for (size_t i = 0; i < robs_size.size(); ++i) {
103 // ROB request was fetched over the network
104 if (robs_history[i] == robmonitor::RETRIEVED) {
105 // size is stored in words, should be in kilobytes
106 ATH_CHECK( fill("NetworkROBSize_perEvent", robs_size[i] / 500., weight) );
107 networkRequestIncremented = true;
108 }
109 // ROB request was cached
110 else if (robs_history[i] == robmonitor::HLT_CACHED || robs_history[i] == robmonitor::DCM_CACHED) {
111 ATH_CHECK( fill("CachedROBSize_perEvent", robs_size[i] / 500., weight) );
112 }
113
114 uint32_t robId = robIdsPerRequest[i];
115 if (variableExists("ROBRequestsPerROS_perEvent")){
116 std::string rosForROB = data.costROSData().getROSForROB(robId);
117 if (!rosForROB.empty()){
118 requestedROSes.insert(rosForROB);
119 nRobsPerRosPerRequest[rosForROB] += 1;
120 nRobsPerRosPerEvent[rosForROB] += 1;
121
122 if (robs_history[i] == robmonitor::RETRIEVED) {
123 requestedNetworkROSes.insert(std::move(rosForROB));
124 }
125 }
126 }
127 }
128
129 // Save number of ROBs per ROS per request
130 for (const auto& robPerRosPair : nRobsPerRosPerRequest) {
131 ATH_CHECK( fill("ROBRequestsPerROS_perEvent", data.costROSData().getBinForROS(robPerRosPair.first), robPerRosPair.second, weight) );
132 }
133
134 // Save the requested ROSes per request
135 for (const std::string& rosName : requestedROSes){
136 nRosPerEvent[rosName] += 1;
137 }
138
139 for (const std::string& rosName : requestedNetworkROSes){
140 nNetworkRosPerEvent[rosName] += 1;
141 }
142
143 ATH_CHECK( increment("Request_perEvent", weight) );
144
145 if (networkRequestIncremented) {
146 ATH_CHECK( increment("NetworkRequest_perEvent", weight) );
147 }
148
149 const float rosTime = timeToMilliSec(request->getDetail<uint64_t>("start"), request->getDetail<uint64_t>("stop"));
150 ATH_CHECK( fill("RequestTime_perEvent", rosTime, weight) );
151 }
152 }
153
154 // Save the requested ROSes per event
155 for (const auto& robPerRosPair : nRosPerEvent) {
156 ATH_CHECK( fill("ROSRequests_perEvent", data.costROSData().getBinForROS(robPerRosPair.first), robPerRosPair.second, weight) );
157 }
158
159 for (const auto& robPerRosPair : nNetworkRosPerEvent) {
160 ATH_CHECK( fill("NetworkROSRequests_perEvent", data.costROSData().getBinForROS(robPerRosPair.first), robPerRosPair.second, weight) );
161 }
162
163 // Save the number of ROBs per ROS per event
164 for (const auto& robPerRosPair : nRobsPerRosPerEvent) {
165 ATH_CHECK( fill("ROBRequestsPerROSPerEvent_perEvent", data.costROSData().getBinForROS(robPerRosPair.first), robPerRosPair.second, weight) );
166 }
167
168 // Monitor unique algorithms associated with chain name
169 if (!data.chainToUniqAlgMap().count(getName())) return StatusCode::SUCCESS;
170
171 for (const size_t algIndex : data.chainToUniqAlgMap().at(getName())){
172 const xAOD::TrigComposite* alg = data.costCollection().at(algIndex);
173 const uint32_t slot = alg->getDetail<uint32_t>("slot");
174 if (slot != data.onlineSlot()) {
175 continue;
176 }
177 const uint64_t start = alg->getDetail<uint64_t>("start"); // in mus
178 const uint64_t stop = alg->getDetail<uint64_t>("stop"); // in mus
179 const float cpuTime = timeToMilliSec(start, stop);
180
181 ATH_CHECK( fill("UniqueTime_perCall", cpuTime, weight) );
182 }
183
184 return StatusCode::SUCCESS;
185}
#define ATH_CHECK
Evaluate an expression and check for errors.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
@ kPerEvent
Variable should buffer fill calls in an accumulator and fill the underlying histogram once at the end...
Definition Variable.h:19
@ kPerCall
Variable should fill underlying histogram on each fill.
Definition Variable.h:18
@ kLinear
Linear x-binning.
Definition Variable.h:27
@ kLog
Logarithmic x-binning.
Definition Variable.h:28
Caches and propagates event data to be used by monitoring algorithms.
Definition CostData.h:26
StatusCode fill(const std::string &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...
float timeToMilliSec(const uint64_t start, const uint64_t stop) const
Helper function.
CounterBase()=delete
Forbid default constructor.
void regTProfile(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 TProfile for this Counter, to be filled in per-event monitoring.
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.
const std::string & getName() const
Getter for Counter's name.
bool variableExists(const std::string &name) const
Check if a variable of a given name exists.
Variable & getVariable(const std::string &name)
Returns a mutable reference to a named Variable.
StatusCode increment(const std::string &name, float weight=1.0)
Convenience function.
virtual StatusCode newEvent(const CostData &data, size_t index, const float weight=1.) override
Concrete implimentation.
CounterChain()=delete
Forbid default constructor.
bool m_isInitialized
bool getDetail(const std::string &name, TYPE &value) const
Get an TYPE detail from the object.
Definition index.py:1
TrigComposite_v1 TrigComposite
Declare the latest version of the class.