File indexing completed on 2025-01-18 10:10:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROOT7_RHistConcurrentFill
0017 #define ROOT7_RHistConcurrentFill
0018
0019 #include "ROOT/RSpan.hxx"
0020 #include "ROOT/RHistBufferedFill.hxx"
0021
0022 #include <mutex>
0023
0024 namespace ROOT {
0025 namespace Experimental {
0026
0027 template <class HIST, int SIZE>
0028 class RHistConcurrentFillManager;
0029
0030
0031
0032
0033
0034
0035
0036 template <class HIST, int SIZE>
0037 class RHistConcurrentFiller: public Internal::RHistBufferedFillBase<RHistConcurrentFiller<HIST, SIZE>, HIST, SIZE> {
0038 RHistConcurrentFillManager<HIST, SIZE> &fManager;
0039
0040 public:
0041 using CoordArray_t = typename HIST::CoordArray_t;
0042 using Weight_t = typename HIST::Weight_t;
0043
0044 RHistConcurrentFiller(RHistConcurrentFillManager<HIST, SIZE> &manager): fManager(manager) {}
0045
0046
0047 using Internal::RHistBufferedFillBase<RHistConcurrentFiller<HIST, SIZE>, HIST, SIZE>::Fill;
0048
0049
0050 void FillN(const std::span<const CoordArray_t> xN, const std::span<const Weight_t> weightN)
0051 {
0052 fManager.FillN(xN, weightN);
0053 }
0054
0055
0056 void FillN(const std::span<const CoordArray_t> xN) { fManager.FillN(xN); }
0057
0058 static constexpr int GetNDim() { return HIST::GetNDim(); }
0059
0060 private:
0061 friend class Internal::RHistBufferedFillBase<RHistConcurrentFiller<HIST, SIZE>, HIST, SIZE>;
0062 void FlushImpl() { fManager.FillN(this->GetCoords(), this->GetWeights()); }
0063 };
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 template <class HIST, int SIZE = 1024>
0077 class RHistConcurrentFillManager {
0078 friend class RHistConcurrentFiller<HIST, SIZE>;
0079
0080 public:
0081 using Hist_t = HIST;
0082 using CoordArray_t = typename HIST::CoordArray_t;
0083 using Weight_t = typename HIST::Weight_t;
0084
0085 private:
0086 HIST &fHist;
0087 std::mutex fFillMutex;
0088
0089 public:
0090 RHistConcurrentFillManager(HIST &hist): fHist(hist) {}
0091
0092 RHistConcurrentFiller<HIST, SIZE> MakeFiller() { return RHistConcurrentFiller<HIST, SIZE>{*this}; }
0093
0094
0095 void FillN(const std::span<const CoordArray_t> xN, const std::span<const Weight_t> weightN)
0096 {
0097 std::lock_guard<std::mutex> lockGuard(fFillMutex);
0098 fHist.FillN(xN, weightN);
0099 }
0100
0101
0102 void FillN(const std::span<const CoordArray_t> xN)
0103 {
0104 std::lock_guard<std::mutex> lockGuard(fFillMutex);
0105 fHist.FillN(xN);
0106 }
0107 };
0108
0109 }
0110 }
0111
0112 #endif