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