25 std::span<std::unique_ptr<RPageSource>> sources)
28 for (
auto &s : sources) {
37 std::size_t originIdx,
40 const std::string &virtualName)
42 auto virtualFieldId = fNextId++;
45 fBuilder.AddField(virtualField);
46 fBuilder.AddFieldLink(virtualParent, virtualFieldId);
47 fIdBiMap.Insert({originIdx, originField.
GetId()}, virtualFieldId);
50 AddVirtualField(originDesc, originIdx,
f, virtualFieldId,
f.GetFieldName());
53 auto physicalId =
c.IsAliasColumn() ? fIdBiMap.GetVirtualId({originIdx,
c.GetPhysicalId()}) : fNextId;
54 fBuilder.AddColumn(fNextId, physicalId, virtualFieldId,
c.GetModel(),
c.GetIndex());
55 fIdBiMap.Insert({originIdx,
c.GetLogicalId()}, fNextId);
62 fBuilder.SetNTuple(fNTupleName,
"");
66 for (std::size_t i = 0; i < fSources.size(); ++i) {
67 fSources[i]->Attach();
69 if (fSources[i]->GetNEntries() != fSources[0]->GetNEntries()) {
73 throw RException(
R__FAIL(
"mismatch in the number of entries of friend RNTuples"));
76 auto descriptorGuard = fSources[i]->GetSharedDescriptorGuard();
77 for (
unsigned j = 0; j < i; ++j) {
78 if (fSources[j]->GetSharedDescriptorGuard()->GetName() == descriptorGuard->GetName()) {
85 AddVirtualField(descriptorGuard.GetRef(), i, descriptorGuard->GetFieldZero(), 0, descriptorGuard->GetName());
87 for (
const auto &cg : descriptorGuard->GetClusterGroupIterable()) {
89 clusterGroupBuilder.ClusterGroupId(fNextId);
90 fBuilder.AddClusterGroup(clusterGroupBuilder.MoveDescriptor().Unwrap());
91 fIdBiMap.Insert({i, cg.GetId()}, fNextId);
95 for (
const auto &
c : descriptorGuard->GetClusterIterable()) {
98 for (
auto originColumnId :
c.GetColumnIds()) {
99 DescriptorId_t virtualColumnId = fIdBiMap.GetVirtualId({i, originColumnId});
101 auto pageRange =
c.GetPageRange(originColumnId).Clone();
102 pageRange.fPhysicalColumnId = virtualColumnId;
104 auto firstElementIndex =
c.GetColumnRange(originColumnId).fFirstElementIndex;
105 auto compressionSettings =
c.GetColumnRange(originColumnId).fCompressionSettings;
107 clusterBuilder.
CommitColumnRange(virtualColumnId, firstElementIndex, compressionSettings, pageRange);
110 fIdBiMap.Insert({i,
c.GetId()}, fNextId);
115 fBuilder.EnsureValidDescriptor();
116 return fBuilder.MoveDescriptor();
119std::unique_ptr<ROOT::Experimental::Internal::RPageSource>
122 std::vector<std::unique_ptr<RPageSource>> cloneSources;
123 cloneSources.reserve(fSources.size());
124 for (
const auto &
f : fSources)
125 cloneSources.emplace_back(
f->Clone());
126 return std::make_unique<RPageSourceFriends>(fNTupleName, cloneSources);
132 auto originFieldId = fIdBiMap.GetOriginId(fieldId);
133 fSources[originFieldId.fSourceIdx]->AddColumn(originFieldId.fId, column);
140 auto originColumnId = fIdBiMap.GetOriginId(columnHandle.
fPhysicalId);
142 fSources[originColumnId.fSourceIdx]->DropColumn(columnHandle);
149 auto originColumnId = fIdBiMap.GetOriginId(virtualColumnId);
152 auto page = fSources[originColumnId.fSourceIdx]->PopulatePage(columnHandle, globalIndex);
154 auto virtualClusterId = fIdBiMap.GetVirtualId({originColumnId.fSourceIdx, page.GetClusterInfo().GetId()});
155 page.ChangeIds(virtualColumnId, virtualClusterId);
164 auto originColumnId = fIdBiMap.GetOriginId(virtualColumnId);
170 auto page = fSources[originColumnId.fSourceIdx]->PopulatePage(columnHandle, originClusterIndex);
172 page.ChangeIds(virtualColumnId, clusterIndex.
GetClusterId());
180 auto originColumnId = fIdBiMap.GetOriginId(physicalColumnId);
185 fSources[originColumnId.fSourceIdx]->LoadSealedPage(physicalColumnId, originClusterIndex, sealedPage);
193 fSources[sourceIdx]->ReleasePage(page);
196std::vector<std::unique_ptr<ROOT::Experimental::Internal::RCluster>>
201 return std::vector<std::unique_ptr<ROOT::Experimental::Internal::RCluster>>(clusterKeys.size());
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
void ObserveMetrics(RNTupleMetrics &observee)
A helper class for piece-wise construction of an RClusterDescriptor.
RResult< RClusterDescriptor > MoveDescriptor()
Move out the full cluster descriptor including page locations.
RClusterDescriptorBuilder & ClusterId(DescriptorId_t clusterId)
RClusterDescriptorBuilder & FirstEntryIndex(std::uint64_t firstEntryIndex)
RResult< void > CommitColumnRange(DescriptorId_t physicalId, std::uint64_t firstElementIndex, std::uint32_t compressionSettings, const RClusterDescriptor::RPageRange &pageRange)
static RClusterGroupDescriptorBuilder FromSummary(const RClusterGroupDescriptor &clusterGroupDesc)
A helper class for piece-wise construction of an RFieldDescriptor.
RResult< RFieldDescriptor > MakeDescriptor() const
Attempt to make a field descriptor.
RFieldDescriptorBuilder & FieldName(const std::string &fieldName)
RFieldDescriptorBuilder & FieldId(DescriptorId_t fieldId)
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...
RPageSourceFriends(std::string_view ntupleName, std::span< std::unique_ptr< RPageSource > > sources)
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 selaedPage.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) final
Register a new column.
std::vector< std::unique_ptr< RPageSource > > fSources
~RPageSourceFriends() final
RNTupleDescriptor AttachImpl() final
RPage PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final
Allocates and fills a page that contains the index-th element.
void ReleasePage(RPage &page) final
Every page store needs to be able to free pages it handed out.
std::unique_ptr< RPageSource > Clone() const final
Open the same storage multiple time, e.g. for reading in multiple threads.
void DropColumn(ColumnHandle_t columnHandle) final
Unregisters a column.
void AddVirtualField(const RNTupleDescriptor &originDesc, std::size_t originIdx, const RFieldDescriptor &originField, DescriptorId_t virtualParent, const std::string &virtualName)
Detail::RNTupleMetrics fMetrics
Abstract interface to read data from an ntuple.
void DropColumn(ColumnHandle_t columnHandle) override
Unregisters a column.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) override
Register a new column.
NTupleSize_t GetId() const
A page is a slice of a column that is mapped into memory.
const RClusterInfo & GetClusterInfo() const
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
DescriptorId_t GetClusterId() const
ClusterSize_t::ValueType GetIndex() const
Base class for all ROOT issued exceptions.
Meta-data stored for every field of an ntuple.
DescriptorId_t GetId() const
The on-storage meta-data of an ntuple.
RFieldDescriptorIterable GetFieldIterable(const RFieldDescriptor &fieldDesc) const
RColumnDescriptorIterable GetColumnIterable() const
Common user-tunable settings for reading ntuples.
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.
DescriptorId_t fPhysicalId
A sealed page contains the bytes of a page as written to storage (packed & compressed).