43constexpr char const* kTreeFileName =
"http://root.cern.ch/files/LHCb/lhcb_B2HHH_MagnetUp.root";
44constexpr char const* kNTupleFileName =
"ntpl003_lhcbOpenData.root";
49 assert(
f && !
f->IsZombie());
52 auto model = RNTupleModel::Create();
62 TLeaf *
l =
static_cast<TLeaf*
>(
b->GetListOfLeaves()->First());
65 auto field = RFieldBase::Create(
l->GetName(),
l->GetTypeName());
66 std::cout <<
"Convert leaf " <<
l->GetName() <<
" [" <<
l->GetTypeName() <<
"]"
67 <<
" --> " <<
"field " << field->GetName() <<
" [" << field->GetType() <<
"]" << std::endl;
71 model->AddField(std::unique_ptr<RFieldBase>(field));
75 void *fieldDataPtr = model->GetDefaultEntry()->GetValue(
l->GetName()).GetRawPtr();
76 tree->SetBranchAddress(
b->GetName(), fieldDataPtr);
80 auto ntuple = RNTupleWriter::Recreate(std::move(model),
"DecayTree", kNTupleFileName);
82 auto nEntries =
tree->GetEntries();
83 for (
decltype(nEntries) i = 0; i < nEntries; ++i) {
87 if (i && i % 100000 == 0)
88 std::cout <<
"Wrote " << i <<
" entries" << std::endl;
93void ntpl003_lhcbOpenData()
102 auto ntuple = RNTupleReader::Open(
"DecayTree", kNTupleFileName);
105 auto viewFlightDistance = ntuple->GetView<
double>(
"B_FlightDistance");
107 auto c =
new TCanvas(
"c",
"B Flight Distance", 200, 10, 700, 500);
108 TH1F h(
"h",
"B Flight Distance", 200, 0, 140);
111 for (
auto i : ntuple->GetViewRange()) {
114 h.Fill(viewFlightDistance(i));
R__EXTERN TSystem * gSystem
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::kUseGeneralPurpose, 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.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
A TTree represents a columnar dataset.