111 const TClass *cl =
nullptr;
125 std::to_string(
field->GetTypeVersion()) +
"]"));
143 RNTupleAtomicTimer
timer(fCounters->fTimeWallWrite, fCounters->fTimeCpuWrite);
150 fCounters->fNPageCommitted.Inc();
151 fCounters->fSzWritePayload.Add(
sealedPage.GetBufferSize());
152 fNBytesCurrentCluster +=
sealedPage.GetBufferSize();
162 RNTupleAtomicTimer
timer(fCounters->fTimeWallZip, fCounters->fTimeCpuZip);
166 fCounters->fSzZip.Add(
page.GetNBytes());
173 const auto nBits = fDescriptorBuilder.GetDescriptor().GetColumnDescriptor(
physicalColumnId).GetBitsOnStorage();
180 RNTupleAtomicTimer
timer(fCounters->fTimeWallWrite, fCounters->fTimeCpuWrite);
182 std::uint64_t
offset = fWriter->ReserveBlob(
batch.fSize,
batch.fBytesPacked);
195 fCounters->fNPageCommitted.Add(
batch.fSealedPages.size());
196 fCounters->fSzWritePayload.Add(
batch.fSize);
197 fNBytesCurrentCluster +=
batch.fSize;
200 batch.fBytesPacked = 0;
201 batch.fSealedPages.clear();
204std::vector<ROOT::RNTupleLocator>
206 const std::vector<bool> &
mask)
208 const std::uint64_t
maxKeySize = fOptions->GetMaxKeySize();
211 std::vector<RNTupleLocator>
locators;
213 std::size_t
iPage = 0;
222 fDescriptorBuilder.GetDescriptor().GetColumnDescriptor(
range.fPhysicalColumnId).GetBitsOnStorage();
256 fCounters->fNPageCommitted.Inc();
257 fCounters->fSzWritePayload.Add(
sealedPageIt->GetBufferSize());
268 if (
batch.fSize > 0) {
277 auto result = fNBytesCurrentCluster;
278 fNBytesCurrentCluster = 0;
300 for (
const auto &
extraTypeInfo : fDescriptorBuilder.GetDescriptor().GetExtraTypeInfoIterable()) {
308 fWriter->UpdateStreamerInfos(fInfosOfClassFields);
314 return fWriter->Commit(GetWriteOptions().GetCompression());
317std::unique_ptr<ROOT::Internal::RPageSink>
333 "cumulative seek distance (excluding header/footer reads)"),
335 "szFile",
"B",
"total file size",
fMetrics,
338 return {true, static_cast<double>(fFileSize)};
343 "ratio of seek distance to bytes read (excluding file structure reads)",
fMetrics,
359 "ratio of bytes read to total file size (excluding file structure reads)",
fMetrics,
374 std::unique_ptr<ROOT::Internal::RRawFile> file,
378 fFile = std::move(file);
389std::unique_ptr<ROOT::Internal::RPageSourceFile>
393 throw RException(
R__FAIL(
"This RNTuple object was not streamed from a ROOT file (TFile or descendant)"));
395 std::unique_ptr<ROOT::Internal::RRawFile>
rawFile;
399 std::string className =
anchor.fFile->IsA()->GetName();
400 auto url =
anchor.fFile->GetEndpointUrl();
401 auto protocol = std::string(
url->GetProtocol());
402 if (className ==
"TFile") {
404 }
else if (className ==
"TDavixFile" || className ==
"TCurlFile" || className ==
"TNetXNGFile") {
410 auto pageSource = std::make_unique<RPageSourceFile>(
"", std::move(
rawFile), options);
418 fClusterPool.StopBackgroundThread();
421std::unique_ptr<ROOT::Internal::RPageSource>
430 auto pageSource = std::make_unique<RPageSourceFile>(
"", fFile->Clone(), options);
441 fAnchor = fReader.GetNTuple(fNTupleName).Unwrap();
443 fReader.SetMaxKeySize(fAnchor->GetMaxKeySize());
445 fDescriptorBuilder.SetVersion(fAnchor->GetVersionEpoch(), fAnchor->GetVersionMajor(), fAnchor->GetVersionMinor(),
446 fAnchor->GetVersionPatch());
447 fDescriptorBuilder.SetOnDiskHeaderSize(fAnchor->GetNBytesHeader());
448 fDescriptorBuilder.AddToOnDiskFooterSize(fAnchor->GetNBytesFooter());
451 const auto bufSize = fAnchor->GetNBytesHeader() + fAnchor->GetNBytesFooter() +
452 std::max(fAnchor->GetLenHeader(), fAnchor->GetLenFooter());
454 fStructureBuffer.fPtrHeader = fStructureBuffer.fBuffer.get();
455 fStructureBuffer.fPtrFooter = fStructureBuffer.fBuffer.get() + fAnchor->GetNBytesHeader();
462 (std::max(fAnchor->GetNBytesHeader(), fAnchor->GetNBytesFooter()) >
readvLimits.fMaxSingleSize) ||
463 (fAnchor->GetNBytesHeader() + fAnchor->GetNBytesFooter() >
readvLimits.fMaxTotalSize)) {
464 RNTupleAtomicTimer
timer(fCounters->fTimeWallRead, fCounters->fTimeCpuRead);
465 fReader.ReadBuffer(fStructureBuffer.fPtrHeader, fAnchor->GetNBytesHeader(), fAnchor->GetSeekHeader());
466 fReader.ReadBuffer(fStructureBuffer.fPtrFooter, fAnchor->GetNBytesFooter(), fAnchor->GetSeekFooter());
467 fCounters->fNRead.Add(2);
469 RNTupleAtomicTimer
timer(fCounters->fTimeWallRead, fCounters->fTimeCpuRead);
470 R__ASSERT(fAnchor->GetNBytesHeader() < std::numeric_limits<std::size_t>::max());
471 R__ASSERT(fAnchor->GetNBytesFooter() < std::numeric_limits<std::size_t>::max());
473 static_cast<std::size_t
>(fAnchor->GetNBytesHeader()), 0},
474 {fStructureBuffer.fPtrFooter, fAnchor->GetSeekFooter(),
475 static_cast<std::size_t
>(fAnchor->GetNBytesFooter()), 0}};
477 fCounters->fNReadV.Inc();
483 auto unzipBuf =
reinterpret_cast<unsigned char *
>(fStructureBuffer.fPtrFooter) + fAnchor->GetNBytesFooter();
493 auto desc = fDescriptorBuilder.MoveDescriptor();
497 if (fNTupleName.empty())
498 fNTupleName = desc.GetName();
500 std::vector<unsigned char> buffer;
501 for (
const auto &
cgDesc : desc.GetClusterGroupIterable()) {
502 buffer.resize(std::max<size_t>(buffer.size(),
503 cgDesc.GetPageListLength() +
cgDesc.GetPageListLocator().GetNBytesOnStorage()));
505 fReader.ReadBuffer(
zipBuffer,
cgDesc.GetPageListLocator().GetNBytesOnStorage(),
506 cgDesc.GetPageListLocator().GetPosition<std::uint64_t>());
508 cgDesc.GetPageListLength(), buffer.data());
514 fFile->SetBuffering(
false);
517 fFileSize = fFile->GetSize();
541 pageInfo.GetLocator().GetPosition<std::uint64_t>());
548 sealedPage.VerifyChecksumIfEnabled().ThrowOnError();
581 RNTupleAtomicTimer
timer(fCounters->fTimeWallRead, fCounters->fTimeCpuRead);
582 const auto offset =
pageInfo.GetLocator().GetPosition<std::uint64_t>();
585 if (fLastOffset != 0) {
586 const auto distance =
static_cast<std::uint64_t
>(std::abs(
587 static_cast<std::int64_t
>(
offset) -
static_cast<std::int64_t
>(fLastOffset)));
588 fFileCounters->fSzSkip.Add(
distance);
593 fCounters->fNPageRead.Inc();
594 fCounters->fNRead.Inc();
595 fCounters->fSzReadPayload.Add(
sealedPage.GetBufferSize());
598 if (!fCurrentCluster || (fCurrentCluster->GetId() !=
clusterId) || !fCurrentCluster->ContainsColumn(
columnId))
599 fCurrentCluster = fClusterPool.GetCluster(
clusterId, fActivePhysicalColumns.ToColumnSet());
608 auto onDiskPage = fCurrentCluster->GetOnDiskPage(key);
615 RNTupleAtomicTimer
timer(fCounters->fTimeWallUnzip, fCounters->fTimeCpuUnzip);
622 fCounters->fNPageUnsealed.Inc();
629 clone->fFile = fFile->Clone();
631 return std::unique_ptr<RPageSourceFile>(clone);
634std::unique_ptr<ROOT::Internal::RCluster>
636 std::vector<ROOT::Internal::RRawFile::RIOVec> &
readRequests)
641 std::uint64_t fOffset = 0;
642 std::uint64_t
fSize = 0;
648 auto pageZeroMap = std::make_unique<ROnDiskPageMap>();
673 std::vector<std::size_t>
gaps;
676 for (
unsigned i = 1; i <
onDiskPages.size(); ++i) {
679 gaps.emplace_back(std::max(gap, std::int64_t(0)));
687 for (
auto g :
gaps) {
709 const std::uint64_t
maxKeySize = fReader.GetMaxKeySize();
714 const std::uint64_t
overhead = std::max(
static_cast<std::int64_t
>(s.fOffset) -
readUpTo, std::int64_t(0));
715 const std::uint64_t
extent = std::max(
static_cast<std::int64_t
>(s.fOffset + s.fSize) -
readUpTo, std::int64_t(0));
719 s.fBufPos =
reinterpret_cast<intptr_t
>(
req.fBuffer) + s.fOffset -
req.fOffset;
728 req.fBuffer =
reinterpret_cast<unsigned char *
>(
req.fBuffer) +
req.fSize;
729 s.fBufPos =
reinterpret_cast<intptr_t
>(
req.fBuffer);
732 req.fOffset = s.fOffset;
736 fCounters->fSzReadPayload.Add(
szPayload);
740 auto buffer =
new unsigned char[
reinterpret_cast<intptr_t
>(
req.fBuffer) +
req.fSize];
741 auto pageMap = std::make_unique<ROOT::Internal::ROnDiskPageMapHeap>(std::unique_ptr<
unsigned char[]>(buffer));
759std::vector<std::unique_ptr<ROOT::Internal::RCluster>>
762 fCounters->fNClusterLoaded.Add(
clusterKeys.size());
764 std::vector<std::unique_ptr<ROOT::Internal::RCluster>>
clusters;
765 std::vector<ROOT::Internal::RRawFile::RIOVec>
readRequests;
783 for (std::size_t i = 0; i <
nBatch; ++i) {
799 for (std::size_t i = 0; i <
nBatch; ++i) {
801 if (fLastOffset != 0) {
802 const auto distance =
static_cast<std::uint64_t
>(std::abs(
803 static_cast<std::int64_t
>(
offset) -
static_cast<std::int64_t
>(fLastOffset)));
804 fFileCounters->fSzSkip.Add(
distance);
811 RNTupleAtomicTimer
timer(fCounters->fTimeWallRead, fCounters->fTimeCpuRead);
814 RNTupleAtomicTimer
timer(fCounters->fTimeWallRead, fCounters->fTimeCpuRead);
817 fCounters->fNReadV.Inc();
818 fCounters->fNRead.Add(
nBatch);
829 fReader.LoadStreamerInfo();
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char mode
A thread-safe integral performance counter.
A metric element that computes its floating point value from other counters.
A collection of Counter objects with a name, a unit, and a description.
CounterPtrT MakeCounter(const std::string &name, Args &&... args)
An interface to read from, or write to, a ROOT file, as well as performing other common operations.
The SoA field provides I/O for an in-memory SoA layout linked to an on-disk collection of the underly...
Managed a set of clusters containing compressed and packed pages.
An in-memory subset of the packed and compressed pages of a cluster.
Read RNTuple data blocks from a TFile container, provided by a RRawFile.
Helper class to compress data blocks in the ROOT compression frame format.
static std::size_t Zip(const void *from, std::size_t nbytes, int compression, void *to)
Returns the size of the compressed data, written into the provided output buffer.
Helper class to uncompress data blocks in the ROOT compression frame format.
static void Unzip(const void *from, size_t nbytes, size_t dataLen, void *to)
The nbytes parameter provides the size ls of the from buffer.
Write RNTuple data blocks in a TFile or a bare file container.
static std::unique_ptr< RNTupleFileWriter > Append(std::string_view ntupleName, TDirectory &fileOrDirectory, std::uint64_t maxKeySize, bool isHidden)
The directory parameter can also be a TFile object (TFile inherits from TDirectory).
static std::unique_ptr< RNTupleFileWriter > Recreate(std::string_view ntupleName, std::string_view path, EContainerFormat containerFormat, const ROOT::RNTupleWriteOptions &options)
Create or truncate the local file given by path with the new empty RNTuple identified by ntupleName.
A helper class for serializing and deserialization of the RNTuple binary format.
static RResult< void > DeserializePageList(const void *buffer, std::uint64_t bufSize, ROOT::DescriptorId_t clusterGroupId, RNTupleDescriptor &desc, EDescriptorDeserializeMode mode)
static RResult< void > DeserializeFooter(const void *buffer, std::uint64_t bufSize, ROOT::Internal::RNTupleDescriptorBuilder &descBuilder)
static RResult< StreamerInfoMap_t > DeserializeStreamerInfos(const std::string &extraTypeInfoContent)
EDescriptorDeserializeMode
static RResult< void > DeserializeHeader(const void *buffer, std::uint64_t bufSize, ROOT::Internal::RNTupleDescriptorBuilder &descBuilder)
A memory region that contains packed and compressed pages.
A page as being stored on disk, that is packed and compressed.
Base class for a sink with a physical storage backend.
void UpdateSchema(const ROOT::Internal::RNTupleModelChangeset &changeset, ROOT::NTupleSize_t firstEntry) override
Incorporate incremental changes to the model into the ntuple descriptor.
void EnableDefaultMetrics(const std::string &prefix)
Enables the default set of metrics provided by RPageSink.
A thread-safe cache of pages loaded from the page source.
Storage provider that write ntuple pages into a file.
void CommitBatchOfPages(CommitBatch &batch, std::vector< RNTupleLocator > &locators)
Subroutine of CommitSealedPageVImpl, used to perform a vector write of the (multi-)range of pages con...
RPageSinkFile(std::string_view ntupleName, const ROOT::RNTupleWriteOptions &options)
std::unique_ptr< RPageSink > CloneAsHidden(std::string_view name, const ROOT::RNTupleWriteOptions &opts) const override
Creates a new sink with the same underlying storage as this but writing to a different RNTuple named ...
std::uint64_t StageClusterImpl() final
Returns the number of bytes written to storage (excluding metadata)
void InitImpl(unsigned char *serializedHeader, std::uint32_t length) final
RNTupleLocator CommitPageImpl(ColumnHandle_t columnHandle, const RPage &page) override
RNTupleLocator WriteSealedPage(const RPageStorage::RSealedPage &sealedPage, std::size_t bytesPacked)
We pass bytesPacked so that TFile::ls() reports a reasonable value for the compression ratio of the c...
RNTupleLocator CommitClusterGroupImpl(unsigned char *serializedPageList, std::uint32_t length) final
Returns the locator of the page list envelope of the given buffer that contains the serialized page l...
RNTupleLocator CommitSealedPageImpl(ROOT::DescriptorId_t physicalColumnId, const RPageStorage::RSealedPage &sealedPage) final
RNTupleLink CommitDatasetImpl() final
std::unique_ptr< ROOT::Internal::RNTupleFileWriter > fWriter
~RPageSinkFile() override
void UpdateSchema(const ROOT::Internal::RNTupleModelChangeset &changeset, ROOT::NTupleSize_t firstEntry) final
Incorporate incremental changes to the model into the ntuple descriptor.
std::vector< RNTupleLocator > CommitSealedPageVImpl(std::span< RPageStorage::RSealedPageGroup > ranges, const std::vector< bool > &mask) final
Vector commit of preprocessed pages.
Storage provider that reads ntuple pages from a file.
std::int64_t fFileSize
Total file size, set once in AttachImpl()
std::unique_ptr< ROOT::Internal::RCluster > PrepareSingleCluster(const ROOT::Internal::RCluster::RKey &clusterKey, std::vector< RRawFile::RIOVec > &readRequests)
Helper function for LoadClusters: it prepares the memory buffer (page map) and the read requests for ...
std::unique_ptr< RPageSource > OpenWithDifferentAnchor(const ROOT::Internal::RNTupleLink &anchorLink, const ROOT::RNTupleReadOptions &options={}) final
Creates a new PageSource using the same underlying file as this but referring to a different RNTuple,...
~RPageSourceFile() override
RPageRef LoadPageImpl(ColumnHandle_t columnHandle, const RClusterInfo &clusterInfo, ROOT::NTupleSize_t idxInCluster) final
static std::unique_ptr< RPageSourceFile > CreateFromAnchor(const RNTuple &anchor, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions())
Used from the RNTuple class to build a datasource if the anchor is already available.
ROOT::RNTupleDescriptor AttachImpl(RNTupleSerializer::EDescriptorDeserializeMode mode) final
LoadStructureImpl() has been called before AttachImpl() is called
std::vector< std::unique_ptr< ROOT::Internal::RCluster > > LoadClusters(std::span< ROOT::Internal::RCluster::RKey > clusterKeys) final
Populates all the pages of the given cluster ids and columns; it is possible that some columns do not...
std::unique_ptr< RFileCounters > fFileCounters
RPageSourceFile(std::string_view ntupleName, const ROOT::RNTupleReadOptions &options)
std::unique_ptr< RPageSource > CloneImpl() const final
The cloned page source creates a new raw file and reader and opens its own file descriptor to the dat...
void LoadStructureImpl() final
void LoadStreamerInfo() final
Forces the loading of ROOT StreamerInfo from the underlying file.
std::unique_ptr< RRawFile > fFile
An RRawFile is used to request the necessary byte ranges from a local or a remote file.
ROOT::Internal::RMiniFileReader fReader
Takes the fFile to read ntuple blobs from it.
void LoadSealedPage(ROOT::DescriptorId_t physicalColumnId, RNTupleLocalIndex localIndex, RSealedPage &sealedPage) final
Read the packed and compressed bytes of a page into the memory buffer provided by sealedPage.
Abstract interface to read data from an ntuple.
void EnableDefaultMetrics(const std::string &prefix)
Enables the default set of metrics provided by RPageSource.
ROOT::Experimental::Detail::RNTupleMetrics fMetrics
Stores information about the cluster in which this page resides.
A page is a slice of a column that is mapped into memory.
static const void * GetPageZeroBuffer()
Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred c...
The RRawFileTFile wraps an open TFile, but does not take ownership.
The RRawFile provides read-only access to local and remote files.
static std::unique_ptr< RRawFile > Create(std::string_view url, ROptions options=ROptions())
Factory method that returns a suitable concrete implementation according to the transport in the url.
The field for a class with dictionary.
Base class for all ROOT issued exceptions.
A field translates read and write calls from/to underlying columns to/from tree values.
The on-storage metadata of an RNTuple.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Generic information about the physical location of data.
Common user-tunable settings for reading RNTuples.
Common user-tunable settings for storing RNTuples.
std::uint64_t GetMaxKeySize() const
Representation of an RNTuple data set in a ROOT file.
const_iterator begin() const
const_iterator end() const
The field for a class using ROOT standard streaming.
TClass instances represent classes, structs and namespaces in the ROOT type system.
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0, Bool_t isTransient=kFALSE) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
Describe directory structure in memory.
const char * GetName() const override
Returns name of object.
std::unique_ptr< T[]> MakeUninitArray(std::size_t size)
Make an array of default-initialized elements.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
The identifiers that specifies the content of a (partial) cluster.
The incremental changes to a RNTupleModel
On-disk pages within a page source are identified by the column and page number.
File-specific I/O performance counters.
Summarizes cluster-level information that are necessary to load a certain page.
A sealed page contains the bytes of a page as written to storage (packed & compressed).
Used for vector reads from multiple offsets into multiple buffers.
Information about a single page in the context of a cluster's page range.