40 std::unique_ptr<ROOT::Internal::RPageSink>
sink)
41 : fFillContext(std::
move(model), std::
move(
sink)), fMetrics(
"RNTupleWriter")
64 std::unique_ptr<Internal::RPageSink>
sink,
67 if (model->GetRegisteredSubfieldNames().size() > 0) {
68 throw RException(
R__FAIL(
"cannot create an RNTupleWriter from a model with registered subfields"));
70 for (
const auto &
field : model->GetConstFieldZero()) {
73 R__FAIL(
"creating a RNTupleWriter from a model containing emulated fields is currently unsupported."));
76 sink = std::make_unique<Internal::RPageSinkBuf>(std::move(
sink));
78 return std::unique_ptr<RNTupleWriter>(
new RNTupleWriter(std::move(model), std::move(
sink)));
81std::unique_ptr<ROOT::RNTupleWriter>
86 return Create(std::move(model), std::move(
sink), options);
89std::unique_ptr<ROOT::RNTupleWriter>
100 model->AddField(
field.Unwrap());
102 return Create(std::move(model), std::move(
sink), options);
105std::unique_ptr<ROOT::RNTupleWriter>
111 throw RException(
R__FAIL(
"RNTupleWriter only supports writing to a ROOT file. Cannot write into a directory "
112 "that is not backed by a file"));
114 if (!file->IsBinary()) {
115 throw RException(
R__FAIL(
"RNTupleWriter only supports writing to a ROOT file. Cannot write into " +
116 std::string(file->GetName())));
118 if (!file->IsWritable()) {
120 "' given to RNTupleWriter is not writable. Open it with 'UPDATE' or 'RECREATE' "
121 "if you want to write into it."));
125 return Create(std::move(model), std::move(
sink), options);
130 if (GetNEntries() == fLastCommittedClusterGroup)
132 fFillContext.fSink->CommitClusterGroup();
133 fLastCommittedClusterGroup = GetNEntries();
138 if (fFillContext.fModel->IsExpired()) {
141 return *fFillContext.fModel;
146 if (fFillContext.GetModel().IsExpired())
149 CommitCluster(
true );
152 for (
auto &
attrSet : fAttributeSets) {
153 CloseAttributeSetImpl(*
attrSet);
156 fFillContext.fSink->CommitDataset();
157 fFillContext.fModel->Expire();
160std::unique_ptr<ROOT::RNTupleWriter>
162 std::unique_ptr<ROOT::Internal::RPageSink>
sink)
167std::unique_ptr<ROOT::RNTupleWriter>
182 "\": names starting with '__' are reserved for internal use."));
195 auto existingIt = std::find_if(fAttributeSets.begin(), fAttributeSets.end(),
196 [&
nameStr](
const auto &set) { return set->GetDescriptor().GetName() == nameStr; });
199 "', but one already exists with that name"));
218 CloseAttributeSetImpl(*
writer);
222 if (it->get() ==
writer.get()) {
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
#define R__LOG_ERROR(...)
static bool IsReservedRNTupleAttrSetName(std::string_view name)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
void ObserveMetrics(RNTupleMetrics &observee)
An interface to read from, or write to, a ROOT file, as well as performing other common operations.
Non-owning handle to an RNTupleAttrSetWriter.
std::weak_ptr< RNTupleAttrSetWriter > fWriter
Class used to write an RNTupleAttrSet in the context of an RNTupleWriter.
static std::unique_ptr< RNTupleAttrSetWriter > Create(const RNTupleFillContext &mainFillContext, std::unique_ptr< ROOT::Internal::RPageSink > sink, std::unique_ptr< RNTupleModel > userModel)
Creates an RNTupleAttrSetWriter associated to the RNTupleWriter owning mainFillContext and writing us...
static std::unique_ptr< RPageSink > Create(std::string_view ntupleName, std::string_view location, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Guess the concrete derived page source from the location.
Base class for all ROOT issued exceptions.
const RError & GetError() const
@ kTraitEmulatedField
This field is a user defined type that was missing dictionaries and was reconstructed from the on-dis...
static RResult< std::unique_ptr< RFieldBase > > Create(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc, ROOT::DescriptorId_t fieldId)
Factory method to resurrect a field from the stored on-disk type information.
std::unique_ptr< ROOT::Internal::RPageStorage::RTaskScheduler > fZipTasks
The page sink's parallel page compression scheduler if IMT is on.
std::unique_ptr< ROOT::Internal::RPageSink > fSink
The RNTupleModel encapulates the schema of an RNTuple.
static std::unique_ptr< RNTupleModel > Create()
Common user-tunable settings for storing RNTuples.
bool GetUseBufferedWrite() const
An RNTuple that gets filled with entries (data) and writes them to storage.
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.
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.
Experimental::Detail::RNTupleMetrics fMetrics
RNTupleFillContext fFillContext
void CommitClusterGroup()
void CloseAttributeSet(ROOT::Experimental::RNTupleAttrSetWriterHandle handle)
Writes the given AttributeSet to the underlying storage and closes it.
ROOT::RNTupleModel & GetUpdatableModel()
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...
RNTupleWriter(std::unique_ptr< ROOT::RNTupleModel > model, std::unique_ptr< Internal::RPageSink > sink)
void CommitDataset()
Closes the underlying file (page sink) and expires the model.
void CloseAttributeSetImpl(ROOT::Experimental::RNTupleAttrSetWriter &attrSet)
const_iterator begin() const
const_iterator end() const
Describe directory structure in memory.
std::pair< std::string_view, std::string_view > DecomposePath(std::string_view path)
Given a "path-like" string (like foo/bar/baz), returns a pair { dirName, baseName }.
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.
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
std::unique_ptr< RNTupleWriter > CreateRNTupleWriter(std::unique_ptr< ROOT::RNTupleModel > model, std::unique_ptr< Internal::RPageSink > sink)
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
bool StartsWith(std::string_view string, std::string_view prefix)