Logo ROOT   6.08/07
Reference Guide
THistBufferedFill.hxx
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.hxx"
19 
20 namespace ROOT {
21 namespace Experimental {
22 
23 namespace Internal {
24 template<class DERIVED, class HIST, int SIZE>
26 public:
27  using CoordArray_t = typename HIST::CoordArray_t;
28  using Weight_t = typename HIST::Weight_t;
29 
30 private:
31  size_t fCursor = 0;
32  std::array<CoordArray_t, SIZE> fXBuf;
33  std::array<Weight_t, SIZE> fWBuf;
34 
35 public:
38 
39  DERIVED& toDerived() { return *static_cast<DERIVED*>(this); }
40  const DERIVED& toDerived() const { return *static_cast<const DERIVED*>(this); }
41 
42  std::array_view<CoordArray_t> GetCoords() const {
43  return std::array_view<CoordArray_t>(fXBuf.begin(), fXBuf.begin() + fCursor);
44  }
45  std::array_view<Weight_t> GetWeights() const {
46  return std::array_view<Weight_t>(fWBuf.begin(), fWBuf.begin() + fCursor);
47  }
48 
49  void Fill(const CoordArray_t& x, Weight_t weight = 1.) {
50  fXBuf[fCursor] = x;
51  fWBuf[fCursor++] = weight;
52  if (fCursor == SIZE) {
53  toDerived().Flush();
54  fCursor = 0;
55  }
56  }
57 };
58 
59 } // namespace Internal
60 
61 
62  /** \class THistBufferedFill
63  Buffers calls to Fill().
64 
65  Once the buffer is full, on destruction of when calling Flush(), it sends the
66  buffers off as an ideally vectorizable FillN() operation. It also serves as a
67  multi-threaded way of filling the same histogram, reducing the locking
68  frequency.
69 
70  The HIST template can be either a THist instance, a THistImpl instance, or
71  a THistLockedFill instance.
72  **/
73 
74  template <class HIST, int SIZE = 1024>
76  public Internal::THistBufferedFillBase<THistBufferedFill<HIST, SIZE>, HIST, SIZE> {
77  public:
78  using Hist_t = HIST;
79  using CoordArray_t = typename HIST::CoordArray_t;
80  using Weight_t = typename HIST::Weight_t;
81 
82  private:
83  HIST& fHist;
84  size_t fCursor = 0;
85  std::array<CoordArray_t, SIZE> fXBuf;
86  std::array<Weight_t, SIZE> fWBuf;
87 
88  public:
89  THistBufferedFill(Hist_t& hist): fHist{hist} {}
90 
91  void FillN(const std::array_view<CoordArray_t> xN,
92  const std::array_view<Weight_t> weightN) {
93  fHist.FillN(xN, weightN);
94  }
95 
96  void FillN(const std::array_view<CoordArray_t> xN) {
97  fHist.FillN(xN);
98  }
99 
100 
101  void Flush() {
102  fHist.FillN(this->GetCoords(), this->GetWeights());
103  }
104 
105 
106  HIST& GetHist() {
107  Flush(); // synchronize!
108  return fHist;
109  }
110  operator HIST&() { return GetHist(); }
111 
112  static constexpr int GetNDim() { return HIST::GetNDim(); }
113  };
114 } // namespace Experimental
115 } // namespace ROOT
116 
117 #endif
void Fill(const CoordArray_t &x, Weight_t weight=1.)
std::array< double, DIMENSIONS > CoordArray_t
Definition: THistUtils.hxx:22
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
std::array< CoordArray_t, SIZE > fXBuf
const uint32_t SIZE
Definition: stressVdt.cxx:21
typename HIST::CoordArray_t CoordArray_t
Double_t x[n]
Definition: legend1.C:17
void FillN(const std::array_view< CoordArray_t > xN, const std::array_view< Weight_t > weightN)
void FillN(const std::array_view< CoordArray_t > xN)
std::array< Weight_t, SIZE > fWBuf
const char * GetHist()
std::array_view< CoordArray_t > GetCoords() const
std::array_view< Weight_t > GetWeights() const