16 #ifndef ROOT7_RHistBufferedFill 
   17 #define ROOT7_RHistBufferedFill 
   22 namespace Experimental {
 
   25 template <
class DERIVED, 
class HIST, 
int SIZE>
 
   26 class RHistBufferedFillBase {
 
   28    using CoordArray_t = 
typename HIST::CoordArray_t;
 
   29    using Weight_t = 
typename HIST::Weight_t;
 
   33    std::array<CoordArray_t, SIZE> fXBuf;
 
   34    std::array<Weight_t, SIZE> fWBuf;
 
   37    RHistBufferedFillBase() {}
 
   38    ~RHistBufferedFillBase() { toDerived().Flush(); }
 
   40    DERIVED &toDerived() { 
return *
static_cast<DERIVED *
>(
this); }
 
   41    const DERIVED &toDerived()
 const { 
return *
static_cast<const DERIVED *
>(
this); }
 
   43    std::span<const CoordArray_t> GetCoords()
 const 
   45       return std::span<const CoordArray_t>(fXBuf.begin(), fXBuf.begin() + fCursor);
 
   47    std::span<const Weight_t> GetWeights()
 const 
   49       return std::span<const Weight_t>(fWBuf.begin(), fWBuf.begin() + fCursor);
 
   52    void Fill(
const CoordArray_t &x, Weight_t weight = 1.)
 
   55       fWBuf[fCursor++] = weight;
 
   56       if (fCursor == SIZE) {
 
   62       toDerived().FlushImpl();
 
   81 template <
class HIST, 
int SIZE = 1024>
 
   82 class RHistBufferedFill: 
public Internal::RHistBufferedFillBase<RHistBufferedFill<HIST, SIZE>, HIST, SIZE> {
 
   85    using CoordArray_t = 
typename HIST::CoordArray_t;
 
   86    using Weight_t = 
typename HIST::Weight_t;
 
   91    std::array<CoordArray_t, SIZE> fXBuf;
 
   92    std::array<Weight_t, SIZE> fWBuf;
 
   94    friend class Internal::RHistBufferedFillBase<RHistBufferedFill<HIST, SIZE>, HIST, SIZE>;
 
   95    void FlushImpl() { fHist.FillN(this->GetCoords(), this->GetWeights()); }
 
   98    RHistBufferedFill(Hist_t &hist): fHist{hist} {}
 
  100    void FillN(
const std::span<const CoordArray_t> xN, 
const std::span<const Weight_t> weightN)
 
  102       fHist.FillN(xN, weightN);
 
  105    void FillN(
const std::span<const CoordArray_t> xN) { fHist.FillN(xN); }
 
  112    operator HIST &() { 
return GetHist(); }
 
  114    static constexpr 
int GetNDim() { 
return HIST::GetNDim(); }