ATLAS Offline Software
CounterROS.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 #include "CounterROS.h"
9 
10 #include <algorithm>
11 #include <string>
12 #include <vector>
13 
14 CounterROS::CounterROS(const std::string& name, const MonitorBase* parent)
15  : CounterBase(name, parent) {
16 
17  regHistogram("Request_perEvent", "Number of requests/Event;Number of requests;Events", VariableType::kPerEvent, LogType::kLinear, -0.5, 49.5, 50);
18  regHistogram("NetworkRequest_perEvent", "Number of network requests/Event;Number of requests;Events", VariableType::kPerEvent, LogType::kLinear, -0.5, 20.5, 21);
19  regHistogram("CachedROBSize_perEvent", "Total Cached ROB Size/Event;ROB size;Events", VariableType::kPerEvent, LogType::kLinear, 0, 1024, 50);
20  regHistogram("NetworkROBSize_perEvent", "Total Network ROB Size/Event;ROB size;Events", VariableType::kPerEvent, LogType::kLinear, 0, 1024, 50);
21  regHistogram("Time_perEvent", "ROB Elapsed Time/Event;Elapsed Time [ms];Events", VariableType::kPerEvent);
22  regHistogram("ROBStatus_perCall", "ROB status/Call;Status;Calls", VariableType::kPerCall, LogType::kLinear, 0, robmonitor::NUM_ROBHIST_CODES+1, robmonitor::NUM_ROBHIST_CODES+1);
23  regHistogram("NROBsPerRequest_perCall", "Number of requested ROBs;Number of requestes ROBs;Number of requests", VariableType::kPerCall, LogType::kLinear, 0.5, 30.5, 30);
24 }
25 
26 CounterROS::CounterROS(const std::string& name, unsigned nRobs, const MonitorBase* parent)
27  : CounterROS(name, parent) {
28 
29  regHistogram("ROBsPerRequest_perCall", "Number of ROB requests;ROBs names;Number of requests", VariableType::kPerCall, LogType::kLinear, 0, nRobs, nRobs);
30 }
31 
32 StatusCode CounterROS::newEvent(const CostData& data, size_t index, const float weight) {
33 
34  // Monitor only ROB data for corresponding ROS
35  const xAOD::TrigComposite* tc = data.rosCollection()[index];
36  const std::vector<uint32_t> robIdsPerRequest = tc->getDetail<std::vector<uint32_t>>("robs_id");
37  const std::vector<uint32_t> robs_size = tc->getDetail<std::vector<uint32_t>>("robs_size");
38  const std::vector<unsigned> robs_history = tc->getDetail<std::vector<unsigned>>("robs_history");
39  const std::vector<unsigned short> robs_status = tc->getDetail<std::vector<unsigned short>>("robs_status");
40 
41 
42  if (m_robIdToBin.empty()) {
43  // Set lables of status histogram
44  ATH_CHECK( getVariable("ROBStatus_perCall").setBinLabel(1, "Unclassified"));
45  ATH_CHECK( getVariable("ROBStatus_perCall").setBinLabel(2, "Retrieved"));
46  ATH_CHECK( getVariable("ROBStatus_perCall").setBinLabel(3, "HLT Cached"));
47  ATH_CHECK( getVariable("ROBStatus_perCall").setBinLabel(4, "DCM Cached"));
48  ATH_CHECK( getVariable("ROBStatus_perCall").setBinLabel(5, "Ignored"));
49  ATH_CHECK( getVariable("ROBStatus_perCall").setBinLabel(6, "Disabled"));
50  ATH_CHECK( getVariable("ROBStatus_perCall").setBinLabel(7, "IsNotOK"));
51 
52  if (variableExists("ROBsPerRequest_perCall")) {
53  // This monitor has it's own binning for ROBs due to the fact that limited number of ROBs are associated with one ROS
54  unsigned robCounter = 0;
55  for (uint32_t robId : data.costROSData().getROBForROS(getName())) {
56  std::string robName = data.costROSData().getROBName(robId);
57  ATH_CHECK( getVariable("ROBsPerRequest_perCall").setBinLabel(robCounter+1, robName));
58 
59  m_robIdToBin[robId] = robCounter;
60  ++robCounter;
61  }
62  }
63  }
64 
65 
66  // Find all ROB requests that are both in request and correspond to this ROS
67  bool networkRequestIncremented = false;
68  int nRequestedRobs = 0;
69  for (size_t i = 0; i < robIdsPerRequest.size(); ++i) {
70 
71  // Check if the ROB was requested by ROS
72  if (data.costROSData().getROSForROB(robIdsPerRequest[i]) != getName() ) continue;
73 
74  if (m_robIdToBin.find(robIdsPerRequest[i]) != m_robIdToBin.end()) {
75  ATH_CHECK( fill("ROBStatus_perCall", getROBHistoryBin(robs_history[i]), weight) );
76  // If status is okay robs_status[i] equals true
77  if (robs_status[i] == false ) {
78  // The last bin of ROBStatus_perCall histogram store isStatusNotOk bool value
79  ATH_CHECK( fill("ROBStatus_perCall", robmonitor::NUM_ROBHIST_CODES, weight) );
80  }
81 
82  // ROB request was fetched over the network
83  if (robs_history[i] == robmonitor::RETRIEVED) {
84  // size is stored in words, should be in kilobytes
85  ATH_CHECK( fill("NetworkROBSize_perEvent", robs_size[i] / 500., weight) );
86  networkRequestIncremented = true;
87  }
88  else if (robs_history[i] == robmonitor::HLT_CACHED || robs_history[i] == robmonitor::DCM_CACHED) {
89  ATH_CHECK( fill("CachedROBSize_perEvent", robs_size[i] / 500., weight) );
90  }
91 
92  if (variableExists("ROBsPerRequest_perCall")){
93  ATH_CHECK( fill("ROBsPerRequest_perCall", m_robIdToBin.at(robIdsPerRequest[i]), weight) );
94  }
95 
96  ++nRequestedRobs;
97  }
98  }
99 
100  ATH_CHECK( fill("NROBsPerRequest_perCall", nRequestedRobs, weight) );
101 
102  ATH_CHECK( increment("Request_perEvent", weight) );
103 
104  if (networkRequestIncremented) {
105  ATH_CHECK( increment("NetworkRequest_perEvent", weight) );
106  }
107 
108  const float rosTime = timeToMilliSec(tc->getDetail<uint64_t>("start"), tc->getDetail<uint64_t>("stop"));
109  ATH_CHECK( fill("Time_perEvent", rosTime, weight) );
110 
111  return StatusCode::SUCCESS;
112 }
113 
114 int CounterROS::getROBHistoryBin(const unsigned history){
115  int history_bin;
116  switch (history) {
118  history_bin = 1;
119  break;
121  history_bin = 2;
122  break;
124  history_bin = 3;
125  break;
126  case robmonitor::IGNORED:
127  history_bin = 4;
128  break;
130  history_bin = 5;
131  break;
132  default: // UNCLASSIFIED
133  history_bin = 0;
134  break;
135  }
136 
137  return history_bin;
138 }
robmonitor::UNDEFINED
@ UNDEFINED
Definition: ROBDataMonitor.h:32
CounterROS
Concrete implimentation of Counter to monitor the data requests for a single Read Out System request ...
Definition: CounterROS.h:15
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CounterBase
Forward declare.
Definition: CounterBase.h:25
CounterBase::regHistogram
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.
Definition: CounterBase.cxx:27
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
index
Definition: index.py:1
CounterBase::fill
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...
Definition: CounterBase.cxx:191
robmonitor::DCM_CACHED
@ DCM_CACHED
Definition: ROBDataMonitor.h:30
kPerEvent
@ kPerEvent
Variable should buffer fill calls in an accumulator and fill the underlying histogram once at the end...
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:19
ROBDataMonitor.h
robmonitor::NUM_ROBHIST_CODES
@ NUM_ROBHIST_CODES
Definition: ROBDataMonitor.h:33
CounterROS::getROBHistoryBin
int getROBHistoryBin(const unsigned history)
Get histogram bin for ROBHistory enum values.
Definition: CounterROS.cxx:114
CounterBase::getName
const std::string & getName() const
Getter for Counter's name.
Definition: CounterBase.cxx:17
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
robmonitor::IGNORED
@ IGNORED
Definition: ROBDataMonitor.h:31
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
CounterBase::variableExists
bool variableExists(const std::string &name) const
Check if a variable of a given name exists.
Definition: CounterBase.cxx:178
TrigCompositeContainer.h
CounterROS::m_robIdToBin
std::map< uint32_t, unsigned > m_robIdToBin
Cached mapping of rob id to bin in ROBsPerRequest_perEvent histogram.
Definition: CounterROS.h:67
kPerCall
@ kPerCall
Variable should fill underlying histogram on each fill.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:18
CounterBase::getVariable
Variable & getVariable(const std::string &name)
Returns a mutable reference to a named Variable.
Definition: CounterBase.cxx:182
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
kLinear
@ kLinear
Linear x-binning.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:27
MonitorBase
Forward declare.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.h:33
robmonitor::RETRIEVED
@ RETRIEVED
Definition: ROBDataMonitor.h:28
robmonitor::HLT_CACHED
@ HLT_CACHED
Definition: ROBDataMonitor.h:29
DeMoScan.index
string index
Definition: DeMoScan.py:364
CounterBase::increment
StatusCode increment(const std::string &name, float weight=1.0)
Convenience function.
Definition: CounterBase.cxx:220
CounterROS.h
CounterROS::CounterROS
CounterROS()=delete
Forbid default constructor.
CounterROS::newEvent
virtual StatusCode newEvent(const CostData &data, size_t index, const float weight=1.) override
Concrete implementation.
Definition: CounterROS.cxx:32
xAOD::TrigComposite_v1::getDetail
bool getDetail(const std::string &name, TYPE &value) const
Get an TYPE detail from the object.
CounterBase::timeToMilliSec
float timeToMilliSec(const uint64_t start, const uint64_t stop) const
Helper function.
Definition: CounterBase.cxx:243
CostData
Caches and propagates event data to be used by monitoring algorithms.
Definition: CostData.h:26