Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTuple.cxx
Go to the documentation of this file.
1/// \file RNTuple.cxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2023-09-19
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2023, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#include <ROOT/RError.hxx>
17#include <ROOT/RNTuple.hxx>
18#include <ROOT/RPageStorage.hxx>
20
21#include <TBuffer.h>
22#include <TError.h>
23#include <TFile.h>
24
25#include <xxhash.h>
26
28{
29 if (buf.IsReading()) {
30 UInt_t offClassBuf;
31 UInt_t bcnt;
32 auto classVersion = buf.ReadVersion(&offClassBuf, &bcnt);
33
34 // Strip class version from checksum calculation
35 UInt_t lenStrip = sizeof(Version_t);
36
37 if (bcnt < lenStrip)
38 throw Experimental::RException(R__FAIL("invalid anchor byte count: " + std::to_string(bcnt)));
39
40 auto lenCkData = bcnt - lenStrip;
41 // Skip byte count and class version
42 auto offCkData = offClassBuf + sizeof(UInt_t) + sizeof(Version_t);
43 auto expectedChecksum = XXH3_64bits(buf.Buffer() + offCkData, lenCkData);
44
45 std::uint64_t onDiskChecksum;
46 buf.ReadClassBuffer(RNTuple::Class(), this, classVersion, offClassBuf, bcnt);
47 if (static_cast<std::size_t>(buf.BufferSize()) < buf.Length() + sizeof(onDiskChecksum))
48 throw Experimental::RException(R__FAIL("the buffer containing RNTuple is too small to contain the checksum!"));
49 buf >> onDiskChecksum;
50
51 if (expectedChecksum != onDiskChecksum)
52 throw Experimental::RException(R__FAIL("checksum mismatch in RNTuple anchor"));
53
54 R__ASSERT(buf.GetParent() && buf.GetParent()->InheritsFrom("TFile"));
55 fFile = static_cast<TFile *>(buf.GetParent());
56 } else {
57 auto offCkData = buf.Length() + sizeof(UInt_t) + sizeof(Version_t);
59 std::uint64_t checksum = XXH3_64bits(buf.Buffer() + offCkData, buf.Length() - offCkData);
60 buf << checksum;
61 }
62}
63
64ROOT::RNTuple ROOT::Experimental::Internal::CreateAnchor(std::uint16_t versionEpoch, std::uint16_t versionMajor,
65 std::uint16_t versionMinor, std::uint16_t versionPatch,
66 std::uint64_t seekHeader, std::uint64_t nbytesHeader,
67 std::uint64_t lenHeader, std::uint64_t seekFooter,
68 std::uint64_t nbytesFooter, std::uint64_t lenFooter,
69 std::uint64_t maxKeySize)
70{
71 RNTuple ntuple;
72 ntuple.fVersionEpoch = versionEpoch;
73 ntuple.fVersionMajor = versionMajor;
74 ntuple.fVersionMinor = versionMinor;
75 ntuple.fVersionPatch = versionPatch;
76 ntuple.fSeekHeader = seekHeader;
77 ntuple.fNBytesHeader = nbytesHeader;
78 ntuple.fLenHeader = lenHeader;
79 ntuple.fSeekFooter = seekFooter;
80 ntuple.fNBytesFooter = nbytesFooter;
81 ntuple.fLenFooter = lenFooter;
82 ntuple.fMaxKeySize = maxKeySize;
83 return ntuple;
84}
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:290
short Version_t
Definition RtypesCore.h:65
unsigned int UInt_t
Definition RtypesCore.h:46
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
Representation of an RNTuple data set in a ROOT file.
Definition RNTuple.hxx:69
std::uint64_t fSeekFooter
The file offset of the footer excluding the TKey part.
Definition RNTuple.hxx:103
std::uint64_t fNBytesFooter
The size of the compressed ntuple footer.
Definition RNTuple.hxx:105
void Streamer(TBuffer &)
Definition RNTuple.cxx:27
std::uint16_t fVersionMinor
Changing the minor version indicates new optional fields added to the RNTuple meta-data.
Definition RNTuple.hxx:93
std::uint64_t fSeekHeader
The file offset of the header excluding the TKey part.
Definition RNTuple.hxx:97
std::uint64_t fMaxKeySize
The maximum size for a TKey payload. Payloads bigger than this size will be written as multiple blobs...
Definition RNTuple.hxx:109
std::uint64_t fNBytesHeader
The size of the compressed ntuple header.
Definition RNTuple.hxx:99
std::uint64_t fLenHeader
The size of the uncompressed ntuple header.
Definition RNTuple.hxx:101
std::uint64_t fLenFooter
The size of the uncompressed ntuple footer.
Definition RNTuple.hxx:107
std::uint16_t fVersionPatch
Changing the patch version indicates new backported features from newer binary format versions.
Definition RNTuple.hxx:95
static TClass * Class()
TFile * fFile
! The file from which the ntuple was streamed, registered in the custom streamer
Definition RNTuple.hxx:111
std::uint16_t fVersionMajor
Changing the major version indicates forward incompatible changes; such changes should correspond to ...
Definition RNTuple.hxx:91
std::uint16_t fVersionEpoch
Version of the RNTuple binary format that the writer supports (see specification).
Definition RNTuple.hxx:87
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition TBuffer.cxx:262
Int_t BufferSize() const
Definition TBuffer.h:98
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Int_t Length() const
Definition TBuffer.h:100
char * Buffer() const
Definition TBuffer.h:96
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:530
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)
Definition RNTuple.cxx:64