|
|
|||
File indexing completed on 2026-08-16 09:21:18
0001 /// \file 0002 /// \warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes. 0003 /// Feedback is welcome! 0004 0005 #ifndef ROOT_RHistFillContext 0006 #define ROOT_RHistFillContext 0007 0008 #include "RHist.hxx" 0009 #include "RHistEngine.hxx" 0010 #include "RHistStats.hxx" 0011 #include "RWeight.hxx" 0012 0013 #include <tuple> 0014 0015 namespace ROOT { 0016 namespace Experimental { 0017 0018 // forward declaration for friend declaration 0019 template <typename BinContentType> 0020 class RHistConcurrentFiller; 0021 0022 /** 0023 A context to concurrently fill an RHist. 0024 0025 \sa RHistConcurrentFiller 0026 0027 \warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes. 0028 Feedback is welcome! 0029 */ 0030 template <typename BinContentType> 0031 class RHistFillContext final { 0032 friend class RHistConcurrentFiller<BinContentType>; 0033 0034 private: 0035 /// A pointer to the filled histogram 0036 RHist<BinContentType> *fHist = nullptr; 0037 0038 /// Local histogram statistics 0039 RHistStats fStats; 0040 0041 /// \sa RHistConcurrentFiller::CreateFillContent() 0042 explicit RHistFillContext(RHist<BinContentType> &hist) : fHist(&hist), fStats(hist.GetNDimensions()) 0043 { 0044 // Propagate disabled dimensions to the local histogram statistics object. 0045 const auto &histStats = hist.GetStats(); 0046 for (std::size_t i = 0; i < histStats.GetNDimensions(); i++) { 0047 if (!histStats.IsEnabled(i)) { 0048 fStats.DisableDimension(i); 0049 } 0050 } 0051 } 0052 RHistFillContext(const RHistFillContext &) = delete; 0053 RHistFillContext(RHistFillContext &&) = default; 0054 RHistFillContext &operator=(const RHistFillContext &) = delete; 0055 RHistFillContext &operator=(RHistFillContext &&) = default; 0056 0057 public: 0058 ~RHistFillContext() { Flush(); } 0059 0060 /// Fill an entry into the histogram. 0061 /// 0062 /// If one of the arguments is outside the corresponding axis and flow bins are disabled, the entry will be silently 0063 /// discarded. 0064 /// 0065 /// Throws an exception if the number of arguments does not match the axis configuration, or if an argument cannot be 0066 /// converted for the axis type at run-time. 0067 /// 0068 /// \param[in] args the arguments for each axis 0069 /// \sa RHist::Fill(const std::tuple<A...> &args) 0070 template <typename... A> 0071 void Fill(const std::tuple<A...> &args) 0072 { 0073 fHist->fEngine.FillAtomic(args); 0074 fStats.Fill(args); 0075 } 0076 0077 /// Fill an entry into the histogram with a weight. 0078 /// 0079 /// This overload is not available for integral bin content types (see \ref RHistEngine::SupportsWeightedFilling). 0080 /// 0081 /// If one of the arguments is outside the corresponding axis and flow bins are disabled, the entry will be silently 0082 /// discarded. 0083 /// 0084 /// Throws an exception if the number of arguments does not match the axis configuration, or if an argument cannot be 0085 /// converted for the axis type at run-time. 0086 /// 0087 /// \param[in] args the arguments for each axis 0088 /// \param[in] weight the weight for this entry 0089 /// \sa RHist::Fill(const std::tuple<A...> &args, RWeight weight) 0090 template <typename... A> 0091 void Fill(const std::tuple<A...> &args, RWeight weight) 0092 { 0093 fHist->fEngine.FillAtomic(args, weight); 0094 fStats.Fill(args, weight); 0095 } 0096 0097 /// Fill an entry into the histogram. 0098 /// 0099 /// For weighted filling, pass an RWeight as the last argument. This is not available for integral bin content types 0100 /// (see \ref RHistEngine::SupportsWeightedFilling). 0101 /// 0102 /// If one of the arguments is outside the corresponding axis and flow bins are disabled, the entry will be silently 0103 /// discarded. 0104 /// 0105 /// Throws an exception if the number of arguments does not match the axis configuration, or if an argument cannot be 0106 /// converted for the axis type at run-time. 0107 /// 0108 /// \param[in] args the arguments for each axis 0109 /// \sa RHist::Fill(const A &...args) 0110 template <typename... A> 0111 void Fill(const A &...args) 0112 { 0113 static_assert(sizeof...(A) >= 1, "need at least one argument to Fill"); 0114 if constexpr (sizeof...(A) >= 1) { 0115 fHist->fEngine.FillAtomic(args...); 0116 fStats.Fill(args...); 0117 } 0118 } 0119 0120 /// Flush locally accumulated entries to the histogram. 0121 void Flush() 0122 { 0123 fHist->fStats.AddAtomic(fStats); 0124 fStats.Clear(); 0125 } 0126 }; 0127 0128 } // namespace Experimental 0129 } // namespace ROOT 0130 0131 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|