Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-16 09:21:23

0001 /// \file
0002 /// \warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes.
0003 /// Feedback is welcome!
0004 
0005 #ifndef ROOT_RSliceSpec
0006 #define ROOT_RSliceSpec
0007 
0008 #include "RBinIndexRange.hxx"
0009 
0010 #include <cstdint>
0011 #include <stdexcept>
0012 #include <utility>
0013 #include <variant>
0014 
0015 namespace ROOT {
0016 namespace Experimental {
0017 
0018 /**
0019 Specification of a slice operation along one dimension.
0020 
0021 \code
0022 using ROOT::Experimental::RSliceSpec;
0023 // When not specifying a range, the slice will include all bins.
0024 RSliceSpec full;
0025 // In the following, assuming range is an RBinIndexRange.
0026 RSliceSpec slice(range);
0027 
0028 // Operations are specified with parameters.
0029 RSliceSpec rebin(RSliceSpec::ROperationRebin(2));
0030 RSliceSpec sum(RSliceSpec::ROperationSum{});
0031 
0032 // Finally, it is possible to combine a range and an operation.
0033 RSliceSpec sliceRebin(range, RSliceSpec::ROperationRebin(2));
0034 RSliceSpec sliceSum(range, RSliceSpec::ROperationSum{});
0035 \endcode
0036 
0037 \warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes.
0038 Feedback is welcome!
0039 */
0040 class RSliceSpec final {
0041 public:
0042    /// Rebin the dimension, grouping a number of original bins into a new one.
0043    class ROperationRebin final {
0044       std::uint64_t fNGroup = 1;
0045 
0046    public:
0047       /// \param[in] nGroup the number of bins to group, must be > 0
0048       ROperationRebin(std::uint64_t nGroup) : fNGroup(nGroup)
0049       {
0050          if (nGroup == 0) {
0051             throw std::invalid_argument("nGroup must be > 0");
0052          }
0053       }
0054 
0055       std::uint64_t GetNGroup() const { return fNGroup; }
0056    };
0057 
0058    /// Sum bins along this dimension, effectively resulting in a projection.
0059    class ROperationSum final {
0060       // empty, no parameters at the moment
0061    };
0062 
0063 private:
0064    /// The range of the slice; can be invalid to signify the full range
0065    RBinIndexRange fRange;
0066    /// The operation to perform, if any
0067    std::variant<std::monostate, ROperationRebin, ROperationSum> fOperation;
0068 
0069 public:
0070    /// A default slice operation that keeps the dimension untouched.
0071    RSliceSpec() = default;
0072 
0073    /// A slice of a dimension.
0074    ///
0075    /// \param[in] range the range of the slice
0076    RSliceSpec(RBinIndexRange range) : fRange(std::move(range)) {}
0077 
0078    /// A rebin operation of a dimension.
0079    RSliceSpec(ROperationRebin rebin) : fOperation(std::move(rebin)) {}
0080 
0081    /// A sum operation of a dimension.
0082    RSliceSpec(ROperationSum sum) : fOperation(std::move(sum)) {}
0083 
0084    /// A rebin operation of a slice of the dimension.
0085    RSliceSpec(RBinIndexRange range, ROperationRebin rebin) : fRange(std::move(range)), fOperation(std::move(rebin)) {}
0086 
0087    /// A sum operation of a slice of the dimension.
0088    RSliceSpec(RBinIndexRange range, ROperationSum sum) : fRange(std::move(range)), fOperation(std::move(sum)) {}
0089 
0090    const RBinIndexRange &GetRange() const { return fRange; }
0091    bool HasOperation() const { return !std::holds_alternative<std::monostate>(fOperation); }
0092    const ROperationRebin *GetOperationRebin() const { return std::get_if<ROperationRebin>(&fOperation); }
0093    const ROperationSum *GetOperationSum() const { return std::get_if<ROperationSum>(&fOperation); }
0094 };
0095 
0096 } // namespace Experimental
0097 } // namespace ROOT
0098 
0099 #endif