44#include <unordered_map>
69 auto [itr,
_] =
fColumnInfos.emplace(physicalColumnId, std::vector<RColumnInfo>());
70 for (
auto &columnInfo : itr->second) {
71 if (columnInfo.fElementId == elementId) {
72 columnInfo.fRefCounter++;
76 itr->second.emplace_back(
RColumnInfo{elementId, 1});
82 auto itr = fColumnInfos.find(physicalColumnId);
84 for (std::size_t i = 0; i < itr->second.size(); ++i) {
85 if (itr->second[i].fElementId != elementId)
88 itr->second[i].fRefCounter--;
89 if (itr->second[i].fRefCounter == 0) {
90 itr->second.erase(itr->second.begin() + i);
91 if (itr->second.empty()) {
92 fColumnInfos.erase(itr);
102 for (
const auto &[physicalColumnId,
_] : fColumnInfos)
103 result.insert(physicalColumnId);
134std::unique_ptr<ROOT::Internal::RPageSource>
138 if (ntupleName.empty()) {
141 if (location.empty()) {
144 if (location.find(
"daos://") == 0)
146 return std::make_unique<ROOT::Experimental::Internal::RPageSourceDaos>(ntupleName, location, options);
153 return std::make_unique<ROOT::Experimental::Internal::RPageSourceS3>(ntupleName, location, options);
155 throw RException(
R__FAIL(
"This RNTuple build does not support S3. Rebuild ROOT with the 'curl' "
156 "cmake option enabled (-Dcurl=ON) to enable the S3 backend."));
160 return std::make_unique<ROOT::Internal::RPageSourceFile>(ntupleName, location, options);
190 fHasStructure =
true;
198 fDeserializationMode =
mode;
203 auto descGuard = GetExclDescriptorGuard();
204 descGuard.MoveIn(AttachImpl());
205 fStructureBuffer.Reset();
208 fCumulativeClusterCounts.reserve(descGuard->GetNClusterGroups());
209 for (
const auto &cgDesc : descGuard->GetClusterGroupIterable()) {
210 sumClusterCount += cgDesc.GetNClusters();
211 fCumulativeClusterCounts.emplace_back(sumClusterCount);
223 auto descGuard = GetExclDescriptorGuard();
225 for (
const auto &cgDesc : descGuard->GetClusterGroupIterable()) {
226 LoadPageList(cgDesc.GetId(), descGuard);
230 fClusterGroupAccessSequence.clear();
236 if (cgDesc.HasClusterDetails())
240 MakeUninitArray<unsigned char>(cgDesc.GetPageListLength() + cgDesc.GetPageListLocator().GetNBytesOnStorage());
241 auto zipBuffer = buffer.get() + cgDesc.GetPageListLength();
242 LoadPageListImpl(cgDesc.GetPageListLocator(), zipBuffer);
246 fDeserializationMode);
251 auto clone = CloneImpl();
253 clone->GetExclDescriptorGuard().MoveIn(GetSharedDescriptorGuard()->Clone());
254 clone->fHasStructure =
true;
255 clone->fIsAttached =
true;
256 clone->fDeserializationMode = fDeserializationMode;
257 clone->fCumulativeClusterCounts = fCumulativeClusterCounts;
270 auto itrSeq = std::find(fClusterGroupAccessSequence.begin(), fClusterGroupAccessSequence.end(), cgId);
273 (itrSeq == fClusterGroupAccessSequence.begin())) {
279 auto exclGuard = GetExclDescriptorGuard();
281 itrSeq = std::find(fClusterGroupAccessSequence.begin(), fClusterGroupAccessSequence.end(), cgId);
283 if (exclGuard->GetClusterGroupDescriptor(cgId).HasClusterDetails()) {
286 assert(itrSeq != fClusterGroupAccessSequence.end());
287 fClusterGroupAccessSequence.erase(itrSeq);
288 fClusterGroupAccessSequence.push_front(cgId);
292 assert(itrSeq == fClusterGroupAccessSequence.end());
293 const auto nClusterGroups = fClusterGroupAccessSequence.size();
295 assert(clusterGroupBudget > 0);
296 if ((nClusterGroups >= clusterGroupBudget) && (nClusterGroups > fPinnedClusterGroups.size())) {
299 auto nRemove = std::min(nClusterGroups - fPinnedClusterGroups.size(), nClusterGroups - clusterGroupBudget + 1);
302 for (
auto lru = fClusterGroupAccessSequence.rbegin(); nRemove > 0;) {
303 if (fPinnedClusterGroups.count(*lru) > 0) {
307 exclGuard->DropClusterGroupDetails(*lru);
310 auto next = fClusterGroupAccessSequence.erase(std::prev(lru.base()));
312 lru = std::make_reverse_iterator(next);
315 assert(fClusterGroupAccessSequence.size() > 0);
317 fClusterGroupAccessSequence.push_front(cgId);
319 LoadPageList(cgId, exclGuard);
328 auto iter = std::lower_bound(fCumulativeClusterCounts.begin(), fCumulativeClusterCounts.end(), clusterId + 1);
329 if (iter == fCumulativeClusterCounts.end())
331 return std::distance(fCumulativeClusterCounts.begin(), iter);
336 return GetSharedDescriptorGuard()->GetNEntries();
341 auto sharedGuard = GetSharedDescriptorGuard();
342 if (sharedGuard->GetNClusters() == 0)
345 const auto lastClusterGroupId = sharedGuard->GetNClusterGroups() - 1;
346 auto descGuard = EnsureClusterDetails(lastClusterGroupId, std::move(sharedGuard));
348 const auto &cgDesc = descGuard->GetClusterGroupDescriptor(lastClusterGroupId);
349 const auto &cd = descGuard->GetClusterDescriptor(cgDesc.GetClusterIds().back());
350 R__ASSERT(cd.ContainsColumn(physicalColumnId));
352 const auto &columnRange = cd.GetColumnRange(physicalColumnId);
353 return columnRange.GetFirstElementIndex() + columnRange.GetNElements();
358 fPinnedClusters.insert(clusterId);
359 ++fPinnedClusterGroups[FindClusterGroupId(clusterId)];
364 fPinnedClusters.erase(clusterId);
365 auto itr = fPinnedClusterGroups.find(FindClusterGroupId(clusterId));
366 assert(itr != fPinnedClusterGroups.end() && itr->second > 0);
367 if (--itr->second == 0)
368 fPinnedClusterGroups.erase(itr);
377 auto sharedGuard = GetSharedDescriptorGuard();
378 assert(clusterId < sharedGuard->GetNClusters());
379 nextId = clusterId + 1;
380 if (nextId == sharedGuard->GetNClusters()) {
384 return EnsureClusterDetails(FindClusterGroupId(nextId), std::move(sharedGuard));
399 std::size_t cgLeft = 0;
401 while (cgLeft <= cgRight) {
402 const std::size_t cgMidpoint = (cgLeft + cgRight) / 2;
403 const auto &cgDesc = *(cgIter + cgMidpoint);
405 if (cgDesc.GetMinEntry() > entryIdx) {
407 cgRight = cgMidpoint - 1;
411 if (cgDesc.GetMinEntry() + cgDesc.GetEntrySpan() <= entryIdx) {
412 cgLeft = cgMidpoint + 1;
418 const auto tgtClusterGroupId = cgDesc.GetId();
419 descGuard = EnsureClusterDetails(tgtClusterGroupId, std::move(descGuard));
422 std::size_t clusterLeft = 0;
423 std::size_t clusterRight = clusterIds.size() - 1;
424 while (clusterLeft <= clusterRight) {
425 const std::size_t clusterMidpoint = (clusterLeft + clusterRight) / 2;
428 if (clusterDesc.GetFirstEntryIndex() > entryIdx) {
430 clusterRight = clusterMidpoint - 1;
434 if (clusterDesc.GetFirstEntryIndex() + clusterDesc.GetNEntries() <= entryIdx) {
435 clusterLeft = clusterMidpoint + 1;
439 cid = clusterIds[clusterMidpoint];
452const std::vector<ROOT::DescriptorId_t> *
460 if (firstColumnRange.GetFirstElementIndex() >
index) {
468 if ((lastColumnRange.GetFirstElementIndex() + lastColumnRange.GetNElements()) <=
index) {
481 const std::vector<ROOT::DescriptorId_t> &clusterIds,
484 std::size_t clusterLeft = 0;
485 std::size_t clusterRight = clusterIds.size() - 1;
486 while (clusterLeft <= clusterRight) {
487 const std::size_t clusterMidpoint = (clusterLeft + clusterRight) / 2;
488 const auto clusterId = clusterIds[clusterMidpoint];
491 if (columnRange.Contains(
index)) {
495 if (columnRange.GetFirstElementIndex() >
index) {
497 clusterRight = clusterMidpoint - 1;
501 if (columnRange.GetFirstElementIndex() + columnRange.GetNElements() <=
index) {
502 clusterLeft = clusterMidpoint + 1;
525 const std::vector<DescriptorId_t> *clusterIds =
nullptr;
531 for (
int i = 0; i < 2; ++i) {
532 descGuard = EnsureClusterDetails(cgHint, std::move(descGuard));
533 if ((clusterIds = SearchInClusterGroup(physicalColumnId,
index, cgHint, descGuard))) {
534 cid = FindClusterIdInList(physicalColumnId,
index, *clusterIds, descGuard);
540 assert(cgHint != cgGuess);
544 const bool isRightSided = cgHint > cgGuess;
545 for (
auto [cgPinned,
_] : fPinnedClusterGroups) {
546 if (isRightSided && (cgPinned < cgHint)) {
549 }
else if (!isRightSided && (cgPinned > cgHint)) {
554 descGuard = EnsureClusterDetails(cgPinned, std::move(descGuard));
556 if ((clusterIds = SearchInClusterGroup(physicalColumnId,
index, cgHint, descGuard))) {
557 cid = FindClusterIdInList(physicalColumnId,
index, *clusterIds, descGuard);
561 if (cgHint < cgPinned) {
569 if (columnDesc.GetIndex() == 0) {
582 return FindClusterId(
index, cid);
590 std::size_t cgLeft = 0;
592 while (cgLeft <= cgRight) {
593 const std::size_t cgMidpoint = (cgLeft + cgRight) / 2;
594 descGuard = EnsureClusterDetails(cgMidpoint, std::move(descGuard));
597 clusterIds = SearchInClusterGroup(physicalColumnId,
index, cgHint, descGuard);
600 cid = FindClusterIdInList(physicalColumnId,
index, *clusterIds, descGuard);
606 }
else if (cgHint < cgMidpoint) {
608 cgRight = cgMidpoint - 1;
611 cgLeft = cgMidpoint + 1;
622 RNTupleAtomicTimer timer(fCounters->fTimeWallUnzip, fCounters->fTimeCpuUnzip);
624 const auto clusterId = cluster->
GetId();
625 auto descriptorGuard = EnsureClusterDetails(FindClusterGroupId(clusterId), GetSharedDescriptorGuard());
626 const auto &clusterDescriptor = descriptorGuard->GetClusterDescriptor(clusterId);
628 fPreloadedClusters[clusterDescriptor.GetFirstEntryIndex()] = clusterId;
630 std::atomic<bool> foundChecksumFailure{
false};
634 std::vector<std::pair<Internal::RPage, Internal::RPagePool::RKey>> allPages;
638 std::size_t nPages = 0;
640 for (
const auto columnId : columnsInCluster) {
641 if (fActivePhysicalColumns.HasColumnInfos(columnId)) {
642 nPages += fActivePhysicalColumns.GetColumnInfos(columnId).size() *
643 clusterDescriptor.GetPageRange(columnId).GetPageInfos().size();
646 allPages.resize(nPages);
647 std::size_t iPage = 0;
649 std::vector<std::unique_ptr<RColumnElementBase>> allElements;
650 for (
const auto columnId : columnsInCluster) {
654 if (!fActivePhysicalColumns.HasColumnInfos(columnId))
656 const auto &columnInfos = fActivePhysicalColumns.GetColumnInfos(columnId);
657 const auto indexOffset = clusterDescriptor.GetColumnRange(columnId).GetFirstElementIndex();
659 allElements.reserve(allElements.size() + columnInfos.size());
660 for (
const auto &info : columnInfos) {
662 const auto element = allElements.back().get();
664 const auto &pageRange = clusterDescriptor.GetPageRange(columnId);
665 std::uint64_t pageNo = 0;
666 std::uint64_t firstInPage = 0;
667 for (
const auto &pi : pageRange.GetPageInfos()) {
672 sealedPage.
SetBufferSize(pi.GetLocator().GetNBytesOnStorage() +
674 sealedPage.
SetBuffer(onDiskPage->GetAddress());
677 auto taskFunc = [
this, columnId, clusterId, firstInPage, sealedPage, element, iPage, indexOffset,
678 &foundChecksumFailure, &allPages]() {
679 auto rv = UnsealPage(sealedPage, *element);
681 foundChecksumFailure =
true;
684 auto newPage = rv.Unwrap();
685 fCounters->fSzUnzip.Add(element->GetSize() * sealedPage.
GetNElements());
687 newPage.SetWindow(indexOffset + firstInPage,
690 allPages[iPage] = std::make_pair(std::move(newPage), keyPagePool);
693 if (sealedPage.
GetNElements() * element->GetSize() < kInlineDecompressionThreshold) {
696 fTaskScheduler->AddTask(taskFunc);
699 firstInPage += pi.GetNElements();
706 fTaskScheduler->Wait();
707 fCounters->fNPageUnsealed.Add(nPages);
709 if (foundChecksumFailure) {
710 throw RException(
R__FAIL(
"page checksum verification failed, data corruption detected"));
713 fPagePool.PreloadPageV(allPages);
721 auto descriptorGuard = EnsureClusterDetails(FindClusterGroupId(clusterKey.
fClusterId), GetSharedDescriptorGuard());
722 const auto &clusterDesc = descriptorGuard->GetClusterDescriptor(clusterKey.
fClusterId);
725 if (clusterDesc.GetColumnRange(physicalColumnId).IsSuppressed())
728 const auto &pageRange = clusterDesc.GetPageRange(physicalColumnId);
730 for (
const auto &pageInfo : pageRange.GetPageInfos()) {
734 pageInfo.GetLocator().GetNBytesOnStorage()));
736 perPageFunc(physicalColumnId, pageNo, pageInfo);
745 if (fLastUsedCluster == clusterId)
750 auto descGuard = EnsureClusterDetails(FindClusterGroupId(clusterId), GetSharedDescriptorGuard());
753 auto itr = fPreloadedClusters.begin();
754 while ((itr != fPreloadedClusters.end()) && (itr->first < firstEntryIndex)) {
755 if (fPinnedClusters.count(itr->second) > 0) {
758 fPagePool.Evict(itr->second);
759 itr = fPreloadedClusters.erase(itr);
762 std::size_t poolWindow = 0;
763 while ((itr != fPreloadedClusters.end()) &&
768 while (itr != fPreloadedClusters.end()) {
769 if (fPinnedClusters.count(itr->second) > 0) {
772 fPagePool.Evict(itr->second);
773 itr = fPreloadedClusters.erase(itr);
777 fLastUsedCluster = clusterId;
787 auto descriptorGuard = EnsureClusterDetails(FindClusterGroupId(clusterId), GetSharedDescriptorGuard());
788 const auto &clusterDescriptor = descriptorGuard->GetClusterDescriptor(clusterId);
789 pageInfo = clusterDescriptor.GetPageRange(physicalColumnId).Find(localIndex.
GetIndexInCluster());
802 LoadSealedPageImpl(pageInfo.
GetLocator(), sealedPage);
809 const auto &pageInfo = pageSummary.
fPageInfo;
814 auto pageZero = fPageAllocator.NewPage(elem.
GetSize(), pageInfo.GetNElements());
815 pageZero.GrowUnchecked(pageInfo.GetNElements());
816 std::memset(pageZero.GetBuffer(), 0, pageZero.GetNBytes());
817 pageZero.SetWindow(pageSummary.
fColumnOffset + pageInfo.GetFirstElementIndex(),
828 return LoadZeroPage(pageSummary, elem);
832 const auto &clusterId = pageSummary.
fClusterId;
833 const auto &pageInfo = pageSummary.
fPageInfo;
837 UpdateLastUsedCluster(clusterId);
842 sealedPage.
SetBufferSize(pageInfo.GetLocator().GetNBytesOnStorage() +
844 std::unique_ptr<unsigned char[]> directReadBuffer;
847 directReadBuffer = MakeUninitArray<unsigned char>(sealedPage.
GetBufferSize());
848 sealedPage.
SetBuffer(directReadBuffer.get());
849 LoadSealedPageImpl(pageInfo.GetLocator(), sealedPage);
851 fCounters->fNPageRead.Inc();
852 fCounters->fNRead.Inc();
855 if (!fCurrentCluster || (fCurrentCluster->GetId() != clusterId) || !fCurrentCluster->ContainsColumn(columnId))
856 fCurrentCluster = fClusterPool.GetCluster(clusterId, fActivePhysicalColumns.ToColumnSet());
857 R__ASSERT(fCurrentCluster->ContainsColumn(columnId));
862 if (!cachedPageRef.Get().IsNull())
863 return cachedPageRef;
866 auto onDiskPage = fCurrentCluster->GetOnDiskPage(key);
868 sealedPage.
SetBuffer(onDiskPage->GetAddress());
873 RNTupleAtomicTimer timer(fCounters->fTimeWallUnzip, fCounters->fTimeCpuUnzip);
874 newPage = UnsealPage(sealedPage, elem).Unwrap();
875 fCounters->fSzUnzip.Add(elem.
GetSize() * pageInfo.GetNElements());
880 fCounters->fNPageUnsealed.Inc();
882 return fPagePool.RegisterPage(std::move(newPage),
RPagePool::RKey{columnId, elemInMemoryType});
890 auto cachedPageRef = fPagePool.GetPage(poolKey, globalIndex);
891 if (!cachedPageRef.Get().IsNull()) {
892 UpdateLastUsedCluster(cachedPageRef.Get().GetClusterInfo().GetId());
893 return cachedPageRef;
899 auto descriptorGuard = FindClusterId(physicalColumnId, globalIndex, pageSummary.
fClusterId);
902 throw RException(
R__FAIL(
"entry with index " + std::to_string(globalIndex) +
" out of bounds"));
904 const auto &clusterDescriptor = descriptorGuard->GetClusterDescriptor(pageSummary.
fClusterId);
905 const auto &columnRange = clusterDescriptor.GetColumnRange(physicalColumnId);
906 if (columnRange.IsSuppressed())
909 pageSummary.
fColumnOffset = columnRange.GetFirstElementIndex();
912 clusterDescriptor.GetPageRange(physicalColumnId).Find(globalIndex - pageSummary.
fColumnOffset);
915 return LoadPageFromSummary(pageSummary, elem);
925 auto cachedPageRef = fPagePool.GetPage(poolKey, localIndex);
926 if (!cachedPageRef.Get().IsNull()) {
927 UpdateLastUsedCluster(clusterId);
928 return cachedPageRef;
936 auto descriptorGuard = EnsureClusterDetails(FindClusterGroupId(clusterId), GetSharedDescriptorGuard());
937 const auto &clusterDescriptor = descriptorGuard->GetClusterDescriptor(clusterId);
938 const auto &columnRange = clusterDescriptor.GetColumnRange(physicalColumnId);
939 if (columnRange.IsSuppressed())
944 pageSummary.
fColumnOffset = columnRange.GetFirstElementIndex();
948 return LoadPageFromSummary(pageSummary, elem);
954 fMetrics.ObserveMetrics(fClusterPool.GetMetrics());
955 fMetrics.ObserveMetrics(fPagePool.GetMetrics());
956 fCounters = std::make_unique<RCounters>(
RCounters{
959 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"szReadPayload",
"B",
"volume read from storage (required)"),
960 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"szReadOverhead",
"B",
"volume read from storage (overhead)"),
963 "number of partial clusters preloaded from storage"),
964 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"nPageRead",
"",
"number of pages read from storage"),
965 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"nPageUnsealed",
"",
"number of pages unzipped and decoded"),
966 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"timeWallRead",
"ns",
"wall clock time spent reading"),
967 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"timeWallUnzip",
"ns",
"wall clock time spent decompressing"),
970 "CPU time spent decompressing"),
972 "bwRead",
"MB/s",
"bandwidth compressed bytes read per second", fMetrics,
974 if (
const auto szReadPayload = metrics.GetLocalCounter(
"szReadPayload")) {
975 if (
const auto szReadOverhead = metrics.GetLocalCounter(
"szReadOverhead")) {
976 if (
const auto timeWallRead = metrics.GetLocalCounter(
"timeWallRead")) {
977 if (
auto walltime = timeWallRead->GetValueAsInt()) {
978 double payload = szReadPayload->GetValueAsInt();
979 double overhead = szReadOverhead->GetValueAsInt();
981 return {
true, (1000. * (payload + overhead) / walltime)};
989 "bwReadUnzip",
"MB/s",
"bandwidth uncompressed bytes read per second", fMetrics,
992 if (
const auto timeWallRead = metrics.
GetLocalCounter(
"timeWallRead")) {
993 if (
auto walltime = timeWallRead->GetValueAsInt()) {
996 return {
true, 1000. * unzip / walltime};
1000 return {
false, -1.};
1003 "bwUnzip",
"MB/s",
"decompression bandwidth of uncompressed bytes per second", fMetrics,
1006 if (
const auto timeWallUnzip = metrics.
GetLocalCounter(
"timeWallUnzip")) {
1007 if (
auto walltime = timeWallUnzip->GetValueAsInt()) {
1010 return {
true, 1000. * unzip / walltime};
1014 return {
false, -1.};
1017 "rtReadEfficiency",
"",
"ratio of payload over all bytes read", fMetrics,
1019 if (
const auto szReadPayload = metrics.
GetLocalCounter(
"szReadPayload")) {
1020 if (
const auto szReadOverhead = metrics.
GetLocalCounter(
"szReadOverhead")) {
1021 if (
auto payload = szReadPayload->GetValueAsInt()) {
1023 return {
true, 1. / (1. + (1. * szReadOverhead->GetValueAsInt()) / payload)};
1027 return {
false, -1.};
1029 *fMetrics.MakeCounter<
RNTupleCalcPerf *>(
"rtCompression",
"",
"ratio of compressed bytes / uncompressed bytes",
1030 fMetrics, [](
const RNTupleMetrics &metrics) -> std::pair<bool, double> {
1031 if (
const auto szReadPayload =
1034 if (
auto unzip = szUnzip->GetValueAsInt()) {
1035 return {
true, (1. * szReadPayload->GetValueAsInt()) / unzip};
1039 return {
false, -1.};
1046 return UnsealPage(sealedPage, element, fPageAllocator);
1058 memset(page.GetBuffer(), 0, page.GetNBytes());
1075 memcpy(page.GetBuffer(), sealedPage.
GetBuffer(), bytesPacked);
1081 page = std::move(tmp);
1090 if (fHasStreamerInfosRegistered)
1093 for (
const auto &extraTypeInfo : fDescriptor.GetExtraTypeInfoIterable()) {
1101 fHasStreamerInfosRegistered =
true;
1116 if (fMaxAllocatedBytes - fCurrentAllocatedBytes >= targetAvailableSize)
1119 auto itr = fColumnsSortedByPageSize.begin();
1120 while (itr != fColumnsSortedByPageSize.end()) {
1121 if (itr->fCurrentPageSize <= pageSizeLimit)
1123 if (itr->fCurrentPageSize == itr->fInitialPageSize) {
1129 auto itrFlush = itr++;
1132 if (itr != fColumnsSortedByPageSize.end())
1136 if (fMaxAllocatedBytes - fCurrentAllocatedBytes >= targetAvailableSize)
1141 itr = fColumnsSortedByPageSize.find(next);
1150 auto itr = fColumnsSortedByPageSize.find(key);
1151 if (itr == fColumnsSortedByPageSize.end()) {
1152 if (!TryEvict(newWritePageSize, 0))
1154 fColumnsSortedByPageSize.insert({&column, newWritePageSize, newWritePageSize});
1155 fCurrentAllocatedBytes += newWritePageSize;
1160 assert(newWritePageSize >= elem.fInitialPageSize);
1162 if (newWritePageSize == elem.fCurrentPageSize)
1165 fColumnsSortedByPageSize.erase(itr);
1167 if (newWritePageSize < elem.fCurrentPageSize) {
1169 fCurrentAllocatedBytes -= elem.fCurrentPageSize - newWritePageSize;
1170 elem.fCurrentPageSize = newWritePageSize;
1171 fColumnsSortedByPageSize.insert(elem);
1176 const auto diffBytes = newWritePageSize - elem.fCurrentPageSize;
1177 if (!TryEvict(diffBytes, elem.fCurrentPageSize)) {
1180 fColumnsSortedByPageSize.insert(elem);
1183 fCurrentAllocatedBytes += diffBytes;
1184 elem.fCurrentPageSize = newWritePageSize;
1185 fColumnsSortedByPageSize.insert(elem);
1192 : fNTupleName(
name), fOptions(options.Clone()), fWritePageMemoryManager(options.GetPageBufferBudget()), fMetrics(
"")
1201 assert(config.
fPage);
1205 unsigned char *pageBuf =
reinterpret_cast<unsigned char *
>(config.
fPage->
GetBuffer());
1206 bool isAdoptedBuffer =
true;
1212 pageBuf =
new unsigned char[nBytesPacked];
1213 isAdoptedBuffer =
false;
1216 auto nBytesZipped = nBytesPacked;
1222 if (!isAdoptedBuffer)
1224 pageBuf =
reinterpret_cast<unsigned char *
>(config.
fBuffer);
1225 isAdoptedBuffer =
true;
1231 sealedPage.ChecksumIfEnabled();
1240 if (fSealPageBuffer.size() < nBytes)
1241 fSealPageBuffer.resize(nBytes);
1244 config.
fPage = &page;
1247 config.
fWriteChecksum = GetWriteOptions().GetEnablePageChecksums();
1249 config.
fBuffer = fSealPageBuffer.data();
1251 return SealPage(config);
1256 for (
const auto &cb : fOnDatasetCommitCallbacks)
1258 return CommitDatasetImpl();
1265 const auto nBytes = elementSize * nElements;
1266 if (!fWritePageMemoryManager.TryUpdate(column, nBytes))
1268 return fPageAllocator.NewPage(elementSize, nElements);
1273std::unique_ptr<ROOT::Internal::RPageSink>
1277 if (ntupleName.empty()) {
1280 if (location.empty()) {
1283 if (location.find(
"daos://") == 0) {
1284#ifdef R__ENABLE_DAOS
1285 return std::make_unique<ROOT::Experimental::Internal::RPageSinkDaos>(ntupleName, location, options);
1293 return std::make_unique<ROOT::Experimental::Internal::RPageSinkS3>(ntupleName, location, options);
1295 throw RException(
R__FAIL(
"This RNTuple build does not support S3. Rebuild ROOT with the 'curl' "
1296 "cmake option enabled (-Dcurl=ON) to enable the S3 backend."));
1301 return std::make_unique<ROOT::Internal::RPageSinkFile>(ntupleName, location, options);
1329 fDescriptorBuilder.AddColumn(columnBuilder.
MoveDescriptor().Unwrap());
1336 if (fIsInitialized) {
1344 const auto &
descriptor = fDescriptorBuilder.GetDescriptor();
1350 const auto &reps =
f.GetColumnRepresentatives();
1353 return reps.size() * reps[0].size();
1355 std::uint32_t nNewPhysicalColumns = 0;
1357 nNewPhysicalColumns += getNColumns(*
f);
1358 for (
const auto &descendant : *
f)
1359 nNewPhysicalColumns += getNColumns(descendant);
1361 fDescriptorBuilder.ShiftAliasColumns(nNewPhysicalColumns);
1366 fDescriptorBuilder.AddField(
f, fieldId);
1367 fDescriptorBuilder.AddFieldLink(
f.GetParent()->GetOnDiskId(), fieldId);
1368 f.SetOnDiskId(fieldId);
1373 auto sourceFieldId =
1375 fDescriptorBuilder.AddField(
f, fieldId);
1376 fDescriptorBuilder.AddFieldLink(
f.GetParent()->GetOnDiskId(), fieldId);
1377 fDescriptorBuilder.AddFieldProjection(sourceFieldId, fieldId);
1378 f.SetOnDiskId(fieldId);
1379 for (
const auto &source :
descriptor.GetColumnIterable(sourceFieldId)) {
1380 auto targetId =
descriptor.GetNLogicalColumns();
1386 .ValueRange(source.GetValueRange())
1387 .Type(source.GetType())
1388 .Index(source.GetIndex())
1389 .RepresentationIndex(source.GetRepresentationIndex());
1390 fDescriptorBuilder.AddColumn(columnBuilder.
MoveDescriptor().Unwrap());
1394 R__ASSERT(firstEntry >= fPrevClusterNEntries);
1395 const auto nColumnsBeforeUpdate =
descriptor.GetNPhysicalColumns();
1398 for (
auto &descendant : *
f)
1399 addField(descendant);
1402 addProjectedField(*
f);
1403 for (
auto &descendant : *
f)
1404 addProjectedField(descendant);
1407 const auto nColumns =
descriptor.GetNPhysicalColumns();
1408 fOpenColumnRanges.reserve(fOpenColumnRanges.size() + (nColumns - nColumnsBeforeUpdate));
1409 fOpenPageRanges.reserve(fOpenPageRanges.size() + (nColumns - nColumnsBeforeUpdate));
1419 fOpenColumnRanges.emplace_back(columnRange);
1422 fOpenPageRanges.emplace_back(std::move(pageRange));
1427 if (fSerializationContext.GetHeaderSize() > 0)
1428 fSerializationContext.MapSchema(
descriptor,
true);
1434 throw RException(
R__FAIL(
"ROOT bug: unexpected type extra info in UpdateExtraTypeInfo()"));
1441 fDescriptorBuilder.SetNTuple(GetNTupleName(), model.GetDescription());
1442 fDescriptorBuilder.SetVersionForWriting();
1443 const auto &
descriptor = fDescriptorBuilder.GetDescriptor();
1446 fDescriptorBuilder.AddField(fieldZero, 0);
1447 fieldZero.SetOnDiskId(0);
1449 projectedFields.GetFieldZero().SetOnDiskId(0);
1452 initialChangeset.fAddedFields.reserve(fieldZero.GetMutableSubfields().size());
1453 for (
auto f : fieldZero.GetMutableSubfields())
1454 initialChangeset.fAddedFields.emplace_back(
f);
1455 initialChangeset.fAddedProjectedFields.reserve(projectedFields.GetFieldZero().GetMutableSubfields().size());
1456 for (
auto f : projectedFields.GetFieldZero().GetMutableSubfields())
1457 initialChangeset.fAddedProjectedFields.emplace_back(
f);
1458 UpdateSchema(initialChangeset, 0U);
1461 auto buffer = MakeUninitArray<unsigned char>(fSerializationContext.GetHeaderSize());
1463 CommitHeaderImpl(buffer.get(), fSerializationContext.GetHeaderSize());
1465 fDescriptorBuilder.BeginHeaderExtension();
1468std::unique_ptr<ROOT::RNTupleModel>
1472 fDescriptorBuilder.SetSchemaFromExisting(srcDescriptor);
1474 fDescriptorBuilder.SetVersionForWriting();
1475 const auto &
descriptor = fDescriptorBuilder.GetDescriptor();
1478 const auto nColumns =
descriptor.GetNPhysicalColumns();
1479 R__ASSERT(fOpenColumnRanges.empty() && fOpenPageRanges.empty());
1480 fOpenColumnRanges.reserve(nColumns);
1481 fOpenPageRanges.reserve(nColumns);
1483 const auto &column =
descriptor.GetColumnDescriptor(i);
1489 fOpenColumnRanges.emplace_back(columnRange);
1492 fOpenPageRanges.emplace_back(std::move(pageRange));
1499 auto nEntries = cluster.GetNEntries();
1500 for (
unsigned int i = 0; i < fOpenColumnRanges.size(); ++i) {
1501 R__ASSERT(fOpenColumnRanges[i].GetPhysicalColumnId() == i);
1502 if (!cluster.ContainsColumn(i))
1504 const auto &columnRange = cluster.GetColumnRange(i);
1505 R__ASSERT(columnRange.GetPhysicalColumnId() == i);
1507 fOpenColumnRanges[i].IncrementFirstElementIndex(columnRange.GetNElements());
1509 fDescriptorBuilder.AddCluster(cluster.Clone());
1510 fPrevClusterNEntries += nEntries;
1516 modelOpts.SetReconstructProjections(
true);
1518 modelOpts.SetEmulateUnknownTypes(
true);
1519 auto model =
descriptor.CreateModel(modelOpts);
1520 if (!copyClusters) {
1522 projectedFields.GetFieldZero().SetOnDiskId(model->GetConstFieldZero().GetOnDiskId());
1527 auto buffer = MakeUninitArray<unsigned char>(fSerializationContext.GetHeaderSize());
1529 CommitHeaderImpl(buffer.get(), fSerializationContext.GetHeaderSize());
1531 fDescriptorBuilder.BeginHeaderExtension();
1534 fIsInitialized =
true;
1541 std::span<const RColumnFormat> newRepresentation,
1542 std::uint64_t clusterOffset)
1544 const auto &
descriptor = fDescriptorBuilder.GetDescriptor();
1552 const std::size_t firstPhysicalIndex = fDescriptorBuilder.GetDescriptor().GetNPhysicalColumns();
1555 fDescriptorBuilder.ShiftAliasColumns(newRepresentation.size());
1557 std::uint16_t columnIndex = 0;
1558 for (
auto columnRepr : newRepresentation) {
1559 std::size_t bitsOnStorage = columnRepr.fBitWidth;
1560 if (!bitsOnStorage) {
1562 if (rangeMin != rangeMax) {
1565 bitsOnStorage = rangeMin;
1569 const auto &firstReprColumnRange = fOpenColumnRanges.at(firstReprColumnId);
1572 const std::uint64_t newReprFirstElemIndex = firstReprColumnRange.GetFirstElementIndex() + clusterOffset;
1579 .
Type(columnRepr.fType)
1584 if (newReprFirstElemIndex)
1586 fDescriptorBuilder.AddColumn(columnBuilder.
MoveDescriptor().Unwrap());
1588 if (newReprFirstElemIndex != 0) {
1605 fOpenColumnRanges.emplace_back(columnRange);
1609 fOpenPageRanges.emplace_back(std::move(pageRange));
1611 fSerializationContext.MapPhysicalColumnId(columnId);
1616 fDescriptorBuilder.EnsureValidDescriptor().ThrowOnError();
1618 return firstPhysicalIndex;
1626 assert(!pointedColumn.IsAliasColumn());
1629 const auto columnId = fDescriptorBuilder.GetDescriptor().GetNLogicalColumns();
1634 .
Type(pointedColumn.GetType())
1635 .
Index(pointedColumn.GetIndex())
1640 fDescriptorBuilder.AddColumn(columnBuilder.
MoveDescriptor().Unwrap());
1642 fDescriptorBuilder.EnsureValidDescriptor().ThrowOnError();
1647 fOpenColumnRanges.at(physicalColumnId).SetIsSuppressed(
true);
1653 fOpenColumnRanges.at(physicalColumnId).IncrementNElements(page.
GetNElements());
1657 RNTupleAtomicTimer timer(fCounters->fTimeWallZip, fCounters->fTimeCpuZip);
1658 sealedPage = SealPage(page, elem);
1660 fCounters->fSzZip.Add(page.
GetNBytes());
1664 pageInfo.
SetLocator(CommitSealedPageImpl(physicalColumnId, sealedPage));
1665 pageInfo.
SetHasChecksum(GetWriteOptions().GetEnablePageChecksums());
1666 fOpenPageRanges.at(physicalColumnId).GetPageInfos().emplace_back(pageInfo);
1672 fOpenColumnRanges.at(physicalColumnId).IncrementNElements(sealedPage.
GetNElements());
1676 pageInfo.
SetLocator(CommitSealedPageImpl(physicalColumnId, sealedPage));
1678 fOpenPageRanges.at(physicalColumnId).GetPageInfos().emplace_back(pageInfo);
1681std::vector<ROOT::RNTupleLocator>
1683 const std::vector<bool> &
mask)
1685 std::vector<ROOT::RNTupleLocator> locators;
1686 locators.reserve(
mask.size());
1688 for (
auto &range : ranges) {
1689 for (
auto sealedPageIt = range.fFirst; sealedPageIt != range.fLast; ++sealedPageIt) {
1691 locators.push_back(CommitSealedPageImpl(range.fPhysicalColumnId, *sealedPageIt));
1694 locators.shrink_to_fit();
1701 struct RSealedPageLink {
1703 std::size_t fLocatorIdx = 0;
1706 std::vector<bool>
mask;
1708 std::vector<std::size_t> locatorIndexes;
1710 std::unordered_map<std::uint64_t, RSealedPageLink> originalPages;
1711 std::size_t iLocator = 0;
1712 for (
auto &range : ranges) {
1713 const auto rangeSize = std::distance(range.fFirst, range.fLast);
1714 mask.reserve(
mask.size() + rangeSize);
1715 locatorIndexes.reserve(locatorIndexes.size() + rangeSize);
1717 for (
auto sealedPageIt = range.fFirst; sealedPageIt != range.fLast; ++sealedPageIt) {
1718 if (!fFeatures.fCanMergePages || !GetWriteOptions().GetEnableSamePageMerging()) {
1719 mask.emplace_back(
true);
1720 locatorIndexes.emplace_back(iLocator++);
1724 R__ASSERT(sealedPageIt->GetHasChecksum());
1726 const auto chk = sealedPageIt->GetChecksum().Unwrap();
1727 auto itr = originalPages.find(chk);
1728 if (itr == originalPages.end()) {
1729 originalPages.insert({chk, {&(*sealedPageIt), iLocator}});
1730 mask.emplace_back(
true);
1731 locatorIndexes.emplace_back(iLocator++);
1735 const auto *
p = itr->second.fSealedPage;
1736 if ((sealedPageIt->GetDataSize() !=
p->GetDataSize()) ||
1737 (memcmp(sealedPageIt->GetBuffer(),
p->GetBuffer(),
p->GetDataSize()) != 0)) {
1738 mask.emplace_back(
true);
1739 locatorIndexes.emplace_back(iLocator++);
1743 mask.emplace_back(
false);
1744 locatorIndexes.emplace_back(itr->second.fLocatorIdx);
1747 mask.shrink_to_fit();
1748 locatorIndexes.shrink_to_fit();
1751 auto locators = CommitSealedPageVImpl(ranges,
mask);
1754 for (
auto &range : ranges) {
1755 for (
auto sealedPageIt = range.fFirst; sealedPageIt != range.fLast; ++sealedPageIt) {
1756 fOpenColumnRanges.at(range.fPhysicalColumnId).IncrementNElements(sealedPageIt->GetNElements());
1760 pageInfo.
SetLocator(locators[locatorIndexes[i++]]);
1762 fOpenPageRanges.at(range.fPhysicalColumnId).GetPageInfos().emplace_back(pageInfo);
1774 for (
unsigned int i = 0; i < fOpenColumnRanges.size(); ++i) {
1775 RStagedCluster::RColumnInfo columnInfo;
1776 columnInfo.fCompressionSettings = fOpenColumnRanges[i].GetCompressionSettings().value();
1777 if (fOpenColumnRanges[i].IsSuppressed()) {
1778 assert(fOpenPageRanges[i].GetPageInfos().empty());
1779 columnInfo.fPageRange.SetPhysicalColumnId(i);
1780 columnInfo.fIsSuppressed =
true;
1782 fOpenColumnRanges[i].SetNElements(0);
1783 fOpenColumnRanges[i].SetIsSuppressed(
false);
1785 std::swap(columnInfo.fPageRange, fOpenPageRanges[i]);
1786 fOpenPageRanges[i].SetPhysicalColumnId(i);
1788 columnInfo.fNElements = fOpenColumnRanges[i].GetNElements();
1789 fOpenColumnRanges[i].SetNElements(0);
1791 stagedCluster.
fColumnInfos.push_back(std::move(columnInfo));
1794 return stagedCluster;
1799 for (
const auto &cluster : clusters) {
1801 clusterBuilder.
ClusterId(fPrevGroupNClusters + fDescriptorBuilder.GetDescriptor().GetNActiveClusters())
1802 .FirstEntryIndex(fPrevClusterNEntries)
1804 for (
const auto &columnInfo : cluster.fColumnInfos) {
1805 const auto colId = columnInfo.fPageRange.GetPhysicalColumnId();
1806 fNPagesInGroup += columnInfo.fPageRange.GetPageInfos().size();
1807 if (columnInfo.fIsSuppressed) {
1808 assert(columnInfo.fPageRange.GetPageInfos().empty());
1811 clusterBuilder.
CommitColumnRange(colId, fOpenColumnRanges[colId].GetFirstElementIndex(),
1812 columnInfo.fCompressionSettings, columnInfo.fPageRange);
1813 fOpenColumnRanges[colId].IncrementFirstElementIndex(columnInfo.fNElements);
1818 for (
const auto &columnInfo : cluster.fColumnInfos) {
1819 if (!columnInfo.fIsSuppressed)
1821 const auto colId = columnInfo.fPageRange.GetPhysicalColumnId();
1825 const auto &columnRangeFromDesc = clusterBuilder.
GetColumnRange(colId);
1827 columnRangeFromDesc.GetNElements());
1830 fDescriptorBuilder.AddCluster(clusterBuilder.
MoveDescriptor().Unwrap());
1831 fPrevClusterNEntries += cluster.fNEntries;
1832 const auto &writeOpts = GetWriteOptions();
1833 if (fNPagesInGroup > writeOpts.GetClusterGroupPageThreshold() && writeOpts.GetClusterGroupPageThreshold() > 0) {
1834 CommitClusterGroup();
1841 const auto &
descriptor = fDescriptorBuilder.GetDescriptor();
1843 const auto nClusters =
descriptor.GetNActiveClusters();
1844 if (nClusters == 0) {
1845 assert(fNPagesInGroup == 0);
1849 std::vector<ROOT::DescriptorId_t> physClusterIDs;
1850 physClusterIDs.reserve(nClusters);
1852 physClusterIDs.emplace_back(fSerializationContext.MapClusterId(fPrevGroupNClusters + i));
1857 auto bufPageList = MakeUninitArray<unsigned char>(szPageList);
1860 const auto clusterGroupId =
descriptor.GetNClusterGroups();
1861 const auto locator = CommitClusterGroupImpl(bufPageList.get(), szPageList);
1864 const auto &firstClusterDesc =
descriptor.GetClusterDescriptor(fPrevGroupNClusters);
1865 const auto &lastClusterDesc =
descriptor.GetClusterDescriptor(fPrevGroupNClusters + nClusters - 1);
1866 cgBuilder.
MinEntry(firstClusterDesc.GetFirstEntryIndex())
1867 .
EntrySpan(lastClusterDesc.GetFirstEntryIndex() + lastClusterDesc.GetNEntries() -
1868 firstClusterDesc.GetFirstEntryIndex())
1870 std::vector<ROOT::DescriptorId_t> clusterIds;
1871 clusterIds.reserve(nClusters);
1873 clusterIds.emplace_back(fPrevGroupNClusters + i);
1876 fDescriptorBuilder.AddClusterGroup(cgBuilder.
MoveDescriptor().Unwrap());
1877 fSerializationContext.MapClusterGroupId(clusterGroupId);
1878 fDescriptorBuilder.GetDescriptor().DropClusterGroupDetails(clusterGroupId);
1880 fPrevGroupNClusters += nClusters;
1890 auto attrSetDesc = attrSetDescBuilder.
SchemaVersion(kSchemaVersionMajor, kSchemaVersionMinor)
1896 fDescriptorBuilder.AddAttributeSet(std::move(attrSetDesc)).ThrowOnError();
1901 if (!fInfosOfStreamerFields.empty()) {
1904 for (
const auto &etDesc : fDescriptorBuilder.GetDescriptor().GetExtraTypeInfoIterable()) {
1908 R__ASSERT(etDesc.GetTypeName().empty());
1909 R__ASSERT(etDesc.GetTypeVersion() == 0);
1911 fInfosOfStreamerFields.merge(etInfo);
1918 fDescriptorBuilder.ReplaceExtraTypeInfo(extraInfoBuilder.
MoveDescriptor().Unwrap());
1921 const auto &
descriptor = fDescriptorBuilder.GetDescriptor();
1924 auto bufFooter = MakeUninitArray<unsigned char>(szFooter);
1927 return CommitDatasetImpl(bufFooter.get(), szFooter);
1933 fCounters = std::make_unique<RCounters>(
RCounters{
1934 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"nPageCommitted",
"",
"number of pages committed to storage"),
1935 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"szWritePayload",
"B",
"volume written for committed pages"),
1937 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"timeWallWrite",
"ns",
"wall clock time spent writing"),
1938 *fMetrics.MakeCounter<
RNTupleAtomicCounter *>(
"timeWallZip",
"ns",
"wall clock time spent compressing"),
1941 "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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
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.
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.
Record wall time and CPU time between construction and destruction.
A helper class for piece-wise construction of an RClusterDescriptor.
RResult< void > MarkSuppressedColumnRange(ROOT::DescriptorId_t physicalId)
Books the given column ID as being suppressed in this cluster.
RResult< void > CommitColumnRange(ROOT::DescriptorId_t physicalId, std::uint64_t firstElementIndex, std::uint32_t compressionSettings, const RClusterDescriptor::RPageRange &pageRange)
RClusterDescriptorBuilder & NEntries(std::uint64_t nEntries)
RResult< void > CommitSuppressedColumnRanges(const RNTupleDescriptor &desc)
Sets the first element index and number of elements for all the suppressed column ranges.
RResult< RClusterDescriptor > MoveDescriptor()
Move out the full cluster descriptor including page locations.
const RClusterDescriptor::RColumnRange & GetColumnRange(ROOT::DescriptorId_t physicalId)
RClusterDescriptorBuilder & ClusterId(ROOT::DescriptorId_t clusterId)
A helper class for piece-wise construction of an RClusterGroupDescriptor.
RClusterGroupDescriptorBuilder & EntrySpan(std::uint64_t entrySpan)
RClusterGroupDescriptorBuilder & PageListLocator(const RNTupleLocator &pageListLocator)
RClusterGroupDescriptorBuilder & PageListLength(std::uint64_t pageListLength)
RClusterGroupDescriptorBuilder & MinEntry(std::uint64_t minEntry)
void AddSortedClusters(const std::vector< ROOT::DescriptorId_t > &clusterIds)
RResult< RClusterGroupDescriptor > MoveDescriptor()
RClusterGroupDescriptorBuilder & ClusterGroupId(ROOT::DescriptorId_t clusterGroupId)
RClusterGroupDescriptorBuilder & NClusters(std::uint32_t nClusters)
An in-memory subset of the packed and compressed pages of a cluster.
std::unordered_set< ROOT::DescriptorId_t > ColumnSet_t
const ColumnSet_t & GetAvailPhysicalColumns() const
const ROnDiskPage * GetOnDiskPage(const ROnDiskPage::Key &key) const
ROOT::DescriptorId_t GetId() const
A helper class for piece-wise construction of an RColumnDescriptor.
RColumnDescriptorBuilder & SetSuppressedDeferred()
RColumnDescriptorBuilder & LogicalColumnId(ROOT::DescriptorId_t logicalColumnId)
RColumnDescriptorBuilder & FieldId(ROOT::DescriptorId_t fieldId)
RColumnDescriptorBuilder & BitsOnStorage(std::uint16_t bitsOnStorage)
RColumnDescriptorBuilder & ValueRange(double min, double max)
RColumnDescriptorBuilder & Type(ROOT::ENTupleColumnType type)
RColumnDescriptorBuilder & PhysicalColumnId(ROOT::DescriptorId_t physicalColumnId)
RColumnDescriptorBuilder & FirstElementIndex(std::uint64_t firstElementIdx)
RColumnDescriptorBuilder & Index(std::uint32_t index)
RColumnDescriptorBuilder & RepresentationIndex(std::uint16_t representationIndex)
RResult< RColumnDescriptor > MoveDescriptor()
Attempt to make a column descriptor.
A column element encapsulates the translation between basic C++ types and their column representation...
virtual bool IsMappable() const
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
static std::pair< std::uint16_t, std::uint16_t > GetValidBitRange(ROOT::ENTupleColumnType type)
Most types have a fixed on-disk bit width.
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-...
std::size_t GetSize() const
virtual RIdentifier GetIdentifier() const =0
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-...
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 ...
std::optional< std::pair< double, double > > GetValueRange() const
std::uint16_t GetRepresentationIndex() const
ROOT::Internal::RColumnElementBase * GetElement() const
ROOT::ENTupleColumnType GetType() const
ROOT::DescriptorId_t GetOnDiskId() const
RWriteColumn * ForWriting()
std::uint16_t GetBitsOnStorage() const
std::uint32_t GetIndex() const
RNTupleAttrSetDescriptorBuilder & Name(std::string_view name)
RNTupleAttrSetDescriptorBuilder & SchemaVersion(std::uint16_t major, std::uint16_t minor)
RResult< ROOT::RNTupleAttrSetDescriptor > MoveDescriptor()
Attempt to make an AttributeSet descriptor.
RNTupleAttrSetDescriptorBuilder & AnchorLocator(const RNTupleLocator &loc)
RNTupleAttrSetDescriptorBuilder & AnchorLength(std::uint32_t length)
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.
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 unsigned int GetClusterBunchSize(const RNTupleReadOptions &options)
static unsigned int GetClusterGroupBudget(const RNTupleReadOptions &options)
static RResult< void > DeserializePageList(const void *buffer, std::uint64_t bufSize, ROOT::DescriptorId_t clusterGroupId, RNTupleDescriptor &desc, EDescriptorDeserializeMode mode)
static RResult< StreamerInfoMap_t > DeserializeStreamerInfos(const std::string &extraTypeInfoContent)
EDescriptorDeserializeMode
static RResult< std::uint32_t > SerializePageList(void *buffer, const RNTupleDescriptor &desc, std::span< ROOT::DescriptorId_t > physClusterIDs, const RContext &context)
static RResult< std::uint32_t > SerializeFooter(void *buffer, const RNTupleDescriptor &desc, const RContext &context)
static RResult< RContext > SerializeHeader(void *buffer, const RNTupleDescriptor &desc)
static std::string SerializeStreamerInfos(const StreamerInfoMap_t &infos)
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.
Abstract interface to allocate and release pages.
virtual RPage NewPage(std::size_t elementSize, std::size_t nElements)=0
Reserves memory large enough to hold nElements of the given size.
RStagedCluster StageCluster(ROOT::NTupleSize_t nNewEntries) final
Stage the current cluster and create a new one for the following data.
void UpdateSchema(const ROOT::Internal::RNTupleModelChangeset &changeset, ROOT::NTupleSize_t firstEntry) override
Incorporate incremental changes to the model into the ntuple descriptor.
std::unique_ptr< RNTupleModel > InitFromDescriptor(const ROOT::RNTupleDescriptor &descriptor, bool copyClusters)
Initialize sink based on an existing descriptor and fill into the descriptor builder,...
void UpdateExtraTypeInfo(const ROOT::RExtraTypeInfoDescriptor &extraTypeInfo) final
Adds an extra type information record to schema.
void CommitAttributeSet(std::string_view attrSetName, const RNTupleLink &attrAnchorInfo) final
Adds the given anchor information (name + locator) into the main RNTuple's descriptor as an attribute...
RPagePersistentSink(std::string_view ntupleName, const ROOT::RNTupleWriteOptions &options)
void CommitSealedPageV(std::span< RSealedPageGroup > ranges) final
Write a vector of preprocessed pages to storage. The corresponding columns must have been added befor...
void AddAliasColumn(const ROOT::RNTupleDescriptor &desc, const ROOT::RFieldDescriptor &field, ROOT::DescriptorId_t physicalId)
Adds a new alias column pointing to an existing column with the given physical id to the given field.
void CommitStagedClusters(std::span< RStagedCluster > clusters) final
Commit staged clusters, logically appending them to the ntuple descriptor.
static std::unique_ptr< RPageSink > Create(std::string_view ntupleName, std::string_view location, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Guess the concrete derived page source from the location.
void InitImpl(RNTupleModel &model) final
Updates the descriptor and calls InitImpl() that handles the backend-specific details (file,...
DescriptorId_t AddColumn(ROOT::DescriptorId_t fieldId, const ROOT::Internal::RColumn &column) final
Add a column belonging to a certain field to the descriptor and return its on-disk ID.
RNTupleLink CommitDatasetImpl() final
virtual std::vector< RNTupleLocator > CommitSealedPageVImpl(std::span< RSealedPageGroup > ranges, const std::vector< bool > &mask)
Vector commit of preprocessed pages.
void CommitSuppressedColumn(DescriptorId_t physicalColumnId) final
Commits a suppressed column for the current cluster.
~RPagePersistentSink() override
void CommitClusterGroup() final
Write out the page locations (page list envelope) for all the committed clusters since the last call ...
void CommitPage(DescriptorId_t physicalColumnId, const RColumnElementBase &elem, const ROOT::Internal::RPage &page) final
Write a page to the storage. The column must have been added before.
void EnableDefaultMetrics(const std::string &prefix)
Enables the default set of metrics provided by RPageSink.
ROOT::DescriptorId_t AddColumnRepresentation(const ROOT::RFieldDescriptor &field, std::span< const ROOT::Internal::RColumnFormat > newRepresentation, std::uint64_t clusterOffset)
Adds a new column representation to the given field.
void CommitSealedPage(ROOT::DescriptorId_t physicalColumnId, const RSealedPage &sealedPage) final
Write a preprocessed page to storage. The column must have been added before.
Abstract interface to write data into an ntuple.
RNTupleLink CommitDataset()
Run the registered callbacks and finalize the current cluster and the entrire data set.
RSealedPage SealPage(const ROOT::Internal::RPage &page, const ROOT::Internal::RColumnElementBase &element)
Helper for streaming a page.
virtual ROOT::Internal::RPage ReservePage(RWriteColumn &column, std::size_t nElements)
Get a new, empty page for the given column that can be filled with up to nElements; nElements must be...
RPageSink(std::string_view ntupleName, const ROOT::RNTupleWriteOptions &options)
virtual const ROOT::RNTupleDescriptor & GetDescriptor() const =0
Return the RNTupleDescriptor being constructed.
std::unordered_map< ROOT::DescriptorId_t, std::vector< RColumnInfo > > fColumnInfos
Maps physical column IDs to all the requested in-memory representations.
void Insert(ROOT::DescriptorId_t physicalColumnId, ROOT::Internal::RColumnElementBase::RIdentifier elementId)
ROOT::Internal::RCluster::ColumnSet_t ToColumnSet() const
void Erase(ROOT::DescriptorId_t physicalColumnId, ROOT::Internal::RColumnElementBase::RIdentifier elementId)
Either a shared or an exclusive lock guard.
An RAII wrapper used for the writable access to RPageSource::fDescriptor. See GetSharedDescriptorGuar...
RAnyDescriptorGuard FindNextClusterId(ROOT::DescriptorId_t clusterId, ROOT::DescriptorId_t &nextId)
Uses FindClusterId to search for the cluster with the entry index following the last entry index of t...
ROOT::Internal::RClusterPool fClusterPool
The cluster pool asynchronously preloads the next few clusters.
void LoadStructure()
Loads header and footer without decompressing or deserializing them.
ROOT::Internal::RPageRef LoadPageFromSummary(const RPageSummary &pageSummary, const RColumnElementBase &elem)
ROOT::Experimental::Detail::RNTupleMetrics fMetrics
void LoadAllPageLists()
Load all remaining cluster details.
ROOT::Internal::RPageRef LoadZeroPage(const RPageSummary &pageSummary, const RColumnElementBase &elem)
ROOT::RNTupleReadOptions fOptions
void RegisterStreamerInfos()
Builds the streamer info records from the descriptor's extra type info section.
ROOT::NTupleSize_t GetNElements(ROOT::DescriptorId_t physicalColumnId)
RAnyDescriptorGuard EnsureClusterDetails(DescriptorId_t cgId, RAnyDescriptorGuard descGuard)
Ensures that fDescriptor has cluster details loaded for the given cluster group ID.
void Attach(ROOT::Internal::RNTupleSerializer::EDescriptorDeserializeMode mode=ROOT::Internal::RNTupleSerializer::EDescriptorDeserializeMode::kForReading)
Open the physical storage container and deserialize header and footer.
void UnzipCluster(ROOT::Internal::RCluster *cluster)
Parallel decompression and unpacking of the pages in the given cluster.
void EnableDefaultMetrics(const std::string &prefix)
Enables the default set of metrics provided by RPageSource.
ROOT::NTupleSize_t GetNEntries()
virtual ROOT::Internal::RPageRef LoadPage(DescriptorId_t physicalColumnId, const RColumnElementBase &elem, ROOT::NTupleSize_t globalIndex)
Allocates and fills a page that contains the index-th element.
DescriptorId_t AddColumn(ROOT::DescriptorId_t fieldId, const ROOT::Internal::RColumn &column)
void UpdateLastUsedCluster(ROOT::DescriptorId_t clusterId)
Does nothing if fLastUsedCluster == clusterId.
std::string fNTupleName
Initially empty if the page source is created from an anchor.
void UnpinCluster(ROOT::DescriptorId_t clusterId)
Allows the given cluster to be evicted from the cluster pool and page pool.
void PinCluster(ROOT::DescriptorId_t clusterId)
Instructs the cluster pool and page pool to consider the given cluster as active (should stay cached)...
ROOT::Internal::RPagePool fPagePool
Pages that are unzipped with IMT are staged into the page pool.
RAnyDescriptorGuard FindClusterId(ROOT::DescriptorId_t physicalColumnId, ROOT::NTupleSize_t index, ROOT::DescriptorId_t &cid)
Returns a shared descriptor guard to ensure that the returned cluster id is useable,...
void LoadSealedPage(ROOT::DescriptorId_t physicalColumnId, RNTupleLocalIndex localIndex, RSealedPage &sealedPage)
Read the packed and compressed bytes of a page into the memory buffer provided by sealedPage.
void LoadPageList(DescriptorId_t clusterGroupId, const RExclDescriptorGuard &exclGuard)
RPageSource(std::string_view ntupleName, const ROOT::RNTupleReadOptions &fOptions)
DescriptorId_t FindClusterGroupId(DescriptorId_t clusterId) const
Uses binary search in fCumulativeClusterCounts to determine the cluster group that the cluster ID bel...
void PrepareLoadCluster(const ROOT::Internal::RCluster::RKey &clusterKey, ROOT::Internal::ROnDiskPageMap &pageZeroMap, const std::function< void(ROOT::DescriptorId_t, ROOT::NTupleSize_t, const ROOT::RClusterDescriptor::RPageInfo &)> &perPageFunc)
Prepare a page range read for the column set in clusterKey.
void SetEntryRange(const REntryRange &range)
Promise to only read from the given entry range.
std::unique_ptr< RPageSource > Clone() const
Open the same storage multiple time, e.g.
void DropColumn(const ROOT::Internal::RColumn &column)
static std::unique_ptr< RPageSource > Create(std::string_view ntupleName, std::string_view location, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions())
Guess the concrete derived page source from the file name (location)
static RResult< ROOT::Internal::RPage > UnsealPage(const RSealedPage &sealedPage, const ROOT::Internal::RColumnElementBase &element, ROOT::Internal::RPageAllocator &pageAlloc)
Helper for unstreaming a page.
Stores information about the cluster in which this page resides.
A page is a slice of a column that is mapped into memory.
std::uint32_t GetNElements() const
std::size_t GetNBytes() const
The space taken by column elements in the buffer.
void * GrowUnchecked(std::uint32_t nElements)
Increases the number elements in the page.
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...
void SetWindow(const ROOT::NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo)
Seek the page to a certain position of the column.
const ROOT::RFieldBase * GetSourceField(const ROOT::RFieldBase *target) const
std::size_t GetWritePageCapacity() const
ROOT::NTupleSize_t GetFirstElementIndex() const
bool TryEvict(std::size_t targetAvailableSize, std::size_t pageSizeLimit)
Flush columns in order of allocated write page size until the sum of all write page allocations leave...
bool TryUpdate(ROOT::Internal::RWriteColumn &column, std::size_t newWritePageSize)
Try to register the new write page size for the given column.
The window of element indexes of a particular column in a particular cluster.
void SetCompressionSettings(std::optional< std::uint32_t > comp)
void SetPhysicalColumnId(ROOT::DescriptorId_t id)
void SetFirstElementIndex(ROOT::NTupleSize_t idx)
void SetNElements(ROOT::NTupleSize_t n)
Metadata for RNTuple clusters.
ROOT::NTupleSize_t GetNEntries() const
const RColumnRange & GetColumnRange(ROOT::DescriptorId_t physicalId) const
ROOT::NTupleSize_t GetFirstEntryIndex() const
bool HasClusterDetails() const
A cluster group is loaded in two stages.
const std::vector< ROOT::DescriptorId_t > & GetClusterIds() const
Base class for all ROOT issued exceptions.
A field translates read and write calls from/to underlying columns to/from tree values.
ROOT::DescriptorId_t GetOnDiskId() const
Metadata stored for every field of an RNTuple.
ROOT::DescriptorId_t GetId() const
const std::vector< ROOT::DescriptorId_t > & GetLogicalColumnIds() const
ROOT::ENTupleStructure GetStructure() const
std::uint32_t GetColumnCardinality() const
ROOT::DescriptorId_t GetParentId() const
bool IsProjectedField() const
The on-storage metadata of an RNTuple.
const RClusterGroupDescriptor & GetClusterGroupDescriptor(ROOT::DescriptorId_t clusterGroupId) const
const RColumnDescriptor & GetColumnDescriptor(ROOT::DescriptorId_t columnId) const
const RFieldDescriptor & GetFieldDescriptor(ROOT::DescriptorId_t fieldId) const
RClusterDescriptorIterable GetActiveClusterIterable() const
RClusterGroupDescriptorIterable GetClusterGroupIterable() const
std::size_t GetNActiveClusters() const
ROOT::NTupleSize_t R__DEPRECATED(6, 46, "This function is ill-conceived in the descriptor " "as not all cluster descriptors may be present. This interface is no longer publicly exposed.") GetNElements(ROOT ROOT::DescriptorId_t GetFieldZeroId() const
Returns the logical parent of all top-level RNTuple data fields.
std::size_t GetNClusters() const
std::size_t GetNPhysicalColumns() const
@ kFeatureFlag_NestedDeferredColumns
Signals that the RNTuple contains at least one deferred column that is part of a collection and was e...
const RClusterDescriptor & GetClusterDescriptor(ROOT::DescriptorId_t clusterId) const
std::size_t GetNClusterGroups() const
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
ROOT::NTupleSize_t GetIndexInCluster() const
ROOT::DescriptorId_t GetClusterId() const
std::uint64_t GetNBytesOnStorage() const
ELocatorType GetType() const
For non-disk locators, the value for the Type field.
The RNTupleModel encapulates the schema of an RNTuple.
Common user-tunable settings for reading RNTuples.
Common user-tunable settings for storing RNTuples.
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...
ROOT::RFieldZero & GetFieldZeroOfModel(RNTupleModel &model)
RResult< void > EnsureValidNameForRNTuple(std::string_view name, std::string_view where)
Check whether a given string is a valid name according to the RNTuple specification.
RProjectedFields & GetProjectedFieldsOfModel(RNTupleModel &model)
std::unique_ptr< RColumnElementBase > GenerateColumnElement(std::type_index inMemoryType, ROOT::ENTupleColumnType onDiskType)
void CallConnectPageSinkOnField(RFieldBase &, ROOT::Internal::RPageSink &, ROOT::NTupleSize_t firstEntry=0)
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr NTupleSize_t kInvalidNTupleIndex
bool StartsWith(std::string_view string, std::string_view prefix)
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr DescriptorId_t kInvalidDescriptorId
The identifiers that specifies the content of a (partial) cluster.
ROOT::DescriptorId_t fClusterId
ColumnSet_t fPhysicalColumnSet
Every concrete RColumnElement type is identified by its on-disk type (column type) and the in-memory ...
std::type_index fInMemoryType
std::uint32_t fLength
Uncompressed length of the anchor, including the checksum.
The incremental changes to a RNTupleModel
std::vector< ROOT::RFieldBase * > fAddedProjectedFields
Points to the projected fields in fModel that were added as part of an updater transaction.
std::vector< ROOT::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.
std::type_index fInMemoryType
Parameters for the SealPage() method.
bool fWriteChecksum
Adds a 8 byte little-endian xxhash3 checksum to the page payload.
std::uint32_t fCompressionSettings
Compression algorithm and level to apply.
void * fBuffer
Location for sealed output. The memory buffer has to be large enough.
const ROOT::Internal::RPage * fPage
Input page to be sealed.
bool fAllowAlias
If false, the output buffer must not point to the input page buffer, which would otherwise be an opti...
const ROOT::Internal::RColumnElementBase * fElement
Corresponds to the page's elements, for size calculation etc.
Cluster that was staged, but not yet logically appended to the RNTuple.
ROOT::NTupleSize_t fNEntries
std::uint64_t fNBytesWritten
std::vector< RColumnInfo > fColumnInfos
Default I/O performance counters that get registered in fMetrics
Used in SetEntryRange / GetEntryRange.
ROOT::NTupleSize_t fNEntries
bool IntersectsWith(const ROOT::RClusterDescriptor &clusterDesc) const
Returns true if the given cluster has entries within the entry range.
ROOT::NTupleSize_t fFirstEntry
Summarizes meta-data necessary to load a certain page. Used by LoadPageFromSummary().
ROOT::RClusterDescriptor::RPageInfoExtended fPageInfo
Location of the page on disk.
std::uint64_t fColumnOffset
The first element number of the page's column in the given cluster.
ROOT::DescriptorId_t fClusterId
ROOT::DescriptorId_t fPhysicalColumnId
A sealed page contains the bytes of a page as written to storage (packed & compressed).
static constexpr std::size_t kNBytesPageChecksum
The page checksum is a 64bit xxhash3.
void SetBufferSize(std::size_t bufferSize)
std::size_t GetBufferSize() const
std::size_t GetDataSize() const
void SetNElements(std::uint32_t nElements)
void SetBuffer(const void *buffer)
bool GetHasChecksum() const
const void * GetBuffer() const
RResult< void > VerifyChecksumIfEnabled() const
std::uint32_t GetNElements() const
void SetHasChecksum(bool hasChecksum)
std::size_t fCurrentPageSize
ROOT::Internal::RWriteColumn * fColumn
bool operator>(const RColumnInfo &other) const
Information about a single page in the context of a cluster's page range.
void SetLocator(const RNTupleLocator &locator)
std::uint32_t GetNElements() const
const RNTupleLocator & GetLocator() const
void SetHasChecksum(bool hasChecksum)
void SetNElements(std::uint32_t n)
Modifiers passed to CreateModel()