ROOT
Version v6.34
master
v6.32
Reference Guide
▼
ROOT
ROOT Reference Documentation
Tutorials
▼
Functional Parts
►
Core ROOT classes
►
std Extension classes
►
Parallelized classes
►
The Geometry Package
►
Graphics
►
Event display with ROOT7
►
GUI
►
Web Widgets
►
Web Display
►
Histogram Library
►
Input/Output Library
►
Math
►
N-D parametric functions
►
VecOps
►
Monte Carlo
►
HTTP server
►
PROOF
►
TMVA
►
RooFit
►
Dataframe
►
ROOT7 classes
►
NTuple-related classes
►
Tree Library
►
TreePlayer Library
▼
Tutorials
►
Histograms tutorials
►
Tree tutorials
►
Dataframe tutorials
▼
ROOT 7 tutorials
►
RCanvas examples
▼
ROOT 7 ntuple tutorials
ntpl001_staff.C
ntpl002_vector.C
ntpl004_dimuon.C
ntpl005_introspection.C
ntpl006_friends.C
ntpl007_mtFill.C
ntpl008_import.C
ntpl009_parallelWriter.C
ntpl010_skim.C
ntpl011_global_temperatures.C
ntpl012_processor.C
ntpl013_staged.C
ntpl014_framework.C
browser.cxx
concurrentfill.cxx
filedialog.cxx
fitpanel.cxx
fitpanel6.cxx
histops.cxx
perf.cxx
perfcomp.cxx
simple.cxx
►
FOAM tutorials
►
Containers tutorials
►
Event display tutorials
►
Event display ROOT7 tutorials
►
Geometry tutorials
►
Fast Fourier Transforms tutorials
►
Fit Tutorials
►
RooFit Tutorials
►
Graphs tutorials
►
Graphics tutorials
►
OpenGL tutorials
►
Tutorials specific to Mac/Cocoa
►
GUI tutorials
►
HistFactory Tutorials
►
HTTP tutorials
►
Image tutorials
►
IO tutorials
►
Math tutorials
►
Matrix tutorials
►
Monte Carlo tutorials
►
Multicore tutorials
►
Net tutorials
►
Physics tutorials
►
PyRoot tutorials
►
Pythia tutorials
►
Quadratic programming package.
►
R tutorials
►
RooStats Tutorials
►
Spectrum tutorials
►
TSPlot tutorials
►
SQL tutorials
►
TMVA tutorials
►
TUnfold tutorials
►
Unuran tutorials
►
VecOps tutorials
►
FITS files interface tutorials
►
XML tutorials
►
Proof tutorials
►
TWebCanvas tutorials
►
Webgui tutorials
►
Legacy tutorials
demos.C
demoshelp.C
hsimple.C
rootlogoff.C
rootlogon.C
►
R Interface for Statistical Computing
►
Namespaces
►
All Classes
►
Files
Release Notes
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
ntpl012_processor.C File Reference
Tutorials
»
ROOT 7 tutorials
»
ROOT 7 ntuple tutorials
Detailed Description
Demonstrate the RNTupleProcessor using multiple RNTuples
// NOTE: The RNTuple classes are experimental at this point.
// Functionality and interface are still subject to changes.
#include <
ROOT/RNTupleModel.hxx
>
#include <
ROOT/RNTupleWriter.hxx
>
#include <
ROOT/RNTupleProcessor.hxx
>
#include <
TCanvas.h
>
#include <
TH1F.h
>
#include <
TRandom.h
>
// Import classes from the `Experimental` namespace for the time being.
using
ROOT::Experimental::RNTupleModel
;
using
ROOT::Experimental::RNTupleOpenSpec
;
using
ROOT::Experimental::RNTupleProcessor
;
using
ROOT::Experimental::RNTupleWriter
;
// Number of events to generate for each ntuple.
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();
*
fldN
=
gRandom
->
Integer
(15);
for
(
int
j
= 0;
j
< *
fldN
; ++
j
) {
float
px, py, pz;
gRandom
->
Rannor
(px, py);
pz = px * px + py * py;
fldVpx
->emplace_back(px);
fldVpy
->emplace_back(py);
fldVpz
->emplace_back(pz);
}
ntuple
->Fill();
}
}
void
Read(
const
std::vector<RNTupleOpenSpec> &
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
model = RNTupleModel::Create();
auto
ptrPx
= model->MakeField<std::vector<float>>(
"vpx"
);
// By passing a model to the processor, we can use the pointers to field values created upon model creation during
// processing. When no model is provided, a default model is created based on the first ntuple specified.
// Access to the entry values in this case can be achieved through RNTupleProcessor::GetEntry() or through its
// iterator.
auto
processor
= RNTupleProcessor::CreateChain(
ntuples
, std::move(model));
for
(
const
auto
&
entry
: *
processor
) {
// The RNTupleProcessor provides some additional bookkeeping information. The local entry number is reset each
// a new ntuple in the chain is opened for processing.
if
(
processor
->GetLocalEntryNumber() == 0) {
std::cout <<
"Processing "
<<
ntuples
.at(
processor
->GetCurrentNTupleNumber()).fNTupleName <<
" ("
<<
processor
->GetNEntriesProcessed() <<
" total entries processed so far)"
<< std::endl;
}
// We can use the pointer to the field obtained while creating our model to read the field's data for the current
// entry.
for
(
auto
x
: *
ptrPx
) {
hPx
.Fill(
x
);
}
}
hPx
.DrawCopy();
}
void
ntpl012_processor
()
{
// The ntuples to generate and subsequently process. The model of the first ntuple will be used to construct the
// entry used by the processor.
std::vector<RNTupleOpenSpec>
ntuples
= {
{
"ntuple1"
,
"ntuple1.root"
}, {
"ntuple2"
,
"ntuple2.root"
}, {
"ntuple3"
,
"ntuple3.root"
}};
for
(
const
auto
&
ntuple
:
ntuples
) {
Write(
ntuple
.fNTupleName,
ntuple
.fStorage);
}
Read(
ntuples
);
}
RNTupleModel.hxx
RNTupleProcessor.hxx
RNTupleWriter.hxx
c
#define c(i)
Definition
RSha256.hxx:101
TCanvas.h
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
TH1F.h
TRandom.h
gRandom
R__EXTERN TRandom * gRandom
Definition
TRandom.h:62
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
ROOT::Experimental::RNTupleModel
The RNTupleModel encapulates the schema of an ntuple.
Definition
RNTupleModel.hxx:136
ROOT::Experimental::RNTupleProcessor
Interface for iterating over entries of RNTuples and vertically concatenated RNTuples (chains).
Definition
RNTupleProcessor.hxx:67
ROOT::Experimental::RNTupleWriter
An RNTuple that gets filled with entries (data) and writes them to storage.
Definition
RNTupleWriter.hxx:60
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:622
TRandom::Rannor
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition
TRandom.cxx:507
TRandom::Integer
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition
TRandom.cxx:361
x
Double_t x[n]
Definition
legend1.C:17
ROOT::Experimental::RNTupleOpenSpec
Used to specify the underlying RNTuples in RNTupleProcessor and RNTupleReader::OpenFriends()
Definition
RNTupleUtil.hxx:254
Date
April 2024
Author
The
ROOT
Team
Definition in file
ntpl012_processor.C
.
tutorials
v7
ntuple
ntpl012_processor.C
ROOT tags/6-34-04 - Reference Guide Generated on Tue Mar 25 2025 04:21:42 (GVA Time) using Doxygen 1.10.0