26#include <ROOT/RField.hxx>
47constexpr char const* kTreeFileName =
"http://root.cern.ch/files/LHCb/lhcb_B2HHH_MagnetUp.root";
48constexpr char const* kNTupleFileName =
"ntpl003_lhcbOpenData.root";
53 assert(
f && !
f->IsZombie());
56 auto model = RNTupleModel::Create();
66 TLeaf *
l =
static_cast<TLeaf*
>(
b->GetListOfLeaves()->First());
69 auto field = RFieldBase::Create(
l->GetName(),
l->GetTypeName()).Unwrap();
70 std::cout <<
"Convert leaf " <<
l->
GetName() <<
" [" <<
l->GetTypeName() <<
"]"
71 <<
" --> " <<
"field " << field->GetName() <<
" [" << field->GetType() <<
"]" << std::endl;
75 model->AddField(std::move(field));
79 void *fieldDataPtr = model->GetDefaultEntry()->GetValue(
l->GetName()).GetRawPtr();
80 tree->SetBranchAddress(
b->GetName(), fieldDataPtr);
84 auto ntuple = RNTupleWriter::Recreate(std::move(model),
"DecayTree", kNTupleFileName);
86 auto nEntries =
tree->GetEntries();
87 for (
decltype(nEntries) i = 0; i < nEntries; ++i) {
91 if (i && i % 100000 == 0)
92 std::cout <<
"Wrote " << i <<
" entries" << std::endl;
97void ntpl003_lhcbOpenData()
105 auto ntuple = RNTupleReader::Open(
"DecayTree", kNTupleFileName);
108 auto viewFlightDistance = ntuple->GetView<
double>(
"B_FlightDistance");
110 auto c =
new TCanvas(
"c",
"B Flight Distance", 200, 10, 700, 500);
111 TH1F h(
"h",
"B Flight Distance", 200, 0, 140);
114 for (
auto i : ntuple->GetEntryRange()) {
117 h.Fill(viewFlightDistance(i));
#define R__LOAD_LIBRARY(LIBRARY)
A field translates read and write calls from/to underlying columns to/from tree values.
The RNTupleModel encapulates the schema of an ntuple.
An RNTuple that is used to read data from storage.
An RNTuple that gets filled with entries (data) and writes them to storage.
A TTree is a list of TBranches.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
1-D histogram with a float per channel (see TH1 documentation)}
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual const char * GetName() const
Returns name of object.
A TTree represents a columnar dataset.