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 if (classVersion < 4)
34 throw RException(R__FAIL("unsupported RNTuple pre-release"));
35
36 // Strip class version and the fChecksum member from checksum calculation
37 const UInt_t lenStrip = sizeof(fChecksum) + sizeof(Version_t);
38 if (bcnt < lenStrip)
39 throw RException(R__FAIL("invalid anchor byte count: " + std::to_string(bcnt)));
40 auto lenCkData = bcnt - lenStrip;
41 // Skip byte count and class version
42 auto offCkData = offClassBuf + sizeof(UInt_t) + sizeof(Version_t);
43 auto checksum = XXH3_64bits(buf.Buffer() + offCkData, lenCkData);
44
45 buf.ReadClassBuffer(RNTuple::Class(), this, classVersion, offClassBuf, bcnt);
46
47 if (checksum != fChecksum)
48 throw RException(R__FAIL("checksum mismatch in RNTuple anchor"));
49
50 R__ASSERT(buf.GetParent() && buf.GetParent()->InheritsFrom("TFile"));
51 fFile = static_cast<TFile *>(buf.GetParent());
52 } else {
53 auto offBcnt = buf.WriteVersion(RNTuple::Class(), kTRUE /* useBcnt */);
54 auto offCkData = buf.GetCurrent() - buf.Buffer();
55 buf << fVersionEpoch;
56 buf << fVersionMajor;
57 buf << fVersionMinor;
58 buf << fVersionPatch;
59 buf << fSeekHeader;
60 buf << fNBytesHeader;
61 buf << fLenHeader;
62 buf << fSeekFooter;
63 buf << fNBytesFooter;
64 buf << fLenFooter;
65 fChecksum = XXH3_64bits(buf.Buffer() + offCkData, buf.Length() - offCkData);
66 buf << fChecksum;
67 buf.SetByteCount(offBcnt, kTRUE /* packInVersion */);
68 }
69}
#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
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define R__ASSERT(e)
Definition TError.h:118
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
std::uint16_t fVersionMajor
Changing the major version indicates forward incompatible changes; such changes should correspond to ...
Definition RNTuple.hxx:79
std::uint64_t fChecksum
The xxhash3 checksum of the serialized other members of the struct (excluding byte count and class ve...
Definition RNTuple.hxx:99
std::uint64_t fSeekFooter
The file offset of the footer excluding the TKey part.
Definition RNTuple.hxx:91
std::uint16_t fVersionMinor
Changing the minor version indicates new optional fields added to the RNTuple meta-data.
Definition RNTuple.hxx:81
std::uint16_t fVersionEpoch
Version of the RNTuple binary format that the writer supports (see specification).
Definition RNTuple.hxx:75
std::uint64_t fNBytesFooter
The size of the compressed ntuple footer.
Definition RNTuple.hxx:93
std::uint64_t fLenFooter
The size of the uncompressed ntuple footer.
Definition RNTuple.hxx:95
void Streamer(TBuffer &)
Definition RNTuple.cxx:27
TFile * fFile
! The file from which the ntuple was streamed, registered in the custom streamer
Definition RNTuple.hxx:101
std::uint64_t fLenHeader
The size of the uncompressed ntuple header.
Definition RNTuple.hxx:89
std::uint64_t fNBytesHeader
The size of the compressed ntuple header.
Definition RNTuple.hxx:87
std::uint16_t fVersionPatch
Changing the patch version indicates new backported features from newer binary format versions.
Definition RNTuple.hxx:83
static TClass * Class()
std::uint64_t fSeekHeader
The file offset of the header excluding the TKey part.
Definition RNTuple.hxx:85
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
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition TBuffer.cxx:262
char * GetCurrent() const
Definition TBuffer.h:97
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=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:525