Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:47

0001 /// \file ROOT/RPageNullSink.hxx
0002 /// \ingroup NTuple ROOT7
0003 /// \author Jonas Hahnfeld <jonas.hahnfeld@cern.ch>
0004 /// \date 2024-01-31
0005 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
0006 /// is welcome!
0007 
0008 /*************************************************************************
0009  * Copyright (C) 1995-2024, Rene Brun and Fons Rademakers.               *
0010  * All rights reserved.                                                  *
0011  *                                                                       *
0012  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0013  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0014  *************************************************************************/
0015 
0016 #ifndef ROOT7_RPageNullSink
0017 #define ROOT7_RPageNullSink
0018 
0019 #include <ROOT/RColumn.hxx>
0020 #include <ROOT/RField.hxx>
0021 #include <ROOT/RNTupleModel.hxx>
0022 #include <ROOT/RPageStorage.hxx>
0023 
0024 namespace ROOT {
0025 namespace Experimental {
0026 namespace Internal {
0027 
0028 /**
0029 \class ROOT::Experimental::Internal::RPageNullSink
0030 \ingroup NTuple
0031 \brief Dummy sink that discards all pages
0032 
0033 The RPageNullSink class is for internal testing only and can be used to measure the software overhead of serializing
0034 elements into pages, without actually writing them onto disk or even serializing the RNTuple headers and footers.
0035 */
0036 class RPageNullSink : public RPageSink {
0037    RPageAllocatorHeap fPageAllocator{};
0038    DescriptorId_t fNColumns = 0;
0039    std::uint64_t fNBytesCurrentCluster = 0;
0040 
0041 public:
0042    RPageNullSink(std::string_view ntupleName, const RNTupleWriteOptions &options) : RPageSink(ntupleName, options) {}
0043 
0044    ColumnHandle_t AddColumn(DescriptorId_t, const RColumn &column) final { return {fNColumns++, &column}; }
0045 
0046    RPage ReservePage(ColumnHandle_t columnHandle, std::size_t nElements) final
0047    {
0048       auto elementSize = columnHandle.fColumn->GetElement()->GetSize();
0049       return fPageAllocator.NewPage(columnHandle.fPhysicalId, elementSize, nElements);
0050    }
0051    void ReleasePage(RPage &page) final { fPageAllocator.DeletePage(page); }
0052 
0053    const RNTupleDescriptor &GetDescriptor() const final
0054    {
0055       static RNTupleDescriptor descriptor;
0056       return descriptor;
0057    }
0058 
0059    void ConnectFields(const std::vector<RFieldBase *> &fields, NTupleSize_t firstEntry)
0060    {
0061       auto connectField = [&](RFieldBase &f) { CallConnectPageSinkOnField(f, *this, firstEntry); };
0062       for (auto *f : fields) {
0063          connectField(*f);
0064          for (auto &descendant : *f) {
0065             connectField(descendant);
0066          }
0067       }
0068    }
0069    void InitImpl(RNTupleModel &model) final { ConnectFields(model.GetFieldZero().GetSubFields(), 0); }
0070    void UpdateSchema(const RNTupleModelChangeset &changeset, NTupleSize_t firstEntry) final
0071    {
0072       ConnectFields(changeset.fAddedFields, firstEntry);
0073    }
0074 
0075    void CommitPage(ColumnHandle_t, const RPage &page) final { fNBytesCurrentCluster += page.GetNBytes(); }
0076    void CommitSealedPage(DescriptorId_t, const RSealedPage &page) final { fNBytesCurrentCluster += page.fSize; }
0077    void CommitSealedPageV(std::span<RSealedPageGroup> ranges) final
0078    {
0079       for (auto &range : ranges) {
0080          for (auto sealedPageIt = range.fFirst; sealedPageIt != range.fLast; ++sealedPageIt) {
0081             fNBytesCurrentCluster += sealedPageIt->fSize;
0082          }
0083       }
0084    }
0085 
0086    std::uint64_t CommitCluster(NTupleSize_t) final
0087    {
0088       std::uint64_t bytes = fNBytesCurrentCluster;
0089       fNBytesCurrentCluster = 0;
0090       return bytes;
0091    }
0092    void CommitClusterGroup() final {}
0093    void CommitDataset() final {}
0094 };
0095 
0096 } // namespace Internal
0097 } // namespace Experimental
0098 } // namespace ROOT
0099 
0100 #endif