File indexing completed on 2025-01-18 10:10:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROOT7_RHistView
0017 #define ROOT7_RHistView
0018
0019 #include "ROOT/RHist.hxx"
0020
0021 namespace ROOT {
0022 namespace Experimental {
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 template <class HISTVIEW>
0041 struct RHistViewOutOfRange {
0042 HISTVIEW &fHistView;
0043 bool operator()(int idx) { return fHistView.IsBinOutOfRange(idx); }
0044 };
0045
0046
0047
0048
0049
0050 template <int DIMENSIONS, class PRECISION, template <int D_, class P_> class... STAT>
0051 class RHistView {
0052 public:
0053 using Hist_t = RHist<DIMENSIONS, PRECISION, STAT...>;
0054 using AxisRange_t = typename Hist_t::AxisIterRange_t;
0055 using HistViewOutOfRange_t = RHistViewOutOfRange<RHistView>;
0056
0057 using const_iterator = Detail::RHistBinIter<typename Hist_t::ImplBase_t>;
0058
0059 RHistView(Hist_t &hist, int nbins, const AxisRange_t &range): fHist(hist), fNBins(nbins), fRange(range) {}
0060
0061 bool IsBinOutOfRange(int idx) const noexcept
0062 {
0063
0064 return idx < 0 || idx > fNBins;
0065 }
0066
0067 void SetRange(int axis, double from, double to)
0068 {
0069 const RAxisBase &axisView = fHist.GetImpl()->GetAxis(axis);
0070 fRange[axis] = axisView.FindBin(from);
0071 fRange[axis] = axisView.FindBin(to);
0072 }
0073
0074 const_iterator begin() const noexcept
0075 {
0076 int beginidx = 0;
0077 size_t nbins = fHist.GetNBins();
0078 while (IsBinOutOfRange(beginidx) && beginidx < nbins)
0079 ++beginidx;
0080 return const_iterator(beginidx, HistViewOutOfRange_t(*this));
0081 }
0082
0083 const_iterator end() const noexcept { return const_iterator(fHist.GetImpl(), fHist.GetImpl().GetNBins()); }
0084
0085 private:
0086 Hist_t &fHist;
0087 int fNBins = 0;
0088 AxisRange_t fRange;
0089 };
0090
0091 }
0092 }
0093
0094 #endif