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

Python interface

RNTupleWriter is an interface to write RNTuples to storage.

A simple way to write an RNTuple in python is by:

  • creating a model and adding fields to it
  • opening an RNTupleWriter
  • creating entries and filling them with data
  • committing entries to the RNTuple via writer.Fill(entry)
import ROOT
# Create the model
# Define the schema by adding fields to the model.
model.MakeField['int']("foo")
# Create a writer as a context manager
with ROOT.RNTupleWriter.Recreate(model, "myNtuple", "file.root") as writer:
# create an entry and use it to write data to the RNTuple
entry = writer.CreateEntry()
for i in range(0,10):
entry['foo'] = i
writer.Fill(entry)
# On destruction, the writer will flush the written data to disk
static std::unique_ptr< RNTupleModel > Create()
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.


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