Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RSliceSpec.hxx
Go to the documentation of this file.
1/// \file
2/// \warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes.
3/// Feedback is welcome!
4
5#ifndef ROOT_RSliceSpec
6#define ROOT_RSliceSpec
7
8#include "RBinIndexRange.hxx"
9
10#include <cstdint>
11#include <stdexcept>
12#include <utility>
13#include <variant>
14
15namespace ROOT {
16namespace Experimental {
17
18/**
19Specification of a slice operation along one dimension.
20
21\code
22using ROOT::Experimental::RSliceSpec;
23// When not specifying a range, the slice will include all bins.
24RSliceSpec full;
25// In the following, assuming range is an RBinIndexRange.
26RSliceSpec slice(range);
27
28// Operations are specified with parameters.
29RSliceSpec rebin(RSliceSpec::ROperationRebin(2));
30RSliceSpec sum(RSliceSpec::ROperationSum{});
31
32// Finally, it is possible to combine a range and an operation.
33RSliceSpec sliceRebin(range, RSliceSpec::ROperationRebin(2));
34RSliceSpec sliceSum(range, RSliceSpec::ROperationSum{});
35\endcode
36
37\warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes.
38Feedback is welcome!
39*/
41public:
42 /// Rebin the dimension, grouping a number of original bins into a new one.
44 std::uint64_t fNGroup = 1;
45
46 public:
47 /// \param[in] nGroup the number of bins to group, must be > 0
49 {
50 if (nGroup == 0) {
51 throw std::invalid_argument("nGroup must be > 0");
52 }
53 }
54
55 std::uint64_t GetNGroup() const { return fNGroup; }
56 };
57
58 /// Sum bins along this dimension, effectively resulting in a projection.
60 // empty, no parameters at the moment
61 };
62
63private:
64 /// The range of the slice; can be invalid to signify the full range
66 /// The operation to perform, if any
67 std::variant<std::monostate, ROperationRebin, ROperationSum> fOperation;
68
69public:
70 /// A default slice operation that keeps the dimension untouched.
71 RSliceSpec() = default;
72
73 /// A slice of a dimension.
74 ///
75 /// \param[in] range the range of the slice
77
78 /// A rebin operation of a dimension.
80
81 /// A sum operation of a dimension.
83
84 /// A rebin operation of a slice of the dimension.
86
87 /// A sum operation of a slice of the dimension.
89
90 const RBinIndexRange &GetRange() const { return fRange; }
91 bool HasOperation() const { return !std::holds_alternative<std::monostate>(fOperation); }
92 const ROperationRebin *GetOperationRebin() const { return std::get_if<ROperationRebin>(&fOperation); }
93 const ROperationSum *GetOperationSum() const { return std::get_if<ROperationSum>(&fOperation); }
94};
95
96} // namespace Experimental
97} // namespace ROOT
98
99#endif
Rebin the dimension, grouping a number of original bins into a new one.
Sum bins along this dimension, effectively resulting in a projection.
Specification of a slice operation along one dimension.
RSliceSpec()=default
A default slice operation that keeps the dimension untouched.
const ROperationSum * GetOperationSum() const
RBinIndexRange fRange
The range of the slice; can be invalid to signify the full range.
std::variant< std::monostate, ROperationRebin, ROperationSum > fOperation
The operation to perform, if any.
const ROperationRebin * GetOperationRebin() const
RSliceSpec(ROperationRebin rebin)
A rebin operation of a dimension.
RSliceSpec(RBinIndexRange range)
A slice of a dimension.
const RBinIndexRange & GetRange() const
RSliceSpec(ROperationSum sum)
A sum operation of a dimension.
RSliceSpec(RBinIndexRange range, ROperationSum sum)
A sum operation of a slice of the dimension.
RSliceSpec(RBinIndexRange range, ROperationRebin rebin)
A rebin operation of a slice of the dimension.
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2338