Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RPageSourceFriends.hxx
Go to the documentation of this file.
1/// \file ROOT/RPageSourceFriends.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2020-08-10
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#ifndef ROOT7_RPageSourceFriends
17#define ROOT7_RPageSourceFriends
18
20#include <ROOT/RPageStorage.hxx>
21#include <ROOT/RSpan.hxx>
22#include <ROOT/RStringView.hxx>
23
24#include <memory>
25#include <vector>
26#include <unordered_map>
27
28namespace ROOT {
29namespace Experimental {
30namespace Detail {
31
32// clang-format off
33/**
34\class ROOT::Experimental::Detail::RPageSourceFriends
35\ingroup NTuple
36\brief Virtual storage that combines several other sources horizontally
37*/
38// clang-format on
39class RPageSourceFriends final : public RPageSource {
40private:
41 struct ROriginId {
42 std::size_t fSourceIdx = 0;
44 };
45
46 /// A bi-directional map of descriptor IDs that translates from physical to virtual column, field, and
47 /// cluster IDs and vice versa.
48 struct RIdBiMap {
49 std::unordered_map<DescriptorId_t, ROriginId> fVirtual2Origin;
50 std::vector<std::unordered_map<DescriptorId_t, DescriptorId_t>> fOrigin2Virtual;
51
52 void Insert(ROriginId originId, DescriptorId_t virtualId)
53 {
54 fOrigin2Virtual.resize(originId.fSourceIdx + 1);
55 fOrigin2Virtual[originId.fSourceIdx][originId.fId] = virtualId;
56 fVirtual2Origin[virtualId] = originId;
57 }
58
59 void Clear()
60 {
61 fVirtual2Origin.clear();
62 fOrigin2Virtual.clear();
63 }
64
65 DescriptorId_t GetVirtualId(const ROriginId &originId) const
66 {
67 return fOrigin2Virtual[originId.fSourceIdx].at(originId.fId);
68 }
69
71 {
72 return fVirtual2Origin.at(virtualId);
73 }
74 };
75
77 std::vector<std::unique_ptr<RPageSource>> fSources;
79
81 DescriptorId_t fNextId = 1; ///< 0 is reserved for the friend zero field
82
83 void AddVirtualField(const RNTupleDescriptor &originDesc, std::size_t originIdx, const RFieldDescriptor &originField,
84 DescriptorId_t virtualParent, const std::string &virtualName);
85
86protected:
88
89public:
90 RPageSourceFriends(std::string_view ntupleName, std::span<std::unique_ptr<RPageSource>> sources);
91
92 std::unique_ptr<RPageSource> Clone() const final;
94
95 ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) final;
96 void DropColumn(ColumnHandle_t columnHandle) final;
97
98 RPage PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final;
99 RPage PopulatePage(ColumnHandle_t columnHandle, const RClusterIndex &clusterIndex) final;
100 void ReleasePage(RPage &page) final;
101
102 void LoadSealedPage(DescriptorId_t columnId, const RClusterIndex &clusterIndex, RSealedPage &sealedPage) final;
103
104 std::vector<std::unique_ptr<RCluster>> LoadClusters(std::span<RCluster::RKey> clusterKeys) final;
105
106 RNTupleMetrics &GetMetrics() final { return fMetrics; }
107};
108
109
110} // namespace Detail
111} // namespace Experimental
112} // namespace ROOT
113
114#endif
An in-memory subset of the packed and compressed pages of a cluster.
Definition RCluster.hxx:154
A collection of Counter objects with a name, a unit, and a description.
Virtual storage that combines several other sources horizontally.
RNTupleMetrics & GetMetrics() final
Returns the default metrics object. Subclasses might alternatively override the method and provide th...
std::unique_ptr< RPageSource > Clone() const final
Open the same storage multiple time, e.g. for reading in multiple threads.
void ReleasePage(RPage &page) final
Every page store needs to be able to free pages it handed out.
void LoadSealedPage(DescriptorId_t columnId, const RClusterIndex &clusterIndex, RSealedPage &sealedPage) final
Read the packed and compressed bytes of a page into the memory buffer provided by selaedPage.
std::vector< std::unique_ptr< RPageSource > > fSources
DescriptorId_t fNextId
0 is reserved for the friend zero field
std::vector< std::unique_ptr< RCluster > > LoadClusters(std::span< RCluster::RKey > clusterKeys) final
Populates all the pages of the given cluster ids and columns; it is possible that some columns do not...
void AddVirtualField(const RNTupleDescriptor &originDesc, std::size_t originIdx, const RFieldDescriptor &originField, DescriptorId_t virtualParent, const std::string &virtualName)
RPage PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final
Allocates and fills a page that contains the index-th element.
void DropColumn(ColumnHandle_t columnHandle) final
Unregisters a column.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) final
Register a new column.
Abstract interface to read data from an ntuple.
A page is a slice of a column that is mapped into memory.
Definition RPage.hxx:41
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Meta-data stored for every field of an ntuple.
A helper class for piece-wise construction of an RNTupleDescriptor.
The on-storage meta-data of an ntuple.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr DescriptorId_t kInvalidDescriptorId
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
A bi-directional map of descriptor IDs that translates from physical to virtual column,...
void Insert(ROriginId originId, DescriptorId_t virtualId)
std::unordered_map< DescriptorId_t, ROriginId > fVirtual2Origin
DescriptorId_t GetVirtualId(const ROriginId &originId) const
ROriginId GetOriginId(DescriptorId_t virtualId) const
std::vector< std::unordered_map< DescriptorId_t, DescriptorId_t > > fOrigin2Virtual
A sealed page contains the bytes of a page as written to storage (packed & compressed).