ROOT  6.06/09
Reference Guide
THistBufferedFill.h
Go to the documentation of this file.
1 /// \file ROOT/THistBufferedFill.h
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-07-03
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #ifndef ROOT7_THistBufferedFill
16 #define ROOT7_THistBufferedFill
17 
18 #include "ROOT/RArrayView.h"
19 
20 namespace ROOT {
21 
22 namespace Internal {
23 template<class DERIVED, class HIST, int SIZE>
25 public:
26  using Coord_t = typename HIST::Coord_t;
27  using Weight_t = typename HIST::Weight_t;
28 
29 private:
30  size_t fCursor = 0;
31  std::array<Coord_t, SIZE> fXBuf;
32  std::array<Weight_t, SIZE> fWBuf;
33 
34 public:
37 
38  DERIVED& toDerived() { return *static_cast<DERIVED*>(this); }
39  const DERIVED& toDerived() const { return *static_cast<const DERIVED*>(this); }
40 
42  return std::array_view<Coord_t>(fXBuf.begin(), fXBuf.begin() + fCursor);
43  }
45  return std::array_view<Weight_t>(fWBuf.begin(), fWBuf.begin() + fCursor);
46  }
47 
48  void Fill(const Coord_t& x, Weight_t weight = 1.) {
49  fXBuf[fCursor] = x;
50  fWBuf[fCursor++] = weight;
51  if (fCursor == SIZE) {
52  toDerived().Flush();
53  fCursor = 0;
54  }
55  }
56 };
57 
58 } // namespace Internal
59 
60 
61  /** \class THistBufferedFill
62  Buffers calls to Fill().
63 
64  Once the buffer is full, on destruction of when calling Flush(), it sends the
65  buffers off as an ideally vectorizable FillN() operation. It also serves as a
66  multi-threaded way of filling the same histogram, reducing the locking
67  frequency.
68 
69  The HIST template can be either a THist instance, a THistImpl instance, or
70  a THistLockedFill instance.
71  **/
72 
73  template <class HIST, int SIZE = 1024>
75  public Internal::THistBufferedFillBase<THistBufferedFill<HIST, SIZE>, HIST, SIZE> {
76  public:
77  using Hist_t = HIST;
78  using Coord_t = typename HIST::Coord_t;
79  using Weight_t = typename HIST::Weight_t;
80 
81  private:
82  HIST& fHist;
83  size_t fCursor = 0;
84  std::array<Coord_t, SIZE> fXBuf;
85  std::array<Weight_t, SIZE> fWBuf;
86 
87  public:
88  THistBufferedFill(Hist_t& hist): fHist{hist} {}
89 
91  const std::array_view<Weight_t> weightN) {
92  fHist.FillN(xN, weightN);
93  }
94 
96  fHist.FillN(xN);
97  }
98 
99 
100  void Flush() {
101  fHist.FillN(this->GetCoords(), this->GetWeights());
102  }
103 
104 
105  HIST& GetHist() {
106  Flush(); // synchronize!
107  return fHist;
108  }
109  operator HIST&() { return GetHist(); }
110 
111  static constexpr int GetNDim() { return HIST::GetNDim(); }
112  };
113 }
114 
115 #endif
Buffers calls to Fill().
std::array_view< Weight_t > GetWeights() const
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
static constexpr int GetNDim()
const uint32_t SIZE
Definition: stressVdt.cxx:21
Double_t x[n]
Definition: legend1.C:17
typename HIST::Coord_t Coord_t
double Coord_t
Definition: RtypesCore.h:81
std::array< Weight_t, SIZE > fWBuf
std::array_view< Coord_t > GetCoords() const
std::array< Coord_t, SIZE > fXBuf
std::array< Weight_t, SIZE > fWBuf
std::array< Coord_t, SIZE > fXBuf
typename HIST::Weight_t Weight_t
void FillN(const std::array_view< Coord_t > xN, const std::array_view< Weight_t > weightN)
void Fill(const Coord_t &x, Weight_t weight=1.)
void FillN(const std::array_view< Coord_t > xN)
THistBufferedFill(Hist_t &hist)