File indexing completed on 2026-08-16 09:21:12
0001
0002
0003
0004
0005 #ifndef ROOT_RAxisVariant
0006 #define ROOT_RAxisVariant
0007
0008 #include "RCategoricalAxis.hxx"
0009 #include "RRegularAxis.hxx"
0010 #include "RVariableBinAxis.hxx"
0011
0012 #include <cstdint>
0013 #include <stdexcept>
0014 #include <utility>
0015 #include <variant>
0016
0017 class TBuffer;
0018
0019 namespace ROOT {
0020 namespace Experimental {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 class RAxisVariant final {
0031 public:
0032 using VariantType = std::variant<RRegularAxis, RVariableBinAxis, RCategoricalAxis>;
0033
0034 private:
0035 VariantType fVariant;
0036
0037 public:
0038 RAxisVariant(VariantType axis) : fVariant(std::move(axis)) {}
0039 RAxisVariant(RRegularAxis axis) : fVariant(std::move(axis)) {}
0040 RAxisVariant(RVariableBinAxis axis) : fVariant(std::move(axis)) {}
0041 RAxisVariant(RCategoricalAxis axis) : fVariant(std::move(axis)) {}
0042
0043 const VariantType &GetVariant() const { return fVariant; }
0044
0045
0046 const RRegularAxis *GetRegularAxis() const { return std::get_if<RRegularAxis>(&fVariant); }
0047
0048 const RVariableBinAxis *GetVariableBinAxis() const { return std::get_if<RVariableBinAxis>(&fVariant); }
0049
0050 const RCategoricalAxis *GetCategoricalAxis() const { return std::get_if<RCategoricalAxis>(&fVariant); }
0051
0052 std::uint64_t GetNNormalBins() const
0053 {
0054 if (auto *regular = GetRegularAxis()) {
0055 return regular->GetNNormalBins();
0056 } else if (auto *variable = GetVariableBinAxis()) {
0057 return variable->GetNNormalBins();
0058 } else if (auto *categorical = GetCategoricalAxis()) {
0059 return categorical->GetNNormalBins();
0060 } else {
0061 throw std::logic_error("unimplemented axis type");
0062 }
0063 }
0064
0065 std::uint64_t GetTotalNBins() const
0066 {
0067 if (auto *regular = GetRegularAxis()) {
0068 return regular->GetTotalNBins();
0069 } else if (auto *variable = GetVariableBinAxis()) {
0070 return variable->GetTotalNBins();
0071 } else if (auto *categorical = GetCategoricalAxis()) {
0072 return categorical->GetTotalNBins();
0073 } else {
0074 throw std::logic_error("unimplemented axis type");
0075 }
0076 }
0077
0078
0079
0080
0081 RBinIndexRange GetNormalRange() const
0082 {
0083 if (auto *regular = GetRegularAxis()) {
0084 return regular->GetNormalRange();
0085 } else if (auto *variable = GetVariableBinAxis()) {
0086 return variable->GetNormalRange();
0087 } else if (auto *categorical = GetCategoricalAxis()) {
0088 return categorical->GetNormalRange();
0089 } else {
0090 throw std::logic_error("unimplemented axis type");
0091 }
0092 }
0093
0094
0095
0096
0097
0098
0099 RBinIndexRange GetNormalRange(RBinIndex begin, RBinIndex end) const
0100 {
0101 if (auto *regular = GetRegularAxis()) {
0102 return regular->GetNormalRange(begin, end);
0103 } else if (auto *variable = GetVariableBinAxis()) {
0104 return variable->GetNormalRange(begin, end);
0105 } else if (auto *categorical = GetCategoricalAxis()) {
0106 return categorical->GetNormalRange(begin, end);
0107 } else {
0108 throw std::logic_error("unimplemented axis type");
0109 }
0110 }
0111
0112
0113
0114
0115
0116
0117 RBinIndexRange GetFullRange() const
0118 {
0119 if (auto *regular = GetRegularAxis()) {
0120 return regular->GetFullRange();
0121 } else if (auto *variable = GetVariableBinAxis()) {
0122 return variable->GetFullRange();
0123 } else if (auto *categorical = GetCategoricalAxis()) {
0124 return categorical->GetFullRange();
0125 } else {
0126 throw std::logic_error("unimplemented axis type");
0127 }
0128 }
0129
0130
0131
0132
0133
0134
0135
0136
0137 RAxisVariant Slice(const RSliceSpec &sliceSpec) const
0138 {
0139 if (auto *regular = GetRegularAxis()) {
0140 return regular->Slice(sliceSpec);
0141 } else if (auto *variable = GetVariableBinAxis()) {
0142 return variable->Slice(sliceSpec);
0143 } else if (auto *categorical = GetCategoricalAxis()) {
0144 return categorical->Slice(sliceSpec);
0145 } else {
0146 throw std::logic_error("unimplemented axis type");
0147 }
0148 }
0149
0150 friend bool operator==(const RAxisVariant &lhs, const RAxisVariant &rhs) { return lhs.fVariant == rhs.fVariant; }
0151
0152
0153 void Streamer(TBuffer &) { throw std::runtime_error("unable to store RAxisVariant"); }
0154 };
0155
0156 }
0157 }
0158
0159 #endif