43 friend class ::ROOT::Experimental::RHistEngine;
45 std::vector<RAxisVariant>
fAxes;
49 explicit RAxes(std::vector<RAxisVariant> axes) :
fAxes(std::move(axes))
52 throw std::invalid_argument(
"must have at least 1 axis object");
57 const std::vector<RAxisVariant> &
Get()
const {
return fAxes; }
69 std::uint64_t totalNBins = 1;
70 for (
auto &&axis :
fAxes) {
71 totalNBins *= axis.GetTotalNBins();
77 template <std::size_t
I, std::size_t
N,
typename... A>
80 using ArgumentType = std::tuple_element_t<
I, std::tuple<A...>>;
81 const auto &axis =
fAxes[
I];
83 if (
auto *regular = axis.GetRegularAxis()) {
84 if constexpr (std::is_convertible_v<ArgumentType, RRegularAxis::ArgumentType>) {
85 index *= regular->GetTotalNBins();
86 linIndex = regular->ComputeLinearizedIndex(std::get<I>(args));
88 throw std::invalid_argument(
"invalid type of argument");
90 }
else if (
auto *variable = axis.GetVariableBinAxis()) {
91 if constexpr (std::is_convertible_v<ArgumentType, RVariableBinAxis::ArgumentType>) {
92 index *= variable->GetTotalNBins();
93 linIndex = variable->ComputeLinearizedIndex(std::get<I>(args));
95 throw std::invalid_argument(
"invalid type of argument");
97 }
else if (
auto *categorical = axis.GetCategoricalAxis()) {
98 if constexpr (std::is_convertible_v<ArgumentType, RCategoricalAxis::ArgumentType>) {
99 index *= categorical->GetTotalNBins();
100 linIndex = categorical->ComputeLinearizedIndex(std::get<I>(args));
102 throw std::invalid_argument(
"invalid type of argument");
105 throw std::logic_error(
"unimplemented axis type");
111 if constexpr (
I + 1 <
N) {
114 return {index,
true};
117 template <std::size_t
N,
typename... A>
131 template <
typename... A>
134 if (
sizeof...(A) !=
fAxes.size()) {
135 throw std::invalid_argument(
"invalid number of arguments to ComputeGlobalIndex");
141 template <
typename Container>
146 throw std::invalid_argument(
"invalid number of indices passed to ComputeGlobalIndex");
148 std::uint64_t globalIndex = 0;
149 for (std::size_t i = 0; i <
N; i++) {
150 const auto &index =
indices[i];
151 const auto &axis =
fAxes[i];
153 if (
auto *regular = axis.GetRegularAxis()) {
154 globalIndex *= regular->GetTotalNBins();
155 linIndex = regular->GetLinearizedIndex(index);
156 }
else if (
auto *variable = axis.GetVariableBinAxis()) {
157 globalIndex *= variable->GetTotalNBins();
158 linIndex = variable->GetLinearizedIndex(index);
159 }
else if (
auto *categorical = axis.GetCategoricalAxis()) {
160 globalIndex *= categorical->GetTotalNBins();
161 linIndex = categorical->GetLinearizedIndex(index);
163 throw std::logic_error(
"unimplemented axis type");
168 globalIndex += linIndex.
fIndex;
170 return {globalIndex,
true};
178 template <std::
size_t N>
198 std::vector<RBinIndexRange> ranges;
199 for (
auto &&axis :
fAxes) {
200 ranges.push_back(axis.GetFullRange());
friend bool operator==(const RAxes &lhs, const RAxes &rhs)
std::size_t GetNDimensions() const
friend bool operator!=(const RAxes &lhs, const RAxes &rhs)
RLinearizedIndex ComputeGlobalIndexImpl(std::size_t index, const std::tuple< A... > &args) const
RLinearizedIndex ComputeGlobalIndex(const std::tuple< A... > &args) const
Compute the global index for all axes.
RBinIndexMultiDimRange GetFullMultiDimRange() const
Get the multidimensional range of all bins.
RLinearizedIndex ComputeGlobalIndexImpl(const std::tuple< A... > &args) const
std::uint64_t ComputeTotalNBins() const
Compute the total number of bins for all axes.
RAxes(std::vector< RAxisVariant > axes)
RLinearizedIndex ComputeGlobalIndexImpl(const Container &indices) const
RLinearizedIndex ComputeGlobalIndex(const std::vector< RBinIndex > &indices) const
Compute the global index for all axes.
void Streamer(TBuffer &)
ROOT Streamer function to throw when trying to store an object of this class.
RLinearizedIndex ComputeGlobalIndex(const std::array< RBinIndex, N > &indices) const
Compute the global index for all axes.
std::vector< RAxisVariant > fAxes
const std::vector< RAxisVariant > & Get() const
A multidimensional range of bin indices.
A histogram data structure to bin data along multiple dimensions.
Buffer base class used for serializing objects.
Namespace for ROOT features in testing.
A linearized index that can be invalid.