43constexpr char const* kTreeFileName =
"http://root.cern/files/LHCb/lhcb_B2HHH_MagnetUp.root";
44constexpr char const* kNTupleFileName =
"ntpl003_lhcbOpenData.root";
49 assert(
f && !
f->IsZombie());
52 auto model = RNTupleModel::CreateBare();
62 TLeaf *
l =
static_cast<TLeaf*
>(
b->GetListOfLeaves()->First());
65 auto field = RFieldBase::Create(
l->
GetName(),
l->GetTypeName()).Unwrap();
66 std::cout <<
"Convert leaf " <<
l->
GetName() <<
" [" <<
l->GetTypeName() <<
"]"
68 <<
"field " << field->GetFieldName() <<
" [" << field->GetTypeName() <<
"]" << std::endl;
72 model->AddField(std::move(field));
76 auto ntuple = RNTupleWriter::Recreate(std::move(model),
"DecayTree", kNTupleFileName);
78 auto entry = ntuple->GetModel().CreateEntry();
80 auto l =
static_cast<TLeaf *
>(
b->GetListOfLeaves()->First());
83 std::shared_ptr<void> fieldDataPtr = entry->GetPtr<
void>(
l->
GetName());
84 tree->SetBranchAddress(
b->GetName(), fieldDataPtr.get());
87 auto nEntries =
tree->GetEntries();
88 for (
decltype(nEntries) i = 0; i < nEntries; ++i) {
92 if (i && i % 100000 == 0)
93 std::cout <<
"Wrote " << i <<
" entries" << std::endl;
98void ntpl003_lhcbOpenData()
106 auto ntuple = RNTupleReader::Open(
"DecayTree", kNTupleFileName);
109 auto viewFlightDistance = ntuple->GetView<
double>(
"B_FlightDistance");
111 auto c =
new TCanvas(
"c",
"B Flight Distance", 200, 10, 700, 500);
112 TH1F h(
"h",
"B Flight Distance", 200, 0, 140);
115 for (
auto i : ntuple->GetEntryRange()) {
118 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.
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.