Logo ROOT   6.16/01
Reference Guide
RHistBufferedFill.hxx
Go to the documentation of this file.
1/// \file ROOT/RHistBufferedFill.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
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_RHistBufferedFill
17#define ROOT7_RHistBufferedFill
18
19#include "ROOT/RSpan.hxx"
20
21namespace ROOT {
22namespace Experimental {
23
24namespace Internal {
25template <class DERIVED, class HIST, int SIZE>
27public:
29 using Weight_t = typename HIST::Weight_t;
30
31private:
32 size_t fCursor = 0;
33 std::array<CoordArray_t, SIZE> fXBuf;
34 std::array<Weight_t, SIZE> fWBuf;
35
36public:
39
40 DERIVED &toDerived() { return *static_cast<DERIVED *>(this); }
41 const DERIVED &toDerived() const { return *static_cast<const DERIVED *>(this); }
42
43 std::span<CoordArray_t> GetCoords() const
44 {
45 return std::span<CoordArray_t>(fXBuf.begin(), fXBuf.begin() + fCursor);
46 }
47 std::span<Weight_t> GetWeights() const
48 {
49 return std::span<Weight_t>(fWBuf.begin(), fWBuf.begin() + fCursor);
50 }
51
52 void Fill(const CoordArray_t &x, Weight_t weight = 1.)
53 {
54 fXBuf[fCursor] = x;
55 fWBuf[fCursor++] = weight;
56 if (fCursor == SIZE) {
57 toDerived().Flush();
58 fCursor = 0;
59 }
60 }
61};
62
63} // namespace Internal
64
65/** \class RHistBufferedFill
66 Buffers calls to Fill().
67
68 Once the buffer is full, on destruction of when calling Flush(), it sends the
69 buffers off as an ideally vectorizable FillN() operation. It also serves as a
70 multi-threaded way of filling the same histogram, reducing the locking
71 frequency.
72
73 The HIST template can be either a RHist instance, a RHistImpl instance, or
74 a RHistLockedFill instance.
75 **/
76
77template <class HIST, int SIZE = 1024>
78class RHistBufferedFill: public Internal::RHistBufferedFillBase<RHistBufferedFill<HIST, SIZE>, HIST, SIZE> {
79public:
80 using Hist_t = HIST;
82 using Weight_t = typename HIST::Weight_t;
83
84private:
85 HIST &fHist;
86 size_t fCursor = 0;
87 std::array<CoordArray_t, SIZE> fXBuf;
88 std::array<Weight_t, SIZE> fWBuf;
89
90public:
92
93 void FillN(const std::span<CoordArray_t> xN, const std::span<Weight_t> weightN)
94 {
95 fHist.FillN(xN, weightN);
96 }
97
98 void FillN(const std::span<CoordArray_t> xN) { fHist.FillN(xN); }
99
100 void Flush() { fHist.FillN(this->GetCoords(), this->GetWeights()); }
101
102 HIST &GetHist()
103 {
104 Flush(); // synchronize!
105 return fHist;
106 }
107 operator HIST &() { return GetHist(); }
108
109 static constexpr int GetNDim() { return HIST::GetNDim(); }
110};
111} // namespace Experimental
112} // namespace ROOT
113
114#endif
void Fill(const CoordArray_t &x, Weight_t weight=1.)
std::array< CoordArray_t, SIZE > fXBuf
typename HIST::CoordArray_t CoordArray_t
std::array< Weight_t, SIZE > fWBuf
void FillN(const std::span< CoordArray_t > xN)
void FillN(const std::span< CoordArray_t > xN, const std::span< Weight_t > weightN)
Double_t x[n]
Definition: legend1.C:17
RCoordArray< DIMENSIONS > CoordArray_t
Definition: RHistUtils.hxx:49
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21