49#ifndef R__LITTLE_ENDIAN
52#define R__LITTLE_ENDIAN 1
54#define R__LITTLE_ENDIAN 0
65 std::uint16_t fValBE = 0;
66 static std::uint16_t Swap(std::uint16_t val)
68#if R__LITTLE_ENDIAN == 1
69 return RByteSwap<
sizeof(val)>::bswap(val);
76 RUInt16BE() =
default;
77 explicit RUInt16BE(
const std::uint16_t val) : fValBE(Swap(val)) {}
78 operator std::uint16_t()
const {
return Swap(fValBE); }
79 RUInt16BE &operator=(
const std::uint16_t val)
89 std::uint32_t fValBE = 0;
90 static std::uint32_t Swap(std::uint32_t val)
92#if R__LITTLE_ENDIAN == 1
93 return RByteSwap<
sizeof(val)>::bswap(val);
100 RUInt32BE() =
default;
101 explicit RUInt32BE(
const std::uint32_t val) : fValBE(Swap(val)) {}
102 operator std::uint32_t()
const {
return Swap(fValBE); }
103 RUInt32BE &operator=(
const std::uint32_t val)
113 std::int32_t fValBE = 0;
114 static std::int32_t Swap(std::int32_t val)
116#if R__LITTLE_ENDIAN == 1
117 return RByteSwap<
sizeof(val)>::bswap(val);
124 RInt32BE() =
default;
125 explicit RInt32BE(
const std::int32_t val) : fValBE(Swap(val)) {}
126 operator std::int32_t()
const {
return Swap(fValBE); }
127 RInt32BE &operator=(
const std::int32_t val)
137 std::uint64_t fValBE = 0;
138 static std::uint64_t Swap(std::uint64_t val)
140#if R__LITTLE_ENDIAN == 1
141 return RByteSwap<
sizeof(val)>::bswap(val);
148 RUInt64BE() =
default;
149 explicit RUInt64BE(
const std::uint64_t val) : fValBE(Swap(val)) {}
150 operator std::uint64_t()
const {
return Swap(fValBE); }
151 RUInt64BE &operator=(
const std::uint64_t val)
164 std::string fSerialized;
167 static constexpr unsigned char kLongStringMarker = 255;
169 RTFString() : fSerialized(1,
'\0') {}
170 RTFString(std::string_view str)
172 if (str.length() < kLongStringMarker) {
173 fSerialized.push_back(
static_cast<char>(str.length()));
175 if (str.length() >
static_cast<std::size_t
>(std::numeric_limits<std::int32_t>::max()))
177 RInt32BE
length{
static_cast<std::int32_t
>(str.length())};
178 fSerialized.push_back(
static_cast<char>(kLongStringMarker));
179 fSerialized.append(
reinterpret_cast<const char *
>(&
length),
sizeof(
length));
181 fSerialized.append(str);
184 std::size_t GetSize()
const {
return fSerialized.size(); }
185 const char *GetData()
const {
return fSerialized.data(); }
194 auto now = std::chrono::system_clock::now();
195 auto tt = std::chrono::system_clock::to_time_t(now);
196 auto tm = *localtime(&
tt);
197 fDatetime = (tm.tm_year + 1900 - 1995) << 26 | (tm.tm_mon + 1) << 22 | tm.tm_mday << 17 | tm.tm_hour << 12 |
198 tm.tm_min << 6 | tm.tm_sec;
200 explicit RTFDatetime(RUInt32BE val) : fDatetime(val) {}
205 static constexpr unsigned kBigKeyVersion = 1000;
208 RUInt16BE fVersion{4};
209 RUInt32BE fObjLen{0};
210 RTFDatetime fDatetime;
211 RUInt16BE fKeyLen{0};
215 RUInt32BE fSeekKey{0};
216 RUInt32BE fSeekPdir{0};
219 RUInt64BE fSeekKey{0};
220 RUInt64BE fSeekPdir{0};
224 RTFKey() : fInfoLong() {}
225 RTFKey(std::uint64_t seekKey, std::uint64_t seekPdir,
const RTFString &clName,
const RTFString &objName,
226 const RTFString &titleName, std::size_t szObjInMem, std::size_t szObjOnDisk = 0)
228 R__ASSERT(szObjInMem <= std::numeric_limits<std::uint32_t>::max());
229 R__ASSERT(szObjOnDisk <= std::numeric_limits<std::uint32_t>::max());
231 fVersion = fVersion + kBigKeyVersion;
232 fObjLen = szObjInMem;
233 const auto keyLen = GetHeaderSize() + clName.GetSize() + objName.GetSize() + titleName.GetSize();
235 if (keyLen >
static_cast<std::size_t
>(std::numeric_limits<std::int16_t>::max()))
237 fKeyLen =
static_cast<std::uint16_t
>(keyLen);
238 fInfoLong.fSeekKey = seekKey;
239 fInfoLong.fSeekPdir = seekPdir;
241 fNbytes = fKeyLen + ((szObjOnDisk == 0) ? szObjInMem : szObjOnDisk);
244 std::uint32_t GetSize()
const
252 std::uint32_t GetHeaderSize()
const
254 if (fVersion >= kBigKeyVersion)
255 return 18 +
sizeof(fInfoLong);
256 return 18 +
sizeof(fInfoShort);
259 std::uint64_t GetSeekKey()
const
261 if (fVersion >= kBigKeyVersion)
262 return fInfoLong.fSeekKey;
263 return fInfoShort.fSeekKey;
269 static constexpr unsigned kBEGIN = 100;
270 static constexpr unsigned kBigHeaderVersion = 1000000;
272 char fMagic[4]{
'r',
'o',
'o',
't'};
279 RUInt32BE fSeekFree{0};
280 RUInt32BE fNbytesFree{0};
282 RUInt32BE fNbytesName{0};
283 unsigned char fUnits{4};
284 RUInt32BE fCompress{0};
285 RUInt32BE fSeekInfo{0};
286 RUInt32BE fNbytesInfo{0};
290 RUInt64BE fSeekFree{0};
291 RUInt32BE fNbytesFree{0};
293 RUInt32BE fNbytesName{0};
294 unsigned char fUnits{8};
295 RUInt32BE fCompress{0};
296 RUInt64BE fSeekInfo{0};
297 RUInt32BE fNbytesInfo{0};
301 RTFHeader() : fInfoShort() {}
302 RTFHeader(
int compression) : fInfoShort() { fInfoShort.fCompress = compression; }
306 if (fVersion >= kBigHeaderVersion)
310 std::uint32_t end = fInfoShort.fEND;
311 std::uint32_t seekFree = fInfoShort.fSeekFree;
312 std::uint32_t nbytesFree = fInfoShort.fNbytesFree;
313 std::uint32_t nFree = fInfoShort.fNfree;
314 std::uint32_t nbytesName = fInfoShort.fNbytesName;
315 std::uint32_t compress = fInfoShort.fCompress;
316 std::uint32_t seekInfo = fInfoShort.fSeekInfo;
317 std::uint32_t nbytesInfo = fInfoShort.fNbytesInfo;
318 fInfoLong.fEND = end;
319 fInfoLong.fSeekFree = seekFree;
320 fInfoLong.fNbytesFree = nbytesFree;
321 fInfoLong.fNfree = nFree;
322 fInfoLong.fNbytesName = nbytesName;
323 fInfoLong.fUnits = 8;
324 fInfoLong.fCompress = compress;
325 fInfoLong.fSeekInfo = seekInfo;
326 fInfoLong.fNbytesInfo = nbytesInfo;
327 fVersion = fVersion + kBigHeaderVersion;
331 bool IsBigFile(std::uint64_t
offset = 0)
const
333 return (fVersion >= kBigHeaderVersion) ||
334 (
offset >
static_cast<unsigned int>(std::numeric_limits<std::int32_t>::max()));
337 std::uint32_t GetSize()
const
339 std::uint32_t sizeHead =
sizeof(fMagic) +
sizeof(fVersion) +
sizeof(fBEGIN);
341 return sizeHead +
sizeof(fInfoLong);
342 return sizeHead +
sizeof(fInfoShort);
345 std::uint64_t GetEnd()
const
348 return fInfoLong.fEND;
349 return fInfoShort.fEND;
352 void SetEnd(std::uint64_t
value)
354 if (IsBigFile(
value)) {
356 fInfoLong.fEND =
value;
358 fInfoShort.fEND =
value;
362 std::uint64_t GetSeekFree()
const
365 return fInfoLong.fSeekFree;
366 return fInfoShort.fSeekFree;
369 void SetSeekFree(std::uint64_t
value)
371 if (IsBigFile(
value)) {
373 fInfoLong.fSeekFree =
value;
375 fInfoShort.fSeekFree =
value;
379 void SetNbytesFree(std::uint32_t
value)
382 fInfoLong.fNbytesFree =
value;
384 fInfoShort.fNbytesFree =
value;
388 void SetNbytesName(std::uint32_t
value)
391 fInfoLong.fNbytesName =
value;
393 fInfoShort.fNbytesName =
value;
397 std::uint64_t GetSeekInfo()
const
400 return fInfoLong.fSeekInfo;
401 return fInfoShort.fSeekInfo;
404 void SetSeekInfo(std::uint64_t
value)
406 if (IsBigFile(
value)) {
408 fInfoLong.fSeekInfo =
value;
410 fInfoShort.fSeekInfo =
value;
414 std::uint64_t GetNbytesInfo()
const
417 return fInfoLong.fNbytesInfo;
418 return fInfoShort.fNbytesInfo;
421 void SetNbytesInfo(std::uint32_t
value)
424 fInfoLong.fNbytesInfo =
value;
426 fInfoShort.fNbytesInfo =
value;
430 void SetCompression(std::uint32_t
value)
433 fInfoLong.fCompress =
value;
435 fInfoShort.fCompress =
value;
442 static constexpr unsigned kBigFreeEntryVersion = 1000;
444 RUInt16BE fVersion{1};
456 RTFFreeEntry() : fInfoShort() {}
457 void Set(std::uint64_t first, std::uint64_t last)
459 if (last >
static_cast<unsigned int>(std::numeric_limits<std::int32_t>::max())) {
460 fVersion = fVersion + kBigFreeEntryVersion;
461 fInfoLong.fFirst = first;
462 fInfoLong.fLast = last;
464 fInfoShort.fFirst = first;
465 fInfoShort.fLast = last;
468 std::uint32_t GetSize() {
return (fVersion >= kBigFreeEntryVersion) ? 18 : 10; }
474 std::uint32_t GetSize()
const {
return sizeof(RTFKeyList); }
475 explicit RTFKeyList(std::uint32_t nKeys) : fNKeys(nKeys) {}
480 static constexpr unsigned kBigFileVersion = 1000;
482 RUInt16BE fClassVersion{5};
485 RUInt32BE fNBytesKeys{0};
486 RUInt32BE fNBytesName{0};
490 RUInt32BE fSeekDir{RTFHeader::kBEGIN};
491 RUInt32BE fSeekParent{0};
492 RUInt32BE fSeekKeys{0};
495 RUInt64BE fSeekDir{RTFHeader::kBEGIN};
496 RUInt64BE fSeekParent{0};
497 RUInt64BE fSeekKeys{0};
501 RTFDirectory() : fInfoShort() {}
504 std::uint32_t GetSize()
const
506 if (fClassVersion >= kBigFileVersion)
507 return sizeof(RTFDirectory);
508 return 18 +
sizeof(fInfoShort);
511 std::uint64_t GetSeekKeys()
const
513 if (fClassVersion >= kBigFileVersion)
514 return fInfoLong.fSeekKeys;
515 return fInfoShort.fSeekKeys;
518 void SetSeekKeys(std::uint64_t seekKeys)
520 if (seekKeys >
static_cast<unsigned int>(std::numeric_limits<std::int32_t>::max())) {
521 std::uint32_t seekDir = fInfoShort.fSeekDir;
522 std::uint32_t seekParent = fInfoShort.fSeekParent;
523 fInfoLong.fSeekDir = seekDir;
524 fInfoLong.fSeekParent = seekParent;
525 fInfoLong.fSeekKeys = seekKeys;
526 fClassVersion = fClassVersion + kBigFileVersion;
528 fInfoShort.fSeekKeys = seekKeys;
535 RUInt16BE fVersionClass{1};
536 unsigned char fUUID[16];
541 char *buffer =
reinterpret_cast<char *
>(
this);
543 assert(
reinterpret_cast<RTFUUID *
>(buffer) <= (
this + 1));
545 std::uint32_t GetSize()
const {
return sizeof(RTFUUID); }
554 RUInt32BE fByteCount{0x40000000 | (
sizeof(RTFNTuple) -
sizeof(fByteCount))};
555 RUInt16BE fVersionClass{2};
556 RUInt16BE fVersionEpoch{0};
557 RUInt16BE fVersionMajor{0};
558 RUInt16BE fVersionMinor{0};
559 RUInt16BE fVersionPatch{0};
560 RUInt64BE fSeekHeader{0};
561 RUInt64BE fNBytesHeader{0};
562 RUInt64BE fLenHeader{0};
563 RUInt64BE fSeekFooter{0};
564 RUInt64BE fNBytesFooter{0};
565 RUInt64BE fLenFooter{0};
566 RUInt64BE fMaxKeySize{0};
568 static constexpr std::uint32_t GetSizePlusChecksum() {
return sizeof(RTFNTuple) +
sizeof(std::uint64_t); }
570 RTFNTuple() =
default;
585 std::uint32_t GetSize()
const {
return sizeof(RTFNTuple); }
587 std::uint32_t GetOffsetCkData() {
return sizeof(fByteCount) +
sizeof(fVersionClass); }
588 std::uint32_t GetSizeCkData() {
return GetSize() - GetOffsetCkData(); }
589 unsigned char *GetPtrCkData() {
return reinterpret_cast<unsigned char *
>(
this) + GetOffsetCkData(); }
593struct RBareFileHeader {
594 char fMagic[7]{
'r',
'n',
't',
'u',
'p',
'l',
'e'};
597 RUInt32BE fFormatVersion{1};
598 RUInt32BE fCompress{0};
605constexpr char const *kBlobClassName =
"RBlob";
607constexpr char const *kNTupleClassName =
"ROOT::RNTuple";
638 void Reserve(
size_t nbytes, std::uint64_t *seekKey)
657 constexpr size_t kChunkOffsetSize =
sizeof(std::uint64_t);
659 assert(nbytes > maxChunkSize);
660 size_t nChunks = (nbytes + maxChunkSize - 1) / maxChunkSize;
662 size_t nbytesTail = nbytes % maxChunkSize;
663 size_t nbytesExtra = (nbytesTail > 0) * (maxChunkSize - nbytesTail);
664 size_t nbytesChunkOffsets = (nChunks - 1) * kChunkOffsetSize;
665 if (nbytesChunkOffsets > nbytesExtra) {
667 nbytesChunkOffsets += kChunkOffsetSize;
674 R__ASSERT(nbytesChunkOffsets <= maxChunkSize);
683 std::size_t headerLength = 1;
684 std::size_t strLength = 0;
685 unsigned char shortLength = 0;
687 if (shortLength == RTFString::kLongStringMarker) {
688 RUInt32BE longLength;
690 strLength = longLength;
691 headerLength +=
sizeof(longLength);
693 strLength = shortLength;
696 str->resize(strLength);
700 return headerLength + strLength;
709 if (std::string(ident, 4) ==
"root")
710 return GetNTupleProper(ntupleName);
712 return GetNTupleBare(ntupleName);
718 std::string_view typeName)
720 RTFDirectory directory;
721 ReadBuffer(&directory,
sizeof(directory), offsetDir);
725 std::uint64_t
offset = directory.GetSeekKeys();
731 for (
unsigned int i = 0; i < nKeys; ++i) {
733 auto offsetNextKey =
offset + key.fKeyLen;
735 offset += key.GetHeaderSize();
736 std::string foundClassName;
738 if (foundClassName != typeName) {
742 std::string foundKeyName;
744 if (foundKeyName == keyName) {
745 return key.GetSeekKey();
762 R__ASSERT(fNbytesKeyAndInfo >= key.fKeyLen);
763 const std::uint64_t nbytesInfo = fNbytesKeyAndInfo - key.fKeyLen;
764 const std::uint64_t seekInfo = fSeekKeyInfo + key.fKeyLen;
765 const std::uint32_t uncompLenInfo = key.fObjLen;
766 auto streamerInfo = MakeUninitArray<char>(uncompLenInfo);
767 if (nbytesInfo == uncompLenInfo) {
769 ReadBuffer(streamerInfo.get(), nbytesInfo, seekInfo);
771 auto buffer = MakeUninitArray<std::byte>(nbytesInfo);
772 ReadBuffer(buffer.get(), nbytesInfo, seekInfo);
782 TList streamerInfoList;
799 RTFHeader fileHeader;
800 ReadBuffer(&fileHeader,
sizeof(fileHeader), 0);
802 fSeekKeyInfo = fileHeader.GetSeekInfo();
803 fNbytesKeyAndInfo = fileHeader.GetNbytesInfo();
806 ReadBuffer(&key,
sizeof(key), fileHeader.fBEGIN);
808 std::uint64_t
offset = fileHeader.fBEGIN + key.fKeyLen;
814 std::string ntuplePathTail(ntuplePath);
815 if (!ntuplePathTail.empty() && ntuplePathTail[0] ==
'/')
816 ntuplePathTail = ntuplePathTail.substr(1);
817 auto pos = std::string::npos;
818 while ((pos = ntuplePathTail.find(
'/')) != std::string::npos) {
819 auto directoryName = ntuplePathTail.substr(0, pos);
820 ntuplePathTail.erase(0, pos + 1);
822 offset = SearchInDirectory(
offset, directoryName,
"TDirectory");
824 return R__FAIL(
"no directory named '" + std::string(directoryName) +
"' in file '" + fRawFile->GetUrl() +
"'");
827 offset = key.GetSeekKey() + key.fKeyLen;
830 auto ntupleName = ntuplePathTail;
832 offset = SearchInDirectory(
offset, ntupleName, kNTupleClassName);
834 return R__FAIL(
"no RNTuple named '" + std::string(ntupleName) +
"' in file '" + fRawFile->GetUrl() +
"'");
838 offset = key.GetSeekKey() + key.fKeyLen;
841 constexpr size_t kMinNTupleSize = 78;
842 static_assert(kMinNTupleSize == RTFNTuple::GetSizePlusChecksum());
843 if (key.fObjLen < kMinNTupleSize) {
844 return R__FAIL(
"invalid anchor size: " + std::to_string(key.fObjLen) +
" < " + std::to_string(
sizeof(RTFNTuple)));
847 const auto objNbytes = key.GetSize() - key.fKeyLen;
848 auto res = GetNTupleProperAtOffset(
offset, objNbytes, key.fObjLen);
854 std::uint64_t compSize,
855 std::uint64_t uncompLen)
857 if (compSize > uncompLen) {
858 return R__FAIL(
"Invalid size and length combination of anchor at offset " + std::to_string(payloadOffset) +
859 " (length: " + std::to_string(uncompLen) +
", bytes on disk: " + std::to_string(compSize) +
")");
864 auto bufAnchor = MakeUninitArray<unsigned char>(std::max<size_t>(uncompLen,
sizeof(RTFNTuple)));
865 RTFNTuple *ntuple =
new (bufAnchor.get()) RTFNTuple;
867 if (compSize < uncompLen) {
869 auto zipBuf = MakeUninitArray<unsigned char>(compSize);
870 ReadBuffer(zipBuf.get(), compSize, payloadOffset);
881 const auto lenCkData = uncompLen - ntuple->GetOffsetCkData() -
sizeof(uint64_t);
882 const auto ckCalc = XXH3_64bits(ntuple->GetPtrCkData(), lenCkData);
885 RUInt64BE *ckOnDiskPtr =
reinterpret_cast<RUInt64BE *
>(bufAnchor.get() + uncompLen -
sizeof(uint64_t));
886 ckOnDisk =
static_cast<uint64_t
>(*ckOnDiskPtr);
887 if (ckCalc != ckOnDisk) {
888 return R__FAIL(
"RNTuple anchor checksum mismatch");
891 return CreateAnchor(ntuple->fVersionEpoch, ntuple->fVersionMajor, ntuple->fVersionMinor, ntuple->fVersionPatch,
892 ntuple->fSeekHeader, ntuple->fNBytesHeader, ntuple->fLenHeader, ntuple->fSeekFooter,
893 ntuple->fNBytesFooter, ntuple->fLenFooter, ntuple->fMaxKeySize);
898 RBareFileHeader fileHeader;
899 ReadBuffer(&fileHeader,
sizeof(fileHeader), 0);
900 auto offset =
sizeof(fileHeader);
901 std::string foundName;
903 if (foundName != ntupleName) {
904 return R__FAIL(
"expected RNTuple named '" + std::string(ntupleName) +
"' but instead found '" + foundName +
905 "' in file '" + fRawFile->GetUrl() +
"'");
910 std::uint64_t onDiskChecksum;
911 ReadBuffer(&onDiskChecksum,
sizeof(onDiskChecksum),
offset +
sizeof(ntuple));
912 auto checksum = XXH3_64bits(ntuple.GetPtrCkData(), ntuple.GetSizeCkData());
913 if (checksum !=
static_cast<uint64_t
>(onDiskChecksum))
914 return R__FAIL(
"RNTuple bare file: anchor checksum mismatch");
916 return CreateAnchor(ntuple.fVersionEpoch, ntuple.fVersionMajor, ntuple.fVersionMinor, ntuple.fVersionPatch,
917 ntuple.fSeekHeader, ntuple.fNBytesHeader, ntuple.fLenHeader, ntuple.fSeekFooter,
918 ntuple.fNBytesFooter, ntuple.fLenFooter, ntuple.fMaxKeySize);
923 TryReadBuffer(buffer, nbytes,
offset).ThrowOnError();
928 const auto ByteReadErr = [](std::size_t expected, std::size_t nread) {
929 return R__FAIL(
"invalid read (expected bytes: " + std::to_string(expected) +
", read: " + std::to_string(nread) +
934 if (fMaxKeySize == 0 || nbytes <= fMaxKeySize) {
936 nread = fRawFile->ReadAt(buffer, nbytes,
offset);
940 const size_t nbytesChunkOffsets = (nChunks - 1) *
sizeof(std::uint64_t);
941 const size_t nbytesFirstChunk = fMaxKeySize - nbytesChunkOffsets;
942 uint8_t *bufCur =
reinterpret_cast<uint8_t *
>(buffer);
945 nread = fRawFile->ReadAt(bufCur, fMaxKeySize,
offset);
946 if (nread != fMaxKeySize)
947 return ByteReadErr(fMaxKeySize, nread);
952 bufCur += nbytesFirstChunk;
953 nread -= nbytesChunkOffsets;
955 const auto chunkOffsets = MakeUninitArray<std::uint64_t>(nChunks - 1);
956 memcpy(chunkOffsets.get(), bufCur, nbytesChunkOffsets);
958 size_t remainingBytes = nbytes - nbytesFirstChunk;
959 std::uint64_t *curChunkOffset = &chunkOffsets[0];
962 std::uint64_t chunkOffset;
966 const size_t bytesToRead = std::min<size_t>(fMaxKeySize, remainingBytes);
968 R__ASSERT(
static_cast<size_t>(bufCur -
reinterpret_cast<uint8_t *
>(buffer)) <= nbytes - bytesToRead);
970 auto nbytesRead = fRawFile->ReadAt(bufCur, bytesToRead, chunkOffset);
971 if (nbytesRead != bytesToRead)
972 return ByteReadErr(bytesToRead, nbytesRead);
974 nread += bytesToRead;
975 bufCur += bytesToRead;
976 remainingBytes -= bytesToRead;
977 }
while (remainingBytes > 0);
981 return ByteReadErr(nbytes, nread);
991 unsigned char buffer[kBlobKeyLen])
993 RTFString strClass{kBlobClassName};
996 RTFKey keyHeader(
offset, RTFHeader::kBEGIN, strClass, strObject, strTitle,
len, nbytes);
997 R__ASSERT(keyHeader.fKeyLen == kBlobKeyLen);
1000 unsigned char *writeBuffer = buffer;
1001 memcpy(writeBuffer, &keyHeader, keyHeader.GetHeaderSize());
1002 writeBuffer += keyHeader.GetHeaderSize();
1003 memcpy(writeBuffer, strClass.GetData(), strClass.GetSize());
1004 writeBuffer += strClass.GetSize();
1005 memcpy(writeBuffer, strObject.GetData(), strObject.GetSize());
1006 writeBuffer += strObject.GetSize();
1007 memcpy(writeBuffer, strTitle.GetData(), strTitle.GetSize());
1008 writeBuffer += strTitle.GetSize();
1009 R__ASSERT(writeBuffer == buffer + kBlobKeyLen);
1018 static_assert(kHeaderBlockSize % kBlockAlign == 0,
"invalid header block size");
1019 if (bufferSize % kBlockAlign != 0)
1020 throw RException(
R__FAIL(
"Buffer size not a multiple of alignment: " + std::to_string(bufferSize)));
1024 fShared = std::make_shared<RSharedData>(
nullptr);
1026 fShared->fBlockSize = bufferSize;
1027 fShared->fControlBlock = std::make_unique<ROOT::Internal::RTFileControlBlock>();
1029 std::align_val_t blockAlign{kBlockAlign};
1030 fShared->fHeaderBlock =
static_cast<unsigned char *
>(::operator
new[](kHeaderBlockSize, blockAlign));
1031 memset(fShared->fHeaderBlock, 0, kHeaderBlockSize);
1032 fShared->fBlock =
static_cast<unsigned char *
>(::operator
new[](fShared->fBlockSize, blockAlign));
1033 memset(fShared->fBlock, 0, fShared->fBlockSize);
1045 ::operator
delete[](fHeaderBlock, blockAlign);
1047 ::operator
delete[](fBlock, blockAlign);
1051int FSeek64(FILE *stream, std::int64_t
offset,
int origin)
1054 return fseeko64(stream,
offset, origin);
1056 return fseek(stream,
offset, origin);
1067 if (shared.fBlockOffset == 0) {
1069 if (headerBlockSize > shared.fFilePos) {
1070 headerBlockSize = shared.fFilePos;
1072 memcpy(shared.fBlock, shared.fHeaderBlock, headerBlockSize);
1075 std::size_t retval = FSeek64(shared.fFile, shared.fBlockOffset, SEEK_SET);
1079 std::size_t lastBlockSize = shared.fFilePos - shared.fBlockOffset;
1080 R__ASSERT(lastBlockSize <= shared.fBlockSize);
1081 if (shared.fDirectIO) {
1085 R__ASSERT(lastBlockSize <= shared.fBlockSize);
1087 retval = fwrite(shared.fBlock, 1, lastBlockSize, shared.fFile);
1088 if (retval != lastBlockSize)
1092 if (shared.fBlockOffset > 0) {
1093 retval = FSeek64(shared.fFile, 0, SEEK_SET);
1102 retval = fflush(shared.fFile);
1113 if ((
offset >= 0) && (
static_cast<std::uint64_t
>(
offset) != shared.fFilePos)) {
1114 shared.fFilePos =
offset;
1119 std::size_t headerBytes = nbytes;
1123 memcpy(shared.fHeaderBlock + shared.fFilePos, buffer, headerBytes);
1126 R__ASSERT(shared.fFilePos >= shared.fBlockOffset);
1128 while (nbytes > 0) {
1129 std::uint64_t posInBlock = shared.fFilePos % shared.fBlockSize;
1130 std::uint64_t blockOffset = shared.fFilePos - posInBlock;
1131 if (blockOffset != shared.fBlockOffset) {
1133 retval = FSeek64(shared.fFile, shared.fBlockOffset, SEEK_SET);
1137 retval = fwrite(shared.fBlock, 1, shared.fBlockSize, shared.fFile);
1138 if (retval != shared.fBlockSize)
1142 memset(shared.fBlock, 0, shared.fBlockSize);
1145 shared.fBlockOffset = blockOffset;
1146 std::size_t blockSize = nbytes;
1147 if (blockSize > shared.fBlockSize - posInBlock) {
1148 blockSize = shared.fBlockSize - posInBlock;
1150 memcpy(shared.fBlock + posInBlock, buffer, blockSize);
1151 buffer =
static_cast<const unsigned char *
>(buffer) + blockSize;
1152 nbytes -= blockSize;
1153 shared.fFilePos += blockSize;
1159 std::int64_t
offset, std::uint64_t directoryOffset,
1160 const std::string &
className,
const std::string &objectName,
1161 const std::string &title)
1166 shared.fKeyOffset =
offset;
1168 RTFString strObject{objectName};
1169 RTFString strTitle{title};
1171 RTFKey key(shared.fKeyOffset, directoryOffset, strClass, strObject, strTitle,
len, nbytes);
1172 Write(&key, key.GetHeaderSize(), shared.fKeyOffset);
1173 Write(strClass.GetData(), strClass.GetSize());
1174 Write(strObject.GetData(), strObject.GetSize());
1175 Write(strTitle.GetData(), strTitle.GetSize());
1176 auto offsetData = shared.fFilePos;
1178 shared.fKeyOffset = offsetData + nbytes;
1180 Write(buffer, nbytes);
1198 auto offsetData = shared.fKeyOffset +
kBlobKeyLen;
1200 shared.fKeyOffset = offsetData + nbytes;
1207template <
typename T>
1211 std::uint64_t offsetKey;
1215 keyBlob.
Reserve(nbytes, &offsetKey);
1222 caller.Write(localKeyBuffer,
kBlobKeyLen, offsetKey);
1239 fDirectory->GetFile()->Seek(
offset);
1240 bool rv = fDirectory->GetFile()->WriteBuffer((
char *)(buffer), nbytes);
1258 bool rv = file->WriteBuffer((
char *)(buffer), nbytes);
1284std::unique_ptr<ROOT::Internal::RNTupleFileWriter>
1288 std::string fileName(path);
1289 size_t idxDirSep = fileName.find_last_of(
"\\/");
1290 if (idxDirSep != std::string::npos) {
1291 fileName.erase(0, idxDirSep + 1);
1294 int flags = O_WRONLY | O_CREAT | O_TRUNC;
1297 flags |= O_LARGEFILE;
1302 int fd = open(std::string(path).c_str(), flags, 0666);
1304 throw RException(
R__FAIL(std::string(
"open failed for file \"") + std::string(path) +
"\": " + strerror(errno)));
1306 FILE *fileStream = fdopen(fd,
"wb");
1309 FILE *fileStream = fopen64(std::string(path.data(), path.size()).c_str(),
"wb");
1311 FILE *fileStream = fopen(std::string(path.data(), path.size()).c_str(),
"wb");
1315 throw RException(
R__FAIL(std::string(
"open failed for file \"") + std::string(path) +
"\": " + strerror(errno)));
1318 std::setvbuf(fileStream,
nullptr, _IONBF, 0);
1320 auto writer = std::unique_ptr<RNTupleFileWriter>(
1324 fileSimple.
fShared->fFile = fileStream;
1326 writer->fFileName = fileName;
1329 switch (containerFormat) {
1330 case EContainerFormat::kTFile:
writer->WriteTFileSkeleton(defaultCompression);
break;
1331 case EContainerFormat::kBare:
1333 writer->WriteBareFileSkeleton(defaultCompression);
1335 default:
R__ASSERT(
false &&
"Internal error: unhandled container format");
1341std::unique_ptr<ROOT::Internal::RNTupleFileWriter>
1343 std::uint64_t maxKeySize,
bool hidden)
1347 throw RException(
R__FAIL(
"invalid attempt to add an RNTuple to a directory that is not backed by a file"));
1356std::unique_ptr<ROOT::Internal::RNTupleFileWriter>
1358 std::uint64_t maxKeySize)
1362 rfile.
fFile = &file;
1363 R__ASSERT(ntupleDir.empty() || ntupleDir[ntupleDir.size() - 1] ==
'/');
1364 rfile.fDir = ntupleDir;
1368std::unique_ptr<ROOT::Internal::RNTupleFileWriter>
1371 if (
auto *tfile = std::get_if<RImplTFile>(&fFile)) {
1372 return Append(ntupleName, *tfile->fDirectory, fNTupleAnchor.fMaxKeySize,
true);
1373 }
else if (
auto *file = std::get_if<RImplSimple>(&fFile)) {
1377 auto writer = std::unique_ptr<RNTupleFileWriter>(
1379 auto &clonedFile = std::get<RImplSimple>(
writer->fFile);
1380 clonedFile.fShared = file->fShared;
1389 RImplSimple *fileSimple = std::get_if<RImplSimple>(&fFile);
1400 fStreamerInfoMap.insert(streamerInfos.cbegin(), streamerInfos.cend());
1405 const auto WriteStreamerInfoToFile = [&](
TFile *file) {
1409 for (
auto [
_, info] : fStreamerInfoMap)
1415 anchorInfo.
fLength = RTFNTuple{}.GetSize() +
sizeof(std::uint64_t);
1418 if (
auto fileProper = std::get_if<RImplTFile>(&fFile)) {
1420 fileProper->fDirectory->WriteObject(&fNTupleAnchor, fNTupleName.c_str());
1421 WriteStreamerInfoToFile(fileProper->fDirectory->GetFile());
1422 auto key =
static_cast<TKey *
>(fileProper->fDirectory->GetListOfKeys()->FindObject(fNTupleName.c_str()));
1428 fileProper->fDirectory->GetFile()->Write();
1433 fileProper->fDirectory->GetListOfKeys()->Remove(key);
1435 }
else if (
auto fileRFile = std::get_if<RImplRFile>(&fFile)) {
1437 fileRFile->fFile->Put(fileRFile->fDir + fNTupleName, fNTupleAnchor);
1439 auto key = fileRFile->fFile->GetKeyInfo(fNTupleName);
1443 fileRFile->fFile->Flush();
1446 auto &fileSimple = std::get<RImplSimple>(fFile);
1447 auto &shared = *fileSimple.fShared;
1450 RTFNTuple ntupleOnDisk(fNTupleAnchor);
1453 std::uint64_t checksum = XXH3_64bits(ntupleOnDisk.GetPtrCkData(), ntupleOnDisk.GetSizeCkData());
1454 memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekNTuple, &ntupleOnDisk, ntupleOnDisk.GetSize());
1455 memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekNTuple + ntupleOnDisk.GetSize(), &checksum,
1462 anchorInfo = WriteTFileNTupleKey(compression);
1465 WriteTFileStreamerInfo(compression);
1466 WriteTFileFreeList();
1469 memcpy(shared.fHeaderBlock, &shared.fControlBlock->fHeader, shared.fControlBlock->fHeader.GetSize());
1470 R__ASSERT(shared.fControlBlock->fSeekFileRecord + shared.fControlBlock->fFileRecord.GetSize() <
1471 RImplSimple::kHeaderBlockSize);
1472 memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekFileRecord, &shared.fControlBlock->fFileRecord,
1473 shared.fControlBlock->fFileRecord.GetSize());
1485 auto writeKey = [
this](
const void *payload,
size_t nBytes,
size_t length) {
1487 WriteIntoReservedBlob(payload, nBytes,
offset);
1491 const std::uint64_t maxKeySize = fNTupleAnchor.fMaxKeySize;
1495 if (
static_cast<std::uint64_t
>(
len) >
static_cast<std::uint64_t
>(std::numeric_limits<std::uint32_t>::max()))
1498 if (nbytes <= maxKeySize) {
1500 return writeKey(
data, nbytes,
len);
1517 const size_t nbytesChunkOffsets = (nChunks - 1) *
sizeof(std::uint64_t);
1518 const size_t nbytesFirstChunk = maxKeySize - nbytesChunkOffsets;
1521 const uint8_t *chunkData =
reinterpret_cast<const uint8_t *
>(
data) + nbytesFirstChunk;
1522 size_t remainingBytes = nbytes - nbytesFirstChunk;
1524 const auto chunkOffsetsToWrite = MakeUninitArray<std::uint64_t>(nChunks - 1);
1525 std::uint64_t chunkOffsetIdx = 0;
1528 const size_t bytesNextChunk = std::min<size_t>(remainingBytes, maxKeySize);
1529 const std::uint64_t
offset = writeKey(chunkData, bytesNextChunk, bytesNextChunk);
1534 remainingBytes -= bytesNextChunk;
1535 chunkData += bytesNextChunk;
1537 }
while (remainingBytes > 0);
1540 const std::uint64_t firstOffset = ReserveBlob(maxKeySize, maxKeySize);
1541 WriteIntoReservedBlob(
data, nbytesFirstChunk, firstOffset);
1542 const std::uint64_t chunkOffsetsOffset = firstOffset + nbytesFirstChunk;
1543 WriteIntoReservedBlob(chunkOffsetsToWrite.get(), nbytesChunkOffsets, chunkOffsetsOffset);
1552 R__ASSERT(nbytes <= fNTupleAnchor.GetMaxKeySize());
1555 if (
auto *fileSimple = std::get_if<RImplSimple>(&fFile)) {
1557 offset = fileSimple->fShared->fKeyOffset;
1558 fileSimple->fShared->fKeyOffset += nbytes;
1560 offset = fileSimple->ReserveBlobKey(nbytes,
len, keyBuffer);
1562 }
else if (
auto *fileProper = std::get_if<RImplTFile>(&fFile)) {
1563 offset = fileProper->ReserveBlobKey(nbytes,
len, keyBuffer);
1565 auto &fileRFile = std::get<RImplRFile>(fFile);
1566 offset = fileRFile.ReserveBlobKey(nbytes,
len, keyBuffer);
1573 if (
auto *fileSimple = std::get_if<RImplSimple>(&fFile)) {
1574 fileSimple->Write(buffer, nbytes,
offset);
1575 }
else if (
auto *fileProper = std::get_if<RImplTFile>(&fFile)) {
1576 fileProper->Write(buffer, nbytes,
offset);
1578 auto &fileRFile = std::get<RImplRFile>(fFile);
1579 fileRFile.Write(buffer, nbytes,
offset);
1585 auto offset = WriteBlob(
data, nbytes, lenHeader);
1586 fNTupleAnchor.fLenHeader = lenHeader;
1587 fNTupleAnchor.fNBytesHeader = nbytes;
1588 fNTupleAnchor.fSeekHeader =
offset;
1594 auto offset = WriteBlob(
data, nbytes, lenFooter);
1595 fNTupleAnchor.fLenFooter = lenFooter;
1596 fNTupleAnchor.fNBytesFooter = nbytes;
1597 fNTupleAnchor.fSeekFooter =
offset;
1603 RBareFileHeader bareHeader;
1604 bareHeader.fCompress = defaultCompression;
1605 auto &fileSimple = std::get<RImplSimple>(fFile);
1606 fileSimple.Write(&bareHeader,
sizeof(bareHeader), 0);
1607 RTFString ntupleName{fNTupleName};
1608 fileSimple.Write(ntupleName.GetData(), ntupleName.GetSize());
1611 RTFNTuple ntupleOnDisk;
1612 fileSimple.fShared->fControlBlock->fSeekNTuple = fileSimple.fShared->fFilePos;
1613 fileSimple.Write(&ntupleOnDisk, ntupleOnDisk.GetSize());
1614 std::uint64_t checksum = 0;
1615 fileSimple.Write(&checksum,
sizeof(checksum));
1616 fileSimple.fShared->fKeyOffset = fileSimple.fShared->fFilePos;
1626 TList streamerInfoList;
1627 for (
auto [
_, info] : fStreamerInfoMap) {
1628 streamerInfoList.
Add(info);
1637 RTFString strTList{
"TList"};
1638 RTFString strStreamerInfo{
"StreamerInfo"};
1639 RTFString strStreamerTitle{
"Doubly linked list"};
1640 auto &fileSimple = std::get<RImplSimple>(fFile);
1641 fileSimple.fShared->fControlBlock->fHeader.SetSeekInfo(fileSimple.fShared->fKeyOffset);
1642 auto keyLen = RTFKey(fileSimple.fShared->fControlBlock->fHeader.GetSeekInfo(), RTFHeader::kBEGIN, strTList,
1643 strStreamerInfo, strStreamerTitle, 0)
1649 assert(buffer.
Length() > keyLen);
1650 const auto bufPayload = buffer.
Buffer() + keyLen;
1651 const auto lenPayload = buffer.
Length() - keyLen;
1653 auto zipStreamerInfos = MakeUninitArray<unsigned char>(lenPayload);
1654 auto szZipStreamerInfos =
RNTupleCompressor::Zip(bufPayload, lenPayload, compression, zipStreamerInfos.get());
1656 fileSimple.WriteKey(zipStreamerInfos.get(), szZipStreamerInfos, lenPayload,
1657 fileSimple.fShared->fControlBlock->fHeader.GetSeekInfo(), RTFHeader::kBEGIN,
"TList",
1658 "StreamerInfo",
"Doubly linked list");
1659 fileSimple.fShared->fControlBlock->fHeader.SetNbytesInfo(fileSimple.fShared->fFilePos -
1660 fileSimple.fShared->fControlBlock->fHeader.GetSeekInfo());
1666 RTFString strRNTupleClass{
"ROOT::RNTuple"};
1667 RTFString strRNTupleName{fNTupleName};
1668 RTFString strFileName{fFileName};
1670 auto &fileSimple = std::get<RImplSimple>(fFile);
1671 RTFKey keyRNTuple(fileSimple.fShared->fControlBlock->fSeekNTuple, RTFHeader::kBEGIN, strRNTupleClass, strRNTupleName,
1672 strEmpty, RTFNTuple::GetSizePlusChecksum(), anchorSize);
1674 auto &fileShared = *fileSimple.fShared;
1675 fileSimple.fShared->fControlBlock->fFileRecord.SetSeekKeys(fileShared.fKeyOffset);
1676 RTFKeyList keyList{1};
1677 RTFKey keyKeyList(fileSimple.fShared->fControlBlock->fFileRecord.GetSeekKeys(), RTFHeader::kBEGIN, strEmpty,
1678 strFileName, strEmpty, keyList.GetSize() + keyRNTuple.fKeyLen);
1679 fileSimple.Write(&keyKeyList, keyKeyList.GetHeaderSize(),
1680 fileSimple.fShared->fControlBlock->fFileRecord.GetSeekKeys());
1681 fileSimple.Write(strEmpty.GetData(), strEmpty.GetSize());
1682 fileSimple.Write(strFileName.GetData(), strFileName.GetSize());
1683 fileSimple.Write(strEmpty.GetData(), strEmpty.GetSize());
1684 fileSimple.Write(&keyList, keyList.GetSize());
1685 fileSimple.Write(&keyRNTuple, keyRNTuple.GetHeaderSize());
1687 fileSimple.Write(strRNTupleClass.GetData(), strRNTupleClass.GetSize());
1688 fileSimple.Write(strRNTupleName.GetData(), strRNTupleName.GetSize());
1689 fileSimple.Write(strEmpty.GetData(), strEmpty.GetSize());
1690 fileSimple.fShared->fControlBlock->fFileRecord.fNBytesKeys =
1691 fileShared.fFilePos - fileSimple.fShared->fControlBlock->fFileRecord.GetSeekKeys();
1692 fileShared.fKeyOffset = fileShared.fFilePos;
1697 auto &fileSimple = std::get<RImplSimple>(fFile);
1698 auto &fileShared = *fileSimple.fShared;
1699 fileSimple.fShared->fControlBlock->fHeader.SetSeekFree(fileShared.fKeyOffset);
1701 RTFString strFileName{fFileName};
1702 RTFFreeEntry freeEntry;
1703 RTFKey keyFreeList(fileSimple.fShared->fControlBlock->fHeader.GetSeekFree(), RTFHeader::kBEGIN, strEmpty,
1704 strFileName, strEmpty, freeEntry.GetSize());
1705 std::uint64_t firstFree = fileSimple.fShared->fControlBlock->fHeader.GetSeekFree() + keyFreeList.GetSize();
1706 freeEntry.Set(firstFree, std::max(2000000000ULL, ((firstFree / 1000000000ULL) + 1) * 1000000000ULL));
1707 fileSimple.WriteKey(&freeEntry, freeEntry.GetSize(), freeEntry.GetSize(),
1708 fileSimple.fShared->fControlBlock->fHeader.GetSeekFree(), RTFHeader::kBEGIN,
"", fFileName,
"");
1709 fileSimple.fShared->fControlBlock->fHeader.SetNbytesFree(fileShared.fFilePos -
1710 fileSimple.fShared->fControlBlock->fHeader.GetSeekFree());
1711 fileSimple.fShared->fControlBlock->fHeader.SetEnd(fileShared.fFilePos);
1716 RTFString strRNTupleClass{
"ROOT::RNTuple"};
1717 RTFString strRNTupleName{fNTupleName};
1720 RTFNTuple ntupleOnDisk(fNTupleAnchor);
1721 RUInt64BE checksum{XXH3_64bits(ntupleOnDisk.GetPtrCkData(), ntupleOnDisk.GetSizeCkData())};
1722 auto &fileSimple = std::get<RImplSimple>(fFile);
1723 fileSimple.fShared->fControlBlock->fSeekNTuple = fileSimple.fShared->fKeyOffset;
1725 char keyBuf[RTFNTuple::GetSizePlusChecksum()];
1728 memcpy(keyBuf, &ntupleOnDisk,
sizeof(RTFNTuple));
1729 memcpy(keyBuf +
sizeof(RTFNTuple), &checksum,
sizeof(checksum));
1731 const auto sizeAnchor =
sizeof(RTFNTuple) +
sizeof(checksum);
1732 char zipAnchor[RTFNTuple::GetSizePlusChecksum()];
1737 fileSimple.WriteKey(zipAnchor, szZipAnchor,
sizeof(keyBuf), fileSimple.fShared->fControlBlock->fSeekNTuple,
1738 RTFHeader::kBEGIN,
"ROOT::RNTuple", fNTupleName,
"");
1740 assert(szZipAnchor < std::numeric_limits<
decltype(anchorLink.
fLength)>::max());
1741 anchorLink.
fLength =
sizeof(keyBuf);
1749 RTFString strTFile{
"TFile"};
1750 RTFString strFileName{fFileName};
1753 auto &fileSimple = std::get<RImplSimple>(fFile);
1754 fileSimple.fShared->fControlBlock->fHeader = RTFHeader(defaultCompression);
1759 RTFKey keyRoot(RTFHeader::kBEGIN, 0, strTFile, strFileName, strEmpty,
1760 sizeof(RTFDirectory) + strFileName.GetSize() + strEmpty.GetSize() + uuid.GetSize());
1761 std::uint32_t nbytesName = keyRoot.fKeyLen + strFileName.GetSize() + 1;
1762 fileSimple.fShared->fControlBlock->fFileRecord.fNBytesName = nbytesName;
1763 fileSimple.fShared->fControlBlock->fHeader.SetNbytesName(nbytesName);
1765 fileSimple.Write(&keyRoot, keyRoot.GetHeaderSize(), RTFHeader::kBEGIN);
1767 fileSimple.Write(strTFile.GetData(), strTFile.GetSize());
1768 fileSimple.Write(strFileName.GetData(), strFileName.GetSize());
1769 fileSimple.Write(strEmpty.GetData(), strEmpty.GetSize());
1771 fileSimple.Write(strFileName.GetData(), strFileName.GetSize());
1772 fileSimple.Write(strEmpty.GetData(), strEmpty.GetSize());
1774 fileSimple.fShared->fControlBlock->fSeekFileRecord = fileSimple.fShared->fFilePos;
1775 fileSimple.Write(&fileSimple.fShared->fControlBlock->fFileRecord,
1776 fileSimple.fShared->fControlBlock->fFileRecord.GetSize());
1777 fileSimple.Write(&uuid, uuid.GetSize());
1780 RUInt32BE padding{0};
1781 for (
int i = 0; i < 3; ++i)
1782 fileSimple.Write(&padding,
sizeof(padding));
1783 fileSimple.fShared->fKeyOffset = fileSimple.fShared->fFilePos;
T ReadBuffer(TBufferFile *buf)
One of the template functions used to read objects from messages.
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
static size_t ComputeNumChunks(size_t nbytes, size_t maxChunkSize)
static std::uint64_t ReadTFString(std::uint64_t offset, ROOT::Internal::RMiniFileReader &reader, std::string *str)
Reads the TFile string at the given offset.
#define ROOT_VERSION_CODE
#define ClassDefInlineOverride(name, id)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
The RKeyBlob writes an invisible key into a TFile.
bool WasAllocatedInAFreeSlot() const
void Reserve(size_t nbytes, std::uint64_t *seekKey)
Register a new key for a data record of size nbytes.
Read RNTuple data blocks from a TFile container, provided by a RRawFile.
void ReadBuffer(void *buffer, size_t nbytes, std::uint64_t offset)
Reads a given byte range from the file into the provided memory buffer.
RMiniFileReader()=default
void LoadStreamerInfo()
Load the streamer info from the file into the global list of streamer infos.
RResult< RNTuple > GetNTupleProperAtOffset(std::uint64_t payloadOffset, std::uint64_t compSize, std::uint64_t uncompLen)
Loads an RNTuple anchor from a TFile at the given file offset (unzipping it if necessary).
RResult< RNTuple > GetNTupleBare(std::string_view ntupleName)
Used when the file container turns out to be a bare file.
ROOT::RResult< void > TryReadBuffer(void *buffer, size_t nbytes, std::uint64_t offset)
Like ReadBuffer but returns a RResult instead of throwing.
std::uint64_t SearchInDirectory(std::uint64_t &offsetDir, std::string_view keyName, std::string_view typeName)
Searches for a key with the given name and type in the key index of the directory starting at offsetD...
RResult< RNTuple > GetNTuple(std::string_view ntupleName)
Extracts header and footer location for the RNTuple identified by ntupleName.
RResult< RNTuple > GetNTupleProper(std::string_view ntuplePath)
Used when the file turns out to be a TFile container.
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.
Write RNTuple data blocks in a TFile or a bare file container.
std::uint64_t ReserveBlob(size_t nbytes, size_t len, unsigned char keyBuffer[kBlobKeyLen]=nullptr)
Reserves a new record as an RBlob key in the file.
ROOT::Internal::RNTupleLink WriteTFileNTupleKey(int compression)
The only key that will be visible in file->ls() Returns the link to the RNTuple anchor.
void WriteTFileStreamerInfo(int compression)
Write the compressed streamer info record with the description of the RNTuple class.
std::string fNTupleName
The identifier of the RNTuple; A single writer object can only write a single RNTuple but multiple wr...
void WriteTFileKeysList(std::uint64_t anchorSize)
Write the TList with the RNTuple key.
void WriteBareFileSkeleton(int defaultCompression)
For a bare file, which is necessarily written by a C file stream, write file header.
std::uint64_t WriteNTupleHeader(const void *data, size_t nbytes, size_t lenHeader)
Writes the compressed header and registeres its location; lenHeader is the size of the uncompressed h...
static std::uint64_t ReserveBlobKey(T &caller, TFile &file, std::size_t nbytes, std::size_t len, unsigned char keyBuffer[kBlobKeyLen])
static std::unique_ptr< RNTupleFileWriter > Append(std::string_view ntupleName, TDirectory &fileOrDirectory, std::uint64_t maxKeySize, bool isHidden)
The directory parameter can also be a TFile object (TFile inherits from TDirectory).
void WriteTFileFreeList()
Last record in the file.
std::unique_ptr< RNTupleFileWriter > CloneAsHidden(std::string_view ntupleName) const
Creates a new RNTupleFileWriter with the same underlying TDirectory as this but writing to a differen...
void WriteTFileSkeleton(int defaultCompression)
For a TFile container written by a C file stream, write the header and TFile object.
RNTupleFileWriter(std::string_view name, std::uint64_t maxKeySize, bool isHidden)
Private constructor used by all factory methods.
void Seek(std::uint64_t offset)
Seek a simple writer to offset.
ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t fStreamerInfoMap
Set of streamer info records that should be written to the file.
std::uint64_t WriteBlob(const void *data, size_t nbytes, size_t len)
Writes a new record as an RBlob key into the file.
static std::unique_ptr< RNTupleFileWriter > Recreate(std::string_view ntupleName, std::string_view path, EContainerFormat containerFormat, const ROOT::RNTupleWriteOptions &options)
Create or truncate the local file given by path with the new empty RNTuple identified by ntupleName.
void WriteIntoReservedBlob(const void *buffer, size_t nbytes, std::int64_t offset)
Write into a reserved record; the caller is responsible for making sure that the written byte range i...
static constexpr std::size_t kBlobKeyLen
The key length of a blob. It is always a big key (version > 1000) with class name RBlob.
RNTupleLink Commit(int compression=RCompressionSetting::EDefaults::kUseGeneralPurpose)
Writes the RNTuple key to the file so that the header and footer keys can be found.
static void PrepareBlobKey(std::int64_t offset, size_t nbytes, size_t len, unsigned char buffer[kBlobKeyLen])
Prepares buffer for a new record as an RBlob key at offset.
std::uint64_t WriteNTupleFooter(const void *data, size_t nbytes, size_t lenFooter)
Writes the compressed footer and registeres its location; lenFooter is the size of the uncompressed f...
bool fIsHidden
True if this RNTuple's anchor must be stored as a hidden key (this is the case e.g....
void UpdateStreamerInfos(const ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t &streamerInfos)
Ensures that the streamer info records passed as argument are written to the file.
RNTuple fNTupleAnchor
Header and footer location of the ntuple, written on Commit()
EContainerFormat
For testing purposes, RNTuple data can be written into a bare file container instead of a ROOT file.
std::map< Int_t, TVirtualStreamerInfo * > StreamerInfoMap_t
static std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t &val)
static std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer)
The RRawFile provides read-only access to local and remote files.
Base class for all ROOT issued exceptions.
An interface to read from, or write to, a ROOT file, as well as performing other common operations.
std::uint64_t GetNBytesOnStorage() const
void SetType(ELocatorType type)
void SetPosition(std::uint64_t position)
void SetNBytesOnStorage(std::uint64_t nBytesOnStorage)
Common user-tunable settings for storing RNTuples.
std::size_t GetWriteBufferSize() const
std::uint64_t GetMaxKeySize() const
bool GetUseDirectIO() const
std::uint32_t GetCompression() const
Representation of an RNTuple data set in a ROOT file.
std::uint64_t GetLenFooter() const
std::uint64_t GetSeekHeader() const
std::uint16_t GetVersionMajor() const
std::uint64_t GetNBytesFooter() const
std::uint64_t GetNBytesHeader() const
std::uint64_t fMaxKeySize
The maximum size for a TKey payload. Payloads bigger than this size will be written as multiple blobs...
std::uint16_t GetVersionMinor() const
std::uint16_t GetVersionPatch() const
std::uint64_t GetMaxKeySize() const
std::uint64_t GetLenHeader() const
std::uint64_t GetSeekFooter() const
std::uint16_t GetVersionEpoch() const
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
void TagStreamerInfo(TVirtualStreamerInfo *info) override
Mark the classindex of the current file as using this TStreamerInfo.
void SetBufferDisplacement() override
void SetParent(TObject *parent)
Set parent owning this buffer.
void SetBufferOffset(Int_t offset=0)
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0, Bool_t isTransient=kFALSE) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
Describe directory structure in memory.
virtual TFile * GetFile() const
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Int_t Sizeof() const override
Return the size in bytes of the key header structure.
Int_t fVersion
Key version identifier.
Int_t fLeft
Number of bytes left in current segment.
Short_t fKeylen
Number of bytes for the key itself.
Long64_t fSeekKey
Location of object on file.
virtual void Create(Int_t nbytes, TFile *f=nullptr)
Create a TKey object of specified size.
virtual char * GetBuffer() const
TString fClassName
Object Class name.
void Streamer(TBuffer &) override
Stream all objects in the collection to or from the I/O buffer.
void Add(TObject *obj) override
virtual TObjLink * FirstLink() const
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
Describes a persistent version of a class.
void BuildCheck(TFile *file=nullptr, Bool_t load=kTRUE) override
Check if built and consistent with the class dictionary.
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
static TUUID UUIDv4()
Create a UUID version 4 (variant 1) UUID according to RFC 4122.
void FillBuffer(char *&buffer)
Stream UUID into output buffer.
RNTuple CreateAnchor(std::uint16_t versionEpoch, std::uint16_t versionMajor, std::uint16_t versionMinor, std::uint16_t versionPatch, std::uint64_t seekHeader, std::uint64_t nbytesHeader, std::uint64_t lenHeader, std::uint64_t seekFooter, std::uint64_t nbytesFooter, std::uint64_t lenFooter, std::uint64_t maxKeySize)
TFile * GetRFileTFile(RFile &rfile)
Helper templated class for swapping bytes; specializations for N={2,4,8} are provided below.
void Write(const void *buffer, size_t nbytes, std::int64_t offset)
Low-level writing using a TFile.
std::uint64_t ReserveBlobKey(size_t nbytes, size_t len, unsigned char keyBuffer[kBlobKeyLen]=nullptr)
Reserves an RBlob opaque key as data record and returns the offset of the record.
void AllocateBuffers(std::size_t bufferSize)
std::uint64_t WriteKey(const void *buffer, std::size_t nbytes, std::size_t len, std::int64_t offset=-1, std::uint64_t directoryOffset=100, const std::string &className="", const std::string &objectName="", const std::string &title="")
Writes a TKey including the data record, given by buffer, into fFile; returns the file offset to the ...
static constexpr int kBlockAlign
Direct I/O requires that all buffers and write lengths are aligned.
void Write(const void *buffer, size_t nbytes, std::int64_t offset=-1)
Writes bytes in the open stream, either at fFilePos or at the given offset.
static constexpr std::size_t kHeaderBlockSize
During commit, WriteTFileKeysList() updates fNBytesKeys and fSeekKeys of the RTFFile located at fSeek...
std::shared_ptr< RSharedData > fShared
std::uint64_t ReserveBlobKey(std::size_t nbytes, std::size_t len, unsigned char keyBuffer[kBlobKeyLen]=nullptr)
Reserves an RBlob opaque key as data record and returns the offset of the record.
TDirectory * fDirectory
A sub directory in fFile or nullptr if the data is stored in the root directory of the file.
void Write(const void *buffer, size_t nbytes, std::int64_t offset)
Low-level writing using a TFile.
std::uint64_t ReserveBlobKey(size_t nbytes, size_t len, unsigned char keyBuffer[kBlobKeyLen]=nullptr)
Reserves an RBlob opaque key as data record and returns the offset of the record.
std::uint32_t fLength
Uncompressed length of the anchor, including the checksum.
If a TFile container is written by a C stream (simple file), on dataset commit, the file header and t...
std::uint64_t fSeekFileRecord
std::uint64_t fSeekNTuple