Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RNTupleFileWriter Class Reference

Write RNTuple data blocks in a TFile or a bare file container.

The writer can create a new TFile container for an RNTuple or add an RNTuple to an existing TFile. Creating a single RNTuple in a new TFile container can be done with a C file stream without a TFile class. Updating an existing TFile requires a proper TFile object. Also, writing a remote file requires a proper TFile object. A stand-alone version of RNTuple can remove the TFile based writer.

Definition at line 119 of file RMiniFile.hxx.

Classes

struct  RImplRFile
struct  RImplSimple
struct  RImplTFile

Public Types

enum class  EContainerFormat { kTFile , kBare }
 For testing purposes, RNTuple data can be written into a bare file container instead of a ROOT file. More...

Public Member Functions

 RNTupleFileWriter (const RNTupleFileWriter &other)=delete
 RNTupleFileWriter (RNTupleFileWriter &&other)=delete
 ~RNTupleFileWriter ()
std::unique_ptr< RNTupleFileWriterCloneAsHidden (std::string_view ntupleName) const
 Creates a new RNTupleFileWriter with the same underlying TDirectory as this but writing to a different RNTuple named ntupleName.
RNTupleLink Commit (int compression=RCompressionSetting::EDefaults::kUseGeneralPurpose)
 Writes the RNTuple key to the file so that the header and footer keys can be found.
std::string_view GetNTupleName () const
RNTupleFileWriteroperator= (const RNTupleFileWriter &other)=delete
RNTupleFileWriteroperator= (RNTupleFileWriter &&other)=delete
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 Seek (std::uint64_t offset)
 Seek a simple writer to offset.
void UpdateStreamerInfos (const ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t &streamerInfos)
 Ensures that the streamer info records passed as argument are 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.
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 is in the previously reserved key.
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 footer.
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 header.

Static Public Member Functions

static std::unique_ptr< RNTupleFileWriterAppend (std::string_view ntupleName, ROOT::Experimental::RFile &file, std::string_view dirPath, std::uint64_t maxKeySize)
static std::unique_ptr< RNTupleFileWriterAppend (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).
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.
static std::unique_ptr< RNTupleFileWriterRecreate (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.

Static Public Attributes

static constexpr std::size_t kBlobKeyLen = 42
 The key length of a blob. It is always a big key (version > 1000) with class name RBlob.

Private Types

using FileType_t = std::variant<RImplSimple, RImplTFile, RImplRFile>
 RImplSimple: for simple use cases, survives without libRIO dependency RImplTFile: for updating existing files and for storing more than just an RNTuple in the file RImplRFile: like RImplTFile but using RFile instead of TFile.

Private Member Functions

 RNTupleFileWriter (std::string_view name, std::uint64_t maxKeySize, bool isHidden)
void WriteBareFileSkeleton (int defaultCompression)
 For a bare file, which is necessarily written by a C file stream, write file header.
void WriteTFileFreeList ()
 Last record in the file.
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 WriteTFileSkeleton (int defaultCompression)
 For a TFile container written by a C file stream, write the header and TFile object.
void WriteTFileStreamerInfo (int compression)
 Write the compressed streamer info record with the description of the RNTuple class.

Static Private Member Functions

template<typename T>
static std::uint64_t ReserveBlobKey (T &caller, TFile &file, std::size_t nbytes, std::size_t len, unsigned char keyBuffer[kBlobKeyLen])

Private Attributes

FileType_t fFile
std::string fFileName
 The file name without parent directory; only required when writing with a C file stream.
bool fIsBare = false
 A simple file can either be written as TFile container or as NTuple bare file.
bool fIsHidden = false
 True if this RNTuple's anchor must be stored as a hidden key (this is the case e.g. for attribute RNTuples).
RNTuple fNTupleAnchor
 Header and footer location of the ntuple, written on Commit().
std::string fNTupleName
 The identifier of the RNTuple; A single writer object can only write a single RNTuple but multiple writers can operate on the same file if (and only if) they use a proper TFile object for writing.
ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t fStreamerInfoMap
 Set of streamer info records that should be written to the file.

#include <ROOT/RMiniFile.hxx>

Member Typedef Documentation

◆ FileType_t

RImplSimple: for simple use cases, survives without libRIO dependency RImplTFile: for updating existing files and for storing more than just an RNTuple in the file RImplRFile: like RImplTFile but using RFile instead of TFile.

Definition at line 207 of file RMiniFile.hxx.

Member Enumeration Documentation

◆ EContainerFormat

For testing purposes, RNTuple data can be written into a bare file container instead of a ROOT file.

Enumerator
kTFile 
kBare 

Definition at line 243 of file RMiniFile.hxx.

Constructor & Destructor Documentation

◆ RNTupleFileWriter() [1/3]

ROOT::Internal::RNTupleFileWriter::RNTupleFileWriter ( std::string_view name,
std::uint64_t maxKeySize,
bool isHidden )
explicitprivate

Definition at line 1224 of file RMiniFile.cxx.

◆ RNTupleFileWriter() [2/3]

◆ RNTupleFileWriter() [3/3]

◆ ~RNTupleFileWriter()

Member Function Documentation

◆ Append() [1/2]

std::unique_ptr< ROOT::Internal::RNTupleFileWriter > ROOT::Internal::RNTupleFileWriter::Append ( std::string_view ntupleName,
ROOT::Experimental::RFile & file,
std::string_view dirPath,
std::uint64_t maxKeySize )
static

Definition at line 1309 of file RMiniFile.cxx.

◆ Append() [2/2]

std::unique_ptr< ROOT::Internal::RNTupleFileWriter > ROOT::Internal::RNTupleFileWriter::Append ( std::string_view ntupleName,
TDirectory & fileOrDirectory,
std::uint64_t maxKeySize,
bool isHidden )
static

The directory parameter can also be a TFile object (TFile inherits from TDirectory).

Definition at line 1294 of file RMiniFile.cxx.

◆ CloneAsHidden()

std::unique_ptr< ROOT::Internal::RNTupleFileWriter > ROOT::Internal::RNTupleFileWriter::CloneAsHidden ( std::string_view ntupleName) const

Creates a new RNTupleFileWriter with the same underlying TDirectory as this but writing to a different RNTuple named ntupleName.

Only one of the two writers can safely write to the file at the same time. The RNTuple written by this cloned writer will be stored in a hidden key (this is a convenient assumption we make now since this method is only used to create attribute RNTuples). This method is currently only supported for TFile-based Writers and will throw an exception if that's not the case.

Definition at line 1321 of file RMiniFile.cxx.

◆ Commit()

ROOT::Internal::RNTupleLink ROOT::Internal::RNTupleFileWriter::Commit ( int compression = RCompressionSetting::EDefaults::kUseGeneralPurpose)

Writes the RNTuple key to the file so that the header and footer keys can be found.

Returns
information about the committed anchor.

Definition at line 1346 of file RMiniFile.cxx.

◆ GetNTupleName()

std::string_view ROOT::Internal::RNTupleFileWriter::GetNTupleName ( ) const
inline

Definition at line 302 of file RMiniFile.hxx.

◆ operator=() [1/2]

RNTupleFileWriter & ROOT::Internal::RNTupleFileWriter::operator= ( const RNTupleFileWriter & other)
delete

◆ operator=() [2/2]

RNTupleFileWriter & ROOT::Internal::RNTupleFileWriter::operator= ( RNTupleFileWriter && other)
delete

◆ PrepareBlobKey()

void ROOT::Internal::RNTupleFileWriter::PrepareBlobKey ( std::int64_t offset,
size_t nbytes,
size_t len,
unsigned char buffer[kBlobKeyLen] )
static

Prepares buffer for a new record as an RBlob key at offset.

Prepare a blob key in the provided buffer, which must provide space for kBlobKeyLen bytes.

(Note that the array type is purely documentation, the argument is actually just a pointer.)

Note that the array type is purely documentation, the argument is actually just a pointer.

Definition at line 957 of file RMiniFile.cxx.

◆ Recreate()

std::unique_ptr< ROOT::Internal::RNTupleFileWriter > ROOT::Internal::RNTupleFileWriter::Recreate ( std::string_view ntupleName,
std::string_view path,
EContainerFormat containerFormat,
const ROOT::RNTupleWriteOptions & options )
static

Create or truncate the local file given by path with the new empty RNTuple identified by ntupleName.

Uses a C stream for writing

Definition at line 1237 of file RMiniFile.cxx.

◆ ReserveBlob()

std::uint64_t ROOT::Internal::RNTupleFileWriter::ReserveBlob ( size_t nbytes,
size_t len,
unsigned char keyBuffer[kBlobKeyLen] = nullptr )

Reserves a new record as an RBlob key in the file.

If keyBuffer is specified, it must be written before the returned offset. (Note that the array type is purely documentation, the argument is actually just a pointer.)

Definition at line 1492 of file RMiniFile.cxx.

◆ ReserveBlobKey()

template<typename T>
std::uint64_t ROOT::Internal::RNTupleFileWriter::ReserveBlobKey ( T & caller,
TFile & file,
std::size_t nbytes,
std::size_t len,
unsigned char keyBuffer[kBlobKeyLen] )
staticprivate

Definition at line 1159 of file RMiniFile.cxx.

◆ Seek()

void ROOT::Internal::RNTupleFileWriter::Seek ( std::uint64_t offset)

Seek a simple writer to offset.

Note that previous data is not flushed immediately, but only by the next write (if necessary).

Definition at line 1330 of file RMiniFile.cxx.

◆ UpdateStreamerInfos()

Ensures that the streamer info records passed as argument are written to the file.

Definition at line 1341 of file RMiniFile.cxx.

◆ WriteBareFileSkeleton()

For a bare file, which is necessarily written by a C file stream, write file header.

Definition at line 1544 of file RMiniFile.cxx.

◆ WriteBlob()

std::uint64_t ROOT::Internal::RNTupleFileWriter::WriteBlob ( const void * data,
size_t nbytes,
size_t len )

Writes a new record as an RBlob key into the file.

Definition at line 1426 of file RMiniFile.cxx.

◆ WriteIntoReservedBlob()

void ROOT::Internal::RNTupleFileWriter::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 is in the previously reserved key.

Definition at line 1514 of file RMiniFile.cxx.

◆ WriteNTupleFooter()

std::uint64_t ROOT::Internal::RNTupleFileWriter::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 footer.

Definition at line 1535 of file RMiniFile.cxx.

◆ WriteNTupleHeader()

std::uint64_t ROOT::Internal::RNTupleFileWriter::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 header.

Definition at line 1526 of file RMiniFile.cxx.

◆ WriteTFileFreeList()

Last record in the file.

Definition at line 1636 of file RMiniFile.cxx.

◆ WriteTFileKeysList()

void ROOT::Internal::RNTupleFileWriter::WriteTFileKeysList ( std::uint64_t anchorSize)
private

Write the TList with the RNTuple key.

Definition at line 1606 of file RMiniFile.cxx.

◆ WriteTFileNTupleKey()

std::uint64_t ROOT::Internal::RNTupleFileWriter::WriteTFileNTupleKey ( int compression)
private

The only key that will be visible in file->ls() Returns the size on disk of the anchor object.

Definition at line 1654 of file RMiniFile.cxx.

◆ WriteTFileSkeleton()

void ROOT::Internal::RNTupleFileWriter::WriteTFileSkeleton ( int defaultCompression)
private

For a TFile container written by a C file stream, write the header and TFile object.

Definition at line 1680 of file RMiniFile.cxx.

◆ WriteTFileStreamerInfo()

Write the compressed streamer info record with the description of the RNTuple class.

Definition at line 1562 of file RMiniFile.cxx.

Member Data Documentation

◆ fFile

◆ fFileName

The file name without parent directory; only required when writing with a C file stream.

Definition at line 218 of file RMiniFile.hxx.

◆ fIsBare

A simple file can either be written as TFile container or as NTuple bare file.

Definition at line 211 of file RMiniFile.hxx.

◆ fIsHidden

True if this RNTuple's anchor must be stored as a hidden key (this is the case e.g. for attribute RNTuples).

Definition at line 213 of file RMiniFile.hxx.

◆ fNTupleAnchor

Header and footer location of the ntuple, written on Commit().

Definition at line 220 of file RMiniFile.hxx.

◆ fNTupleName

The identifier of the RNTuple; A single writer object can only write a single RNTuple but multiple writers can operate on the same file if (and only if) they use a proper TFile object for writing.

Definition at line 216 of file RMiniFile.hxx.

◆ fStreamerInfoMap

Set of streamer info records that should be written to the file.

The RNTuple class description is always present.

Definition at line 223 of file RMiniFile.hxx.

◆ kBlobKeyLen

std::size_t ROOT::Internal::RNTupleFileWriter::kBlobKeyLen = 42
staticconstexpr

The key length of a blob. It is always a big key (version > 1000) with class name RBlob.

Definition at line 122 of file RMiniFile.hxx.


The documentation for this class was generated from the following files: