ATLAS Offline Software
Loading...
Searching...
No Matches
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.
 CounterChain (const std::string &name, const MonitorBase *parent)
 Construct counter.
 CounterChain (const std::string &name, unsigned nRos, const MonitorBase *parent)
 Construct counter.
virtual ~CounterChain ()=default
 Default destructor.
CounterChainoperator= (const CounterChain &)=delete
 Forbid assignment.
 CounterChain (const CounterChain &)=delete
 Forbid copy.
virtual StatusCode newEvent (const CostData &data, size_t index, const float weight=1.) override
 Concrete implimentation.
const std::string & getName () const
 Getter for Counter's name.
const MonitorBasegetParent () const
 Return cached non-owning const ptr to this Counter's parent Monitor.
bool variableExists (const std::string &name) const
 Check if a variable of a given name exists.
VariablegetVariable (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 Variable.
StatusCode fill (std::string_view 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.
StatusCode increment (std::string_view name, float weight=1.0)
 Convenience function.
StatusCode setDenominator (const std::string &name, float value)
 Optional for per-Event Variables.
virtual StatusCode endEvent (float weight=1.0)
 Called by the framework.

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.
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.
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.
TH1 * bookGetPointer (TH1 *hist, const std::string &tDir="") const
 Appends Counter name (to histogram path) and forwards histogram book request to parent Monitor.
float timeToMilliSec (const uint64_t start, const uint64_t stop) const
 Helper function.

Private Attributes

bool m_isInitialized {}
const std::string m_name
 Counter's name.
const MonitorBasem_parent {}
 Counter's parent Monitor.
std::unordered_map< std::string, Variable, CxxUtils::TransparentStringHash, std::equal_to<> > m_variables
 Store of Counter's Variables.

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 12 of file CounterChain.cxx.

13 : CounterBase(name, parent), m_isInitialized(false)
14{
15 regHistogram("Group_perCall", "Chain group/Call;Group;Calls", VariableType::kPerCall, kLinear, -0.5, 9.5, 10);
16 regHistogram("Chain_perEvent", "Chain calls/Event;Chain call;Events", VariableType::kPerEvent, kLinear, -0.5, 49.5);
17 regHistogram("AlgCalls_perEvent", "Algorithm Calls/Event;Calls;Events", VariableType::kPerEvent, kLinear, -0.5, 999.5, 100);
18 regHistogram("Time_perCall", "CPU Time/Call;Time [ms];Calls", VariableType::kPerCall, kLog, 0.01, 100000);
19 regHistogram("Time_perEvent", "CPU Time/Event;Time [ms];Events", VariableType::kPerEvent);
20 regHistogram("UniqueTime_perCall", "Unique CPU Time/Call;Time [ms];Calls", VariableType::kPerCall, kLog, 0.01, 100000);
21 regHistogram("ChainPassed_perEvent", "Passed chain/Event;Passsed;Events", VariableType::kPerEvent, kLinear, -0.5, 1.5, 2);
22 regHistogram("Request_perEvent", "Number of requests/Event;Number of requests;Events", VariableType::kPerEvent, LogType::kLinear, -0.5, 299.5, 300);
23 regHistogram("NetworkRequest_perEvent", "Number of network requests/Event;Number of requests;Events", VariableType::kPerEvent, LogType::kLinear, -0.5, 149.5, 150);
24 regHistogram("CachedROBSize_perEvent", "Cached ROB Size/Event;ROB size;Events", VariableType::kPerEvent, LogType::kLinear, 0, 1024, 50);
25 regHistogram("NetworkROBSize_perEvent", "Network ROB Size/Event;ROB size;Events", VariableType::kPerEvent, LogType::kLinear, 0, 1024, 50);
26 regHistogram("RequestTime_perEvent", "ROB Elapsed Time/Event;Elapsed Time [ms];Events", VariableType::kPerEvent);
27}
@ 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
CounterBase()=delete
Forbid default constructor.
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.
bool m_isInitialized

◆ 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 29 of file CounterChain.cxx.

30 : CounterChain(name, parent)
31{
32 regTProfile("ROSRequests_perEvent", "Number of ROS requests;ROS names;Numer of requests to ROS per event", VariableType::kPerCall, LogType::kLinear, 0, nRos, nRos);
33 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);
34 regTProfile("ROBRequestsPerROS_perEvent", "Number of ROBs per ROS requests;ROS names;Numer of ROBs requested per request", VariableType::kPerCall, LogType::kLinear, 0, nRos, nRos);
35 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);
36}
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.
CounterChain()=delete
Forbid default constructor.

◆ ~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 235 of file CounterBase.cxx.

235 {
236 std::string dir = getName();
237 if (tDir != "") {
238 dir += "/";
239 dir += tDir;
240 }
241 return getParent()->bookGetPointer(hist, dir);
242}
const MonitorBase * getParent() const
Return cached non-owning const ptr to this Counter's parent Monitor.
const std::string & getName() const
Getter for Counter's name.
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Appends Monitor name (to histogram path) and forwards histogram book request to parent Range.

◆ 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 227 of file CounterBase.cxx.

227 {
228 for (auto& nameVariablePair : m_variables) {
229 ATH_CHECK( nameVariablePair.second.endEvent() );
230 }
231 return StatusCode::SUCCESS;
232}
#define ATH_CHECK
Evaluate an expression and check for errors.
std::unordered_map< std::string, Variable, CxxUtils::TransparentStringHash, std::equal_to<> > m_variables
Store of Counter's Variables.

◆ fill() [1/2]

StatusCode CounterBase::fill ( std::string_view 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 193 of file CounterBase.cxx.

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

◆ fill() [2/2]

StatusCode CounterBase::fill ( std::string_view 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 202 of file CounterBase.cxx.

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

◆ getName()

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

Getter for Counter's name.

Returns
Counter's name const string reference.

Definition at line 19 of file CounterBase.cxx.

19 {
20 return m_name;
21}
const std::string m_name
Counter's name.

◆ 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 24 of file CounterBase.cxx.

24 {
25 return m_parent;
26}
const MonitorBase * m_parent
Counter's parent Monitor.

◆ getVariable()

Variable & CounterBase::getVariable ( std::string_view 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 184 of file CounterBase.cxx.

184 {
185 auto it = m_variables.find(name);
186 if (it == m_variables.end()) {
187 throw std::runtime_error( std::format("CounterBase::getVariable: No variable with name {}", name) );
188 }
189 return (it->second);
190}

◆ increment()

StatusCode CounterBase::increment ( std::string_view 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 222 of file CounterBase.cxx.

222 {
223 return fill(name, 1.0, weight);
224}
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...

◆ 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 39 of file CounterChain.cxx.

39 {
40
41 ATH_CHECK( increment("Chain_perEvent", weight) );
42
43 if (!m_isInitialized && variableExists("ROSRequests_perEvent")) {
44 // Set histograms labels
45 for (const auto& rosToRobPair : data.costROSData().getROStoROBMap()) {
46 int binForROS = data.costROSData().getBinForROS(rosToRobPair.first) + 1;
47 ATH_CHECK( getVariable("ROSRequests_perEvent").setBinLabel(binForROS, rosToRobPair.first));
48 ATH_CHECK( getVariable("NetworkROSRequests_perEvent").setBinLabel(binForROS, rosToRobPair.first));
49 ATH_CHECK( getVariable("ROBRequestsPerROS_perEvent").setBinLabel(binForROS, rosToRobPair.first));
50 ATH_CHECK( getVariable("ROBRequestsPerROSPerEvent_perEvent").setBinLabel(binForROS, rosToRobPair.first));
51 }
52
53 // Fill the bins with groups and add the labels
54 int bin = 1;
55 for (const std::string& group : data.seededChains()[index].groups){
56 ATH_CHECK( getVariable("Group_perCall").setBinLabel(bin, group) );
57 ATH_CHECK( getVariable("Group_perCall").fill(group, weight) );
58 ++bin;
59 }
60
61 m_isInitialized = true;
62 }
63
64 if (data.seededChains()[index].isPassRaw){
65 ATH_CHECK( increment("ChainPassed_perEvent", weight) );
66 }
67
68 // Monitor algorithms associated with chain name
69 if (!data.chainToAlgMap().count(getName())) return StatusCode::SUCCESS;
70
71 std::map<std::string, int> nRosPerEvent; // Accumulate how many times ROS was requested in a request per this event
72 std::map<std::string, int> nNetworkRosPerEvent; // Accumulate how many times ROS was requested in a request per this event
73 std::map<std::string, int> nRobsPerRosPerEvent; // Accumulate how many ROBs ROS requested per this event
74 const std::string slotStr{"slot"};
75 const std::string startStr{"start"};
76 const std::string stopStr{"stop"};
77 for (const size_t algIndex : data.chainToAlgMap().at(getName())){
78 const xAOD::TrigComposite* alg = data.costCollection().at(algIndex);
79 const uint32_t slot = alg->getDetail<uint32_t>(slotStr);
80 if (slot != data.onlineSlot()) {
81 continue; // When monitoring the master slot, this Monitor ignores algs running in different slots
82 }
83
84 ATH_CHECK( increment("AlgCalls_perEvent", weight) );
85
86 const uint64_t start = alg->getDetail<uint64_t>(startStr); // in mus
87 const uint64_t stop = alg->getDetail<uint64_t>(stopStr); // in mus
88 const float cpuTime = timeToMilliSec(start, stop);
89 ATH_CHECK( fill("Time_perEvent", cpuTime, weight) );
90 ATH_CHECK( fill("Time_perCall", cpuTime, weight) );
91
92 // Monitor data requests
93 if (!data.algToRequestMap().count(algIndex)) continue;
94 static const std::string idStr{"robs_id"};
95 static const std::string historyStr{"robs_history"};
96 static const std::string sizeStr{"robs_size"};
97 for (size_t requestIdx : data.algToRequestMap().at(algIndex)) {
98 const xAOD::TrigComposite* request = data.rosCollection().at(requestIdx);
99 const std::vector<uint32_t> robIdsPerRequest = request->getDetail<std::vector<uint32_t>>(idStr);
100 const std::vector<unsigned> robs_history = request->getDetail<std::vector<unsigned>>(historyStr);
101 const std::vector<uint32_t> robs_size = request->getDetail<std::vector<uint32_t>>(sizeStr);
102
103 std::map<std::string, int> nRobsPerRosPerRequest; // Accumulate how many ROBs ROS requested per request
104
105 bool networkRequestIncremented = false;
106 std::set<std::string> requestedROSes;
107 std::set<std::string> requestedNetworkROSes;
108 for (size_t i = 0; i < robs_size.size(); ++i) {
109 // ROB request was fetched over the network
110 if (robs_history[i] == robmonitor::RETRIEVED) {
111 // size is stored in words, should be in kilobytes
112 ATH_CHECK( fill("NetworkROBSize_perEvent", robs_size[i] / 500., weight) );
113 networkRequestIncremented = true;
114 }
115 // ROB request was cached
116 else if (robs_history[i] == robmonitor::HLT_CACHED || robs_history[i] == robmonitor::DCM_CACHED) {
117 ATH_CHECK( fill("CachedROBSize_perEvent", robs_size[i] / 500., weight) );
118 }
119
120 uint32_t robId = robIdsPerRequest[i];
121 if (variableExists("ROBRequestsPerROS_perEvent")){
122 std::string rosForROB = data.costROSData().getROSForROB(robId);
123 if (!rosForROB.empty()){
124 requestedROSes.insert(rosForROB);
125 nRobsPerRosPerRequest[rosForROB] += 1;
126 nRobsPerRosPerEvent[rosForROB] += 1;
127
128 if (robs_history[i] == robmonitor::RETRIEVED) {
129 requestedNetworkROSes.insert(std::move(rosForROB));
130 }
131 }
132 }
133 }
134
135 // Save number of ROBs per ROS per request
136 for (const auto& robPerRosPair : nRobsPerRosPerRequest) {
137 ATH_CHECK( fill("ROBRequestsPerROS_perEvent", data.costROSData().getBinForROS(robPerRosPair.first), robPerRosPair.second, weight) );
138 }
139
140 // Save the requested ROSes per request
141 for (const std::string& rosName : requestedROSes){
142 nRosPerEvent[rosName] += 1;
143 }
144
145 for (const std::string& rosName : requestedNetworkROSes){
146 nNetworkRosPerEvent[rosName] += 1;
147 }
148
149 ATH_CHECK( increment("Request_perEvent", weight) );
150
151 if (networkRequestIncremented) {
152 ATH_CHECK( increment("NetworkRequest_perEvent", weight) );
153 }
154
155 const float rosTime = timeToMilliSec(request->getDetail<uint64_t>("start"), request->getDetail<uint64_t>("stop"));
156 ATH_CHECK( fill("RequestTime_perEvent", rosTime, weight) );
157 }
158 }
159
160 // Save the requested ROSes per event
161 for (const auto& robPerRosPair : nRosPerEvent) {
162 ATH_CHECK( fill("ROSRequests_perEvent", data.costROSData().getBinForROS(robPerRosPair.first), robPerRosPair.second, weight) );
163 }
164
165 for (const auto& robPerRosPair : nNetworkRosPerEvent) {
166 ATH_CHECK( fill("NetworkROSRequests_perEvent", data.costROSData().getBinForROS(robPerRosPair.first), robPerRosPair.second, weight) );
167 }
168
169 // Save the number of ROBs per ROS per event
170 for (const auto& robPerRosPair : nRobsPerRosPerEvent) {
171 ATH_CHECK( fill("ROBRequestsPerROSPerEvent_perEvent", data.costROSData().getBinForROS(robPerRosPair.first), robPerRosPair.second, weight) );
172 }
173
174 // Monitor unique algorithms associated with chain name
175 if (!data.chainToUniqAlgMap().count(getName())) return StatusCode::SUCCESS;
176
177 for (const size_t algIndex : data.chainToUniqAlgMap().at(getName())){
178 const xAOD::TrigComposite* alg = data.costCollection().at(algIndex);
179 const uint32_t slot = alg->getDetail<uint32_t>(slotStr);
180 if (slot != data.onlineSlot()) {
181 continue;
182 }
183 const uint64_t start = alg->getDetail<uint64_t>(startStr); // in mus
184 const uint64_t stop = alg->getDetail<uint64_t>(stopStr); // in mus
185 const float cpuTime = timeToMilliSec(start, stop);
186
187 ATH_CHECK( fill("UniqueTime_perCall", cpuTime, weight) );
188 }
189
190 return StatusCode::SUCCESS;
191}
float timeToMilliSec(const uint64_t start, const uint64_t stop) const
Helper function.
StatusCode increment(std::string_view name, float weight=1.0)
Convenience function.
bool variableExists(const std::string &name) const
Check if a variable of a given name exists.
Variable & getVariable(std::string_view name)
Returns a mutable reference to a named Variable.
bool getDetail(const std::string &name, TYPE &value) const
Get an TYPE detail from the object.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
setEventNumber uint32_t

◆ 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 111 of file CounterBase.cxx.

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

◆ 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 29 of file CounterBase.cxx.

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

◆ 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 70 of file CounterBase.cxx.

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

◆ 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 212 of file CounterBase.cxx.

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

◆ 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 245 of file CounterBase.cxx.

245 {
246 if (stop < start) {
247 throw std::runtime_error("Asked for a stop time " + std::to_string(stop) + " which is before the start time " + std::to_string(start));
248 }
249 const uint64_t difference = stop - start;
250 return (difference * 1e-3); // micro to ms
251}
difference(file_1="Geometry_1.json", file_2="Geometry_2.json", output_file="Geometry_diff.json")

◆ 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 180 of file CounterBase.cxx.

180 {
181 return m_variables.contains(name);
182}

Member Data Documentation

◆ m_isInitialized

bool CounterChain::m_isInitialized {}
private

Definition at line 60 of file CounterChain.h.

60{};

◆ m_name

const std::string CounterBase::m_name
privateinherited

Counter's name.

Definition at line 210 of file CounterBase.h.

◆ m_parent

const MonitorBase* CounterBase::m_parent {}
privateinherited

Counter's parent Monitor.

Cached non-owning const pointer.

Definition at line 211 of file CounterBase.h.

211{};

◆ m_variables

std::unordered_map< std::string, Variable, CxxUtils::TransparentStringHash, std::equal_to<> > CounterBase::m_variables
privateinherited

Store of Counter's Variables.

These wrap a histogram pointer. Keyed by name.

Definition at line 212 of file CounterBase.h.


The documentation for this class was generated from the following files: