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