|
| 1 | +/// \file |
| 2 | +/// \warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes. |
| 3 | +/// Feedback is welcome! |
| 4 | + |
| 5 | +#ifndef ROOT_RHistFillContext |
| 6 | +#define ROOT_RHistFillContext |
| 7 | + |
| 8 | +#include "RHist.hxx" |
| 9 | +#include "RHistEngine.hxx" |
| 10 | +#include "RHistStats.hxx" |
| 11 | + |
| 12 | +namespace ROOT { |
| 13 | +namespace Experimental { |
| 14 | + |
| 15 | +// forward declaration for friend declaration |
| 16 | +template <typename BinContentType> |
| 17 | +class RHistConcurrentFiller; |
| 18 | + |
| 19 | +/** |
| 20 | +A context to concurrently fill an RHist. |
| 21 | +
|
| 22 | +\sa RHistConcurrentFiller |
| 23 | +
|
| 24 | +\warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes. |
| 25 | +Feedback is welcome! |
| 26 | +*/ |
| 27 | +template <typename BinContentType> |
| 28 | +class RHistFillContext final { |
| 29 | + friend class RHistConcurrentFiller<BinContentType>; |
| 30 | + |
| 31 | +private: |
| 32 | + /// A pointer to the filled histogram |
| 33 | + RHist<BinContentType> *fHist; |
| 34 | + |
| 35 | + /// Local histogram statistics |
| 36 | + RHistStats fStats; |
| 37 | + |
| 38 | + /// \sa RHistConcurrentFiller::CreateFillContent() |
| 39 | + explicit RHistFillContext(RHist<BinContentType> &hist) : fHist(&hist), fStats(hist.GetStats()) |
| 40 | + { |
| 41 | + // The histogram may already have some statistics. Reset them after copying the structure. |
| 42 | + fStats.Clear(); |
| 43 | + } |
| 44 | + RHistFillContext(const RHistFillContext<BinContentType> &) = delete; |
| 45 | + RHistFillContext(RHistFillContext<BinContentType> &&) = default; |
| 46 | + RHistFillContext<BinContentType> &operator=(const RHistFillContext<BinContentType> &) = delete; |
| 47 | + RHistFillContext<BinContentType> &operator=(RHistFillContext<BinContentType> &&) = default; |
| 48 | + |
| 49 | +public: |
| 50 | + ~RHistFillContext() { Flush(); } |
| 51 | + |
| 52 | + /// Fill an entry into the histogram. |
| 53 | + /// |
| 54 | + /// If one of the arguments is outside the corresponding axis and flow bins are disabled, the entry will be silently |
| 55 | + /// discarded. |
| 56 | + /// |
| 57 | + /// Throws an exception if the number of arguments does not match the axis configuration, or if an argument cannot be |
| 58 | + /// converted for the axis type at run-time. |
| 59 | + /// |
| 60 | + /// \param[in] args the arguments for each axis |
| 61 | + /// \sa RHist::Fill(const std::tuple<A...> &args) |
| 62 | + template <typename... A> |
| 63 | + void Fill(const std::tuple<A...> &args) |
| 64 | + { |
| 65 | + fHist->fEngine.FillAtomic(args); |
| 66 | + fStats.Fill(args); |
| 67 | + } |
| 68 | + |
| 69 | + /// Fill an entry into the histogram with a weight. |
| 70 | + /// |
| 71 | + /// This overload is not available for integral bin content types (see \ref RHistEngine::SupportsWeightedFilling). |
| 72 | + /// |
| 73 | + /// If one of the arguments is outside the corresponding axis and flow bins are disabled, the entry will be silently |
| 74 | + /// discarded. |
| 75 | + /// |
| 76 | + /// Throws an exception if the number of arguments does not match the axis configuration, or if an argument cannot be |
| 77 | + /// converted for the axis type at run-time. |
| 78 | + /// |
| 79 | + /// \param[in] args the arguments for each axis |
| 80 | + /// \param[in] weight the weight for this entry |
| 81 | + /// \sa RHist::Fill(const std::tuple<A...> &args, RWeight weight) |
| 82 | + template <typename... A> |
| 83 | + void Fill(const std::tuple<A...> &args, RWeight weight) |
| 84 | + { |
| 85 | + fHist->fEngine.FillAtomic(args, weight); |
| 86 | + fStats.Fill(args, weight); |
| 87 | + } |
| 88 | + |
| 89 | + /// Fill an entry into the histogram. |
| 90 | + /// |
| 91 | + /// For weighted filling, pass an RWeight as the last argument. This is not available for integral bin content types |
| 92 | + /// (see \ref RHistEngine::SupportsWeightedFilling). |
| 93 | + /// |
| 94 | + /// If one of the arguments is outside the corresponding axis and flow bins are disabled, the entry will be silently |
| 95 | + /// discarded. |
| 96 | + /// |
| 97 | + /// Throws an exception if the number of arguments does not match the axis configuration, or if an argument cannot be |
| 98 | + /// converted for the axis type at run-time. |
| 99 | + /// |
| 100 | + /// \param[in] args the arguments for each axis |
| 101 | + /// \sa RHist::Fill(const A &...args) |
| 102 | + template <typename... A> |
| 103 | + void Fill(const A &...args) |
| 104 | + { |
| 105 | + fHist->fEngine.FillAtomic(args...); |
| 106 | + fStats.Fill(args...); |
| 107 | + } |
| 108 | + |
| 109 | + /// Flush locally accumulated entries to the histogram. |
| 110 | + void Flush() |
| 111 | + { |
| 112 | + fHist->fStats.AddAtomic(fStats); |
| 113 | + fStats.Clear(); |
| 114 | + } |
| 115 | +}; |
| 116 | + |
| 117 | +} // namespace Experimental |
| 118 | +} // namespace ROOT |
| 119 | + |
| 120 | +#endif |
0 commit comments