Logo ROOT   6.18/05
Reference Guide
RHistConcurrentFill.hxx
Go to the documentation of this file.
1/// \file ROOT/RHistConcurrentFill.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_RHistConcurrentFill
17#define ROOT7_RHistConcurrentFill
18
19#include "ROOT/RSpan.hxx"
21
22#include <mutex>
23
24namespace ROOT {
25namespace Experimental {
26
27template <class HIST, int SIZE>
28class RHistConcurrentFillManager;
29
30/**
31 \class RHistConcurrentFiller
32 Buffers a thread's Fill calls and submits them to the
33 RHistConcurrentFillManager. Enables multi-threaded filling.
34 **/
35
36template <class HIST, int SIZE>
37class RHistConcurrentFiller: public Internal::RHistBufferedFillBase<RHistConcurrentFiller<HIST, SIZE>, HIST, SIZE> {
39
40public:
42 using Weight_t = typename HIST::Weight_t;
43
45
46 /// Thread-specific HIST::Fill().
48
49 /// Thread-specific HIST::FillN().
50 void FillN(const std::span<CoordArray_t> xN, const std::span<Weight_t> weightN)
51 {
52 fManager.FillN(xN, weightN);
53 }
54
55 /// Thread-specific HIST::FillN().
56 void FillN(const std::span<CoordArray_t> xN) { fManager.FillN(xN); }
57
58 /// The buffer is full, flush it out.
59 void Flush() { fManager.FillN(this->GetCoords(), this->GetWeights()); }
60
61 HIST &GetHist() { return fManager->GetHist(); }
62 operator HIST &() { return GetHist(); }
63
64 static constexpr int GetNDim() { return HIST::GetNDim(); }
65};
66
67/**
68 \class RHistConcurrentFillManager
69 Manages the synchronization of calls to FillN().
70
71 The HIST template can be a RHist instance. This class hands out
72 RHistConcurrentFiller objects that can concurrently fill the histogram. They
73 buffer calls to Fill() until the buffer is full, and then swap the buffer
74 with that of the RHistConcurrentFillManager. The manager than fills the
75 histogram.
76 **/
77
78template <class HIST, int SIZE = 1024>
80 friend class RHistConcurrentFiller<HIST, SIZE>;
81
82public:
83 using Hist_t = HIST;
85 using Weight_t = typename HIST::Weight_t;
86
87private:
88 HIST &fHist;
89 std::mutex fFillMutex; // should become a spin lock
90
91public:
92 RHistConcurrentFillManager(HIST &hist): fHist(hist) {}
93
95
96 /// Thread-specific HIST::FillN().
97 void FillN(const std::span<CoordArray_t> xN, const std::span<Weight_t> weightN)
98 {
99 std::lock_guard<std::mutex> lockGuard(fFillMutex);
100 fHist.FillN(xN, weightN);
101 }
102
103 /// Thread-specific HIST::FillN().
104 void FillN(const std::span<CoordArray_t> xN)
105 {
106 std::lock_guard<std::mutex> lockGuard(fFillMutex);
107 fHist.FillN(xN);
108 }
109};
110
111} // namespace Experimental
112} // namespace ROOT
113
114#endif
void FillN(const std::span< CoordArray_t > xN, const std::span< Weight_t > weightN)
Thread-specific HIST::FillN().
RHistConcurrentFiller< HIST, SIZE > MakeFiller()
void FillN(const std::span< CoordArray_t > xN)
Thread-specific HIST::FillN().
Buffers a thread's Fill calls and submits them to the RHistConcurrentFillManager.
void FillN(const std::span< CoordArray_t > xN)
Thread-specific HIST::FillN().
void FillN(const std::span< CoordArray_t > xN, const std::span< Weight_t > weightN)
Thread-specific HIST::FillN().
void Flush()
The buffer is full, flush it out.
RHistConcurrentFiller(RHistConcurrentFillManager< HIST, SIZE > &manager)
RHistConcurrentFillManager< HIST, SIZE > & fManager
RCoordArray< DIMENSIONS > CoordArray_t
Definition: RHistUtils.hxx:49
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21