File indexing completed on 2026-08-16 09:21:18
0001
0002
0003
0004
0005 #ifndef ROOT_RHistConcurrentFiller
0006 #define ROOT_RHistConcurrentFiller
0007
0008 #include "RHist.hxx"
0009 #include "RHistFillContext.hxx"
0010
0011 #include <exception>
0012 #include <memory>
0013 #include <mutex>
0014 #include <stdexcept>
0015 #include <vector>
0016
0017 namespace ROOT {
0018 namespace Experimental {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 template <typename BinContentType>
0037 class RHistConcurrentFiller final {
0038
0039 std::shared_ptr<RHist<BinContentType>> fHist;
0040
0041
0042 std::mutex fMutex;
0043
0044 std::vector<std::weak_ptr<RHistFillContext<BinContentType>>> fFillContexts;
0045
0046 public:
0047
0048
0049
0050 explicit RHistConcurrentFiller(std::shared_ptr<RHist<BinContentType>> hist) : fHist(hist)
0051 {
0052 if (!hist) {
0053 throw std::invalid_argument("hist must not be nullptr");
0054 }
0055 }
0056
0057 RHistConcurrentFiller(const RHistConcurrentFiller &) = delete;
0058 RHistConcurrentFiller(RHistConcurrentFiller &&) = delete;
0059 RHistConcurrentFiller &operator=(const RHistConcurrentFiller &) = delete;
0060 RHistConcurrentFiller &operator=(RHistConcurrentFiller &&) = delete;
0061
0062 ~RHistConcurrentFiller()
0063 {
0064 for (const auto &context : fFillContexts) {
0065 if (!context.expired()) {
0066
0067
0068 std::terminate();
0069 }
0070 }
0071 }
0072
0073 const std::shared_ptr<RHist<BinContentType>> &GetHist() const { return fHist; }
0074
0075
0076 std::shared_ptr<RHistFillContext<BinContentType>> CreateFillContext()
0077 {
0078
0079
0080 std::shared_ptr<RHistFillContext<BinContentType>> context(new RHistFillContext<BinContentType>(*fHist));
0081
0082 {
0083 std::lock_guard g(fMutex);
0084 fFillContexts.push_back(context);
0085 }
0086
0087 return context;
0088 }
0089 };
0090
0091 }
0092 }
0093
0094 #endif