14#ifndef ROOT_RNTupleWriter
15#define ROOT_RNTupleWriter
38class RNTupleWriteOptions;
40namespace Experimental {
41class RNTupleAttrSetWriterHandle;
51std::unique_ptr<RNTupleWriter>
59std::unique_ptr<RNTupleWriter>
85auto model = ROOT::RNTupleModel::Create();
86// Define the schema by adding Fields to the model.
87// MakeField returns a shared_ptr to the value to be written (in this case, a shared_ptr<int>)
88auto pFoo = model->MakeField<int>("foo");
91auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "myNTuple", "some/file.root");
94for (int i = 0; i < 10; ++i) {
95 // Assign the value you want to each RNTuple Field (in this case there is only one Field "foo").
98 // Fill() writes the entire entry to the RNTuple.
99 // After calling Fill() you can safely write another value into `pFoo` knowing that the previous one was
104// On destruction, the writer will flush the written data to disk.
107The caller has to make sure that the data that gets filled into an RNTuple is not modified for the time of the
108Fill() call. The Fill call serializes the C++ object into the column format and
109writes data into the corresponding column page buffers.
111The actual writing of the buffers to storage is deferred and can be triggered by FlushCluster() or by
112destructing the writer.
114On I/O errors, a ROOT::RException is thrown.
120 friend std::unique_ptr<RNTupleWriter>
122 friend std::unique_ptr<RNTupleWriter>
134 RNTupleWriter(std::unique_ptr<ROOT::RNTupleModel> model, std::unique_ptr<Internal::RPageSink>
sink);
145 static std::unique_ptr<RNTupleWriter>
Create(std::unique_ptr<ROOT::RNTupleModel> model,
146 std::unique_ptr<Internal::RPageSink>
sink,
163 static std::unique_ptr<RNTupleWriter>
168 static std::unique_ptr<RNTupleWriter>
176 static std::unique_ptr<RNTupleWriter>
Append(std::unique_ptr<ROOT::RNTupleModel> model, std::string_view
ntupleName,
266 return std::make_unique<ROOT::RNTupleModel::RUpdater>(*
this);
A container of const raw pointers, corresponding to a row in the data set.
A collection of Counter objects with a name, a unit, and a description.
An interface to read from, or write to, a ROOT file, as well as performing other common operations.
Non-owning handle to an RNTupleAttrSetWriter.
Class used to write an RNTupleAttrSet in the context of an RNTupleWriter.
Abstract interface to write data into an ntuple.
The REntry is a collection of values in an RNTuple corresponding to a complete row in the data set.
A context for filling entries (data) into clusters of an RNTuple.
void FlushCluster()
Flush so far filled entries to storage.
ROOT::NTupleSize_t GetLastFlushed() const
Return the entry number that was last flushed in a cluster.
ROOT::NTupleSize_t GetNEntries() const
Return the number of entries filled so far.
void FlushColumns()
Flush column data, preparing for CommitCluster or to reduce memory usage.
std::unique_ptr< ROOT::REntry > CreateEntry() const
std::unique_ptr< ROOT::Detail::RRawPtrWriteEntry > CreateRawPtrWriteEntry() const
std::unique_ptr< ROOT::RNTupleModel > fModel
Needs to be destructed before fSink.
std::unique_ptr< ROOT::Internal::RPageSink > fSink
void FillNoFlush(ROOT::REntry &entry, ROOT::RNTupleFillStatus &status)
Fill an entry into this context, but don't commit the cluster.
std::size_t Fill(ROOT::REntry &entry)
Fill an entry into this context.
A status object after filling an entry.
A model is usually immutable after passing it to an RNTupleWriter.
The RNTupleModel encapulates the schema of an RNTuple.
Common user-tunable settings for storing RNTuples.
An RNTuple that gets filled with entries (data) and writes them to storage.
std::unique_ptr< ROOT::REntry > CreateEntry() const
static std::unique_ptr< RNTupleWriter > Create(std::unique_ptr< ROOT::RNTupleModel > model, std::unique_ptr< Internal::RPageSink > sink, const ROOT::RNTupleWriteOptions &options)
Create a writer, potentially wrapping the sink in a RPageSinkBuf.
RNTupleWriter(RNTupleWriter &&)=delete
static std::unique_ptr< RNTupleWriter > Recreate(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Creates an RNTupleWriter backed by storage, overwriting it if one with the same URI exists.
std::vector< std::shared_ptr< Experimental::RNTupleAttrSetWriter > > fAttributeSets
All the Attribute Sets created from this Writer.
RNTupleWriter(const RNTupleWriter &)=delete
std::unique_ptr< ROOT::Detail::RRawPtrWriteEntry > CreateRawPtrWriteEntry() const
Experimental::Detail::RNTupleMetrics fMetrics
RNTupleWriter & operator=(RNTupleWriter &&)=delete
const Experimental::Detail::RNTupleMetrics & GetMetrics() const
RNTupleFillContext fFillContext
void CommitClusterGroup()
void CloseAttributeSet(ROOT::Experimental::RNTupleAttrSetWriterHandle handle)
Writes the given AttributeSet to the underlying storage and closes it.
ROOT::RNTupleModel & GetUpdatableModel()
Internal::RPageSink & GetSink()
ROOT::Experimental::RNTupleAttrSetWriterHandle CreateAttributeSet(std::unique_ptr< RNTupleModel > model, std::string_view name, const ROOT::RNTupleWriteOptions *options=nullptr)
Creates a new Attribute Set called name associated to this Writer and returns a non-owning pointer to...
static std::unique_ptr< RNTupleWriter > Append(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, TDirectory &fileOrDirectory, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Creates an RNTupleWriter that writes into an existing TFile or TDirectory, without overwriting its co...
std::size_t Fill(ROOT::REntry &entry)
Multiple entries can have been instantiated from the ntuple model.
std::size_t Fill(ROOT::Detail::RRawPtrWriteEntry &entry)
Fill an RRawPtrWriteEntry into this ntuple.
void FillNoFlush(ROOT::REntry &entry, RNTupleFillStatus &status)
Fill an entry into this ntuple, but don't commit the cluster.
RNTupleWriter(std::unique_ptr< ROOT::RNTupleModel > model, std::unique_ptr< Internal::RPageSink > sink)
ROOT::NTupleSize_t GetLastCommitted() const
Return the entry number that was last committed in a cluster.
ROOT::NTupleSize_t GetLastCommittedClusterGroup() const
Return the entry number that was last committed in a cluster group.
void CommitDataset()
Closes the underlying file (page sink) and expires the model.
const ROOT::RNTupleModel & GetModel() const
ROOT::NTupleSize_t fLastCommittedClusterGroup
void FlushColumns()
Flush column data, preparing for CommitCluster or to reduce memory usage.
RNTupleWriter & operator=(const RNTupleWriter &)=delete
ROOT::NTupleSize_t GetLastFlushed() const
Return the entry number that was last flushed in a cluster.
void FillNoFlush(ROOT::Detail::RRawPtrWriteEntry &entry, RNTupleFillStatus &status)
Fill an RRawPtrWriteEntry into this ntuple, but don't commit the cluster.
std::unique_ptr< ROOT::RNTupleModel::RUpdater > CreateModelUpdater()
Get a RNTupleModel::RUpdater that provides limited support for incremental updates to the underlying ...
void FlushCluster()
Flush so far filled entries to storage.
ROOT::NTupleSize_t GetNEntries() const
Return the number of entries filled so far.
void CommitCluster(bool commitClusterGroup=false)
Ensure that the data from the so far seen Fill calls has been written to storage.
void CloseAttributeSetImpl(ROOT::Experimental::RNTupleAttrSetWriter &attrSet)
std::size_t Fill()
The simplest user interface if the default entry that comes with the ntuple model is used.
Describe directory structure in memory.
std::unique_ptr< RNTupleWriter > RNTupleWriter_Append(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntuplePath, ROOT::Experimental::RFile &file, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Creates an RNTupleWriter that writes into the given file, appending to it.
std::unique_ptr< RNTupleWriter > CreateRNTupleWriter(std::unique_ptr< ROOT::RNTupleModel > model, std::unique_ptr< Internal::RPageSink > sink)
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.