5#ifndef ROOT_RCategoricalAxis
6#define ROOT_RCategoricalAxis
19#include <unordered_set>
26namespace Experimental {
62 throw std::invalid_argument(
"must have at least one category");
65 std::unordered_set<std::string_view> set;
66 for (std::size_t i = 0; i <
fCategories.size(); i++) {
68 std::string
msg =
"duplicate category '" +
fCategories[i] +
"' for bin " + std::to_string(i);
69 throw std::invalid_argument(
msg);
81 return lhs.fCategories ==
rhs.fCategories &&
lhs.fEnableOverflowBin ==
rhs.fEnableOverflowBin;
95 for (std::size_t bin = 0; bin <
fCategories.size(); bin++) {
114 if (
index.IsUnderflow()) {
117 }
else if (
index.IsOverflow()) {
119 }
else if (
index.IsInvalid()) {
123 std::uint64_t bin =
index.GetIndex();
143 throw std::invalid_argument(
"begin must be a normal bin");
146 throw std::invalid_argument(
"begin must be inside the axis");
149 throw std::invalid_argument(
"end must be a normal bin");
152 throw std::invalid_argument(
"end must be inside or past the axis");
154 if (!(end >= begin)) {
155 throw std::invalid_argument(
"end must be >= begin");
180 if (
sliceSpec.GetOperationSum() !=
nullptr) {
181 throw std::runtime_error(
"sum operation makes dimension disappear");
185 throw std::runtime_error(
"slicing of RCategoricalAxis not implemented");
187 if (
sliceSpec.GetOperationRebin() !=
nullptr) {
188 throw std::runtime_error(
"cannot rebin RCategoricalAxis");
197 void Streamer(
TBuffer &) {
throw std::runtime_error(
"unable to store RCategoricalAxis"); }
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
A bin index with special values for underflow and overflow bins.
bool IsNormal() const
A bin index is normal iff it is not one of the special values.
std::uint64_t GetIndex() const
Return the index for a normal bin.
An axis with categorical bins.
std::uint64_t GetNNormalBins() const
RCategoricalAxis(std::vector< std::string > categories, bool enableOverflowBin=true)
Construct an axis object with categories.
std::vector< std::string > fCategories
The categories as defined by the user.
std::string_view ArgumentType
RBinIndexRange GetFullRange() const
Get the full range of all bins.
RBinIndexRange GetNormalRange(RBinIndex begin, RBinIndex end) const
Get a range of normal bins.
bool HasOverflowBin() const
RCategoricalAxis Slice(const RSliceSpec &sliceSpec) const
Slice this axis according to the specification.
RLinearizedIndex ComputeLinearizedIndex(std::string_view x) const
Compute the linarized index for a single argument.
bool fEnableOverflowBin
Whether the overflow bin is enabled.
std::uint64_t GetTotalNBins() const
const std::vector< std::string > & GetCategories() const
friend bool operator==(const RCategoricalAxis &lhs, const RCategoricalAxis &rhs)
RBinIndexRange GetNormalRange() const
Get the range of all normal bins.
void Streamer(TBuffer &)
ROOT Streamer function to throw when trying to store an object of this class.
RLinearizedIndex GetLinearizedIndex(RBinIndex index) const
Get the linearized index for an RBinIndex.
Specification of a slice operation along one dimension.
Buffer base class used for serializing objects.
static RBinIndexRange CreateBinIndexRange(RBinIndex begin, RBinIndex end, std::uint64_t nNormalBins)
Internal function to create RBinIndexRange.
A linearized index that can be invalid.