Demonstrate how to read/write an RNTuple with RFile.
import ROOT
import os
def write_rntuple_to_rfile(fileName):
model.MakeField["int"]("intField")
entry = writer.CreateEntry()
for i in range(10):
entry["intField"] = i
writer.Fill(entry)
def read_rntuple_from_rfile(fileName):
rntuple = file.Get("ntuple")
entry = reader.CreateEntry()
for i in reader.GetEntryRange():
reader.LoadEntry(i, entry)
print(f"value[{i}] = {entry['intField']}")
fileName = "rfile_rntuple_py.root"
try:
write_rntuple_to_rfile(fileName)
read_rntuple_from_rfile(fileName)
os.remove(fileName)
except FileNotFoundError:
pass
static std::unique_ptr< RFile > Open(std::string_view path, const ROpenOptions &opts=ROpenOptions())
Opens the file for reading.
static std::unique_ptr< RFile > Recreate(std::string_view path, const RRecreateOptions &opts=RRecreateOptions())
Opens the file for reading/writing, overwriting it if it already exists.
static std::unique_ptr< RNTupleModel > Create()
static std::unique_ptr< RNTupleReader > Open(std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions())
Open an RNTuple for reading.
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...