Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RNTuple.cxx
Go to the documentation of this file.
1/// \file RNTuple.cxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \date 2023-09-19
4
5/*************************************************************************
6 * Copyright (C) 1995-2023, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include <ROOT/RError.hxx>
14#include <ROOT/RNTuple.hxx>
15#include <ROOT/RPageStorage.hxx>
17
18#include <TBuffer.h>
19#include <TError.h>
20#include <TFile.h>
21
22#include <xxhash.h>
23
25{
26 if (buf.IsReading()) {
27 // Skip byte count and class version
28 auto offCkData = buf.Length() + sizeof(UInt_t) + sizeof(Version_t);
30 std::uint64_t expectedChecksum = XXH3_64bits(buf.Buffer() + offCkData, buf.Length() - offCkData);
31
32 std::uint64_t onDiskChecksum;
33 if (static_cast<std::size_t>(buf.BufferSize()) < buf.Length() + sizeof(onDiskChecksum))
34 throw RException(R__FAIL("the buffer containing RNTuple is too small to contain the checksum!"));
35 buf >> onDiskChecksum;
36
37 if (expectedChecksum != onDiskChecksum)
38 throw RException(R__FAIL("checksum mismatch in RNTuple anchor"));
39
40 R__ASSERT(buf.GetParent() && buf.GetParent()->InheritsFrom("TFile"));
41 fFile = static_cast<TFile *>(buf.GetParent());
42 } else {
43 auto offCkData = buf.Length() + sizeof(UInt_t) + sizeof(Version_t);
45 std::uint64_t checksum = XXH3_64bits(buf.Buffer() + offCkData, buf.Length() - offCkData);
46 buf << checksum;
47 }
48}
49
51ROOT::Internal::CreateAnchor(std::uint16_t versionEpoch, std::uint16_t versionMajor, std::uint16_t versionMinor,
52 std::uint16_t versionPatch, std::uint64_t seekHeader, std::uint64_t nbytesHeader,
53 std::uint64_t lenHeader, std::uint64_t seekFooter, std::uint64_t nbytesFooter,
54 std::uint64_t lenFooter, std::uint64_t maxKeySize)
55{
56 RNTuple ntuple;
57 ntuple.fVersionEpoch = versionEpoch;
58 ntuple.fVersionMajor = versionMajor;
59 ntuple.fVersionMinor = versionMinor;
60 ntuple.fVersionPatch = versionPatch;
61 ntuple.fSeekHeader = seekHeader;
62 ntuple.fNBytesHeader = nbytesHeader;
63 ntuple.fLenHeader = lenHeader;
64 ntuple.fSeekFooter = seekFooter;
65 ntuple.fNBytesFooter = nbytesFooter;
66 ntuple.fLenFooter = lenFooter;
67 ntuple.fMaxKeySize = maxKeySize;
68 return ntuple;
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:299
short Version_t
Class version identifier (short).
Definition RtypesCore.h:79
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
#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:67
void Streamer(TBuffer &)
Definition RNTuple.cxx:24
static TClass * Class()
TFile * fFile
! The file from which the ntuple was streamed, registered in the custom streamer
Definition RNTuple.hxx:122
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition TBuffer.cxx:261
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 file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
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:51