Logo ROOT   master
Reference Guide
RHistBinIter.hxx
Go to the documentation of this file.
1 /// \file ROOT/RHistBinIter.h
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-08-07
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_RHistBinIter
17 #define ROOT7_RHistBinIter
18 
19 #include "ROOT/RIndexIter.hxx"
20 
21 namespace ROOT {
22 namespace Experimental {
23 namespace Detail {
24 
25 /**
26 \class RHistBinRef
27 Represents a bin reference. Value of the bin iteration.
28 
29 Provides access to bin content, bin geometry (from, to, center), and statistics
30 (for instance higher moments) associated to the bin.
31 */
32 
33 template <class HISTIMPL>
34 class RHistBinRef {
35 public:
36  using HistImpl_t = HISTIMPL;
38  using Weight_t = typename HISTIMPL::Weight_t;
39  using HistBinStat_t = decltype(((HISTIMPL *)0x123)->GetStat().GetView(1));
40 
41 private:
42  size_t fIndex{0}; ///< Bin index
43  HistImpl_t *fHist{nullptr}; ///< The bin's histogram.
45 
46 public:
47  /// Construct from a histogram.
48  RHistBinRef(HistImpl_t &hist, size_t idx): fIndex(idx), fHist(&hist), fStatView(hist.GetStat().GetView(idx)) {}
49 
50  /// \{
51  /// \name Statistics operations
52  /// Get the bin content (or reference to it, for non-const HistImpl_t).
53  auto GetContent() { return fStatView.GetContent(); }
54 
55  /// Get the bin uncertainty.
56  double GetUncertainty() const { return fStatView.GetUncertainty(); }
57 
58  /// Get a (const, for const HistImpl_t) reference to the bin-view of the
59  /// histogram statistics (uncertainty etc).
60  HistBinStat_t GetStat() const { return fStatView; }
61  /// \}
62 
63  /// \{
64  /// \name Bin operations
65  /// Get the bin center as an array over all dimensions.
66  CoordArray_t GetCenter() const { return fHist->GetBinCenter(fIndex); }
67 
68  /// Get the bin lower edge as an array over all dimensions.
69  CoordArray_t GetFrom() const { return fHist->GetBinFrom(fIndex); }
70 
71  /// Get the bin upper edge as an array over all dimensions.
72  CoordArray_t GetTo() const { return fHist->GetBinTo(fIndex); }
73  /// \}
74 };
75 
76 /**
77  \class RHistBinPtr
78  Points to a histogram bin (or actually a `RHistBinRef`).
79  */
80 template <class HISTIMPL>
81 class RHistBinPtr {
82 public:
84 
85  const Ref_t &operator->() const noexcept { return fRef; }
86 
87 private:
88  Ref_t fRef; ///< Underlying bin reference
89 };
90 
91 /**
92  \class RHistBinIter
93  Iterates over the bins of a RHist or RHistImpl.
94  */
95 
96 template <class HISTIMPL>
97 class RHistBinIter: public Internal::RIndexIter<RHistBinRef<HISTIMPL>, RHistBinPtr<HISTIMPL>> {
98 public:
101 
102 private:
104 
105  HISTIMPL &fHist; ///< The histogram we iterate over.
106 
107 public:
108  /// Construct a RHistBinIter from a histogram.
109  RHistBinIter(HISTIMPL &hist): IndexIter_t(0), fHist(hist) {}
110 
111  /// Construct a RHistBinIter from a histogram, setting the current index.
112  RHistBinIter(HISTIMPL &hist, size_t idx): IndexIter_t(idx), fHist(hist) {}
113 
114  ///\{
115  ///\name Value access
116  Ref_t operator*() const noexcept { return Ref_t{fHist, IndexIter_t::GetIndex()}; }
117 
118  Ptr_t operator->() const noexcept { return Ptr_t{*this}; }
119  ///\}
120 };
121 
122 } // namespace Detail
123 } // namespace Experimental
124 } // namespace ROOT
125 
126 #endif
Iterates over an index; the REFERENCE is defined by the REFERENCE template parameter.
Definition: RIndexIter.hxx:35
Returns the available number of logical cores.
Definition: StringConv.hxx:21
Ref_t fRef
Underlying bin reference.
const Ref_t & operator->() const noexcept
RHistBinIter(HISTIMPL &hist)
Construct a RHistBinIter from a histogram.
Points to a histogram bin (or actually a RHistBinRef).
RHistBinIter(HISTIMPL &hist, size_t idx)
Construct a RHistBinIter from a histogram, setting the current index.
RHistBinRef(HistImpl_t &hist, size_t idx)
Construct from a histogram.
RCoordArray< DIMENSIONS > CoordArray_t
Definition: RHistUtils.hxx:53
Iterates over the bins of a RHist or RHistImpl.
HistBinStat_t GetStat() const
Get a (const, for const HistImpl_t) reference to the bin-view of the histogram statistics (uncertaint...
decltype(((HISTIMPL *) 0x123) ->GetStat().GetView(1)) HistBinStat_t
double GetUncertainty() const
Get the bin uncertainty.
HistImpl_t * fHist
The bin&#39;s histogram.
typename HISTIMPL::Weight_t Weight_t
typename HISTIMPL::CoordArray_t CoordArray_t
HISTIMPL & fHist
The histogram we iterate over.
Represents a bin reference.
CoordArray_t GetTo() const
Get the bin upper edge as an array over all dimensions.
CoordArray_t GetFrom() const
Get the bin lower edge as an array over all dimensions.