34 std::unique_ptr<ROOT::Experimental::Internal::RPageSink> sink)
35 : fFillContext(std::move(model), std::move(sink)), fMetrics(
"RNTupleWriter")
40 fZipTasks = std::make_unique<Internal::RNTupleImtTaskScheduler>();
57std::unique_ptr<ROOT::Experimental::RNTupleWriter>
61 if (model->GetRegisteredSubfields().size() > 0) {
62 throw RException(
R__FAIL(
"cannot create an RNTupleWriter from a model with registered subfields"));
65 sink = std::make_unique<Internal::RPageSinkBuf>(std::move(sink));
67 return std::unique_ptr<RNTupleWriter>(
new RNTupleWriter(std::move(model), std::move(sink)));
70std::unique_ptr<ROOT::Experimental::RNTupleWriter>
75 return Create(std::move(model), std::move(sink), options);
78std::unique_ptr<ROOT::Experimental::RNTupleWriter>
80 std::string_view ntupleName, std::string_view storage,
85 for (
const auto &fieldDesc : fields) {
86 std::string typeName(fieldDesc.first);
87 std::string fieldName(fieldDesc.second);
89 model->AddField(field.Unwrap());
91 return Create(std::move(model), std::move(sink), options);
94std::unique_ptr<ROOT::Experimental::RNTupleWriter>
98 auto file = fileOrDirectory.
GetFile();
100 throw RException(
R__FAIL(
"RNTupleWriter only supports writing to a ROOT file. Cannot write into a directory "
101 "that is not backed by a file"));
103 if (!file->IsBinary()) {
104 throw RException(
R__FAIL(
"RNTupleWriter only supports writing to a ROOT file. Cannot write into " +
105 std::string(file->GetName())));
108 auto sink = std::make_unique<Internal::RPageSinkFile>(ntupleName, fileOrDirectory, options);
109 return Create(std::move(model), std::move(sink), options);
114 if (GetNEntries() == fLastCommittedClusterGroup)
116 fFillContext.fSink->CommitClusterGroup();
117 fLastCommittedClusterGroup = GetNEntries();
122 if (fFillContext.fModel->IsExpired()) {
125 return *fFillContext.fModel;
130 if (fFillContext.GetModel().IsExpired())
133 CommitCluster(
true );
134 fFillContext.fSink->CommitDataset();
135 fFillContext.fModel->Expire();
138std::unique_ptr<ROOT::Experimental::RNTupleWriter>
140 std::unique_ptr<ROOT::Experimental::Internal::RPageSink> sink)
142 return std::unique_ptr<ROOT::Experimental::RNTupleWriter>(
#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(...)
void ObserveMetrics(RNTupleMetrics &observee)
static std::unique_ptr< RPageSink > Create(std::string_view ntupleName, std::string_view location, const RNTupleWriteOptions &options=RNTupleWriteOptions())
Guess the concrete derived page source from the location.
static RResult< std::unique_ptr< RFieldBase > > Create(const std::string &fieldName, const std::string &canonicalType, const std::string &typeAlias, bool continueOnError=false)
Factory method to resurrect a field from the stored on-disk type information.
std::unique_ptr< Internal::RPageSink > fSink
The RNTupleModel encapulates the schema of an ntuple.
static std::unique_ptr< RNTupleModel > Create()
Common user-tunable settings for storing ntuples.
bool GetUseBufferedWrite() const
An RNTuple that gets filled with entries (data) and writes them to storage.
RNTupleWriter(std::unique_ptr< RNTupleModel > model, std::unique_ptr< Internal::RPageSink > sink)
RNTupleModel & GetUpdatableModel()
static std::unique_ptr< RNTupleWriter > Append(std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, TDirectory &fileOrDirectory, const RNTupleWriteOptions &options=RNTupleWriteOptions())
Throws an exception if the model is null.
std::unique_ptr< Internal::RPageStorage::RTaskScheduler > fZipTasks
The page sink's parallel page compression scheduler if IMT is on.
static std::unique_ptr< RNTupleWriter > Create(std::unique_ptr< RNTupleModel > model, std::unique_ptr< Internal::RPageSink > sink, const RNTupleWriteOptions &options)
Create a writer, potentially wrapping the sink in a RPageSinkBuf.
void CommitDataset()
Closes the underlying file (page sink) and expires the model.
void CommitClusterGroup()
Detail::RNTupleMetrics fMetrics
static std::unique_ptr< RNTupleWriter > Recreate(std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const RNTupleWriteOptions &options=RNTupleWriteOptions())
Throws an exception if the model is null.
RNTupleFillContext fFillContext
std::string GetReport() const
Format a dignostics report, e.g. for an exception message.
Base class for all ROOT issued exceptions.
const RError & GetError() const
Describe directory structure in memory.
virtual TFile * GetFile() const
std::unique_ptr< RNTupleWriter > CreateRNTupleWriter(std::unique_ptr< RNTupleModel > model, std::unique_ptr< Internal::RPageSink > sink)
RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.