ATLAS Offline Software
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
CounterChain Class Reference

Concrete implimentation of Counter to monitor all properties of a given Chain instance. More...

#include <CounterChain.h>

Inheritance diagram for CounterChain:
Collaboration diagram for CounterChain:

Public Member Functions

 CounterChain ()=delete
 Forbid default constructor. More...
 
 CounterChain (const std::string &name, const MonitorBase *parent)
 Construct counter. More...
 
 CounterChain (const std::string &name, unsigned nRos, const MonitorBase *parent)
 Construct counter. More...
 
virtual ~CounterChain ()=default
 Default destructor. More...
 
CounterChainoperator= (const CounterChain &)=delete
 Forbid assignment. More...
 
 CounterChain (const CounterChain &)=delete
 Forbid copy. More...
 
virtual StatusCode newEvent (const CostData &data, size_t index, const float weight=1.) override
 Concrete implimentation. More...
 
const std::string & getName () const
 Getter for Counter's name. More...
 
const MonitorBasegetParent () const
 Return cached non-owning const ptr to this Counter's parent Monitor. More...
 
bool variableExists (const std::string &name) const
 Check if a variable of a given name exists. More...
 
VariablegetVariable (const std::string &name)
 Returns a mutable reference to a named Variable. More...
 
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 Variable. More...
 
StatusCode fill (const std::string &name, float xvalue, float yvalue, float weight)
 Fill (for per-Call) or accumulate in a buffer (for per-Event) a quantity histogrammed by a named Variable. More...
 
StatusCode increment (const std::string &name, float weight=1.0)
 Convenience function. More...
 
StatusCode setDenominator (const std::string &name, float value)
 Optional for per-Event Variables. More...
 
virtual StatusCode endEvent (float weight=1.0)
 Called by the framework. More...
 

Protected Member Functions

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. More...
 
void regHistogram (const std::string &name, const std::string &title, const VariableType type, const LogType xaxis, const float xmin, const float xmax, const size_t xbins, const LogType yaxis, const float ymin, const float ymax, const size_t ybins)
 Book a 2D histogram for this Counter, to be filled in per-event monitoring. More...
 
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. More...
 
TH1 * bookGetPointer (TH1 *hist, const std::string &tDir="") const
 Appends Counter name (to histogram path) and forwards histogram book request to parent Monitor. More...
 
float timeToMilliSec (const uint64_t start, const uint64_t stop) const
 Helper function. More...
 

Private Attributes

bool m_isInitialized
 
const std::string m_name
 Counter's name. More...
 
const MonitorBasem_parent
 Counter's parent Monitor. More...
 
std::unordered_map< std::string, Variablem_variables
 Store of Counter's Variables. More...
 

Detailed Description

Concrete implimentation of Counter to monitor all properties of a given Chain instance.

Definition at line 14 of file CounterChain.h.

Constructor & Destructor Documentation

◆ CounterChain() [1/4]

CounterChain::CounterChain ( )
delete

Forbid default constructor.

◆ CounterChain() [2/4]

CounterChain::CounterChain ( const std::string &  name,
const MonitorBase parent 
)

Construct counter.

Parameters
[in]nameCounter's name
[in]parentCounter's parent monitor, cached non-owning pointer.

Definition at line 11 of file CounterChain.cxx.

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 }

◆ CounterChain() [3/4]

CounterChain::CounterChain ( const std::string &  name,
unsigned  nRos,
const MonitorBase parent 
)

Construct counter.

Parameters
[in]nameCounter's name
[in]nRosNumber of possible ROSes
[in]parentCounter's parent monitor, cached non-owning pointer.

Definition at line 28 of file CounterChain.cxx.

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 }

◆ ~CounterChain()

virtual CounterChain::~CounterChain ( )
virtualdefault

Default destructor.

◆ CounterChain() [4/4]

CounterChain::CounterChain ( const CounterChain )
delete

Forbid copy.

Member Function Documentation

◆ bookGetPointer()

TH1 * CounterBase::bookGetPointer ( TH1 *  hist,
const std::string &  tDir = "" 
) const
protectedinherited

Appends Counter name (to histogram path) and forwards histogram book request to parent Monitor.

Parameters
[in]histBare pointer to histogram. Ownership transferred to THistSvc.
[in]tDirHistogram name & directory.
Returns
Cached pointer to histogram. Used to fill histogram without having to perform THishSvc lookup.

Definition at line 233 of file CounterBase.cxx.

233  {
234  std::string dir = getName();
235  if (tDir != "") {
236  dir += "/";
237  dir += tDir;
238  }
239  return getParent()->bookGetPointer(hist, dir);
240 }

◆ endEvent()

StatusCode CounterBase::endEvent ( float  weight = 1.0)
virtualinherited

Called by the framework.

Causes per-Event Variables to fill their histograms with their accumulated data.

Definition at line 225 of file CounterBase.cxx.

225  {
226  for (auto& nameVariablePair : m_variables) {
227  ATH_CHECK( nameVariablePair.second.endEvent() );
228  }
229  return StatusCode::SUCCESS;
230 }

◆ fill() [1/2]

StatusCode CounterBase::fill ( const std::string &  name,
float  value,
float  weight = 1.0 
)
inherited

Fill (for per-Call) or accumulate in a buffer (for per-Event) a quantity histogrammed by a named Variable.

Parameters
[in]nameVariable to increment
[in]valueThe payload value
[in]weightGlobal event weight

Definition at line 191 of file CounterBase.cxx.

191  {
192  auto it = m_variables.find(name);
193  if (it == m_variables.end()) {
194  return StatusCode::FAILURE;
195  }
196  ATH_CHECK( it->second.fill(value, weight) );
197  return StatusCode::SUCCESS;
198 }

◆ fill() [2/2]

StatusCode CounterBase::fill ( const std::string &  name,
float  xvalue,
float  yvalue,
float  weight 
)
inherited

Fill (for per-Call) or accumulate in a buffer (for per-Event) a quantity histogrammed by a named Variable.

Parameters
[in]nameVariable to increment
[in]xvalueThe payload x-axis value
[in]yvalueThe payload y-axis value
[in]weightGlobal event weight

Definition at line 200 of file CounterBase.cxx.

200  {
201  auto it = m_variables.find(name);
202  if (it == m_variables.end()) {
203  return StatusCode::FAILURE;
204  }
205  ATH_CHECK( it->second.fill(xvalue, yvalue, weight) );
206  return StatusCode::SUCCESS;
207 }

◆ getName()

const std::string & CounterBase::getName ( ) const
inherited

Getter for Counter's name.

Returns
Counter's name const string reference.

Definition at line 17 of file CounterBase.cxx.

17  {
18  return m_name;
19 }

◆ getParent()

const MonitorBase * CounterBase::getParent ( ) const
inherited

Return cached non-owning const ptr to this Counter's parent Monitor.

Returns
Cached pointer parent Monitor.

Definition at line 22 of file CounterBase.cxx.

22  {
23  return m_parent;
24 }

◆ getVariable()

Variable & CounterBase::getVariable ( const std::string &  name)
inherited

Returns a mutable reference to a named Variable.

Throws if no such Variable exists. Used when more complicated logic is needed on a Variable than simply using the fill() method.

Parameters
[in]nameVariable to return
Returns
Mutable reference to Variable

Definition at line 182 of file CounterBase.cxx.

182  {
183  auto it = m_variables.find(name);
184  if (it == m_variables.end()) {
185  throw std::runtime_error( "CounterBase::getVariable: No varialbe with name " + name );
186  }
187  return (it->second);
188 }

◆ increment()

StatusCode CounterBase::increment ( const std::string &  name,
float  weight = 1.0 
)
inherited

Convenience function.

Equivalent to fill(name, 1.0, weight);

Parameters
[in]nameVariable to increment
[in]weightGlobal event weight

Definition at line 220 of file CounterBase.cxx.

220  {
221  return fill(name, 1.0, weight);
222 }

◆ newEvent()

StatusCode CounterChain::newEvent ( const CostData data,
size_t  index,
const float  weight = 1. 
)
overridevirtual

Concrete implimentation.

Monitores chain at specified index. Expected to match this instances name().

Parameters
[in]dataAccess to event data
[in]indexIndex within appropriate event data container which is to be analysed by this Counter
[in]weightGlobal event weight

Implements CounterBase.

Definition at line 38 of file CounterChain.cxx.

38  {
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(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 }

◆ operator=()

CounterChain& CounterChain::operator= ( const CounterChain )
delete

Forbid assignment.

◆ regHistogram() [1/2]

void CounterBase::regHistogram ( const std::string &  name,
const std::string &  title,
const VariableType  type,
const LogType  xaxis,
const float  xmin,
const float  xmax,
const size_t  xbins,
const LogType  yaxis,
const float  ymin,
const float  ymax,
const size_t  ybins 
)
protectedinherited

Book a 2D histogram for this Counter, to be filled in per-event monitoring.

Parameters
[in]nameThe name of the histogram (and corresponding Variable)
[in]titleROOT histogram title string in format "title;xaxis;yaxis"
[in]xaxisControls if the x-axis should use fixed-width or logarithmic bin boundaries.
[in]xminX-axis minimum bound.
[in]xmaxX-axis maximum bound.
[in]xbinsNumber of histogram bins.
[in]yaxisControls if the y-axis should use fixed-width or logarithmic bin boundaries.
[in]yminY-axis minimum bound.
[in]ymaxY-axis maximum bound.
[in]ybinsNumber of histogram bins.

Definition at line 109 of file CounterBase.cxx.

120 {
121  std::string hisSvcName = getParent()->getParent()->getName() + "_" + getParent()->getName() + "_" + getName() + "_" + name;
122  std::unique_ptr<TH2F> hist;
123 
124  if (xmax <= xmin || ymax <= ymin || xbins == 0 || ybins == 0) {
125  throw std::runtime_error("CounterBase::regHistogram: Cannot have max <= min or bins == 0");
126  }
127 
128  if (xaxis == kLinear && yaxis == kLinear) {
129  hist = std::make_unique<TH2F>(hisSvcName.c_str(), title.c_str(), xbins, xmin, xmax, ybins, ymin, ymax);
130  } else if (xaxis == kLog || yaxis == kLog) {
131  if ( (xaxis == kLog && xmin <= 0) || (yaxis == kLog && ymin <= 0) ) {
132  throw std::runtime_error("CounterBase::regHistogram: Cannot have min <= 0 with log binning");
133  }
134  std::unique_ptr<double[]> xlogbins = std::make_unique<double[]>(xbins+1);
135  std::unique_ptr<double[]> ylogbins = std::make_unique<double[]>(ybins+1);
136  if (xaxis == kLog){
137  const double xlogmin = log10(xmin);
138  const double xlogmax = log10(xmax);
139  const double dlogx = (xlogmax-xlogmin)/((double)xbins);
140  for (size_t i = 0; i <= xbins; ++i) {
141  const double xlog = xlogmin + i*dlogx;
142  xlogbins[i] = exp( log(10) * xlog );
143  }
144  } else {
145  const double dx = (xmax-xmin)/((double)xbins);
146  for (size_t i = 0; i <= xbins; ++i) {
147  xlogbins[i] = xmin + i*dx;
148  }
149  }
150 
151  if (yaxis == kLog){
152  const double ylogmin = log10(ymin);
153  const double ylogmax = log10(ymax);
154  const double dlogy = (ylogmax-ylogmin)/((double)ybins);
155  for (size_t i = 0; i <= ybins; ++i) {
156  const double ylog = ylogmin + i*dlogy;
157  ylogbins[i] = exp( log(10) * ylog );
158  }
159  } else {
160  const double dy = (ymax-ymin)/((double)ybins);
161  for (size_t i = 0; i <= ybins; ++i) {
162  ylogbins[i] = ymin + i*dy;
163  }
164  }
165 
166  hist = std::make_unique<TH2F>(hisSvcName.c_str(), title.c_str(), xbins, xlogbins.get(), ybins, ylogbins.get());
167  } else {
168  throw std::runtime_error("CounterBase::regHistogram: Unknown logarithm flag");
169  }
170 
171  m_variables.emplace(std::piecewise_construct,
172  std::forward_as_tuple(name),
173  std::forward_as_tuple(name, bookGetPointer(hist.release()), type)
174  );
175  // Histogram is now owned by THistSvc. A cache of the ptr is kept in the Variable
176 }

◆ regHistogram() [2/2]

void CounterBase::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 
)
protectedinherited

Book a histogram for this Counter, to be filled in per-event monitoring.

Parameters
[in]nameThe name of the histogram (and corresponding Variable)
[in]titleROOT histogram title string in format "title;xaxis;yaxis"
[in]xaxisControls if the x-axis should use fixed-width or logarithmic bin boundaries.
[in]minX-axis minimum bound.
[in]maxX-axis maximum bound.
[in]binsNumber of histogram bins.

Definition at line 27 of file CounterBase.cxx.

34 {
35  std::string hisSvcName = getParent()->getParent()->getName() + "_" + getParent()->getName() + "_" + getName() + "_" + name;
36  std::unique_ptr<TH1F> hist;
37 
38  if (max <= min || bins == 0) {
39  throw std::runtime_error("CounterBase::regHistogram: Cannot have max <= min or bins == 0");
40  }
41 
42  if (xaxis == kLinear) {
43  hist = std::make_unique<TH1F>(hisSvcName.c_str(), title.c_str(), bins, min, max);
44  } else if (xaxis == kLog) {
45  if (min <= 0) {
46  throw std::runtime_error("CounterBase::regHistogram: Cannot have min <= 0 with log binning");
47  }
48  std::unique_ptr<double[]> xbins = std::make_unique<double[]>(bins+1);
49  const double xlogmin = log10(min);
50  const double xlogmax = log10(max);
51  const double dlogx = (xlogmax-xlogmin)/((double)bins);
52  for (size_t i = 0; i <= bins; ++i) {
53  const double xlog = xlogmin + i*dlogx;
54  xbins[i] = exp( log(10) * xlog );
55  }
56  hist = std::make_unique<TH1F>(hisSvcName.c_str(), title.c_str(), bins, xbins.get());
57  } else {
58  throw std::runtime_error("CounterBase::regHistogram: Unknown logarithm flag");
59  }
60 
61  m_variables.emplace(std::piecewise_construct,
62  std::forward_as_tuple(name),
63  std::forward_as_tuple(name, bookGetPointer(hist.release()), type)
64  );
65  // Histogram is now owned by THistSvc. A cache of the ptr is kept in the Variable
66 }

◆ regTProfile()

void CounterBase::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 
)
protectedinherited

Book a TProfile for this Counter, to be filled in per-event monitoring.

Parameters
[in]nameThe name of the histogram (and corresponding Variable)
[in]titleROOT histogram title string in format "title;xaxis;yaxis"
[in]xaxisControls if the x-axis should use fixed-width or logarithmic bin boundaries.
[in]minX-axis minimum bound.
[in]maxX-axis maximum bound.
[in]binsNumber of histogram bins.

Definition at line 68 of file CounterBase.cxx.

75 {
76  std::string hisSvcName = getParent()->getParent()->getName() + "_" + getParent()->getName() + "_" + getName() + "_" + name;
77  std::unique_ptr<TProfile> hist;
78 
79  if (max <= min || bins == 0) {
80  throw std::runtime_error("CounterBase::regTProfile: Cannot have max <= min or bins == 0");
81  }
82 
83  if (xaxis == kLinear) {
84  hist = std::make_unique<TProfile>(hisSvcName.c_str(), title.c_str(), bins, min, max);
85  } else if (xaxis == kLog) {
86  if (min <= 0) {
87  throw std::runtime_error("CounterBase::regTProfile: Cannot have min <= 0 with log binning");
88  }
89  std::unique_ptr<double[]> xbins = std::make_unique<double[]>(bins+1);
90  const double xlogmin = log10(min);
91  const double xlogmax = log10(max);
92  const double dlogx = (xlogmax-xlogmin)/((double)bins);
93  for (size_t i = 0; i <= bins; ++i) {
94  const double xlog = xlogmin + i*dlogx;
95  xbins[i] = exp( log(10) * xlog );
96  }
97  hist = std::make_unique<TProfile>(hisSvcName.c_str(), title.c_str(), bins, xbins.get());
98  } else {
99  throw std::runtime_error("CounterBase::regTProfile: Unknown logarithm flag");
100  }
101 
102  m_variables.emplace(std::piecewise_construct,
103  std::forward_as_tuple(name),
104  std::forward_as_tuple(name, bookGetPointer(hist.release()), type)
105  );
106  // Histogram is now owned by THistSvc. A cache of the ptr is kept in the Variable
107 }

◆ setDenominator()

StatusCode CounterBase::setDenominator ( const std::string &  name,
float  value 
)
inherited

Optional for per-Event Variables.

Sets a denominator to divide the value through by before filling.

Parameters
[in]nameVariable to set the denominator for.
[in]valueThe denominator

Definition at line 210 of file CounterBase.cxx.

210  {
211  auto it = m_variables.find(name);
212  if (it == m_variables.end()) {
213  return StatusCode::FAILURE;
214  }
215  it->second.setDenominator(value);
216  return StatusCode::SUCCESS;
217 }

◆ timeToMilliSec()

float CounterBase::timeToMilliSec ( const uint64_t  start,
const uint64_t  stop 
) const
protectedinherited

Helper function.

Compute the time difference in discreet microseconds and covert to fractional milliseconds.

Returns
Time difference in milliseconds, floating point.

Definition at line 243 of file CounterBase.cxx.

243  {
244  if (stop < start) {
245  throw std::runtime_error("Asked for a stop time " + std::to_string(stop) + " which is before the start time " + std::to_string(start));
246  }
247  const uint64_t difference = stop - start;
248  return (difference * 1e-3); // micro to ms
249 }

◆ variableExists()

bool CounterBase::variableExists ( const std::string &  name) const
inherited

Check if a variable of a given name exists.

Parameters
[in]nameName of Variable.
Returns
True if variable already exists.

Definition at line 178 of file CounterBase.cxx.

178  {
179  return (m_variables.count(name) == 1);
180 }

Member Data Documentation

◆ m_isInitialized

bool CounterChain::m_isInitialized
private

Definition at line 60 of file CounterChain.h.

◆ m_name

const std::string CounterBase::m_name
privateinherited

Counter's name.

Definition at line 203 of file CounterBase.h.

◆ m_parent

const MonitorBase* CounterBase::m_parent
privateinherited

Counter's parent Monitor.

Cached non-owning const pointer.

Definition at line 204 of file CounterBase.h.

◆ m_variables

std::unordered_map< std::string, Variable > CounterBase::m_variables
privateinherited

Store of Counter's Variables.

These wrap a histogram pointer. Keyed by name.

Definition at line 205 of file CounterBase.h.


The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ymin
double ymin
Definition: listroot.cxx:63
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
SGout2dot.alg
alg
Definition: SGout2dot.py:243
max
#define max(a, b)
Definition: cfImp.cxx:41
MonitorBase::bookGetPointer
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Appends Monitor name (to histogram path) and forwards histogram book request to parent Range.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx:37
CounterChain::m_isInitialized
bool m_isInitialized
Definition: CounterChain.h:60
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
plotmaker.hist
hist
Definition: plotmaker.py:148
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
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
skel.it
it
Definition: skel.GENtoEVGEN.py:396
PixelAthClusterMonAlgCfg.ybins
ybins
Definition: PixelAthClusterMonAlgCfg.py:169
bin
Definition: BinsDiffFromStripMedian.h:43
athena.value
value
Definition: athena.py:124
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
CounterBase::CounterBase
CounterBase()=delete
Forbid default constructor.
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
CounterBase::getName
const std::string & getName() const
Getter for Counter's name.
Definition: CounterBase.cxx:17
MonitoredRange::getName
const std::string & getName() const
Getter for Range's name.
Definition: MonitoredRange.cxx:24
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
MonitorBase::getParent
const MonitoredRange * getParent() const
Return cached non-owning const ptr to this Monitor's parent Range.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx:24
kLog
@ kLog
Logarithmic x-binning.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:28
lumiFormat.i
int i
Definition: lumiFormat.py:85
CounterBase::bookGetPointer
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Appends Counter name (to histogram path) and forwards histogram book request to parent Monitor.
Definition: CounterBase.cxx:233
xmin
double xmin
Definition: listroot.cxx:60
CounterChain::CounterChain
CounterChain()=delete
Forbid default constructor.
MonitorBase::getName
const std::string & getName() const
Getter for Monitor's name.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx:19
covarianceTool.title
title
Definition: covarianceTool.py:542
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
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
CounterBase::m_parent
const MonitorBase * m_parent
Counter's parent Monitor.
Definition: CounterBase.h:204
CounterBase::variableExists
bool variableExists(const std::string &name) const
Check if a variable of a given name exists.
Definition: CounterBase.cxx:178
beamspotman.dir
string dir
Definition: beamspotman.py:623
min
#define min(a, b)
Definition: cfImp.cxx:40
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
CounterBase::regTProfile
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.
Definition: CounterBase.cxx:68
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
CounterBase::getParent
const MonitorBase * getParent() const
Return cached non-owning const ptr to this Counter's parent Monitor.
Definition: CounterBase.cxx:22
kLinear
@ kLinear
Linear x-binning.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:27
LArCellBinning.xbins
int xbins
Definition: LArCellBinning.py:163
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
robmonitor::RETRIEVED
@ RETRIEVED
Definition: ROBDataMonitor.h:28
robmonitor::HLT_CACHED
@ HLT_CACHED
Definition: ROBDataMonitor.h:29
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
CounterBase::increment
StatusCode increment(const std::string &name, float weight=1.0)
Convenience function.
Definition: CounterBase.cxx:220
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
xmax
double xmax
Definition: listroot.cxx:61
CounterBase::m_variables
std::unordered_map< std::string, Variable > m_variables
Store of Counter's Variables.
Definition: CounterBase.h:205
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
CounterBase::m_name
const std::string m_name
Counter's name.
Definition: CounterBase.h:203
ymax
double ymax
Definition: listroot.cxx:64