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