Demonstrate how to read a TTree with RFile.
Note that, due to how TTree handles lifetime and its relationship with TDirectory, writing TTree through RFile is currently unsupported.
#include <iostream>
void read_tree_from_rfile(const char *fileName)
{
auto tree = file->Get<
TTree>(
"tree");
int intVal;
tree->SetBranchAddress("intBranch", &intVal);
for (auto i = 0; i < tree->GetEntries(); ++i) {
tree->GetEntry(i);
std::cout << "value[" << i << "] = " << intVal << "\n";
}
}
void rfile003_ttree()
{
const char *const fileName = "rfile_ttree.root";
read_tree_from_rfile(fileName);
}
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
R__EXTERN TSystem * gSystem
static std::unique_ptr< RFile > Open(std::string_view path, const ROpenOptions &opts=ROpenOptions())
Opens the file for reading.
RResultPtr< RInterface< RLoopManager > > Snapshot(std::string_view treename, std::string_view filename, const ColumnNames_t &columnList, const RSnapshotOptions &options=RSnapshotOptions())
RInterface< Proxied > Define(std::string_view name, F expression, const ColumnNames_t &columns={})
Define a new column.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
virtual int Unlink(const char *name)
Unlink, i.e.
A TTree represents a columnar dataset.
value[0] = 0
value[1] = 1
value[2] = 2
value[3] = 3
value[4] = 4
value[5] = 5
value[6] = 6
value[7] = 7
value[8] = 8
value[9] = 9
- Warning
- This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
- Date
- 2026-10-12
- Author
- Giacomo Parolini giaco.nosp@m.mo.p.nosp@m.aroli.nosp@m.ni@c.nosp@m.ern.c.nosp@m.h
Definition in file rfile003_ttree.C.