Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ntuple] set NEntries in RPagePersistentSink::InitFromDescriptor #17306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tree/ntuple/v7/inc/ROOT/RNTupleDescriptor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,8 @@ public:
RResult<void> AddClusterGroup(RClusterGroupDescriptor &&clusterGroup);
RResult<void> AddCluster(RClusterDescriptor &&clusterDesc);

RResult<void> AddNEntries(std::uint64_t nEntries);

RResult<void> AddExtraTypeInfo(RExtraTypeInfoDescriptor &&extraTypeInfoDesc);

/// Clears so-far stored clusters, fields, and columns and return to a pristine ntuple descriptor
Expand Down
21 changes: 12 additions & 9 deletions tree/ntuple/v7/src/RNTupleDescriptor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,9 @@ ROOT::Experimental::RNTupleDescriptor::AddClusterGroupDetails(DescriptorId_t clu
return R__FAIL("invalid attempt to re-populate existing cluster");
}
}
std::sort(clusterIds.begin(), clusterIds.end(),
[this](DescriptorId_t a, DescriptorId_t b)
{
return fClusterDescriptors[a].GetFirstEntryIndex() < fClusterDescriptors[b].GetFirstEntryIndex();
});
std::sort(clusterIds.begin(), clusterIds.end(), [this](DescriptorId_t a, DescriptorId_t b) {
return fClusterDescriptors[a].GetFirstEntryIndex() < fClusterDescriptors[b].GetFirstEntryIndex();
});
auto cgBuilder = Internal::RClusterGroupDescriptorBuilder::FromSummary(iter->second);
cgBuilder.AddSortedClusters(clusterIds);
iter->second = cgBuilder.MoveDescriptor().Unwrap();
Expand Down Expand Up @@ -949,10 +947,9 @@ ROOT::Experimental::RNTupleDescriptor ROOT::Experimental::Internal::RNTupleDescr
for (const auto &[id, _] : fDescriptor.fClusterGroupDescriptors)
fDescriptor.fSortedClusterGroupIds.emplace_back(id);
std::sort(fDescriptor.fSortedClusterGroupIds.begin(), fDescriptor.fSortedClusterGroupIds.end(),
[this](DescriptorId_t a, DescriptorId_t b)
{
return fDescriptor.fClusterGroupDescriptors[a].GetMinEntry() <
fDescriptor.fClusterGroupDescriptors[b].GetMinEntry();
[this](DescriptorId_t a, DescriptorId_t b) {
return fDescriptor.fClusterGroupDescriptors[a].GetMinEntry() <
fDescriptor.fClusterGroupDescriptors[b].GetMinEntry();
});
RNTupleDescriptor result;
std::swap(result, fDescriptor);
Expand Down Expand Up @@ -1173,6 +1170,12 @@ ROOT::Experimental::Internal::RNTupleDescriptorBuilder::AddClusterGroup(RCluster
return RResult<void>::Success();
}

ROOT::RResult<void> ROOT::Experimental::Internal::RNTupleDescriptorBuilder::AddNEntries(std::uint64_t nEntries)
{
fDescriptor.fNEntries += nEntries;
return RResult<void>::Success();
}

void ROOT::Experimental::Internal::RNTupleDescriptorBuilder::Reset()
{
fDescriptor.fName = "";
Expand Down
10 changes: 10 additions & 0 deletions tree/ntuple/v7/src/RPageStorage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ void ROOT::Experimental::Internal::RPageSource::UnzipClusterImpl(RCluster *clust
continue;
const auto &columnInfos = fActivePhysicalColumns.GetColumnInfos(columnId);

allElements.reserve(allElements.size() + columnInfos.size());
for (const auto &info : columnInfos) {
allElements.emplace_back(GenerateColumnElement(info.fElementId));

Expand Down Expand Up @@ -857,6 +858,8 @@ void ROOT::Experimental::Internal::RPagePersistentSink::UpdateSchema(const RNTup
}

const auto nColumns = descriptor.GetNPhysicalColumns();
fOpenColumnRanges.reserve(fOpenColumnRanges.size() + (nColumns - nColumnsBeforeUpdate));
fOpenPageRanges.reserve(fOpenPageRanges.size() + (nColumns - nColumnsBeforeUpdate));
for (DescriptorId_t i = nColumnsBeforeUpdate; i < nColumns; ++i) {
RClusterDescriptor::RColumnRange columnRange;
columnRange.fPhysicalColumnId = i;
Expand Down Expand Up @@ -899,8 +902,10 @@ void ROOT::Experimental::Internal::RPagePersistentSink::InitImpl(RNTupleModel &m
projectedFields.GetFieldZero().SetOnDiskId(0);

RNTupleModelChangeset initialChangeset{model};
initialChangeset.fAddedFields.reserve(fieldZero.GetSubFields().size());
for (auto f : fieldZero.GetSubFields())
initialChangeset.fAddedFields.emplace_back(f);
initialChangeset.fAddedProjectedFields.reserve(projectedFields.GetFieldZero().GetSubFields().size());
for (auto f : projectedFields.GetFieldZero().GetSubFields())
initialChangeset.fAddedProjectedFields.emplace_back(f);
UpdateSchema(initialChangeset, 0U);
Expand Down Expand Up @@ -943,6 +948,9 @@ void ROOT::Experimental::Internal::RPagePersistentSink::InitFromDescriptor(const
}
fDescriptorBuilder.AddCluster(clusterBuilder.MoveDescriptor().Unwrap());
fPrevClusterNEntries += nEntries;
// Even though the number of entries are set when we call AddClusterGroup, we want them to be correct already
// at the end of this function.
fDescriptorBuilder.AddNEntries(nEntries);

clusterId = descriptor.FindNextClusterId(clusterId);
}
Expand Down Expand Up @@ -1133,6 +1141,7 @@ void ROOT::Experimental::Internal::RPagePersistentSink::CommitClusterGroup()

const auto nClusters = descriptor.GetNActiveClusters();
std::vector<DescriptorId_t> physClusterIDs;
physClusterIDs.reserve(nClusters);
for (auto i = fNextClusterInGroup; i < nClusters; ++i) {
physClusterIDs.emplace_back(fSerializationContext.MapClusterId(i));
}
Expand All @@ -1156,6 +1165,7 @@ void ROOT::Experimental::Internal::RPagePersistentSink::CommitClusterGroup()
.NClusters(nClusters - fNextClusterInGroup);
}
std::vector<DescriptorId_t> clusterIds;
clusterIds.reserve(nClusters);
for (auto i = fNextClusterInGroup; i < nClusters; ++i) {
clusterIds.emplace_back(i);
}
Expand Down
Loading