Skip to content

Commit 49f4811

Browse files
committed
[ntuple] Prevent redundant processor (re-)connection in chains
1 parent 8faf9bc commit 49f4811

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

tree/ntuple/src/RNTupleProcessor.cxx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,21 @@ ROOT::Experimental::RNTupleChainProcessor::AddFieldToEntry(const std::string &fi
347347

348348
ROOT::NTupleSize_t ROOT::Experimental::RNTupleChainProcessor::LoadEntry(ROOT::NTupleSize_t entryNumber)
349349
{
350-
ROOT::NTupleSize_t localEntryNumber = entryNumber;
351-
std::size_t currProcessorNumber = 0;
350+
// If the requested entry number is lower than the current entry number, we have to again localise the correnct local
351+
// entry number starting from the first processor in the chain. Otherwise, we can continue looking from the inner
352+
// processor that is currently connected, which is much faster when the chain consists of many inner processors.
352353
if (entryNumber < fCurrentEntryNumber) {
353354
fCurrentProcessorNumber = 0;
354355
ConnectInnerProcessor(fCurrentProcessorNumber);
355356
}
356357

358+
std::size_t currProcessorNumber = fCurrentProcessorNumber;
359+
ROOT::NTupleSize_t entriesSeen = 0;
360+
for (unsigned i = 0; i < currProcessorNumber; ++i) {
361+
entriesSeen += fInnerProcessors[i]->GetNEntries();
362+
}
363+
ROOT::NTupleSize_t localEntryNumber = entryNumber - entriesSeen;
364+
357365
// As long as the entry fails to load from the current processor, we decrement the local entry number with the number
358366
// of entries in this processor and try with the next processor until we find the correct local entry number.
359367
while (fInnerProcessors[currProcessorNumber]->LoadEntry(localEntryNumber) == kInvalidNTupleIndex) {

0 commit comments

Comments
 (0)