Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::RNTupleParallelWriter Class Reference

A writer to fill an RNTuple from multiple contexts.

Compared to the sequential RNTupleWriter, a parallel writer enables the creation of multiple RNTupleFillContext (see CreateFillContext()). Each fill context prepares independent clusters that are appended to the common RNTuple with internal synchronization. Before destruction, all fill contexts must have flushed their data and been destroyed (or data could be lost!).

For user convenience, CreateFillContext() is thread-safe and may be called from multiple threads in parallel at any time, also after some data has already been written. Internally, the original model is cloned and ownership is passed to a newly created RNTupleFillContext. For that reason, it is recommended to use RNTupleModel::CreateBare when creating the model for parallel writing and avoid the allocation of a useless default REntry per context.

Note that the sequence of independently prepared clusters is indeterminate and therefore entries are only partially ordered: Entries from one context are totally ordered as they were filled. However, there is no orderering with other contexts and the entries may be appended to the RNTuple either before or after other entries written in parallel into other contexts. In addition, two consecutive entries in one fill context can end up separated in the final RNTuple, if they happen to fall onto a cluster boundary and other contexts append more entries before the next cluster is full.

At the moment, the parallel writer does not (yet) support incremental updates of the underlying model. Please refer to RNTupleWriter::CreateModelUpdater if required for your use case.

Definition at line 61 of file RNTupleParallelWriter.hxx.

Public Member Functions

 ~RNTupleParallelWriter ()
 
void CommitDataset ()
 Automatically called by the destructor.
 
std::shared_ptr< RNTupleFillContextCreateFillContext ()
 Create a new RNTupleFillContext that can be used to fill entries and prepare clusters in parallel.
 
void EnableMetrics ()
 
const Experimental::Detail::RNTupleMetricsGetMetrics () const
 

Static Public Member Functions

static std::unique_ptr< RNTupleParallelWriterAppend (std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, TDirectory &fileOrDirectory, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
 Append an RNTuple to the existing file.
 
static std::unique_ptr< RNTupleParallelWriterRecreate (std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
 Recreate a new file and return a writer to write an RNTuple.
 

Private Member Functions

 RNTupleParallelWriter (const RNTupleParallelWriter &)=delete
 
 RNTupleParallelWriter (std::unique_ptr< ROOT::RNTupleModel > model, std::unique_ptr< ROOT::Internal::RPageSink > sink)
 
RNTupleParallelWriteroperator= (const RNTupleParallelWriter &)=delete
 

Private Attributes

std::vector< std::weak_ptr< RNTupleFillContext > > fFillContexts
 List of all created helpers. They must be destroyed before this RNTupleParallelWriter is destructed.
 
Experimental::Detail::RNTupleMetrics fMetrics
 
std::unique_ptr< ROOT::RNTupleModelfModel
 The original RNTupleModel connected to fSink; needs to be destructed before it.
 
std::mutex fMutex
 A global mutex to protect the internal data structures of this object.
 
std::unique_ptr< ROOT::Internal::RPageSinkfSink
 The final RPageSink that represents the synchronization point.
 
std::mutex fSinkMutex
 A mutex to synchronize the final page sink.
 

#include <ROOT/RNTupleParallelWriter.hxx>

Constructor & Destructor Documentation

◆ RNTupleParallelWriter() [1/2]

ROOT::RNTupleParallelWriter::RNTupleParallelWriter ( std::unique_ptr< ROOT::RNTupleModel > model,
std::unique_ptr< ROOT::Internal::RPageSink > sink )
private

Definition at line 120 of file RNTupleParallelWriter.cxx.

◆ RNTupleParallelWriter() [2/2]

ROOT::RNTupleParallelWriter::RNTupleParallelWriter ( const RNTupleParallelWriter & )
privatedelete

◆ ~RNTupleParallelWriter()

ROOT::RNTupleParallelWriter::~RNTupleParallelWriter ( )

Definition at line 132 of file RNTupleParallelWriter.cxx.

Member Function Documentation

◆ Append()

std::unique_ptr< ROOT::RNTupleParallelWriter > ROOT::RNTupleParallelWriter::Append ( std::unique_ptr< ROOT::RNTupleModel > model,
std::string_view ntupleName,
TDirectory & fileOrDirectory,
const ROOT::RNTupleWriteOptions & options = ROOT::RNTupleWriteOptions() )
static

Append an RNTuple to the existing file.

While the writer synchronizes between multiple fill contexts created from the same writer, there is no synchronization with other writers or other clients that write into the same file. The caller must ensure that the underlying file is not be accessed while data is filled into any created context. To improve performance, it is allowed to use special methods that are guaranteed to not interact with the underlying file, such as RNTupleFillContext::FillNoFlush().

Definition at line 172 of file RNTupleParallelWriter.cxx.

◆ CommitDataset()

void ROOT::RNTupleParallelWriter::CommitDataset ( )

Automatically called by the destructor.

Definition at line 141 of file RNTupleParallelWriter.cxx.

◆ CreateFillContext()

std::shared_ptr< ROOT::RNTupleFillContext > ROOT::RNTupleParallelWriter::CreateFillContext ( )

Create a new RNTupleFillContext that can be used to fill entries and prepare clusters in parallel.

This method is thread-safe and may be called from multiple threads in parallel at any time, also after some data has already been written.

Note that all fill contexts must be destroyed before CommitDataset() is called.

Definition at line 194 of file RNTupleParallelWriter.cxx.

◆ EnableMetrics()

void ROOT::RNTupleParallelWriter::EnableMetrics ( )
inline

Definition at line 107 of file RNTupleParallelWriter.hxx.

◆ GetMetrics()

const Experimental::Detail::RNTupleMetrics & ROOT::RNTupleParallelWriter::GetMetrics ( ) const
inline

Definition at line 108 of file RNTupleParallelWriter.hxx.

◆ operator=()

RNTupleParallelWriter & ROOT::RNTupleParallelWriter::operator= ( const RNTupleParallelWriter & )
privatedelete

◆ Recreate()

std::unique_ptr< ROOT::RNTupleParallelWriter > ROOT::RNTupleParallelWriter::Recreate ( std::unique_ptr< ROOT::RNTupleModel > model,
std::string_view ntupleName,
std::string_view storage,
const ROOT::RNTupleWriteOptions & options = ROOT::RNTupleWriteOptions() )
static

Recreate a new file and return a writer to write an RNTuple.

Definition at line 159 of file RNTupleParallelWriter.cxx.

Member Data Documentation

◆ fFillContexts

std::vector<std::weak_ptr<RNTupleFillContext> > ROOT::RNTupleParallelWriter::fFillContexts
private

List of all created helpers. They must be destroyed before this RNTupleParallelWriter is destructed.

Definition at line 73 of file RNTupleParallelWriter.hxx.

◆ fMetrics

Experimental::Detail::RNTupleMetrics ROOT::RNTupleParallelWriter::fMetrics
private

Definition at line 71 of file RNTupleParallelWriter.hxx.

◆ fModel

std::unique_ptr<ROOT::RNTupleModel> ROOT::RNTupleParallelWriter::fModel
private

The original RNTupleModel connected to fSink; needs to be destructed before it.

Definition at line 70 of file RNTupleParallelWriter.hxx.

◆ fMutex

std::mutex ROOT::RNTupleParallelWriter::fMutex
private

A global mutex to protect the internal data structures of this object.

Definition at line 64 of file RNTupleParallelWriter.hxx.

◆ fSink

std::unique_ptr<ROOT::Internal::RPageSink> ROOT::RNTupleParallelWriter::fSink
private

The final RPageSink that represents the synchronization point.

Definition at line 68 of file RNTupleParallelWriter.hxx.

◆ fSinkMutex

std::mutex ROOT::RNTupleParallelWriter::fSinkMutex
private

A mutex to synchronize the final page sink.

Definition at line 66 of file RNTupleParallelWriter.hxx.

Libraries for ROOT::RNTupleParallelWriter:

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