diff --git a/tree/ntuple/v7/inc/ROOT/RNTupleDescriptor.hxx b/tree/ntuple/v7/inc/ROOT/RNTupleDescriptor.hxx index ff2cb565a3825..bad70cbcffdc2 100644 --- a/tree/ntuple/v7/inc/ROOT/RNTupleDescriptor.hxx +++ b/tree/ntuple/v7/inc/ROOT/RNTupleDescriptor.hxx @@ -1405,6 +1405,8 @@ public: RResult AddClusterGroup(RClusterGroupDescriptor &&clusterGroup); RResult AddCluster(RClusterDescriptor &&clusterDesc); + RResult AddNEntries(std::uint64_t nEntries); + RResult AddExtraTypeInfo(RExtraTypeInfoDescriptor &&extraTypeInfoDesc); /// Clears so-far stored clusters, fields, and columns and return to a pristine ntuple descriptor diff --git a/tree/ntuple/v7/src/RNTupleDescriptor.cxx b/tree/ntuple/v7/src/RNTupleDescriptor.cxx index c9f7ed49e4e29..51c471856f231 100644 --- a/tree/ntuple/v7/src/RNTupleDescriptor.cxx +++ b/tree/ntuple/v7/src/RNTupleDescriptor.cxx @@ -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(); @@ -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); @@ -1173,6 +1170,12 @@ ROOT::Experimental::Internal::RNTupleDescriptorBuilder::AddClusterGroup(RCluster return RResult::Success(); } +ROOT::RResult ROOT::Experimental::Internal::RNTupleDescriptorBuilder::AddNEntries(std::uint64_t nEntries) +{ + fDescriptor.fNEntries += nEntries; + return RResult::Success(); +} + void ROOT::Experimental::Internal::RNTupleDescriptorBuilder::Reset() { fDescriptor.fName = ""; diff --git a/tree/ntuple/v7/src/RPageStorage.cxx b/tree/ntuple/v7/src/RPageStorage.cxx index 3ad80586d8621..ebe156d32d6df 100644 --- a/tree/ntuple/v7/src/RPageStorage.cxx +++ b/tree/ntuple/v7/src/RPageStorage.cxx @@ -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)); @@ -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; @@ -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); @@ -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); } @@ -1133,6 +1141,7 @@ void ROOT::Experimental::Internal::RPagePersistentSink::CommitClusterGroup() const auto nClusters = descriptor.GetNActiveClusters(); std::vector physClusterIDs; + physClusterIDs.reserve(nClusters); for (auto i = fNextClusterInGroup; i < nClusters; ++i) { physClusterIDs.emplace_back(fSerializationContext.MapClusterId(i)); } @@ -1156,6 +1165,7 @@ void ROOT::Experimental::Internal::RPagePersistentSink::CommitClusterGroup() .NClusters(nClusters - fNextClusterInGroup); } std::vector clusterIds; + clusterIds.reserve(nClusters); for (auto i = fNextClusterInGroup; i < nClusters; ++i) { clusterIds.emplace_back(i); }