Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RHistView.hxx
Go to the documentation of this file.
1 /// \file ROOT/RHistView.h
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-08-06
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_RHistView
17 #define ROOT7_RHistView
18 
19 #include "ROOT/RHist.hxx"
20 
21 namespace ROOT {
22 namespace Experimental {
23 
24 /*
25  * Need RHist::iterator for full range, takes a predicate for "in range?"
26  * Returns true for RHist; for RHistView, checks range, returns false if not in
27  * range. i+= 7 then does i++ seven times and checks at each step.
28  * iterator is simply an int with a predicate functor. end is end of the
29  * histogram - i.e. the number of bins (incl over / underflow).
30  *
31  * Add is then an operation (through a functor) on two bins.
32  *
33  * Drawing: need adaptor from RHist<n,p>::GetBinContent(...) to
34  * RHistPrecNormalizer<n>::Get(i) that casts the bin content to a double. That
35  * should be in internal but outside the drawing library (that needs to
36  * communicate through abstract interfaces and can thus not instantiate
37  * templates with user precision parameters.
38  */
39 
40 template <class HISTVIEW>
41 struct RHistViewOutOfRange {
42  HISTVIEW &fHistView;
43  bool operator()(int idx) { return fHistView.IsBinOutOfRange(idx); }
44 };
45 
46 /**
47  \class RHistView
48  A view on a histogram, selecting a range on a subset of dimensions.
49  */
50 template <int DIMENSIONS, class PRECISION, template <int D_, class P_> class... STAT>
51 class RHistView {
52 public:
53  using Hist_t = RHist<DIMENSIONS, PRECISION, STAT...>;
54  using AxisRange_t = typename Hist_t::AxisIterRange_t;
55  using HistViewOutOfRange_t = RHistViewOutOfRange<RHistView>;
56 
57  using const_iterator = Detail::RHistBinIter<typename Hist_t::ImplBase_t>;
58 
59  RHistView(Hist_t &hist, int nbins, const AxisRange_t &range): fHist(hist), fNBins(nbins), fRange(range) {}
60 
61  bool IsBinOutOfRange(int idx) const noexcept
62  {
63  // RODO: use fRange!
64  return idx < 0 || idx > fNBins;
65  }
66 
67  void SetRange(int axis, double from, double to)
68  {
69  RAxisView axisView = fHist.GetImpl()->GetAxis(axis);
70  fRange[axis] = axisView.FindBin(from);
71  fRange[axis] = axisView.FindBin(to);
72  }
73 
74  const_iterator begin() const noexcept
75  {
76  int beginidx = 0;
77  size_t nbins = fHist.GetNBins();
78  while (IsBinOutOfRange(beginidx) && beginidx < nbins)
79  ++beginidx;
80  return const_iterator(beginidx, HistViewOutOfRange_t(*this));
81  }
82 
83  const_iterator end() const noexcept { return const_iterator(fHist.GetImpl(), fHist.GetImpl().GetNBins()); }
84 
85 private:
86  Hist_t &fHist;
87  int fNBins = 0;
88  AxisRange_t fRange;
89 };
90 
91 } // namespace Experimental
92 } // namespace ROOT
93 
94 #endif