49#ifndef R__LITTLE_ENDIAN
52#define R__LITTLE_ENDIAN 1
54#define R__LITTLE_ENDIAN 0
69 std::uint16_t fValBE = 0;
70 static std::uint16_t Swap(std::uint16_t val)
72#if R__LITTLE_ENDIAN == 1
73 return RByteSwap<
sizeof(val)>::bswap(val);
80 RUInt16BE() =
default;
81 explicit RUInt16BE(
const std::uint16_t val) : fValBE(Swap(val)) {}
82 operator std::uint16_t()
const {
return Swap(fValBE); }
83 RUInt16BE &operator=(
const std::uint16_t val)
93 std::uint32_t fValBE = 0;
94 static std::uint32_t Swap(std::uint32_t val)
96#if R__LITTLE_ENDIAN == 1
97 return RByteSwap<
sizeof(val)>::bswap(val);
104 RUInt32BE() =
default;
105 explicit RUInt32BE(
const std::uint32_t val) : fValBE(Swap(val)) {}
106 operator std::uint32_t()
const {
return Swap(fValBE); }
107 RUInt32BE &operator=(
const std::uint32_t val)
117 std::int32_t fValBE = 0;
118 static std::int32_t Swap(std::int32_t val)
120#if R__LITTLE_ENDIAN == 1
121 return RByteSwap<
sizeof(val)>::bswap(val);
128 RInt32BE() =
default;
129 explicit RInt32BE(
const std::int32_t val) : fValBE(Swap(val)) {}
130 operator std::int32_t()
const {
return Swap(fValBE); }
131 RInt32BE &operator=(
const std::int32_t val)
141 std::uint64_t fValBE = 0;
142 static std::uint64_t Swap(std::uint64_t val)
144#if R__LITTLE_ENDIAN == 1
145 return RByteSwap<
sizeof(val)>::bswap(val);
152 RUInt64BE() =
default;
153 explicit RUInt64BE(
const std::uint64_t val) : fValBE(Swap(val)) {}
154 operator std::uint64_t()
const {
return Swap(fValBE); }
155 RUInt64BE &operator=(
const std::uint64_t val)
165 unsigned char fLName{0};
167 RTFString() =
default;
168 RTFString(
const std::string &str)
173 fLName =
static_cast<unsigned char>(str.length());
174 memcpy(fData, str.data(), fLName);
176 std::size_t GetSize()
const
190 auto now = std::chrono::system_clock::now();
191 auto tt = std::chrono::system_clock::to_time_t(
now);
193 fDatetime = (
tm.tm_year + 1900 - 1995) << 26 | (
tm.tm_mon + 1) << 22 |
tm.tm_mday << 17 |
tm.tm_hour << 12 |
194 tm.tm_min << 6 |
tm.tm_sec;
196 explicit RTFDatetime(RUInt32BE val) : fDatetime(val) {}
201 static constexpr unsigned kBigKeyVersion = 1000;
204 RUInt16BE fVersion{4};
205 RUInt32BE fObjLen{0};
206 RTFDatetime fDatetime;
207 RUInt16BE fKeyLen{0};
211 RUInt32BE fSeekKey{0};
212 RUInt32BE fSeekPdir{0};
215 RUInt64BE fSeekKey{0};
216 RUInt64BE fSeekPdir{0};
220 RTFKey() : fInfoLong() {}
227 fVersion = fVersion + kBigKeyVersion;
229 fKeyLen =
static_cast<RUInt16BE
>(GetHeaderSize() +
clName.GetSize() +
objName.GetSize() +
titleName.GetSize());
236 std::uint32_t GetSize()
const
244 std::uint32_t GetHeaderSize()
const
246 if (fVersion >= kBigKeyVersion)
247 return 18 +
sizeof(fInfoLong);
248 return 18 +
sizeof(fInfoShort);
251 std::uint64_t GetSeekKey()
const
253 if (fVersion >= kBigKeyVersion)
254 return fInfoLong.fSeekKey;
255 return fInfoShort.fSeekKey;
261 static constexpr unsigned kBEGIN = 100;
262 static constexpr unsigned kBigHeaderVersion = 1000000;
264 char fMagic[4]{
'r',
'o',
'o',
't'};
271 RUInt32BE fSeekFree{0};
272 RUInt32BE fNbytesFree{0};
274 RUInt32BE fNbytesName{0};
275 unsigned char fUnits{4};
276 RUInt32BE fCompress{0};
277 RUInt32BE fSeekInfo{0};
278 RUInt32BE fNbytesInfo{0};
282 RUInt64BE fSeekFree{0};
283 RUInt32BE fNbytesFree{0};
285 RUInt32BE fNbytesName{0};
286 unsigned char fUnits{8};
287 RUInt32BE fCompress{0};
288 RUInt64BE fSeekInfo{0};
289 RUInt32BE fNbytesInfo{0};
293 RTFHeader() : fInfoShort() {}
298 if (fVersion >= kBigHeaderVersion)
302 std::uint32_t end = fInfoShort.fEND;
303 std::uint32_t
seekFree = fInfoShort.fSeekFree;
304 std::uint32_t
nbytesFree = fInfoShort.fNbytesFree;
305 std::uint32_t
nFree = fInfoShort.fNfree;
306 std::uint32_t
nbytesName = fInfoShort.fNbytesName;
307 std::uint32_t
compress = fInfoShort.fCompress;
308 std::uint32_t
seekInfo = fInfoShort.fSeekInfo;
309 std::uint32_t
nbytesInfo = fInfoShort.fNbytesInfo;
310 fInfoLong.fEND = end;
313 fInfoLong.fNfree =
nFree;
315 fInfoLong.fUnits = 8;
319 fVersion = fVersion + kBigHeaderVersion;
325 return (fVersion >= kBigHeaderVersion) ||
326 (
offset >
static_cast<unsigned int>(std::numeric_limits<std::int32_t>::max()));
329 std::uint32_t GetSize()
const
331 std::uint32_t
sizeHead =
sizeof(fMagic) +
sizeof(fVersion) +
sizeof(fBEGIN);
333 return sizeHead +
sizeof(fInfoLong);
334 return sizeHead +
sizeof(fInfoShort);
337 std::uint64_t GetEnd()
const
340 return fInfoLong.fEND;
341 return fInfoShort.fEND;
348 fInfoLong.fEND =
value;
350 fInfoShort.fEND =
value;
354 std::uint64_t GetSeekFree()
const
357 return fInfoLong.fSeekFree;
358 return fInfoShort.fSeekFree;
365 fInfoLong.fSeekFree =
value;
367 fInfoShort.fSeekFree =
value;
374 fInfoLong.fNbytesFree =
value;
376 fInfoShort.fNbytesFree =
value;
383 fInfoLong.fNbytesName =
value;
385 fInfoShort.fNbytesName =
value;
389 std::uint64_t GetSeekInfo()
const
392 return fInfoLong.fSeekInfo;
393 return fInfoShort.fSeekInfo;
400 fInfoLong.fSeekInfo =
value;
402 fInfoShort.fSeekInfo =
value;
406 std::uint64_t GetNbytesInfo()
const
409 return fInfoLong.fNbytesInfo;
410 return fInfoShort.fNbytesInfo;
416 fInfoLong.fNbytesInfo =
value;
418 fInfoShort.fNbytesInfo =
value;
422 void SetCompression(std::uint32_t
value)
425 fInfoLong.fCompress =
value;
427 fInfoShort.fCompress =
value;
434 static constexpr unsigned kBigFreeEntryVersion = 1000;
436 RUInt16BE fVersion{1};
448 RTFFreeEntry() : fInfoShort() {}
449 void Set(std::uint64_t first, std::uint64_t last)
451 if (last >
static_cast<unsigned int>(std::numeric_limits<std::int32_t>::max())) {
452 fVersion = fVersion + kBigFreeEntryVersion;
453 fInfoLong.fFirst = first;
454 fInfoLong.fLast = last;
456 fInfoShort.fFirst = first;
457 fInfoShort.fLast = last;
460 std::uint32_t GetSize() {
return (fVersion >= kBigFreeEntryVersion) ? 18 : 10; }
466 std::uint32_t GetSize()
const {
return sizeof(RTFKeyList); }
467 explicit RTFKeyList(std::uint32_t
nKeys) : fNKeys(
nKeys) {}
472 static constexpr unsigned kBigFileVersion = 1000;
474 RUInt16BE fClassVersion{5};
477 RUInt32BE fNBytesKeys{0};
478 RUInt32BE fNBytesName{0};
482 RUInt32BE fSeekDir{RTFHeader::kBEGIN};
483 RUInt32BE fSeekParent{0};
484 RUInt32BE fSeekKeys{0};
487 RUInt64BE fSeekDir{RTFHeader::kBEGIN};
488 RUInt64BE fSeekParent{0};
489 RUInt64BE fSeekKeys{0};
493 RTFDirectory() : fInfoShort() {}
496 std::uint32_t GetSize()
const
498 if (fClassVersion >= kBigFileVersion)
499 return sizeof(RTFDirectory);
500 return 18 +
sizeof(fInfoShort);
503 std::uint64_t GetSeekKeys()
const
505 if (fClassVersion >= kBigFileVersion)
506 return fInfoLong.fSeekKeys;
507 return fInfoShort.fSeekKeys;
512 if (
seekKeys >
static_cast<unsigned int>(std::numeric_limits<std::int32_t>::max())) {
513 std::uint32_t
seekDir = fInfoShort.fSeekDir;
514 std::uint32_t
seekParent = fInfoShort.fSeekParent;
518 fClassVersion = fClassVersion + kBigFileVersion;
527 RUInt16BE fVersionClass{1};
528 unsigned char fUUID[16];
533 char *buffer =
reinterpret_cast<char *
>(
this);
534 uuid.FillBuffer(buffer);
535 assert(
reinterpret_cast<RTFUUID *
>(buffer) <= (
this + 1));
537 std::uint32_t GetSize()
const {
return sizeof(RTFUUID); }
546 RUInt32BE fByteCount{0x40000000 | (
sizeof(RTFNTuple) -
sizeof(fByteCount))};
547 RUInt16BE fVersionClass{2};
548 RUInt16BE fVersionEpoch{0};
549 RUInt16BE fVersionMajor{0};
550 RUInt16BE fVersionMinor{0};
551 RUInt16BE fVersionPatch{0};
552 RUInt64BE fSeekHeader{0};
553 RUInt64BE fNBytesHeader{0};
554 RUInt64BE fLenHeader{0};
555 RUInt64BE fSeekFooter{0};
556 RUInt64BE fNBytesFooter{0};
557 RUInt64BE fLenFooter{0};
558 RUInt64BE fMaxKeySize{0};
560 static constexpr std::uint32_t
GetSizePlusChecksum() {
return sizeof(RTFNTuple) +
sizeof(std::uint64_t); }
562 RTFNTuple() =
default;
577 std::uint32_t GetSize()
const {
return sizeof(RTFNTuple); }
579 std::uint32_t
GetOffsetCkData() {
return sizeof(fByteCount) +
sizeof(fVersionClass); }
585struct RBareFileHeader {
586 char fMagic[7]{
'r',
'n',
't',
'u',
'p',
'l',
'e'};
589 RUInt32BE fFormatVersion{1};
590 RUInt32BE fCompress{0};
677 if (std::string(
ident, 4) ==
"root")
686 std::string_view typeName)
699 for (
unsigned int i = 0; i <
nKeys; ++i) {
703 offset += key.GetHeaderSize();
707 if (std::string_view(
name.fData,
name.fLName) != typeName) {
715 return key.GetSeekKey();
757 auto obj =
lnk->GetObject();
788 auto pos = std::string::npos;
795 return R__FAIL(
"no directory named '" + std::string(
directoryName) +
"' in file '" + fRawFile->GetUrl() +
"'");
798 offset = key.GetSeekKey() + key.fKeyLen;
805 return R__FAIL(
"no RNTuple named '" + std::string(
ntupleName) +
"' in file '" + fRawFile->GetUrl() +
"'");
809 offset = key.GetSeekKey() + key.fKeyLen;
813 static_assert(
kMinNTupleSize == RTFNTuple::GetSizePlusChecksum());
815 return R__FAIL(
"invalid anchor size: " + std::to_string(key.fObjLen) +
" < " + std::to_string(
sizeof(RTFNTuple)));
818 const auto objNbytes = key.GetSize() - key.fKeyLen;
849 ckOnDisk =
static_cast<uint64_t
>(*ckOnDiskPtr);
851 return R__FAIL(
"RNTuple anchor checksum mismatch");
869 return R__FAIL(
"expected RNTuple named '" + std::string(
ntupleName) +
"' but instead found '" +
870 std::string(
foundName) +
"' in file '" + fRawFile->GetUrl() +
"'");
880 return R__FAIL(
"RNTuple bare file: anchor checksum mismatch");
895 return R__FAIL(
"invalid read (expected bytes: " + std::to_string(
expected) +
", read: " + std::to_string(
nread) +
900 if (fMaxKeySize == 0 ||
nbytes <= fMaxKeySize) {
908 uint8_t *
bufCur =
reinterpret_cast<uint8_t *
>(buffer);
912 if (
nread != fMaxKeySize)
957 unsigned char buffer[kBlobKeyLen])
984 static_assert(kHeaderBlockSize % kBlockAlign == 0,
"invalid header block size");
985 if (bufferSize % kBlockAlign != 0)
986 throw RException(
R__FAIL(
"Buffer size not a multiple of alignment: " + std::to_string(bufferSize)));
990 fShared = std::make_shared<RSharedData>(
nullptr);
992 fShared->fBlockSize = bufferSize;
993 fShared->fControlBlock = std::make_unique<ROOT::Internal::RTFileControlBlock>();
996 fShared->fHeaderBlock =
static_cast<unsigned char *
>(
::operator new[](kHeaderBlockSize,
blockAlign));
997 memset(fShared->fHeaderBlock, 0, kHeaderBlockSize);
998 fShared->fBlock =
static_cast<unsigned char *
>(
::operator new[](fShared->fBlockSize,
blockAlign));
999 memset(fShared->fBlock, 0, fShared->fBlockSize);
1033 if (shared.fBlockOffset == 0) {
1045 std::size_t
lastBlockSize = shared.fFilePos - shared.fBlockOffset;
1047 if (shared.fDirectIO) {
1058 if (shared.fBlockOffset > 0) {
1079 if ((
offset >= 0) && (
static_cast<std::uint64_t
>(
offset) != shared.fFilePos)) {
1080 shared.fFilePos =
offset;
1092 R__ASSERT(shared.fFilePos >= shared.fBlockOffset);
1095 std::uint64_t
posInBlock = shared.fFilePos % shared.fBlockSize;
1103 retval = fwrite(shared.fBlock, 1, shared.fBlockSize, shared.fFile);
1104 if (
retval != shared.fBlockSize)
1108 memset(shared.fBlock, 0, shared.fBlockSize);
1112 std::size_t blockSize =
nbytes;
1113 if (blockSize > shared.fBlockSize -
posInBlock) {
1117 buffer =
static_cast<const unsigned char *
>(buffer) + blockSize;
1119 shared.fFilePos += blockSize;
1126 const std::string &className,
const std::string &objectName,
1127 const std::string &title)
1132 shared.fKeyOffset =
offset;
1138 Write(&key, key.GetHeaderSize(), shared.fKeyOffset);
1173template <
typename T>
1191 if (
keyBlob.WasAllocatedInAFreeSlot()) {
1205 fDirectory->GetFile()->Seek(
offset);
1206 bool rv = fDirectory->GetFile()->WriteBuffer((
char *)(buffer),
nbytes);
1224 bool rv = file->WriteBuffer((
char *)(buffer),
nbytes);
1250std::unique_ptr<ROOT::Internal::RNTupleFileWriter>
1254 std::string fileName(path);
1255 size_t idxDirSep = fileName.find_last_of(
"\\/");
1268 int fd = open(std::string(path).c_str(), flags, 0666);
1286 auto writer = std::unique_ptr<RNTupleFileWriter>(
1292 writer->fFileName = fileName;
1297 case EContainerFormat::kBare:
1301 default:
R__ASSERT(
false &&
"Internal error: unhandled container format");
1307std::unique_ptr<ROOT::Internal::RNTupleFileWriter>
1313 throw RException(
R__FAIL(
"invalid attempt to add an RNTuple to a directory that is not backed by a file"));
1322std::unique_ptr<ROOT::Internal::RNTupleFileWriter>
1328 rfile.fFile = &file;
1334std::unique_ptr<ROOT::Internal::RNTupleFileWriter>
1337 if (
auto *tfile = std::get_if<RImplTFile>(&fFile)) {
1338 return Append(
ntupleName, *tfile->fDirectory, fNTupleAnchor.fMaxKeySize,
true);
1339 }
else if (
auto *file = std::get_if<RImplSimple>(&fFile)) {
1343 auto writer = std::unique_ptr<RNTupleFileWriter>(
1375 for (
auto [
_,
info] : fStreamerInfoMap)
1381 anchorInfo.fLength = RTFNTuple{}.GetSize() +
sizeof(std::uint64_t);
1384 if (
auto fileProper = std::get_if<RImplTFile>(&fFile)) {
1386 fileProper->fDirectory->WriteObject(&fNTupleAnchor, fNTupleName.c_str());
1388 auto key =
static_cast<TKey *
>(
fileProper->fDirectory->GetListOfKeys()->FindObject(fNTupleName.c_str()));
1390 anchorInfo.fLocator.SetPosition(key->GetSeekKey() + key->GetKeylen());
1391 anchorInfo.fLocator.SetNBytesOnStorage(key->GetNbytes() - key->GetKeylen());
1399 fileProper->fDirectory->GetListOfKeys()->Remove(key);
1401 }
else if (
auto fileRFile = std::get_if<RImplRFile>(&fFile)) {
1405 auto key =
fileRFile->fFile->GetKeyInfo(fNTupleName);
1407 anchorInfo.fLocator.SetPosition(key->GetSeekKey() + key->GetNBytesKey());
1408 anchorInfo.fLocator.SetNBytesOnStorage(key->GetNBytesObj());
1412 auto &
fileSimple = std::get<RImplSimple>(fFile);
1416 anchorInfo.fLocator.SetPosition(shared.fControlBlock->fSeekNTuple);
1431 WriteTFileFreeList();
1434 memcpy(shared.fHeaderBlock, &shared.fControlBlock->fHeader, shared.fControlBlock->fHeader.GetSize());
1435 R__ASSERT(shared.fControlBlock->fSeekFileRecord + shared.fControlBlock->fFileRecord.GetSize() <
1436 RImplSimple::kHeaderBlockSize);
1437 memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekFileRecord, &shared.fControlBlock->fFileRecord,
1438 shared.fControlBlock->fFileRecord.GetSize());
1457 const std::uint64_t
maxKeySize = fNTupleAnchor.fMaxKeySize;
1461 if (
static_cast<std::uint64_t
>(
len) >
static_cast<std::uint64_t
>(std::numeric_limits<std::uint32_t>::max()))
1521 if (
auto *
fileSimple = std::get_if<RImplSimple>(&fFile)) {
1528 }
else if (
auto *
fileProper = std::get_if<RImplTFile>(&fFile)) {
1531 auto &
fileRFile = std::get<RImplRFile>(fFile);
1539 if (
auto *
fileSimple = std::get_if<RImplSimple>(&fFile)) {
1541 }
else if (
auto *
fileProper = std::get_if<RImplTFile>(&fFile)) {
1544 auto &
fileRFile = std::get<RImplRFile>(fFile);
1553 fNTupleAnchor.fNBytesHeader =
nbytes;
1554 fNTupleAnchor.fSeekHeader =
offset;
1562 fNTupleAnchor.fNBytesFooter =
nbytes;
1563 fNTupleAnchor.fSeekFooter =
offset;
1571 auto &
fileSimple = std::get<RImplSimple>(fFile);
1593 for (
auto [
_,
info] : fStreamerInfoMap) {
1606 auto &
fileSimple = std::get<RImplSimple>(fFile);
1623 fileSimple.fShared->fControlBlock->fHeader.GetSeekInfo(), RTFHeader::kBEGIN,
"TList",
1624 "StreamerInfo",
"Doubly linked list");
1626 fileSimple.fShared->fControlBlock->fHeader.GetSeekInfo());
1636 auto &
fileSimple = std::get<RImplSimple>(fFile);
1646 fileSimple.fShared->fControlBlock->fFileRecord.GetSeekKeys());
1656 fileSimple.fShared->fControlBlock->fFileRecord.fNBytesKeys =
1663 auto &
fileSimple = std::get<RImplSimple>(fFile);
1674 fileSimple.fShared->fControlBlock->fHeader.GetSeekFree(), RTFHeader::kBEGIN,
"", fFileName,
"");
1676 fileSimple.fShared->fControlBlock->fHeader.GetSeekFree());
1688 auto &
fileSimple = std::get<RImplSimple>(fFile);
1691 char keyBuf[RTFNTuple::GetSizePlusChecksum()];
1698 char zipAnchor[RTFNTuple::GetSizePlusChecksum()];
1702 RTFHeader::kBEGIN,
"ROOT::RNTuple", fNTupleName,
"");
1712 auto &
fileSimple = std::get<RImplSimple>(fFile);
1735 fileSimple.fShared->fControlBlock->fFileRecord.GetSize());
1740 for (
int i = 0; i < 3; ++i)
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)
#define ROOT_VERSION_CODE
#define ClassDefInlineOverride(name, id)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void 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
An interface to read from, or write to, a ROOT file, as well as performing other common operations.
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.
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()
Attempts to load the streamer info from the file.
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.
Helper class to compress data blocks in the ROOT compression frame format.
static std::size_t Zip(const void *from, std::size_t nbytes, int compression, void *to)
Returns the size of the compressed data, written into the provided output buffer.
Helper class to uncompress data blocks in the ROOT compression frame format.
static void Unzip(const void *from, size_t nbytes, size_t dataLen, void *to)
The nbytes parameter provides the size ls of the from buffer.
Write RNTuple data blocks in a TFile or a bare file container.
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.
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.
std::uint64_t WriteTFileNTupleKey(int compression)
The only key that will be visible in file->ls() Returns the size on disk of the anchor object.
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)
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.
A helper class for serializing and deserialization of the RNTuple binary format.
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.
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 fMaxKeySize
The maximum size for a TKey payload. Payloads bigger than this size will be written as multiple blobs...
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)
Describe directory structure in memory.
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.
TString fClassName
Object Class name.
Wrapper around a TObject so it can be stored in a TList.
Describes a persistent version of a class.
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.
TFile * GetRFileTFile(RFile &rfile)
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)
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.
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.
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