Logo ROOT   6.12/07
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
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_THistConcurrentFill
17 #define ROOT7_THistConcurrentFill
18 
19 #include "ROOT/RArrayView.hxx"
21 
22 #include <mutex>
23 
24 namespace ROOT {
25 namespace Experimental {
26 
27 template <class HIST, int SIZE>
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>
37 class THistConcurrentFiller: public Internal::THistBufferedFillBase<THistConcurrentFiller<HIST, SIZE>, HIST, SIZE> {
39 
40 public:
41  using CoordArray_t = typename HIST::CoordArray_t;
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::array_view<CoordArray_t> xN, const std::array_view<Weight_t> weightN)
51  {
52  fManager.FillN(xN, weightN);
53  }
54 
55  /// Thread-specific HIST::FillN().
56  void FillN(const std::array_view<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 THistConcurrentFillManager
69  Manages the synchronization of calls to FillN().
70 
71  The HIST template can be a THist instance. This class hands out
72  THistConcurrentFiller 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 THistConcurrentFillManager. The manager than fills the
75  histogram.
76  **/
77 
78 template <class HIST, int SIZE = 1024>
80  friend class THistConcurrentFiller<HIST, SIZE>;
81 
82 public:
83  using Hist_t = HIST;
84  using CoordArray_t = typename HIST::CoordArray_t;
85  using Weight_t = typename HIST::Weight_t;
86 
87 private:
88  HIST &fHist;
89  std::mutex fFillMutex; // should become a spin lock
90 
91 public:
92  THistConcurrentFillManager(HIST &hist): fHist(hist) {}
93 
95 
96  /// Thread-specific HIST::FillN().
97  void FillN(const std::array_view<CoordArray_t> xN, const std::array_view<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::array_view<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
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
TCoordArray< DIMENSIONS > CoordArray_t
Definition: THistUtils.hxx:49
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().