Logo ROOT  
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;
37  using CoordArray_t = typename HISTIMPL::CoordArray_t;
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
ROOT::Experimental::Detail::RHistBinPtr::operator->
const Ref_t & operator->() const noexcept
Definition: RHistBinIter.hxx:103
ROOT::Experimental::Detail::RHistBinPtr::fRef
Ref_t fRef
Underlying bin reference.
Definition: RHistBinIter.hxx:106
ROOT::Experimental::Detail::RHistBinRef::GetTo
CoordArray_t GetTo() const
Get the bin upper edge as an array over all dimensions.
Definition: RHistBinIter.hxx:90
ROOT::Experimental::Detail::RHistBinRef::CoordArray_t
typename HISTIMPL::CoordArray_t CoordArray_t
Definition: RHistBinIter.hxx:55
ROOT::Experimental::Detail::RHistBinIter
Definition: RHistBinIter.hxx:115
ROOT::Experimental::Detail::RHistBinPtr::Ref_t
RHistBinRef< HISTIMPL > Ref_t
Definition: RHistBinIter.hxx:101
ROOT::Experimental::Internal::RIndexIter
Definition: RIndexIter.hxx:53
ROOT::Experimental::Detail::RHistBinRef::fHist
HistImpl_t * fHist
The bin's histogram.
Definition: RHistBinIter.hxx:61
ROOT::Experimental::Detail::RHistBinRef::fStatView
HistBinStat_t fStatView
Definition: RHistBinIter.hxx:62
ROOT::Experimental::Detail::RHistBinRef::fIndex
size_t fIndex
Bin index.
Definition: RHistBinIter.hxx:60
ROOT::Experimental::Detail::RHistBinRef::GetUncertainty
double GetUncertainty() const
Get the bin uncertainty.
Definition: RHistBinIter.hxx:74
ROOT::Experimental::Detail::RHistBinPtr
Definition: RHistBinIter.hxx:99
ROOT::Experimental::Detail::RHistBinIter::fHist
HISTIMPL & fHist
The histogram we iterate over.
Definition: RHistBinIter.hxx:123
ROOT::Experimental::Detail::RHistBinRef::GetCenter
CoordArray_t GetCenter() const
Definition: RHistBinIter.hxx:84
ROOT::Experimental::Detail::RHistBinRef::RHistBinRef
RHistBinRef(HistImpl_t &hist, size_t idx)
Construct from a histogram.
Definition: RHistBinIter.hxx:66
ROOT::Experimental::Detail::RHistBinIter::RHistBinIter
RHistBinIter(HISTIMPL &hist)
Construct a RHistBinIter from a histogram.
Definition: RHistBinIter.hxx:127
ROOT::Experimental::Detail::RHistBinIter::operator*
Ref_t operator*() const noexcept
Definition: RHistBinIter.hxx:134
ROOT::Experimental::Detail::RHistBinRef::GetStat
HistBinStat_t GetStat() const
Get a (const, for const HistImpl_t) reference to the bin-view of the histogram statistics (uncertaint...
Definition: RHistBinIter.hxx:78
ROOT::Experimental::Detail::RHistBinRef::GetFrom
CoordArray_t GetFrom() const
Get the bin lower edge as an array over all dimensions.
Definition: RHistBinIter.hxx:87
ROOT::Experimental::Detail::RHistBinRef::Weight_t
typename HISTIMPL::Weight_t Weight_t
Definition: RHistBinIter.hxx:56
ROOT::Experimental::Detail::RHistBinRef::HistBinStat_t
decltype(((HISTIMPL *) 0x123) ->GetStat().GetView(1)) HistBinStat_t
Definition: RHistBinIter.hxx:57
ROOT::Experimental::Hist::CoordArray_t
RCoordArray< DIMENSIONS > CoordArray_t
Definition: RHistUtils.hxx:71
ROOT::Experimental::Detail::RHistBinIter::Ptr_t
RHistBinPtr< HISTIMPL > Ptr_t
Definition: RHistBinIter.hxx:118
RIndexIter.hxx
ROOT::Experimental::Detail::RHistBinIter::Ref_t
RHistBinRef< HISTIMPL > Ref_t
Definition: RHistBinIter.hxx:117
ROOT::Experimental::Detail::RHistBinIter::operator->
Ptr_t operator->() const noexcept
Definition: RHistBinIter.hxx:136
ROOT::Experimental::Detail::RHistBinRef::HistImpl_t
HISTIMPL HistImpl_t
Definition: RHistBinIter.hxx:54
ROOT::Experimental::Detail::RHistBinRef::GetContent
auto GetContent()
Definition: RHistBinIter.hxx:71
ROOT::Experimental::Internal::RIndexIter< RHistBinRef< HISTIMPL >, RHistBinPtr< HISTIMPL > >::GetIndex
size_t GetIndex() const noexcept
Get the current index value.
Definition: RIndexIter.hxx:63
ROOT::Experimental::Detail::RHistBinIter::IndexIter_t
Internal::RIndexIter< RHistBinRef< HISTIMPL >, RHistBinPtr< HISTIMPL > > IndexIter_t
Definition: RHistBinIter.hxx:121
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Experimental::Detail::RHistBinRef
Definition: RHistBinIter.hxx:52