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 <string_view>
23
24#include <memory>
25#include <vector>
26#include <unordered_map>
27
28namespace ROOT {
29namespace Experimental {
30namespace Internal {
31
32// clang-format off
33/**
34\class ROOT::Experimental::Internal::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 /// TODO(jblomer): Not only the columns, but actually all the different objects of the descriptor would need
80 /// their own maps to avoid descriptor ID clashes. The need for the distinct column map was triggered by adding
81 /// support for multi-column representations. A follow-up patch should either fix the friend page source properly
82 /// or remove it in favor of the RNTupleProcessor.
84
86 DescriptorId_t fNextId = 1; ///< 0 is reserved for the friend zero field
87
88 void AddVirtualField(const RNTupleDescriptor &originDesc, std::size_t originIdx, const RFieldDescriptor &originField,
89 DescriptorId_t virtualParent, const std::string &virtualName);
90
91protected:
92 void LoadStructureImpl() final {}
94 std::unique_ptr<RPageSource> CloneImpl() const final;
95
96 // Unused because we overwrite LoadPage()
97 virtual RPageRef LoadPageImpl(ColumnHandle_t /* columnHandle */, const RClusterInfo & /* clusterInfo */,
98 ClusterSize_t::ValueType /* idxInCluster */)
99 {
100 return RPageRef();
101 }
102
103public:
104 RPageSourceFriends(std::string_view ntupleName, std::span<std::unique_ptr<RPageSource>> sources);
106
107 ColumnHandle_t AddColumn(DescriptorId_t fieldId, RColumn &column) final;
108 void DropColumn(ColumnHandle_t columnHandle) final;
109
110 RPageRef LoadPage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final;
111 RPageRef LoadPage(ColumnHandle_t columnHandle, RClusterIndex clusterIndex) final;
112
113 void LoadSealedPage(DescriptorId_t physicalColumnId, RClusterIndex clusterIndex, RSealedPage &sealedPage) final;
114
115 std::vector<std::unique_ptr<RCluster>> LoadClusters(std::span<RCluster::RKey> clusterKeys) final;
116
117 Detail::RNTupleMetrics &GetMetrics() final { return fMetrics; }
118}; // class RPageSourceFriends
119
120} // namespace Internal
121} // namespace Experimental
122} // namespace ROOT
123
124#endif
A collection of Counter objects with a name, a unit, and a description.
An in-memory subset of the packed and compressed pages of a cluster.
Definition RCluster.hxx:152
A column is a storage-backed array of a simple, fixed-size type, from which pages can be mapped into ...
Definition RColumn.hxx:40
A helper class for piece-wise construction of an RNTupleDescriptor.
Reference to a page stored in the page pool.
Definition RPagePool.hxx:93
Virtual storage that combines several other sources horizontally.
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 LoadSealedPage(DescriptorId_t physicalColumnId, RClusterIndex clusterIndex, RSealedPage &sealedPage) final
Read the packed and compressed bytes of a page into the memory buffer provided by sealedPage.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, RColumn &column) final
Register a new column.
std::vector< std::unique_ptr< RPageSource > > fSources
virtual RPageRef LoadPageImpl(ColumnHandle_t, const RClusterInfo &, ClusterSize_t::ValueType)
RPageRef LoadPage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final
Allocates and fills a page that contains the index-th element.
RNTupleDescriptor AttachImpl() final
LoadStructureImpl() has been called before AttachImpl() is called
RIdBiMap fColumnMap
TODO(jblomer): Not only the columns, but actually all the different objects of the descriptor would n...
void DropColumn(ColumnHandle_t columnHandle) final
Unregisters a column.
Detail::RNTupleMetrics & GetMetrics() final
Returns the default metrics object.
std::unique_ptr< RPageSource > CloneImpl() const final
Returns a new, unattached page source for the same data set.
void AddVirtualField(const RNTupleDescriptor &originDesc, std::size_t originIdx, const RFieldDescriptor &originField, DescriptorId_t virtualParent, const std::string &virtualName)
DescriptorId_t fNextId
0 is reserved for the friend zero field
Abstract interface to read data from an ntuple.
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.
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
A bi-directional map of descriptor IDs that translates from physical to virtual column,...
DescriptorId_t GetVirtualId(const ROriginId &originId) const
ROriginId GetOriginId(DescriptorId_t virtualId) const
std::vector< std::unordered_map< DescriptorId_t, DescriptorId_t > > fOrigin2Virtual
void Insert(ROriginId originId, DescriptorId_t virtualId)
std::unordered_map< DescriptorId_t, ROriginId > fVirtual2Origin
Summarizes cluster-level information that are necessary to load a certain page.
A sealed page contains the bytes of a page as written to storage (packed & compressed).
Wrap the integer in a struct in order to avoid template specialization clash with std::uint64_t.