ATLAS Offline Software
Loading...
Searching...
No Matches
Monitored::detail Namespace Reference

Classes

struct  get_value_type
 Get element type for containers. More...
struct  get_value_type< ActsTrk::TrackContainer >
struct  get_value_type< std::reference_wrapper< T > >
 Specializations for reference_wrappers which are hopefully never chosen. More...
struct  get_value_type< std::reference_wrapper< T[N]> >
struct  get_value_type< T[N]>
 Get element type for arrays. More...
struct  make_pointer_const
struct  make_pointer_const< T * >

Functions

template<typename T = int>
int findToolIndex (const ToolHandleArray< GenericMonitoringTool > &toolArray, const std::string &name)
 Finds the index of an element in a tool handle array by its string name.
template<typename H, typename W, typename M, typename ... Ms>
void doFill (H *hist, W weight, size_t i, const M &m1, const Ms &... m)
 Perform (arbitrary dimension) histogram fill with weight.
template<typename W>
void doFill (TProfile *, W, size_t, const double &, const char *const &)
template<typename W>
void doFill (TProfile *, W, size_t, const char *const &, const char *const &)
template<typename W>
void doFill (TProfile2D *, W, size_t, const double &, const double &, const char *const &)
template<typename W>
void doFill (TProfile2D *, W, size_t, const char *const &, const char *const &, const char *const &)
template<typename W>
void doFill (TProfile2D *, W, size_t, const char *const &, const double &, const char *const &)
template<typename W>
void doFill (TProfile2D *, W, size_t, const double &, const char *const &, const char *const &)
template<Axis AXIS, typename H>
constexpr auto getAxis (H *hist)
 Helper to get corresponding TAxis selected by Monitored::Axis.
template<Axis AXIS, typename H>
double getFillValue (const H *hist, const IMonitoredVariable *var, size_t i)
 Return value for filling i'th entry of var into AXIS for hist.
bool shouldRebinHistogram (const TAxis *axis, const double value)
 Method checks if histogram should be rebinned.
template<Axis AXIS, typename H>
void rebinHistogram (H *hist, const double value)
 Method that rebins a histogram.
template<typename T>
bool fillWillRebinHistogram (const TAxis *axis, T value)
 Check if Fill would result in rebinning.
template<>
bool fillWillRebinHistogram (const TAxis *axis, const char *value)
 Check if Fill would result in rebinning for alphanumeric axis.
template<typename H, typename T, T... a, typename ... Vs>
bool fillWillRebinHistogram (H *hist, std::integer_sequence< T, a... >, const Vs &... v)
 Check if any of the histogram axes will be rebinned.

Variables

auto noWeight = [](size_t){ return 1.0; }
 no weight for filling
auto noCut = [](size_t){ return true; }
 no cut for filling
constexpr std::array axis_name {"X", "Y", "Z"}
 Convert axis to ROOT-compatible character.
constexpr std::array axis_bit {TH1::kXaxis, TH1::kYaxis, TH1::kZaxis}

Function Documentation

◆ doFill() [1/7]

template<typename H, typename W, typename M, typename ... Ms>
void Monitored::detail::doFill ( H * hist,
W weight,
size_t i,
const M & m1,
const Ms &... m )

Perform (arbitrary dimension) histogram fill with weight.

Parameters
histhistogram to fill
weightweight accessor
iIMonitoredVariable entry to fill
m1,m...IMonitoredVariable list to fill from

Definition at line 164 of file HistogramFillerUtils.h.

164 {
165
166 // Template magic: Recursively convert all M to double or string
167 if constexpr(std::is_same_v<M, Monitored::IMonitoredVariable>) {
168 // For >=2D: If one variable has a single entry, do repeated fills with that value
169 const size_t j = m1.size()==1 ? 0 : i;
170 if (not m1.hasStringRepresentation())
171 doFill(hist, weight, i, m..., m1.get(j));
172 else
173 doFill(hist, weight, i, m..., m1.getString(j).c_str());
174 } else {
175 // In case re-binning occurs need to take the OH lock for online (no-op offline)
176 if ( ATH_UNLIKELY(fillWillRebinHistogram(hist, std::index_sequence_for<M, Ms...>{},
177 m1, m...)) ){
179 // Rebinning requires a lock on the global ROOT directory state
180 std::scoped_lock<std::mutex> dirLock(HistogramFactory::globalROOTMutex());
181 hist->Fill(m1, m..., weight(i));
182 }
183 else hist->Fill(m1, m..., weight(i));
184 }
185 }
#define ATH_UNLIKELY(x)
static std::mutex & globalROOTMutex()
Scoped lock to be used for threaded histogram operations.
bool fillWillRebinHistogram(const TAxis *axis, T value)
Check if Fill would result in rebinning.
void doFill(H *hist, W weight, size_t i, const M &m1, const Ms &... m)
Perform (arbitrary dimension) histogram fill with weight.

◆ doFill() [2/7]

template<typename W>
void Monitored::detail::doFill ( TProfile * ,
W ,
size_t ,
const char *const & ,
const char *const &  )

Definition at line 192 of file HistogramFillerUtils.h.

192{}

◆ doFill() [3/7]

template<typename W>
void Monitored::detail::doFill ( TProfile * ,
W ,
size_t ,
const double & ,
const char *const &  )

Definition at line 190 of file HistogramFillerUtils.h.

190{}

◆ doFill() [4/7]

template<typename W>
void Monitored::detail::doFill ( TProfile2D * ,
W ,
size_t ,
const char *const & ,
const char *const & ,
const char *const &  )

Definition at line 196 of file HistogramFillerUtils.h.

196{}

◆ doFill() [5/7]

template<typename W>
void Monitored::detail::doFill ( TProfile2D * ,
W ,
size_t ,
const char *const & ,
const double & ,
const char *const &  )

Definition at line 198 of file HistogramFillerUtils.h.

198{}

◆ doFill() [6/7]

template<typename W>
void Monitored::detail::doFill ( TProfile2D * ,
W ,
size_t ,
const double & ,
const char *const & ,
const char *const &  )

Definition at line 200 of file HistogramFillerUtils.h.

200{}

◆ doFill() [7/7]

template<typename W>
void Monitored::detail::doFill ( TProfile2D * ,
W ,
size_t ,
const double & ,
const double & ,
const char *const &  )

Definition at line 194 of file HistogramFillerUtils.h.

194{}

◆ fillWillRebinHistogram() [1/3]

template<>
bool Monitored::detail::fillWillRebinHistogram ( const TAxis * axis,
const char * value )

Check if Fill would result in rebinning for alphanumeric axis.

Note that even adding a new label to an unlabeled bin is not thread-safe and needs to be treated as "rebinning" (ADHI-4881).

Definition at line 130 of file HistogramFillerUtils.h.

130 {
131 // valid bin found
132 if ( not axis or axis->FindFixBin(value)>0 ) return false;
133
134 // If there are no labels yet at least one unlabeled bin is available
135 const THashList* labels = axis->GetLabels();
136 if ( not labels ) return false;
137
138 return true;
139 }

◆ fillWillRebinHistogram() [2/3]

template<typename T>
bool Monitored::detail::fillWillRebinHistogram ( const TAxis * axis,
T value )

Check if Fill would result in rebinning.

Determine if Fill(value) would result in a rebinning of the histogram.

Definition at line 113 of file HistogramFillerUtils.h.

113 {
114 if (not axis) return false;
115 const int bin = axis->FindFixBin(value);
116 // if under/overflow
117 if ( bin==0 or bin==axis->GetNbins()+1 ) {
118 return true;
119 }
120 return false;
121 }

◆ fillWillRebinHistogram() [3/3]

template<typename H, typename T, T... a, typename ... Vs>
bool Monitored::detail::fillWillRebinHistogram ( H * hist,
std::integer_sequence< T, a... > ,
const Vs &... v )

Check if any of the histogram axes will be rebinned.

Parameters
histhistogram to check
a...integer sequence of axes to check (0, 1, ...)
v...x, y, ... values to fill

Definition at line 149 of file HistogramFillerUtils.h.

149 {
150 // First check if axis is extensible, then if value would be outside of range
151 return (... || (getAxis<static_cast<Axis>(a)>(hist)->CanExtend() and
152 detail::fillWillRebinHistogram(getAxis<static_cast<Axis>(a)>(hist), v)));
153 }
static Double_t a
constexpr auto getAxis(H *hist)
Helper to get corresponding TAxis selected by Monitored::Axis.
Axis
Helper type for histogram axis selection.

◆ findToolIndex()

template<typename T = int>
int Monitored::detail::findToolIndex ( const ToolHandleArray< GenericMonitoringTool > & toolArray,
const std::string & name )

Finds the index of an element in a tool handle array by its string name.

Definition at line 138 of file MonitoredGroup.h.

138 {
139 auto it = std::find_if(toolArray.begin(),toolArray.end(),[&](const auto& r) {return r.name()==name;});
140 return it!=toolArray.end()
141 ? std::distance(toolArray.begin(),it)
142 : throw std::runtime_error("The tool "+name+" could not be found in the tool array.");
143 }
STL class.
int r
Definition globals.cxx:22
STL namespace.

◆ getAxis()

template<Axis AXIS, typename H>
auto Monitored::detail::getAxis ( H * hist)
constexpr

Helper to get corresponding TAxis selected by Monitored::Axis.

(works for const/non-const TAxis/TH1 thanks to auto return type)

Definition at line 40 of file HistogramFillerUtils.h.

40 {
41 if constexpr (AXIS==Axis::X) return hist->GetXaxis();
42 else if constexpr (AXIS==Axis::Y) return hist->GetYaxis();
43 else return hist->GetZaxis();
44 }

◆ getFillValue()

template<Axis AXIS, typename H>
double Monitored::detail::getFillValue ( const H * hist,
const IMonitoredVariable * var,
size_t i )

Return value for filling i'th entry of var into AXIS for hist.

If var is string-valued performs a bin lookup first.

Template Parameters
AXISHistograms axis
Parameters
histHistogram
varMonitoredVariable for value lookup
iindex for IMonitoredVariable value lookup

Definition at line 56 of file HistogramFillerUtils.h.

56 {
57 if ( var->hasStringRepresentation() ) {
58 const TAxis* axis = getAxis<AXIS>(hist);
59 const int binNumber = axis->FindFixBin( var->getString(i).c_str() );
60 return axis->GetBinCenter(binNumber);
61 } else {
62 return var->get(i);
63 }
64 }

◆ rebinHistogram()

template<Axis AXIS, typename H>
void Monitored::detail::rebinHistogram ( H * hist,
const double value )

Method that rebins a histogram.

Algorithm will increase a size of the histogram until value can be included in new range of values. Examples for xMin=1.0, xMax=3.0; value=2.9, xMax will be unchanged value=3.0, xMax will be doubled value=4.9, xMax will be doubled value=5.0, xMax will be quadrupled value=5.1, xMax will be quadrupled value=8.9, xMax will be quadrupled value=9.0, xMax will be octupled value=9.1, xMax will be octupled

Definition at line 89 of file HistogramFillerUtils.h.

89 {
90 hist->SetCanExtend(axis_bit[AXIS]);
91 TAxis* a = getAxis<AXIS>(hist);
92
93 // Rebinning requires to take OH lock in online (no-op offline)
95 // Rebinning requires a lock on the global ROOT directory state
96 std::scoped_lock<std::mutex> dirLock(HistogramFactory::globalROOTMutex());
97 do {
98 // need to unset cleanup bit of parent histogram during this operation
99 // since it gets copied to a hidden temporary (probably unintentionally)
100 bool curcleanup = hist->TestBit(TObject::kMustCleanup);
101 hist->ResetBit(TObject::kMustCleanup);
102 hist->LabelsInflate(axis_name[AXIS]);
103 hist->SetBit(TObject::kMustCleanup, curcleanup);
104 } while (shouldRebinHistogram(a, value));
105 }
constexpr std::array axis_bit
constexpr std::array axis_name
Convert axis to ROOT-compatible character.
bool shouldRebinHistogram(const TAxis *axis, const double value)
Method checks if histogram should be rebinned.

◆ shouldRebinHistogram()

bool Monitored::detail::shouldRebinHistogram ( const TAxis * axis,
const double value )

Method checks if histogram should be rebinned.

It should happen when the new value is greater or equal to the greatest value of the histogram axis.

Definition at line 70 of file HistogramFillerUtils.h.

70 {
71 return axis ? axis->GetXmax() <= value : false;
72 }

Variable Documentation

◆ axis_bit

std::array Monitored::detail::axis_bit {TH1::kXaxis, TH1::kYaxis, TH1::kZaxis}
constexpr

Definition at line 33 of file HistogramFillerUtils.h.

33{TH1::kXaxis, TH1::kYaxis, TH1::kZaxis};

◆ axis_name

std::array Monitored::detail::axis_name {"X", "Y", "Z"}
constexpr

Convert axis to ROOT-compatible character.

Definition at line 32 of file HistogramFillerUtils.h.

32{"X", "Y", "Z"};

◆ noCut

auto Monitored::detail::noCut = [](size_t){ return true; }

no cut for filling

Definition at line 29 of file HistogramFillerUtils.h.

29{ return true; };

◆ noWeight

auto Monitored::detail::noWeight = [](size_t){ return 1.0; }

no weight for filling

Definition at line 28 of file HistogramFillerUtils.h.

28{ return 1.0; };