42constexpr char const* kTreeFileName =
"http://root.cern.ch/files/LHCb/lhcb_B2HHH_MagnetUp.root";
43constexpr char const* kNTupleFileName =
"ntpl003_lhcbOpenData.root";
48 assert(
f && !
f->IsZombie());
51 auto model = RNTupleModel::Create();
61 TLeaf *
l =
static_cast<TLeaf*
>(
b->GetListOfLeaves()->First());
64 auto field = RFieldBase::Create(
l->GetName(),
l->GetTypeName());
65 std::cout <<
"Convert leaf " <<
l->GetName() <<
" [" <<
l->GetTypeName() <<
"]"
66 <<
" --> " <<
"field " << field->GetName() <<
" [" << field->GetType() <<
"]" << std::endl;
70 model->AddField(std::unique_ptr<RFieldBase>(field));
74 void *fieldDataPtr = model->GetDefaultEntry()->GetValue(
l->GetName()).GetRawPtr();
75 tree->SetBranchAddress(
b->GetName(), fieldDataPtr);
79 auto ntuple = RNTupleWriter::Recreate(std::move(model),
"DecayTree", kNTupleFileName);
81 auto nEntries =
tree->GetEntries();
82 for (
decltype(nEntries) i = 0; i < nEntries; ++i) {
86 if (i && i % 100000 == 0)
87 std::cout <<
"Wrote " << i <<
" entries" << std::endl;
92void ntpl003_lhcbOpenData()
100 auto ntuple = RNTupleReader::Open(
"DecayTree", kNTupleFileName);
103 auto viewFlightDistance = ntuple->GetView<
double>(
"B_FlightDistance");
105 auto c =
new TCanvas(
"c",
"B Flight Distance", 200, 10, 700, 500);
106 TH1F h(
"h",
"B Flight Distance", 200, 0, 140);
109 for (
auto i : ntuple->GetEntryRange()) {
112 h.Fill(viewFlightDistance(i));
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.
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.
TRangeDynCast is an adaptater class that allows the typed iteration through a TCollection.
A TTree represents a columnar dataset.