5#ifndef ROOT_RHistEngine
6#define ROOT_RHistEngine
68template <
typename BinContentType>
75 friend class RHist<BinContentType>;
106 template <
typename... Axes>
119 RHistEngine(std::uint64_t nNormalBins, std::pair<double, double> interval)
149 const std::vector<RAxisVariant> &
GetAxes()
const {
return fAxes.Get(); }
171 template <std::
size_t N>
177 throw std::invalid_argument(
"invalid number of indices passed to GetBinContent");
181 throw std::invalid_argument(
"bin not found in GetBinContent");
210 throw std::invalid_argument(
"invalid number of indices passed to GetBinContent");
214 throw std::invalid_argument(
"bin not found in GetBinContent");
239 template <
typename... A>
269 template <std::
size_t N,
typename V>
275 throw std::invalid_argument(
"invalid number of indices passed to SetBinContent");
279 throw std::invalid_argument(
"bin not found in SetBinContent");
291 template <
typename... A, std::size_t...
I>
321 template <
typename... A>
324 auto t = std::forward_as_tuple(args...);
356 template <
typename... A>
357 void Fill(
const std::tuple<A...> &args)
362 throw std::invalid_argument(
"invalid number of arguments to Fill");
392 template <
typename... A>
400 throw std::invalid_argument(
"invalid number of arguments to Fill");
421 template <
typename... A,
typename W>
422 void Fill(
const std::tuple<A...> &args,
const W &weight)
424 static_assert(std::is_class_v<BinContentType>,
425 "user-defined weight types are only supported for user-defined bin content types");
430 throw std::invalid_argument(
"invalid number of arguments to Fill");
463 template <
typename... A>
466 static_assert(
sizeof...(A) >= 1,
"need at least one argument to Fill");
467 if constexpr (
sizeof...(A) >= 1) {
468 auto t = std::forward_as_tuple(args...);
471 static constexpr std::size_t
N =
sizeof...(A) - 1;
472 if (
N !=
fAxes.GetNDimensions()) {
473 throw std::invalid_argument(
"invalid number of arguments to Fill");
475 RWeight weight = std::get<N>(t);
491 template <
typename... A>
497 throw std::invalid_argument(
"invalid number of arguments to Fill");
513 template <
typename... A>
521 throw std::invalid_argument(
"invalid number of arguments to Fill");
537 template <
typename... A,
typename W>
538 void FillAtomic(
const std::tuple<A...> &args,
const W &weight)
540 static_assert(std::is_class_v<BinContentType>,
541 "user-defined weight types are only supported for user-defined bin content types");
546 throw std::invalid_argument(
"invalid number of arguments to Fill");
559 template <
typename... A>
562 static_assert(
sizeof...(A) >= 1,
"need at least one argument to Fill");
563 if constexpr (
sizeof...(A) >= 1) {
564 auto t = std::forward_as_tuple(args...);
567 static constexpr std::size_t
N =
sizeof...(A) - 1;
568 if (
N !=
fAxes.GetNDimensions()) {
569 throw std::invalid_argument(
"invalid number of arguments to Fill");
571 RWeight weight = std::get<N>(t);
595 throw std::invalid_argument(
"axes configurations not identical in Add");
610 throw std::invalid_argument(
"axes configurations not identical in AddAtomic");
647 template <
typename U>
664 static_assert(!std::is_integral_v<BinContentType>,
"scaling is not supported for integral bin content types");
677 throw std::invalid_argument(
"invalid number of specifications passed to Slice");
681 std::vector<RAxisVariant> axes;
682 for (std::size_t i = 0; i < sliceSpecs.size(); i++) {
684 if (sliceSpecs[i].GetOperationSum() ==
nullptr) {
685 axes.push_back(
fAxes.Get()[i].Slice(sliceSpecs[i]));
689 throw std::invalid_argument(
"summing across all dimensions is not supported");
699 auto origRange =
fAxes.GetFullMultiDimRange();
700 auto origRangeIt = origRange.begin();
703 const auto &origIndices = *origRangeIt;
708 assert(origIndex.
fIndex == i);
711 bool success = mapper.
Map(origIndices, mappedIndices);
714 assert(mappedIndex.
fValid);
767 bool dropped =
false;
807 template <
typename... A>
810 std::vector<RSliceSpec> sliceSpecs{args...};
811 return Slice(sliceSpecs);
Bin configurations for all dimensions of a histogram.
RLinearizedIndex ComputeGlobalIndex(const std::tuple< A... > &args) const
Compute the global index for all axes.
Mapper of bin indices for slice operations.
bool Map(const std::vector< RBinIndex > &original, std::vector< RBinIndex > &mapped) const
Map a vector of RBinIndex according to the slice specifications.
std::size_t GetMappedDimensionality() const
A variant of all supported axis types.
A multidimensional range of bin indices.
A bin index with special values for underflow and overflow bins.
RHistEngine Slice(const std::vector< RSliceSpec > &sliceSpecs) const
Slice this histogram with an RSliceSpec per dimension.
RHistEngine(const RAxisVariant &axis1, const Axes &...axes)
Construct a histogram engine.
void Fill(const A &...args)
Fill an entry into the histogram.
const std::vector< RAxisVariant > & GetAxes() const
RBinIndexMultiDimRange GetFullMultiDimRange() const
Get the multidimensional range of all bins.
RHistEngine Clone() const
Clone this histogram engine.
RHistEngine & operator=(RHistEngine &&)=default
Efficiently move a histogram engine.
void SetBinContent(const A &...args)
Set the content of a single bin.
void Scale(double factor)
Scale all histogram bin contents.
void Fill(const std::tuple< A... > &args)
Fill an entry into the histogram.
void FillAtomic(const std::tuple< A... > &args)
Fill an entry into the histogram using atomic instructions.
RHistEngine(std::uint64_t nNormalBins, std::pair< double, double > interval)
Construct a one-dimensional histogram engine with a regular axis.
RHistEngine & operator=(const RHistEngine &)=delete
The copy assignment operator is deleted.
const BinContentType & GetBinContent(const std::vector< RBinIndex > &indices) const
Get the content of a single bin.
RHistEngine(RHistEngine &&)=default
Efficiently move construct a histogram engine.
RHistEngine(const RHistEngine &)=delete
The copy constructor is deleted.
const BinContentType & GetBinContent(const std::array< RBinIndex, N > &indices) const
Get the content of a single bin.
const BinContentType & GetBinContent(const A &...args) const
Get the content of a single bin.
RHistEngine SliceImpl(const std::vector< RSliceSpec > &sliceSpecs, bool &dropped) const
void SetBinContent(const std::array< RBinIndex, N > &indices, const V &value)
Set the content of a single bin.
void AddAtomic(const RHistEngine &other)
Add all bin contents of another histogram using atomic instructions.
std::size_t GetNDimensions() const
void Fill(const std::tuple< A... > &args, const W &weight)
Fill an entry into the histogram with a user-defined weight.
void Add(const RHistEngine &other)
Add all bin contents of another histogram.
void FillAtomic(const std::tuple< A... > &args, RWeight weight)
Fill an entry into the histogram with a weight using atomic instructions.
static constexpr bool SupportsWeightedFilling
Whether this histogram engine type supports weighted filling.
void Clear()
Clear all bin contents.
RHistEngine Slice(const A &...args) const
Slice this histogram with an RSliceSpec per dimension.
std::uint64_t GetTotalNBins() const
void FillAtomic(const std::tuple< A... > &args, const W &weight)
Fill an entry into the histogram with a user-defined weight using atomic instructions.
void SetBinContentImpl(const std::tuple< A... > &args, std::index_sequence< I... >)
RHistEngine(std::vector< RAxisVariant > axes)
Construct a histogram engine.
void FillAtomic(const A &...args)
Fill an entry into the histogram using atomic instructions.
Internal::RAxes fAxes
The axis configuration for this histogram. Relevant methods are forwarded from the public interface.
void Fill(const std::tuple< A... > &args, RWeight weight)
Fill an entry into the histogram with a weight.
RHistEngine(std::initializer_list< RAxisVariant > axes)
Construct a histogram engine.
void Streamer(TBuffer &)
ROOT Streamer function to throw when trying to store an object of this class.
std::vector< BinContentType > fBinContents
The bin contents for this histogram.
RHistEngine< U > Convert() const
Convert this histogram engine to a different bin content type.
A histogram for aggregation of data along multiple dimensions.
A regular axis with equidistant bins in the interval .
Buffer base class used for serializing objects.
std::enable_if_t< std::is_arithmetic_v< T > > AtomicInc(T *ptr)
std::enable_if_t< std::is_integral_v< T > > AtomicAdd(T *ptr, T val)
Namespace for ROOT features in testing.
A linearized index that can be invalid.
A weight for filling histograms.