Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RProfileFillContext.hxx
Go to the documentation of this file.
1/// \file
2/// \warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes.
3/// Feedback is welcome!
4
5#ifndef ROOT_RProfileFillContext
6#define ROOT_RProfileFillContext
7
8#include "RProfile.hxx"
9#include "RHistEngine.hxx"
10#include "RHistStats.hxx"
11#include "RHistUtils.hxx"
12#include "RWeight.hxx"
13
14#include <cstddef>
15#include <tuple>
16
17namespace ROOT {
18namespace Experimental {
19
20/**
21A context to concurrently fill an RProfile.
22
23\sa RProfileConcurrentFiller
24
25\warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes.
26Feedback is welcome!
27*/
30
31private:
32 /// A pointer to the filled profile histogram
33 RProfile *fProfile = nullptr;
34
35 /// Local histogram statistics
37
38 /// \sa RProfileConcurrentFiller::CreateFillContent()
39 explicit RProfileFillContext(RProfile &profile) : fProfile(&profile), fStats(profile.GetNDimensions() + 1)
40 {
41 // Propagate disabled dimensions to the local histogram statistics object.
42 const auto &stats = profile.GetStats();
43 for (std::size_t i = 0; i < stats.GetNDimensions(); i++) {
44 if (!stats.IsEnabled(i)) {
46 }
47 }
48 }
53
54public:
56
57 /// Fill an entry into the profile histogram.
58 ///
59 /// If one of the arguments is outside the corresponding axis and flow bins are disabled, the entry will be silently
60 /// discarded.
61 ///
62 /// Throws an exception if the number of arguments does not match the axis configuration, or if an argument cannot be
63 /// converted for the axis type at run-time.
64 ///
65 /// \param[in] args the arguments for each axis
66 /// \param[in] v the additional argument
67 /// \sa RProfile::Fill(const std::tuple<A...> &args, const V &value)
68 template <typename... A, typename V>
69 void Fill(const std::tuple<A...> &args, const V &value)
70 {
72 fProfile->fEngine.FillAtomic(args, wrapper);
73 // Avoid a second conversion of value, which we already did in wrapper.
75 }
76
77 /// Fill an entry into the profile histogram with a weight.
78 ///
79 /// If one of the arguments is outside the corresponding axis and flow bins are disabled, the entry will be silently
80 /// discarded.
81 ///
82 /// Throws an exception if the number of arguments does not match the axis configuration, or if an argument cannot be
83 /// converted for the axis type at run-time.
84 ///
85 /// \param[in] args the arguments for each axis
86 /// \param[in] v the additional argument
87 /// \param[in] weight the weight for this entry
88 /// \sa RProfile::Fill(const std::tuple<A...> &args, const V &value, RWeight weight)
89 template <typename... A, typename V>
90 void Fill(const std::tuple<A...> &args, const V &value, RWeight weight)
91 {
93 fProfile->fEngine.FillAtomic(args, wrapper);
94 // Avoid a second conversion of value, which we already did in wrapper.
95 fStats.Fill(Internal::AppendReference(args, wrapper.fValue), weight);
96 }
97
98 /// Fill an entry into the profile histogram.
99 ///
100 /// For weighted filling, pass an RWeight as the last argument.
101 ///
102 /// If one of the arguments is outside the corresponding axis and flow bins are disabled, the entry will be silently
103 /// discarded.
104 ///
105 /// Throws an exception if the number of arguments does not match the axis configuration, or if an argument cannot be
106 /// converted for the axis type at run-time.
107 ///
108 /// \param[in] args the arguments for each axis
109 /// \sa RProfile::Fill(const A &...args)
110 template <typename... A>
111 void Fill(const A &...args)
112 {
113 static_assert(sizeof...(A) >= 2, "need at least two arguments to Fill");
114 if constexpr (sizeof...(A) >= 2) {
115 auto t = std::forward_as_tuple(args...);
116 if constexpr (std::is_same_v<typename Internal::LastType<A...>::type, RWeight>) {
117 static constexpr std::size_t N = sizeof...(A) - 2;
118 if (N != fProfile->GetNDimensions()) {
119 throw std::invalid_argument("invalid number of arguments to Fill");
120 }
121 RWeight weight = std::get<N + 1>(t);
122 RProfile::RValueWeightWrapper wrapper(std::get<N>(t), weight.fValue);
123 fProfile->fEngine.FillAtomicImpl<N>(t, wrapper);
124 } else {
125 static constexpr std::size_t N = sizeof...(A) - 1;
126 if (N != fProfile->GetNDimensions()) {
127 throw std::invalid_argument("invalid number of arguments to Fill");
128 }
129 RProfile::RValueWrapper wrapper(std::get<N>(t));
130 fProfile->fEngine.FillAtomicImpl<N>(t, wrapper);
131 }
132 fStats.Fill(args...);
133 }
134 }
135
136 /// Flush locally accumulated entries to the profile histogram.
137 void Flush()
138 {
140 fStats.Clear();
141 }
142};
143
144} // namespace Experimental
145} // namespace ROOT
146
147#endif
#define N
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Histogram statistics of unbinned values.
void Clear()
Clear this statistics object.
void AddAtomic(const RHistStats &other)
Add all entries from another statistics object using atomic instructions.
void Fill(const std::tuple< A... > &args)
Fill an entry into this statistics object.
void DisableDimension(std::size_t dim)
Disable one dimension of this statistics object.
A histogram filler to concurrently fill an RProfile.
A context to concurrently fill an RProfile.
RProfileFillContext & operator=(RProfileFillContext &&)=default
void Fill(const std::tuple< A... > &args, const V &value)
Fill an entry into the profile histogram.
RProfileFillContext(const RProfileFillContext &)=delete
void Fill(const A &...args)
Fill an entry into the profile histogram.
void Fill(const std::tuple< A... > &args, const V &value, RWeight weight)
Fill an entry into the profile histogram with a weight.
void Flush()
Flush locally accumulated entries to the profile histogram.
RProfileFillContext & operator=(const RProfileFillContext &)=delete
RProfile * fProfile
A pointer to the filled profile histogram.
RProfileFillContext(RProfileFillContext &&)=default
RHistStats fStats
Local histogram statistics.
A profile histogram, computing statistical quantities of an additional variable per bin.
Definition RProfile.hxx:58
RHistStats fStats
The global histogram statistics.
Definition RProfile.hxx:157
std::size_t GetNDimensions() const
Definition RProfile.hxx:239
const RHistStats & GetStats() const
Definition RProfile.hxx:236
RHistEngine< RProfileBin > fEngine
The histogram engine including the bin contents.
Definition RProfile.hxx:155
std::tuple< const Ts &..., const A & > AppendReference(const std::tuple< Ts... > &t, const A &a)
A weight for filling histograms.
Definition RWeight.hxx:17