Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /// \file ROOT/RPageSourceFriends.hxx
0002 /// \ingroup NTuple ROOT7
0003 /// \author Jakob Blomer <jblomer@cern.ch>
0004 /// \date 2020-08-10
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-2020, 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_RPageSourceFriends
0017 #define ROOT7_RPageSourceFriends
0018 
0019 #include <ROOT/RNTupleMetrics.hxx>
0020 #include <ROOT/RPageStorage.hxx>
0021 #include <ROOT/RSpan.hxx>
0022 #include <string_view>
0023 
0024 #include <memory>
0025 #include <vector>
0026 #include <unordered_map>
0027 
0028 namespace ROOT {
0029 namespace Experimental {
0030 namespace Internal {
0031 
0032 // clang-format off
0033 /**
0034 \class ROOT::Experimental::Internal::RPageSourceFriends
0035 \ingroup NTuple
0036 \brief Virtual storage that combines several other sources horizontally
0037 */
0038 // clang-format on
0039 class RPageSourceFriends final : public RPageSource {
0040 private:
0041    struct ROriginId {
0042       std::size_t fSourceIdx = 0;
0043       DescriptorId_t fId = kInvalidDescriptorId;
0044    };
0045 
0046    /// A bi-directional map of descriptor IDs that translates from physical to virtual column, field, and
0047    /// cluster IDs and vice versa.
0048    struct RIdBiMap {
0049       std::unordered_map<DescriptorId_t, ROriginId> fVirtual2Origin;
0050       std::vector<std::unordered_map<DescriptorId_t, DescriptorId_t>> fOrigin2Virtual;
0051 
0052       void Insert(ROriginId originId, DescriptorId_t virtualId)
0053       {
0054          fOrigin2Virtual.resize(originId.fSourceIdx + 1);
0055          fOrigin2Virtual[originId.fSourceIdx][originId.fId] = virtualId;
0056          fVirtual2Origin[virtualId] = originId;
0057       }
0058 
0059       void Clear()
0060       {
0061          fVirtual2Origin.clear();
0062          fOrigin2Virtual.clear();
0063       }
0064 
0065       DescriptorId_t GetVirtualId(const ROriginId &originId) const
0066       {
0067          return fOrigin2Virtual[originId.fSourceIdx].at(originId.fId);
0068       }
0069 
0070       ROriginId GetOriginId(DescriptorId_t virtualId) const
0071       {
0072          return fVirtual2Origin.at(virtualId);
0073       }
0074    };
0075 
0076    Detail::RNTupleMetrics fMetrics;
0077    std::vector<std::unique_ptr<RPageSource>> fSources;
0078    RIdBiMap fIdBiMap;
0079 
0080    RNTupleDescriptorBuilder fBuilder;
0081    DescriptorId_t fNextId = 1;  ///< 0 is reserved for the friend zero field
0082 
0083    void AddVirtualField(const RNTupleDescriptor &originDesc, std::size_t originIdx, const RFieldDescriptor &originField,
0084                         DescriptorId_t virtualParent, const std::string &virtualName);
0085 
0086 protected:
0087    RNTupleDescriptor AttachImpl() final;
0088 
0089 public:
0090    RPageSourceFriends(std::string_view ntupleName, std::span<std::unique_ptr<RPageSource>> sources);
0091 
0092    std::unique_ptr<RPageSource> Clone() const final;
0093    ~RPageSourceFriends() final;
0094 
0095    ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) final;
0096    void DropColumn(ColumnHandle_t columnHandle) final;
0097 
0098    RPage PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final;
0099    RPage PopulatePage(ColumnHandle_t columnHandle, RClusterIndex clusterIndex) final;
0100    void ReleasePage(RPage &page) final;
0101 
0102    void LoadSealedPage(DescriptorId_t physicalColumnId, RClusterIndex clusterIndex, RSealedPage &sealedPage) final;
0103 
0104    std::vector<std::unique_ptr<RCluster>> LoadClusters(std::span<RCluster::RKey> clusterKeys) final;
0105 
0106    Detail::RNTupleMetrics &GetMetrics() final { return fMetrics; }
0107 }; // class RPageSourceFriends
0108 
0109 } // namespace Internal
0110 } // namespace Experimental
0111 } // namespace ROOT
0112 
0113 #endif