Skip to content

Commit 3e6186d

Browse files
committed
[ntuple] factor out loading of zero pages
1 parent b91754d commit 3e6186d

4 files changed

Lines changed: 40 additions & 31 deletions

File tree

tree/ntuple/inc/ROOT/RPageStorage.hxx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,16 @@ The page source also gives access to the ntuple's metadata.
567567
*/
568568
// clang-format on
569569
class RPageSource : public RPageStorage {
570+
protected:
571+
/// Summarizes meta-data necessary to load a certain page. Used by LoadPageImpl().
572+
struct RPageSummary {
573+
ROOT::DescriptorId_t fClusterId = 0;
574+
/// The first element number of the page's column in the given cluster
575+
std::uint64_t fColumnOffset = 0;
576+
/// Location of the page on disk
577+
ROOT::RClusterDescriptor::RPageInfoExtended fPageInfo;
578+
};
579+
570580
public:
571581
/// Used in SetEntryRange / GetEntryRange
572582
struct REntryRange {
@@ -640,6 +650,9 @@ private:
640650
/// Must not be called when the descriptor guard is taken.
641651
void UpdateLastUsedCluster(ROOT::DescriptorId_t clusterId);
642652

653+
// Common treatment of zero pages that would otherwise need to be handled in LoadPageImpl()
654+
ROOT::Internal::RPageRef LoadZeroPage(ColumnHandle_t columnHandle, const RPageSummary &pageSummary);
655+
643656
protected:
644657
/// Default I/O performance counters that get registered in `fMetrics`
645658
struct RCounters {
@@ -693,15 +706,6 @@ protected:
693706
}
694707
};
695708

696-
/// Summarizes meta-data is necessary to load a certain page. Used by LoadPageImpl().
697-
struct RPageSummary {
698-
ROOT::DescriptorId_t fClusterId = 0;
699-
/// The first element number of the page's column in the given cluster
700-
std::uint64_t fColumnOffset = 0;
701-
/// Location of the page on disk
702-
ROOT::RClusterDescriptor::RPageInfoExtended fPageInfo;
703-
};
704-
705709
std::unique_ptr<RCounters> fCounters;
706710

707711
ROOT::RNTupleReadOptions fOptions;
@@ -725,7 +729,7 @@ protected:
725729
virtual std::unique_ptr<RPageSource> CloneImpl() const = 0;
726730
// Only called if a task scheduler is set. No-op be default.
727731
virtual void UnzipClusterImpl(ROOT::Internal::RCluster *cluster);
728-
// Returns a page from storage if not found in the page pool. Should be able to handle zero page locators.
732+
// Returns a page from storage if not found in the page pool. Will never receive requests for zero pages.
729733
virtual ROOT::Internal::RPageRef LoadPageImpl(ColumnHandle_t columnHandle, const RPageSummary &pageSummary) = 0;
730734

731735
/// Prepare a page range read for the column set in `clusterKey`. Specifically, pages referencing the

tree/ntuple/src/RPageStorage.cxx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,24 @@ void ROOT::Internal::RPageSource::UpdateLastUsedCluster(ROOT::DescriptorId_t clu
392392
fLastUsedCluster = clusterId;
393393
}
394394

395+
ROOT::Internal::RPageRef
396+
ROOT::Internal::RPageSource::LoadZeroPage(ColumnHandle_t columnHandle, const RPageSummary &pageSummary)
397+
{
398+
const auto &pageInfo = pageSummary.fPageInfo;
399+
assert(pageInfo.GetLocator().GetType() == RNTupleLocator::kTypePageZero);
400+
401+
const auto element = columnHandle.fColumn->GetElement();
402+
const auto elementSize = element->GetSize();
403+
const auto elementInMemoryType = element->GetIdentifier().fInMemoryType;
404+
405+
auto pageZero = fPageAllocator->NewPage(elementSize, pageInfo.GetNElements());
406+
pageZero.GrowUnchecked(pageInfo.GetNElements());
407+
std::memset(pageZero.GetBuffer(), 0, pageZero.GetNBytes());
408+
pageZero.SetWindow(pageSummary.fColumnOffset + pageInfo.GetFirstElementIndex(),
409+
RPage::RClusterInfo(pageSummary.fClusterId, pageSummary.fColumnOffset));
410+
return fPagePool.RegisterPage(std::move(pageZero), RPagePool::RKey{columnHandle.fPhysicalId, elementInMemoryType});
411+
}
412+
395413
ROOT::Internal::RPageRef
396414
ROOT::Internal::RPageSource::LoadPage(ColumnHandle_t columnHandle, ROOT::NTupleSize_t globalIndex)
397415
{
@@ -422,8 +440,11 @@ ROOT::Internal::RPageSource::LoadPage(ColumnHandle_t columnHandle, ROOT::NTupleS
422440
pageSummary.fPageInfo = clusterDescriptor.GetPageRange(columnId).Find(globalIndex - pageSummary.fColumnOffset);
423441
}
424442

425-
if (pageSummary.fPageInfo.GetLocator().GetType() == RNTupleLocator::kTypeUnknown)
443+
if (pageSummary.fPageInfo.GetLocator().GetType() == RNTupleLocator::kTypeUnknown) {
426444
throw RException(R__FAIL("tried to read a page with an unknown locator"));
445+
} else if (pageSummary.fPageInfo.GetLocator().GetType() == RNTupleLocator::kTypePageZero) {
446+
return LoadZeroPage(columnHandle, pageSummary);
447+
}
427448

428449
UpdateLastUsedCluster(pageSummary.fClusterId);
429450
return LoadPageImpl(columnHandle, pageSummary);
@@ -458,8 +479,11 @@ ROOT::Internal::RPageSource::LoadPage(ColumnHandle_t columnHandle, RNTupleLocalI
458479
pageSummary.fPageInfo = clusterDescriptor.GetPageRange(columnId).Find(localIndex.GetIndexInCluster());
459480
}
460481

461-
if (pageSummary.fPageInfo.GetLocator().GetType() == RNTupleLocator::kTypeUnknown)
482+
if (pageSummary.fPageInfo.GetLocator().GetType() == RNTupleLocator::kTypeUnknown) {
462483
throw RException(R__FAIL("tried to read a page with an unknown locator"));
484+
} else if (pageSummary.fPageInfo.GetLocator().GetType() == RNTupleLocator::kTypePageZero) {
485+
return LoadZeroPage(columnHandle, pageSummary);
486+
}
463487

464488
UpdateLastUsedCluster(clusterId);
465489
return LoadPageImpl(columnHandle, pageSummary);

tree/ntuple/src/RPageStorageDaos.cxx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,6 @@ ROOT::Internal::RPageRef ROOT::Experimental::Internal::RPageSourceDaos::LoadPage
561561
const auto elementSize = element->GetSize();
562562
const auto elementInMemoryType = element->GetIdentifier().fInMemoryType;
563563

564-
if (pageInfo.GetLocator().GetType() == RNTupleLocator::kTypePageZero) {
565-
auto pageZero = fPageAllocator->NewPage(elementSize, pageInfo.GetNElements());
566-
pageZero.GrowUnchecked(pageInfo.GetNElements());
567-
memset(pageZero.GetBuffer(), 0, pageZero.GetNBytes());
568-
pageZero.SetWindow(pageSummary.fColumnOffset + pageInfo.GetFirstElementIndex(),
569-
ROOT::Internal::RPage::RClusterInfo(clusterId, pageSummary.fColumnOffset));
570-
return fPagePool.RegisterPage(std::move(pageZero),
571-
ROOT::Internal::RPagePool::RKey{columnId, elementInMemoryType});
572-
}
573-
574564
RSealedPage sealedPage;
575565
sealedPage.SetNElements(pageInfo.GetNElements());
576566
sealedPage.SetHasChecksum(pageInfo.HasChecksum());

tree/ntuple/src/RPageStorageFile.cxx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,6 @@ ROOT::Internal::RPageSourceFile::LoadPageImpl(ColumnHandle_t columnHandle, const
558558
const auto elementSize = element->GetSize();
559559
const auto elementInMemoryType = element->GetIdentifier().fInMemoryType;
560560

561-
if (pageInfo.GetLocator().GetType() == RNTupleLocator::kTypePageZero) {
562-
auto pageZero = fPageAllocator->NewPage(elementSize, pageInfo.GetNElements());
563-
pageZero.GrowUnchecked(pageInfo.GetNElements());
564-
memset(pageZero.GetBuffer(), 0, pageZero.GetNBytes());
565-
pageZero.SetWindow(pageSummary.fColumnOffset + pageInfo.GetFirstElementIndex(),
566-
ROOT::Internal::RPage::RClusterInfo(clusterId, pageSummary.fColumnOffset));
567-
return fPagePool.RegisterPage(std::move(pageZero), RPagePool::RKey{columnId, elementInMemoryType});
568-
}
569-
570561
RSealedPage sealedPage;
571562
sealedPage.SetNElements(pageInfo.GetNElements());
572563
sealedPage.SetHasChecksum(pageInfo.HasChecksum());

0 commit comments

Comments
 (0)