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() ? fColumnMap.GetVirtualId({originIdx,
c.GetPhysicalId()}) : fNextId;
63 fBuilder.AddColumn(columnBuilder.
MakeDescriptor().Unwrap()).ThrowOnError();
64 fColumnMap.Insert({originIdx,
c.GetLogicalId()}, fNextId);
71 fBuilder.SetNTuple(fNTupleName,
"");
75 for (std::size_t i = 0; i < fSources.size(); ++i) {
76 fSources[i]->Attach();
78 if (fSources[i]->GetNEntries() != fSources[0]->GetNEntries()) {
83 throw RException(
R__FAIL(
"mismatch in the number of entries of friend RNTuples"));
86 auto descriptorGuard = fSources[i]->GetSharedDescriptorGuard();
87 for (
unsigned j = 0; j < i; ++j) {
88 if (fSources[j]->GetSharedDescriptorGuard()->GetName() == descriptorGuard->GetName()) {
96 AddVirtualField(descriptorGuard.GetRef(), i, descriptorGuard->GetFieldZero(), 0, descriptorGuard->GetName());
98 for (
const auto &cg : descriptorGuard->GetClusterGroupIterable()) {
100 clusterGroupBuilder.ClusterGroupId(fNextId);
101 fBuilder.AddClusterGroup(clusterGroupBuilder.MoveDescriptor().Unwrap());
102 fIdBiMap.Insert({i, cg.GetId()}, fNextId);
106 for (
const auto &
c : descriptorGuard->GetClusterIterable()) {
109 for (
const auto &originColumnRange :
c.GetColumnRangeIterable()) {
110 DescriptorId_t virtualColumnId = fColumnMap.GetVirtualId({i, originColumnRange.fPhysicalColumnId});
111 if (originColumnRange.fIsSuppressed) {
114 auto pageRange =
c.GetPageRange(originColumnRange.fPhysicalColumnId).Clone();
115 pageRange.fPhysicalColumnId = virtualColumnId;
117 auto firstElementIndex = originColumnRange.fFirstElementIndex;
118 auto compressionSettings = originColumnRange.fCompressionSettings;
120 clusterBuilder.
CommitColumnRange(virtualColumnId, firstElementIndex, compressionSettings, pageRange);
125 fIdBiMap.Insert({i,
c.GetId()}, fNextId);
130 fBuilder.EnsureValidDescriptor();
131 return fBuilder.MoveDescriptor();
134std::unique_ptr<ROOT::Experimental::Internal::RPageSource>
137 std::vector<std::unique_ptr<RPageSource>> cloneSources;
138 cloneSources.reserve(fSources.size());
139 for (
const auto &
f : fSources)
140 cloneSources.emplace_back(
f->Clone());
141 auto clone = std::make_unique<RPageSourceFriends>(fNTupleName, cloneSources);
142 clone->fIdBiMap = fIdBiMap;
143 clone->fColumnMap = fColumnMap;
150 auto originFieldId = fIdBiMap.GetOriginId(fieldId);
151 fSources[originFieldId.fSourceIdx]->AddColumn(originFieldId.fId, column);
158 auto originColumnId = fColumnMap.GetOriginId(columnHandle.
fPhysicalId);
160 fSources[originColumnId.fSourceIdx]->DropColumn(columnHandle);
167 auto originColumnId = fColumnMap.GetOriginId(virtualColumnId);
170 auto pageRef = fSources[originColumnId.fSourceIdx]->LoadPage(columnHandle, globalIndex);
172 if (!pageRef.Get().IsValid())
175 auto virtualClusterId = fIdBiMap.GetVirtualId({originColumnId.fSourceIdx, pageRef.Get().GetClusterInfo().GetId()});
176 pageRef.ChangeIds(virtualColumnId, virtualClusterId);
185 auto originColumnId = fColumnMap.GetOriginId(virtualColumnId);
189 auto pageRef = fSources[originColumnId.fSourceIdx]->LoadPage(columnHandle, originClusterIndex);
191 if (!pageRef.Get().IsValid())
194 pageRef.ChangeIds(virtualColumnId, clusterIndex.
GetClusterId());
202 auto originColumnId = fColumnMap.GetOriginId(physicalColumnId);
205 fSources[originColumnId.fSourceIdx]->LoadSealedPage(physicalColumnId, originClusterIndex, sealedPage);
208std::vector<std::unique_ptr<ROOT::Experimental::Internal::RCluster>>
213 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 > MarkSuppressedColumnRange(DescriptorId_t physicalId)
Books the given column ID as being suppressed in this cluster.
RResult< void > CommitColumnRange(DescriptorId_t physicalId, std::uint64_t firstElementIndex, std::uint32_t compressionSettings, const RClusterDescriptor::RPageRange &pageRange)
RResult< void > CommitSuppressedColumnRanges(const RNTupleDescriptor &desc)
Sets the first element index and number of elements for all the suppressed column ranges.
static RClusterGroupDescriptorBuilder FromSummary(const RClusterGroupDescriptor &clusterGroupDesc)
A helper class for piece-wise construction of an RColumnDescriptor.
RColumnDescriptorBuilder & PhysicalColumnId(DescriptorId_t physicalColumnId)
RColumnDescriptorBuilder & Type(EColumnType type)
RColumnDescriptorBuilder & BitsOnStorage(std::uint16_t bitsOnStorage)
RColumnDescriptorBuilder & RepresentationIndex(std::uint16_t representationIndex)
RColumnDescriptorBuilder & FieldId(DescriptorId_t fieldId)
RColumnDescriptorBuilder & Index(std::uint32_t index)
RResult< RColumnDescriptor > MakeDescriptor() const
Attempt to make a column descriptor.
RColumnDescriptorBuilder & LogicalColumnId(DescriptorId_t logicalColumnId)
RColumnDescriptorBuilder & ValueRange(double min, double max)
A column is a storage-backed array of a simple, fixed-size type, from which pages can be mapped into ...
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 sealedPage.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, RColumn &column) final
Register a new column.
std::vector< std::unique_ptr< RPageSource > > fSources
RPageRef LoadPage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final
Allocates and fills a page that contains the index-th element.
~RPageSourceFriends() final
RNTupleDescriptor AttachImpl() final
LoadStructureImpl() has been called before AttachImpl() is called
void DropColumn(ColumnHandle_t columnHandle) final
Unregisters a column.
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)
Detail::RNTupleMetrics fMetrics
Abstract interface to read data from an ntuple.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, RColumn &column) override
Register a new column.
void DropColumn(ColumnHandle_t columnHandle) override
Unregisters a column.
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.
RColumnDescriptorIterable GetColumnIterable() const
RFieldDescriptorIterable GetFieldIterable(const RFieldDescriptor &fieldDesc) 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).