38#include <unordered_map>
53 auto charBuf =
reinterpret_cast<const unsigned char *
>(
fBuffer);
54 auto checksumBuf =
const_cast<unsigned char *
>(charBuf) + GetDataSize();
55 std::uint64_t xxhash3;
67 return R__FAIL(
"page checksum verification failed, data corruption detected");
74 return R__FAIL(
"invalid attempt to extract non-existing page checksum");
76 assert(fBufferSize >= kNBytesPageChecksum);
77 std::uint64_t checksum;
79 reinterpret_cast<const unsigned char *
>(
fBuffer) + fBufferSize - kNBytesPageChecksum, checksum);
87 for (
unsigned i = 0; i < fIDs.size(); ++i) {
88 if (fIDs[i] == physicalColumnID) {
93 fIDs.emplace_back(physicalColumnID);
94 fRefCounters.emplace_back(1);
99 for (
unsigned i = 0; i < fIDs.size(); ++i) {
100 if (fIDs[i] == physicalColumnID) {
101 if (--fRefCounters[i] == 0) {
102 fIDs.erase(fIDs.begin() + i);
103 fRefCounters.erase(fRefCounters.begin() + i);
114 for (
const auto &
id : fIDs)
142std::unique_ptr<ROOT::Experimental::Internal::RPageSource>
146 if (ntupleName.empty()) {
149 if (location.empty()) {
152 if (location.find(
"daos://") == 0)
154 return std::make_unique<RPageSourceDaos>(ntupleName, location, options);
159 return std::make_unique<RPageSourceFile>(ntupleName, location, options);
169 fActivePhysicalColumns.Insert(physicalId);
175 fActivePhysicalColumns.Erase(columnHandle.
fPhysicalId);
190 fHasStructure =
true;
197 GetExclDescriptorGuard().MoveIn(AttachImpl());
203 auto clone = CloneImpl();
205 clone->GetExclDescriptorGuard().MoveIn(std::move(*GetSharedDescriptorGuard()->Clone()));
206 clone->fHasStructure =
true;
207 clone->fIsAttached =
true;
214 return GetSharedDescriptorGuard()->GetNEntries();
219 return GetSharedDescriptorGuard()->GetNElements(columnHandle.
fPhysicalId);
231 UnzipClusterImpl(cluster);
238 const auto clusterId = cluster->
GetId();
239 auto descriptorGuard = GetSharedDescriptorGuard();
240 const auto &clusterDescriptor = descriptorGuard->GetClusterDescriptor(clusterId);
242 std::vector<std::unique_ptr<RColumnElementBase>> allElements;
244 std::atomic<bool> foundChecksumFailure{
false};
247 for (
const auto columnId : columnsInCluster) {
248 const auto &columnDesc = descriptorGuard->GetColumnDescriptor(columnId);
252 const auto &pageRange = clusterDescriptor.GetPageRange(columnId);
253 std::uint64_t pageNo = 0;
254 std::uint64_t firstInPage = 0;
255 for (
const auto &pi : pageRange.fPageInfos) {
261 sealedPage.
SetBufferSize(pi.fLocator.fBytesOnStorage + pi.fHasChecksum * kNBytesPageChecksum);
262 sealedPage.
SetBuffer(onDiskPage->GetAddress());
265 auto taskFunc = [
this, columnId, clusterId, firstInPage, sealedPage, element = allElements.back().get(),
266 &foundChecksumFailure,
267 indexOffset = clusterDescriptor.GetColumnRange(columnId).fFirstElementIndex]() {
268 auto rv = UnsealPage(sealedPage, *element, columnId);
270 foundChecksumFailure =
true;
273 auto newPage = rv.Unwrap();
274 fCounters->fSzUnzip.Add(element->GetSize() * sealedPage.
GetNElements());
277 fPagePool.PreloadPage(std::move(newPage));
280 fTaskScheduler->AddTask(taskFunc);
282 firstInPage += pi.fNElements;
289 fTaskScheduler->Wait();
291 if (foundChecksumFailure) {
292 throw RException(
R__FAIL(
"page checksum verification failed, data corruption detected"));
300 auto descriptorGuard = GetSharedDescriptorGuard();
301 const auto &clusterDesc = descriptorGuard->GetClusterDescriptor(clusterKey.
fClusterId);
304 if (clusterDesc.GetColumnRange(physicalColumnId).fIsSuppressed)
307 const auto &pageRange = clusterDesc.GetPageRange(physicalColumnId);
309 for (
const auto &pageInfo : pageRange.fPageInfos) {
315 perPageFunc(physicalColumnId, pageNo, pageInfo);
326 auto cachedPageRef = fPagePool.GetPage(columnId, globalIndex);
327 if (!cachedPageRef.Get().IsNull())
328 return cachedPageRef;
330 std::uint64_t idxInCluster;
333 auto descriptorGuard = GetSharedDescriptorGuard();
334 clusterInfo.
fClusterId = descriptorGuard->FindClusterId(columnId, globalIndex);
337 throw RException(
R__FAIL(
"entry with index " + std::to_string(globalIndex) +
" out of bounds"));
339 const auto &clusterDescriptor = descriptorGuard->GetClusterDescriptor(clusterInfo.
fClusterId);
340 const auto &columnRange = clusterDescriptor.GetColumnRange(columnId);
341 if (columnRange.fIsSuppressed)
347 clusterInfo.
fPageInfo = clusterDescriptor.GetPageRange(columnId).Find(idxInCluster);
350 return LoadPageImpl(columnHandle, clusterInfo, idxInCluster);
357 const auto idxInCluster = clusterIndex.
GetIndex();
359 auto cachedPageRef = fPagePool.GetPage(columnId, clusterIndex);
360 if (!cachedPageRef.Get().IsNull())
361 return cachedPageRef;
368 auto descriptorGuard = GetSharedDescriptorGuard();
369 const auto &clusterDescriptor = descriptorGuard->GetClusterDescriptor(clusterId);
370 const auto &columnRange = clusterDescriptor.GetColumnRange(columnId);
371 if (columnRange.fIsSuppressed)
376 clusterInfo.
fPageInfo = clusterDescriptor.GetPageRange(columnId).Find(idxInCluster);
379 return LoadPageImpl(columnHandle, clusterInfo, idxInCluster);
385 fCounters = std::make_unique<RCounters>(
RCounters{
389 "volume read from storage (required)"),
391 "volume read from storage (overhead)"),
394 "number of partial clusters preloaded from storage"),
397 "number of pages unzipped and decoded"),
400 "wall clock time spent decompressing"),
402 "CPU time spent reading"),
404 "CPU time spent decompressing"),
406 "bwRead",
"MB/s",
"bandwidth compressed bytes read per second", fMetrics,
408 if (
const auto szReadPayload = metrics.GetLocalCounter(
"szReadPayload")) {
409 if (
const auto szReadOverhead = metrics.GetLocalCounter(
"szReadOverhead")) {
410 if (
const auto timeWallRead = metrics.GetLocalCounter(
"timeWallRead")) {
411 if (
auto walltime = timeWallRead->GetValueAsInt()) {
412 double payload = szReadPayload->GetValueAsInt();
413 double overhead = szReadOverhead->GetValueAsInt();
415 return {
true, (1000. * (payload + overhead) / walltime)};
423 "bwReadUnzip",
"MB/s",
"bandwidth uncompressed bytes read per second", fMetrics,
426 if (
const auto timeWallRead = metrics.
GetLocalCounter(
"timeWallRead")) {
427 if (
auto walltime = timeWallRead->GetValueAsInt()) {
430 return {
true, 1000. * unzip / walltime};
437 "bwUnzip",
"MB/s",
"decompression bandwidth of uncompressed bytes per second", fMetrics,
440 if (
const auto timeWallUnzip = metrics.
GetLocalCounter(
"timeWallUnzip")) {
441 if (
auto walltime = timeWallUnzip->GetValueAsInt()) {
444 return {
true, 1000. * unzip / walltime};
451 "rtReadEfficiency",
"",
"ratio of payload over all bytes read", fMetrics,
453 if (
const auto szReadPayload = metrics.
GetLocalCounter(
"szReadPayload")) {
454 if (
const auto szReadOverhead = metrics.
GetLocalCounter(
"szReadOverhead")) {
455 if (
auto payload = szReadPayload->GetValueAsInt()) {
457 return {
true, 1./(1. + (1. * szReadOverhead->GetValueAsInt()) / payload)};
464 "rtCompression",
"",
"ratio of compressed bytes / uncompressed bytes", fMetrics,
466 if (
const auto szReadPayload = metrics.
GetLocalCounter(
"szReadPayload")) {
468 if (
auto unzip = szUnzip->GetValueAsInt()) {
469 return {
true, (1. * szReadPayload->GetValueAsInt()) / unzip};
494 auto page = fPageAllocator->NewPage(physicalColumnId, element.
GetSize(), sealedPage.
GetNElements());
501 memcpy(page.GetBuffer(), sealedPage.
GetBuffer(), bytesPacked);
505 auto tmp = fPageAllocator->NewPage(physicalColumnId, element.
GetSize(), sealedPage.
GetNElements());
507 page = std::move(tmp);
526 assert(config.
fPage);
530 unsigned char *pageBuf =
reinterpret_cast<unsigned char *
>(config.
fPage->
GetBuffer());
531 bool isAdoptedBuffer =
true;
533 auto nBytesChecksum = config.
fWriteChecksum * kNBytesPageChecksum;
537 pageBuf =
new unsigned char[nBytesPacked];
538 isAdoptedBuffer =
false;
541 auto nBytesZipped = nBytesPacked;
546 if (!isAdoptedBuffer)
548 pageBuf =
reinterpret_cast<unsigned char *
>(config.
fBuffer);
549 isAdoptedBuffer =
true;
554 RSealedPage sealedPage{pageBuf,
static_cast<std::uint32_t
>(nBytesZipped + nBytesChecksum),
556 sealedPage.ChecksumIfEnabled();
564 const auto nBytes = page.
GetNBytes() + GetWriteOptions().GetEnablePageChecksums() * kNBytesPageChecksum;
565 if (fSealPageBuffer.size() < nBytes)
566 fSealPageBuffer.resize(nBytes);
569 config.
fPage = &page;
572 config.
fWriteChecksum = GetWriteOptions().GetEnablePageChecksums();
574 config.
fBuffer = fSealPageBuffer.data();
576 return SealPage(config);
581 for (
const auto &cb : fOnDatasetCommitCallbacks)
591 return fPageAllocator->NewPage(columnHandle.
fPhysicalId, elementSize, nElements);
596std::unique_ptr<ROOT::Experimental::Internal::RPageSink>
600 if (ntupleName.empty()) {
603 if (location.empty()) {
606 if (location.find(
"daos://") == 0) {
608 return std::make_unique<RPageSinkDaos>(ntupleName, location, options);
615 return std::make_unique<RPageSinkFile>(ntupleName, location, options);
629 auto columnId = fDescriptorBuilder.GetDescriptor().GetNPhysicalColumns();
643 fDescriptorBuilder.AddColumn(columnBuilder.
MakeDescriptor().Unwrap());
650 const auto &descriptor = fDescriptorBuilder.GetDescriptor();
652 auto fieldId = descriptor.GetNFields();
654 fDescriptorBuilder.AddFieldLink(
f.GetParent()->GetOnDiskId(), fieldId);
655 f.SetOnDiskId(fieldId);
659 auto fieldId = descriptor.GetNFields();
662 fDescriptorBuilder.AddFieldLink(
f.GetParent()->GetOnDiskId(), fieldId);
663 fDescriptorBuilder.AddFieldProjection(sourceFieldId, fieldId);
664 f.SetOnDiskId(fieldId);
665 for (
const auto &source : descriptor.GetColumnIterable(sourceFieldId)) {
666 auto targetId = descriptor.GetNLogicalColumns();
672 .Type(source.GetType())
673 .Index(source.GetIndex())
674 .RepresentationIndex(source.GetRepresentationIndex());
675 fDescriptorBuilder.AddColumn(columnBuilder.
MakeDescriptor().Unwrap());
679 R__ASSERT(firstEntry >= fPrevClusterNEntries);
680 const auto nColumnsBeforeUpdate = descriptor.GetNPhysicalColumns();
683 for (
auto &descendant : *
f)
684 addField(descendant);
687 addProjectedField(*
f);
688 for (
auto &descendant : *
f)
689 addProjectedField(descendant);
692 const auto nColumns = descriptor.GetNPhysicalColumns();
693 for (
DescriptorId_t i = nColumnsBeforeUpdate; i < nColumns; ++i) {
699 columnRange.
fFirstElementIndex = descriptor.GetColumnDescriptor(i).GetFirstElementIndex();
702 fOpenColumnRanges.emplace_back(columnRange);
705 fOpenPageRanges.emplace_back(std::move(pageRange));
710 if (fSerializationContext.GetHeaderSize() > 0)
711 fSerializationContext.MapSchema(descriptor,
true);
718 throw RException(
R__FAIL(
"ROOT bug: unexpected type extra info in UpdateExtraTypeInfo()"));
725 fDescriptorBuilder.SetNTuple(fNTupleName, model.
GetDescription());
726 const auto &descriptor = fDescriptorBuilder.GetDescriptor();
734 for (
auto f : fieldZero.GetSubFields())
735 initialChangeset.fAddedFields.emplace_back(
f);
737 initialChangeset.fAddedProjectedFields.emplace_back(
f);
738 UpdateSchema(initialChangeset, 0U);
741 auto buffer = std::make_unique<unsigned char[]>(fSerializationContext.GetHeaderSize());
743 InitImpl(buffer.get(), fSerializationContext.GetHeaderSize());
745 fDescriptorBuilder.BeginHeaderExtension();
762 clusterBuilder.
ClusterId(fDescriptorBuilder.GetDescriptor().GetNActiveClusters())
766 for (
unsigned int i = 0; i < fOpenColumnRanges.size(); ++i) {
767 R__ASSERT(fOpenColumnRanges[i].fPhysicalColumnId == i);
768 const auto &columnRange = cluster.GetColumnRange(i);
769 R__ASSERT(columnRange.fPhysicalColumnId == i);
770 const auto &pageRange = cluster.GetPageRange(i);
771 R__ASSERT(pageRange.fPhysicalColumnId == i);
772 clusterBuilder.
CommitColumnRange(i, fOpenColumnRanges[i].fFirstElementIndex, columnRange.fCompressionSettings,
774 fOpenColumnRanges[i].fFirstElementIndex += columnRange.fNElements;
776 fDescriptorBuilder.AddCluster(clusterBuilder.
MoveDescriptor().Unwrap());
777 fPrevClusterNEntries += nEntries;
785 fOpenColumnRanges.at(columnHandle.
fPhysicalId).fIsSuppressed =
true;
794 pageInfo.
fLocator = CommitPageImpl(columnHandle, page);
795 pageInfo.
fHasChecksum = GetWriteOptions().GetEnablePageChecksums();
796 fOpenPageRanges.at(columnHandle.
fPhysicalId).fPageInfos.emplace_back(pageInfo);
802 fOpenColumnRanges.at(physicalColumnId).fNElements += sealedPage.
GetNElements();
806 pageInfo.
fLocator = CommitSealedPageImpl(physicalColumnId, sealedPage);
808 fOpenPageRanges.at(physicalColumnId).fPageInfos.emplace_back(pageInfo);
811std::vector<ROOT::Experimental::RNTupleLocator>
813 std::span<RPageStorage::RSealedPageGroup> ranges,
const std::vector<bool> &
mask)
815 std::vector<ROOT::Experimental::RNTupleLocator> locators;
816 locators.reserve(
mask.size());
818 for (
auto &range : ranges) {
819 for (
auto sealedPageIt = range.fFirst; sealedPageIt != range.fLast; ++sealedPageIt) {
821 locators.push_back(CommitSealedPageImpl(range.fPhysicalColumnId, *sealedPageIt));
824 locators.shrink_to_fit();
829 std::span<RPageStorage::RSealedPageGroup> ranges)
832 struct RSealedPageLink {
834 std::size_t fLocatorIdx = 0;
837 std::vector<bool>
mask;
839 std::vector<std::size_t> locatorIndexes;
841 std::unordered_map<std::uint64_t, RSealedPageLink> originalPages;
842 std::size_t iLocator = 0;
843 for (
auto &range : ranges) {
844 const auto rangeSize = std::distance(range.fFirst, range.fLast);
845 mask.reserve(
mask.size() + rangeSize);
846 locatorIndexes.reserve(locatorIndexes.size() + rangeSize);
848 for (
auto sealedPageIt = range.fFirst; sealedPageIt != range.fLast; ++sealedPageIt) {
849 if (!fFeatures.fCanMergePages || !sealedPageIt->GetHasChecksum()) {
850 mask.emplace_back(
true);
851 locatorIndexes.emplace_back(iLocator++);
855 const auto chk = sealedPageIt->GetChecksum().Unwrap();
856 auto itr = originalPages.find(chk);
857 if (itr == originalPages.end()) {
858 originalPages.insert({chk, {&(*sealedPageIt), iLocator}});
859 mask.emplace_back(
true);
860 locatorIndexes.emplace_back(iLocator++);
864 const auto *
p = itr->second.fSealedPage;
865 if (sealedPageIt->GetDataSize() !=
p->GetDataSize() ||
866 memcmp(sealedPageIt->GetBuffer(),
p->GetBuffer(),
p->GetDataSize())) {
867 mask.emplace_back(
true);
868 locatorIndexes.emplace_back(iLocator++);
872 mask.emplace_back(
false);
873 locatorIndexes.emplace_back(itr->second.fLocatorIdx);
876 mask.shrink_to_fit();
877 locatorIndexes.shrink_to_fit();
880 auto locators = CommitSealedPageVImpl(ranges,
mask);
883 for (
auto &range : ranges) {
884 for (
auto sealedPageIt = range.fFirst; sealedPageIt != range.fLast; ++sealedPageIt) {
885 fOpenColumnRanges.at(range.fPhysicalColumnId).fNElements += sealedPageIt->GetNElements();
888 pageInfo.
fNElements = sealedPageIt->GetNElements();
889 pageInfo.
fLocator = locators[locatorIndexes[i++]];
891 fOpenPageRanges.at(range.fPhysicalColumnId).fPageInfos.emplace_back(pageInfo);
899 auto nbytes = CommitClusterImpl();
902 clusterBuilder.
ClusterId(fDescriptorBuilder.GetDescriptor().GetNActiveClusters())
905 for (
unsigned int i = 0; i < fOpenColumnRanges.size(); ++i) {
906 if (fOpenColumnRanges[i].fIsSuppressed) {
907 assert(fOpenPageRanges[i].fPageInfos.empty());
912 std::swap(fullRange, fOpenPageRanges[i]);
914 fOpenColumnRanges[i].fCompressionSettings, fullRange);
915 fOpenColumnRanges[i].fFirstElementIndex += fOpenColumnRanges[i].fNElements;
916 fOpenColumnRanges[i].fNElements = 0;
921 for (
unsigned int i = 0; i < fOpenColumnRanges.size(); ++i) {
922 if (!fOpenColumnRanges[i].fIsSuppressed)
928 const auto &columnRangeFromDesc = clusterBuilder.
GetColumnRange(i);
929 fOpenColumnRanges[i].
fFirstElementIndex = columnRangeFromDesc.fFirstElementIndex + columnRangeFromDesc.fNElements;
930 fOpenColumnRanges[i].fNElements = 0;
931 fOpenColumnRanges[i].fIsSuppressed =
false;
934 fDescriptorBuilder.AddCluster(clusterBuilder.
MoveDescriptor().Unwrap());
935 fPrevClusterNEntries += nNewEntries;
941 const auto &descriptor = fDescriptorBuilder.GetDescriptor();
943 const auto nClusters = descriptor.GetNActiveClusters();
944 std::vector<DescriptorId_t> physClusterIDs;
945 for (
auto i = fNextClusterInGroup; i < nClusters; ++i) {
946 physClusterIDs.emplace_back(fSerializationContext.MapClusterId(i));
950 auto bufPageList = std::make_unique<unsigned char[]>(szPageList);
953 const auto clusterGroupId = descriptor.GetNClusterGroups();
954 const auto locator = CommitClusterGroupImpl(bufPageList.get(), szPageList);
957 if (fNextClusterInGroup == nClusters) {
960 const auto &firstClusterDesc = descriptor.GetClusterDescriptor(fNextClusterInGroup);
961 const auto &lastClusterDesc = descriptor.GetClusterDescriptor(nClusters - 1);
962 cgBuilder.
MinEntry(firstClusterDesc.GetFirstEntryIndex())
963 .
EntrySpan(lastClusterDesc.GetFirstEntryIndex() + lastClusterDesc.GetNEntries() -
964 firstClusterDesc.GetFirstEntryIndex())
965 .
NClusters(nClusters - fNextClusterInGroup);
967 std::vector<DescriptorId_t> clusterIds;
968 for (
auto i = fNextClusterInGroup; i < nClusters; ++i) {
969 clusterIds.emplace_back(i);
972 fDescriptorBuilder.AddClusterGroup(cgBuilder.
MoveDescriptor().Unwrap());
973 fSerializationContext.MapClusterGroupId(clusterGroupId);
975 fNextClusterInGroup = nClusters;
980 if (!fStreamerInfos.empty()) {
984 fDescriptorBuilder.AddExtraTypeInfo(extraInfoBuilder.
MoveDescriptor().Unwrap());
987 const auto &descriptor = fDescriptorBuilder.GetDescriptor();
990 auto bufFooter = std::make_unique<unsigned char[]>(szFooter);
993 CommitDatasetImpl(bufFooter.get(), szFooter);
999 fCounters = std::make_unique<RCounters>(
RCounters{
1001 "number of pages committed to storage"),
1003 "volume written for committed pages"),
1008 "CPU time spent writing"),
1010 "CPU time spent compressing")});
#define R__FORWARD_ERROR(res)
Short-hand to return an RResult<T> in an error state (i.e. after checking)
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
winID h TVirtualViewer3D TVirtualGLPainter p
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 result
A thread-safe integral performance counter.
A metric element that computes its floating point value from other counters.
std::int64_t GetValueAsInt() const override
A collection of Counter objects with a name, a unit, and a description.
const RNTuplePerfCounter * GetLocalCounter(std::string_view name) const
Searches counters registered in this object only. Returns nullptr if name is not found.
An either thread-safe or non thread safe counter for CPU ticks.
Record wall time and CPU time between construction and destruction.
A helper class for piece-wise construction of an RClusterDescriptor.
RResult< RClusterDescriptor > MoveDescriptor()
Move out the full cluster descriptor including page locations.
RClusterDescriptorBuilder & ClusterId(DescriptorId_t clusterId)
RClusterDescriptorBuilder & NEntries(std::uint64_t nEntries)
RClusterDescriptorBuilder & FirstEntryIndex(std::uint64_t firstEntryIndex)
const RClusterDescriptor::RColumnRange & GetColumnRange(DescriptorId_t physicalId)
RResult< void > MarkSuppressedColumnRange(DescriptorId_t physicalId)
Books the given column ID as being suppressed in this cluster.
RResult< void > CommitColumnRange(DescriptorId_t physicalId, std::uint64_t firstElementIndex, std::uint32_t compressionSettings, const RClusterDescriptor::RPageRange &pageRange)
RResult< void > CommitSuppressedColumnRanges(const RNTupleDescriptor &desc)
Sets the first element index and number of elements for all the suppressed column ranges.
A helper class for piece-wise construction of an RClusterGroupDescriptor.
RClusterGroupDescriptorBuilder & PageListLocator(const RNTupleLocator &pageListLocator)
void AddClusters(const std::vector< DescriptorId_t > &clusterIds)
RClusterGroupDescriptorBuilder & MinEntry(std::uint64_t minEntry)
RClusterGroupDescriptorBuilder & ClusterGroupId(DescriptorId_t clusterGroupId)
RClusterGroupDescriptorBuilder & EntrySpan(std::uint64_t entrySpan)
RClusterGroupDescriptorBuilder & NClusters(std::uint32_t nClusters)
RClusterGroupDescriptorBuilder & PageListLength(std::uint64_t pageListLength)
RResult< RClusterGroupDescriptor > MoveDescriptor()
An in-memory subset of the packed and compressed pages of a cluster.
const ColumnSet_t & GetAvailPhysicalColumns() const
const ROnDiskPage * GetOnDiskPage(const ROnDiskPage::Key &key) const
size_t GetNOnDiskPages() const
DescriptorId_t GetId() const
std::unordered_set< DescriptorId_t > ColumnSet_t
A helper class for piece-wise construction of an RColumnDescriptor.
RColumnDescriptorBuilder & PhysicalColumnId(DescriptorId_t physicalColumnId)
RColumnDescriptorBuilder & Type(EColumnType type)
RColumnDescriptorBuilder & SetSuppressedDeferred()
RColumnDescriptorBuilder & BitsOnStorage(std::uint16_t bitsOnStorage)
RColumnDescriptorBuilder & RepresentationIndex(std::uint16_t representationIndex)
RColumnDescriptorBuilder & FieldId(DescriptorId_t fieldId)
RColumnDescriptorBuilder & Index(std::uint32_t index)
RColumnDescriptorBuilder & FirstElementIndex(std::uint64_t firstElementIdx)
RResult< RColumnDescriptor > MakeDescriptor() const
Attempt to make a column descriptor.
RColumnDescriptorBuilder & LogicalColumnId(DescriptorId_t logicalColumnId)
A column element encapsulates the translation between basic C++ types and their column representation...
std::size_t GetSize() const
virtual bool IsMappable() const
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
virtual void Pack(void *destination, const void *source, std::size_t count) const
If the on-storage layout and the in-memory layout differ, packing creates an on-disk page from an in-...
virtual void Unpack(void *destination, const void *source, std::size_t count) const
If the on-storage layout and the in-memory layout differ, unpacking creates a memory page from an on-...
static std::unique_ptr< RColumnElementBase > Generate(EColumnType type)
If CppT == void, use the default C++ type for the given column type.
std::size_t GetPackedSize(std::size_t nElements=1U) const
A column is a storage-backed array of a simple, fixed-size type, from which pages can be mapped into ...
RColumnElementBase * GetElement() const
std::uint16_t GetRepresentationIndex() const
EColumnType GetType() const
std::uint32_t GetIndex() const
NTupleSize_t GetFirstElementIndex() const
std::uint16_t GetBitsOnStorage() const
static RFieldDescriptorBuilder FromField(const RFieldBase &field)
Make a new RFieldDescriptorBuilder based off a live NTuple field.
RResult< RFieldDescriptor > MakeDescriptor() const
Attempt to make a field descriptor.
RFieldDescriptorBuilder & FieldId(DescriptorId_t fieldId)
size_t Zip(const void *from, size_t nbytes, int compression, Writer_t fnWriter)
Returns the size of the compressed data.
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.
static std::uint32_t SerializeXxHash3(const unsigned char *data, std::uint64_t length, std::uint64_t &xxhash3, void *buffer)
Writes a XxHash-3 64bit checksum of the byte range given by data and length.
static RContext SerializeHeader(void *buffer, const RNTupleDescriptor &desc)
static std::string SerializeStreamerInfos(const StreamerInfoMap_t &infos)
static std::uint32_t SerializePageList(void *buffer, const RNTupleDescriptor &desc, std::span< DescriptorId_t > physClusterIDs, const RContext &context)
static RResult< StreamerInfoMap_t > DeserializeStreamerInfos(const std::string &extraTypeInfoContent)
static RResult< void > VerifyXxHash3(const unsigned char *data, std::uint64_t length, std::uint64_t &xxhash3)
Expects an xxhash3 checksum in the 8 bytes following data + length and verifies it.
static std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t &val)
static std::uint32_t SerializeFooter(void *buffer, const RNTupleDescriptor &desc, const RContext &context)
A memory region that contains packed and compressed pages.
void Register(const ROnDiskPage::Key &key, const ROnDiskPage &onDiskPage)
Inserts information about a page stored in fMemory.
A page as being stored on disk, that is packed and compressed.
Uses standard C++ memory allocation for the column data pages.
virtual void InitImpl(unsigned char *serializedHeader, std::uint32_t length)=0
~RPagePersistentSink() override
virtual std::vector< RNTupleLocator > CommitSealedPageVImpl(std::span< RPageStorage::RSealedPageGroup > ranges, const std::vector< bool > &mask)
Vector commit of preprocessed pages.
void InitFromDescriptor(const RNTupleDescriptor &descriptor)
Initialize sink based on an existing descriptor and fill into the descriptor builder.
std::uint64_t CommitCluster(NTupleSize_t nEntries) final
Finalize the current cluster and create a new one for the following data.
void CommitPage(ColumnHandle_t columnHandle, const RPage &page) final
Write a page to the storage. The column must have been added before.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) final
Register a new column.
static std::unique_ptr< RPageSink > Create(std::string_view ntupleName, std::string_view location, const RNTupleWriteOptions &options=RNTupleWriteOptions())
Guess the concrete derived page source from the location.
RPagePersistentSink(std::string_view ntupleName, const RNTupleWriteOptions &options)
void CommitClusterGroup() final
Write out the page locations (page list envelope) for all the committed clusters since the last call ...
void UpdateSchema(const RNTupleModelChangeset &changeset, NTupleSize_t firstEntry) final
Incorporate incremental changes to the model into the ntuple descriptor.
void CommitSealedPage(DescriptorId_t physicalColumnId, const RPageStorage::RSealedPage &sealedPage) final
Write a preprocessed page to storage. The column must have been added before.
void CommitSealedPageV(std::span< RPageStorage::RSealedPageGroup > ranges) final
Write a vector of preprocessed pages to storage. The corresponding columns must have been added befor...
void CommitSuppressedColumn(ColumnHandle_t columnHandle) final
Commits a suppressed column for the current cluster.
void EnableDefaultMetrics(const std::string &prefix)
Enables the default set of metrics provided by RPageSink.
void UpdateExtraTypeInfo(const RExtraTypeInfoDescriptor &extraTypeInfo) final
Adds an extra type information record to schema.
void CommitDatasetImpl() final
Abstract interface to write data into an ntuple.
RPageSink(std::string_view ntupleName, const RNTupleWriteOptions &options)
void CommitDataset()
Run the registered callbacks and finalize the current cluster and the entrire data set.
virtual RPage ReservePage(ColumnHandle_t columnHandle, std::size_t nElements)
Get a new, empty page for the given column that can be filled with up to nElements; nElements must be...
RSealedPage SealPage(const RPage &page, const RColumnElementBase &element)
Helper for streaming a page.
RCluster::ColumnSet_t ToColumnSet() const
void Erase(DescriptorId_t physicalColumnID)
void Insert(DescriptorId_t physicalColumnID)
void LoadStructure()
Loads header and footer without decompressing or deserializing them.
RPageSource(std::string_view ntupleName, const RNTupleReadOptions &fOptions)
void PrepareLoadCluster(const RCluster::RKey &clusterKey, ROnDiskPageMap &pageZeroMap, std::function< void(DescriptorId_t, NTupleSize_t, const RClusterDescriptor::RPageRange::RPageInfo &)> perPageFunc)
Prepare a page range read for the column set in clusterKey.
std::unique_ptr< RPageSource > Clone() const
Open the same storage multiple time, e.g.
void EnableDefaultMetrics(const std::string &prefix)
Enables the default set of metrics provided by RPageSource.
void DropColumn(ColumnHandle_t columnHandle) override
Unregisters a column.
static std::unique_ptr< RPageSource > Create(std::string_view ntupleName, std::string_view location, const RNTupleReadOptions &options=RNTupleReadOptions())
Guess the concrete derived page source from the file name (location)
NTupleSize_t GetNElements(ColumnHandle_t columnHandle)
void UnzipCluster(RCluster *cluster)
Parallel decompression and unpacking of the pages in the given cluster.
ColumnId_t GetColumnId(ColumnHandle_t columnHandle)
virtual RPageRef LoadPage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex)
Allocates and fills a page that contains the index-th element.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) override
Register a new column.
void SetEntryRange(const REntryRange &range)
Promise to only read from the given entry range.
virtual void UnzipClusterImpl(RCluster *cluster)
RResult< RPage > UnsealPage(const RSealedPage &sealedPage, const RColumnElementBase &element, DescriptorId_t physicalColumnId)
Helper for unstreaming a page.
void Attach()
Open the physical storage container and deserialize header and footer.
NTupleSize_t GetNEntries()
Common functionality of an ntuple storage for both reading and writing.
RPageStorage(std::string_view name)
Stores information about the cluster in which this page resides.
A page is a slice of a column that is mapped into memory.
static RPage MakePageZero(ColumnId_t columnId, ClusterSize_t::ValueType elementSize)
Make a 'zero' page for column columnId (that is comprised of 0x00 bytes only).
std::uint32_t GetNBytes() const
The space taken by column elements in the buffer.
std::uint32_t GetNElements() const
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...
Meta-data for a set of ntuple clusters.
NTupleSize_t GetFirstEntryIndex() const
ClusterSize_t GetNEntries() const
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
DescriptorId_t GetClusterId() const
ClusterSize_t::ValueType GetIndex() const
Base class for all ROOT issued exceptions.
A field translates read and write calls from/to underlying columns to/from tree values.
std::vector< RFieldBase * > GetSubFields()
void SetOnDiskId(DescriptorId_t id)
DescriptorId_t GetOnDiskId() const
The on-storage meta-data of an ntuple.
std::unique_ptr< RNTupleModel > CreateModel(const RCreateModelOptions &options=RCreateModelOptions()) const
Re-create the C++ model from the stored meta-data.
DescriptorId_t FindNextClusterId(DescriptorId_t clusterId) const
DescriptorId_t FindClusterId(DescriptorId_t physicalColumnId, NTupleSize_t index) const
const RClusterDescriptor & GetClusterDescriptor(DescriptorId_t clusterId) const
RFieldZero * GetFieldZero() const
const RFieldBase * GetSourceField(const RFieldBase *target) const
The RNTupleModel encapulates the schema of an ntuple.
const std::string & GetDescription() const
const RProjectedFields & GetProjectedFields() const
RFieldZero & GetFieldZero()
Non-const access to the root field is used to commit clusters during writing, and to make adjustments...
Common user-tunable settings for reading ntuples.
Common user-tunable settings for storing ntuples.
void ThrowOnError()
Short-hand method to throw an exception in the case of errors.
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
void CallConnectPageSinkOnField(RFieldBase &, RPageSink &, NTupleSize_t firstEntry=0)
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr NTupleSize_t kInvalidNTupleIndex
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
constexpr DescriptorId_t kInvalidDescriptorId
The identifiers that specifies the content of a (partial) cluster.
DescriptorId_t fClusterId
ColumnSet_t fPhysicalColumnSet
The incremental changes to a RNTupleModel
std::vector< RFieldBase * > fAddedProjectedFields
Points to the projected fields in fModel that were added as part of an updater transaction.
std::vector< RFieldBase * > fAddedFields
Points to the fields in fModel that were added as part of an updater transaction.
On-disk pages within a page source are identified by the column and page number.
Default I/O performance counters that get registered in fMetrics.
Parameters for the SealPage() method.
const RColumnElementBase * fElement
Corresponds to the page's elements, for size calculation etc.
void * fBuffer
Location for sealed output. The memory buffer has to be large enough.
bool fAllowAlias
If false, the output buffer must not point to the input page buffer, which would otherwise be an opti...
int fCompressionSetting
Compression algorithm and level to apply.
bool fWriteChecksum
Adds a 8 byte little-endian xxhash3 checksum to the page payload.
const RPage * fPage
Input page to be sealed.
Summarizes cluster-level information that are necessary to load a certain page.
DescriptorId_t fClusterId
std::uint64_t fColumnOffset
The first element number of the page's column in the given cluster.
RClusterDescriptor::RPageRange::RPageInfoExtended fPageInfo
Location of the page on disk.
Default I/O performance counters that get registered in fMetrics
Used in SetEntryRange / GetEntryRange.
bool IntersectsWith(const RClusterDescriptor &clusterDesc) const
Returns true if the given cluster has entries within the entry range.
DescriptorId_t fPhysicalId
A sealed page contains the bytes of a page as written to storage (packed & compressed).
const void * GetBuffer() const
void SetHasChecksum(bool hasChecksum)
void SetNElements(std::uint32_t nElements)
std::uint32_t GetDataSize() const
void SetBuffer(const void *buffer)
RResult< void > VerifyChecksumIfEnabled() const
RResult< std::uint64_t > GetChecksum() const
Returns a failure if the sealed page has no checksum.
std::uint32_t GetBufferSize() const
std::uint32_t GetNElements() const
void SetBufferSize(std::uint32_t bufferSize)
bool GetHasChecksum() const
The window of element indexes of a particular column in a particular cluster.
NTupleSize_t fFirstElementIndex
The global index of the first column element in the cluster.
int fCompressionSettings
The usual format for ROOT compression settings (see Compression.h).
ClusterSize_t fNElements
The number of column elements in the cluster.
DescriptorId_t fPhysicalColumnId