30constexpr int kNEvents = 10000;
32void Write(std::string_view ntupleName, std::string_view ntupleFileName)
34 auto model = RNTupleModel::Create();
36 auto fldVpx = model->MakeField<std::vector<float>>(
"vpx");
37 auto fldVpy = model->MakeField<std::vector<float>>(
"vpy");
38 auto fldVpz = model->MakeField<std::vector<float>>(
"vpz");
39 auto fldN = model->MakeField<std::uint64_t>(
"vn");
41 auto ntuple = RNTupleWriter::Recreate(std::move(model), ntupleName, ntupleFileName);
43 for (
int i = 0; i < kNEvents; ++i) {
49 for (
int j = 0; j < *fldN; ++j) {
52 pz = px * px + py * py;
54 fldVpx->emplace_back(px);
55 fldVpy->emplace_back(py);
56 fldVpz->emplace_back(pz);
63void Read(
const std::vector<RNTupleOpenSpec> &ntuples)
65 auto c =
new TCanvas(
"c",
"RNTupleProcessor Example", 200, 10, 700, 500);
66 TH1F hPx(
"h",
"This is the px distribution", 100, -4, 4);
69 auto model = RNTupleModel::Create();
70 auto ptrPx = model->MakeField<std::vector<float>>(
"vpx");
76 auto processor = RNTupleProcessor::CreateChain(ntuples, std::move(model));
78 for (
const auto &entry : *processor) {
81 if (processor->GetLocalEntryNumber() == 0) {
82 std::cout <<
"Processing " << ntuples.at(processor->GetCurrentNTupleNumber()).fNTupleName <<
" ("
83 << processor->GetNEntriesProcessed() <<
" total entries processed so far)" << std::endl;
88 for (
auto x : *ptrPx) {
96void ntpl012_processor()
100 std::vector<RNTupleOpenSpec> ntuples = {
101 {
"ntuple1",
"ntuple1.root"}, {
"ntuple2",
"ntuple2.root"}, {
"ntuple3",
"ntuple3.root"}};
103 for (
const auto &ntuple : ntuples) {
104 Write(ntuple.fNTupleName, ntuple.fStorage);
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 ].
Used to specify the underlying RNTuples in RNTupleProcessor and RNTupleReader::OpenFriends()