constexpr int kNEvents = 10000;
void Write(std::string_view ntupleName, std::string_view ntupleFileName)
{
auto model = RNTupleModel::Create();
auto fldVpx = model->MakeField<std::vector<float>>("vpx");
auto fldVpy = model->MakeField<std::vector<float>>("vpy");
auto fldVpz = model->MakeField<std::vector<float>>("vpz");
auto fldN = model->MakeField<std::uint64_t>("vn");
auto ntuple = RNTupleWriter::Recreate(std::move(model), ntupleName, ntupleFileName);
for (int i = 0; i < kNEvents; ++i) {
fldVpx->clear();
fldVpy->clear();
fldVpz->clear();
for (int j = 0; j < *fldN; ++j) {
float px, py, pz;
pz = px * px + py * py;
fldVpx->emplace_back(px);
fldVpy->emplace_back(py);
fldVpz->emplace_back(pz);
}
ntuple->Fill();
}
}
void Read(const std::vector<RNTupleSourceSpec> &ntuples)
{
auto c =
new TCanvas(
"c",
"RNTupleProcessor Example", 200, 10, 700, 500);
TH1F hPx(
"h",
"This is the px distribution", 100, -4, 4);
hPx.SetFillColor(48);
auto ptrPx = processor.GetEntry().GetPtr<std::vector<float>>("vpx");
for (const auto &entry : processor) {
if (entry.GetLocalEntryIndex() == 0) {
std::cout << "Processing " << ntuples.at(entry.GetNTupleIndex()).fName << " (" << entry.GetGlobalEntryIndex()
<< " total entries processed so far)" << std::endl;
}
}
}
hPx.DrawCopy();
}
void ntpl012_processor()
{
std::vector<RNTupleSourceSpec> ntuples = {
{"ntuple1", "ntuple1.root"}, {"ntuple2", "ntuple2.root"}, {"ntuple3", "ntuple3.root"}};
for (const auto &ntuple : ntuples) {
Write(ntuple.fName, ntuple.fLocation);
}
Read(ntuples);
}
R__EXTERN TRandom * gRandom
The RNTupleModel encapulates the schema of an ntuple.
Interface for iterating over entries of RNTuples and vertically concatenated RNTuples (chains).
An RNTuple that gets filled with entries (data) and writes them to storage.
1-D histogram with a float per channel (see TH1 documentation)
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Helper type representing the name and storage location of an RNTuple.