24
24
using ROOT ::Experimental ::RNTupleOpenSpec ;
25
25
using ROOT ::Experimental ::RNTupleProcessor ;
26
26
27
- const std ::string kMainNTupleName = "mainNTuple" ;
27
+ const std ::string kPrimaryNTupleName = "mainNTuple" ;
28
28
const std ::string kMainNTuplePath = "main_ntuple.root" ;
29
29
const std ::string kAuxNTupleName = "auxNTuple" ;
30
30
const std ::string kAuxNTuplePath = "aux_ntuple.root" ;
31
31
32
- // Number of events to generate for the auxiliary ntuple. The main ntuple will have a fifth of this number.
32
+ // Number of events to generate for the auxiliary ntuple. The primary ntuple will have a fifth of this number.
33
33
constexpr int kNEvents = 10000 ;
34
34
35
- void WriteMain (std ::string_view ntupleName , std ::string_view ntupleFileName )
35
+ void WritePrimary (std ::string_view ntupleName , std ::string_view ntupleFileName )
36
36
{
37
37
auto model = ROOT ::RNTupleModel ::Create ();
38
38
@@ -41,15 +41,15 @@ void WriteMain(std::string_view ntupleName, std::string_view ntupleFileName)
41
41
42
42
auto writer = ROOT ::RNTupleWriter ::Recreate (std ::move (model ), ntupleName , ntupleFileName );
43
43
44
- // The main ntuple only contains a subset of the entries present in the auxiliary ntuple.
44
+ // The primary ntuple only contains a subset of the entries present in the auxiliary ntuple.
45
45
for (int i = 0 ; i < kNEvents ; i += 5 ) {
46
46
* fldI = i ;
47
47
* fldVpx = gRandom -> Gaus ();
48
48
49
49
writer -> Fill ();
50
50
}
51
51
52
- std ::cout << "Wrote " << writer -> GetNEntries () << " to the main RNTuple" << std ::endl ;
52
+ std ::cout << "Wrote " << writer -> GetNEntries () << " to the primary RNTuple" << std ::endl ;
53
53
}
54
54
55
55
void WriteAux (std ::string_view ntupleName , std ::string_view ntupleFileName )
@@ -77,23 +77,23 @@ void Read()
77
77
TH1F hPy ("h" , "This is the px + py distribution" , 100 , -4 , 4 );
78
78
hPy .SetFillColor (48 );
79
79
80
- // The first specified ntuple is the main ntuple and will be used to drive the processor loop. The subsequent
81
- // list of ntuples (in this case, only one) are auxiliary and will be joined with the entries from the main ntuple.
82
- // We specify field "i" as the join field. This field, which should be present in all ntuples specified is used to
83
- // identify which entries belong together. Multiple join fields can be specified, in which case the combination of
84
- // field values is used. It is possible to specify up to 4 join fields. Providing an empty list of join fields
85
- // signals to the processor that all entries are aligned.
80
+ // The first specified ntuple is the primary ntuple and will be used to drive the processor loop. The subsequent
81
+ // list of ntuples (in this case, only one) are auxiliary and will be joined with the entries from the primary
82
+ // ntuple. We specify field "i" as the join field. This field, which should be present in all ntuples specified is
83
+ // used to identify which entries belong together. Multiple join fields can be specified, in which case the
84
+ // combination of field values is used. It is possible to specify up to 4 join fields. Providing an empty list of
85
+ // join fields signals to the processor that all entries are aligned.
86
86
auto processor =
87
- RNTupleProcessor ::CreateJoin ({kMainNTupleName , kMainNTuplePath }, {kAuxNTupleName , kAuxNTuplePath }, {"i" });
87
+ RNTupleProcessor ::CreateJoin ({kPrimaryNTupleName , kMainNTuplePath }, {kAuxNTupleName , kAuxNTuplePath }, {"i" });
88
88
89
- float px , py ;
90
- for (const auto & entry : * processor ) {
91
- // Fields from the main ntuple are accessed by their original name.
92
- px = * entry .GetPtr < float > ("vpx" );
93
- // Fields from auxiliary ntuples are accessed by prepending the name of the auxiliary ntuple.
94
- py = * entry .GetPtr < float > (kAuxNTupleName + ".vpy" );
89
+ // Access to the processor's entry values is provided through RNTupleProcessor::GetValuePtr().
90
+ // Fields from the primary ntuple are accessed by their original name.
91
+ auto px = processor -> GetValuePtr < float > ("vpx" );
92
+ // Fields from auxiliary ntuples are accessed by prepending the name of the auxiliary ntuple.
93
+ auto py = processor -> GetValuePtr < float > (kAuxNTupleName + ".vpy" );
95
94
96
- hPy .Fill (px + py );
95
+ for (const auto & _ : * processor ) {
96
+ hPy .Fill (* px + * py );
97
97
}
98
98
99
99
std ::cout << "Processed a total of " << processor -> GetNEntriesProcessed () << " entries" << std ::endl ;
@@ -103,7 +103,7 @@ void Read()
103
103
104
104
void ntpl015_processor_join ()
105
105
{
106
- WriteMain ( kMainNTupleName , kMainNTuplePath );
106
+ WritePrimary ( kPrimaryNTupleName , kMainNTuplePath );
107
107
WriteAux (kAuxNTupleName , kAuxNTuplePath );
108
108
109
109
Read ();
0 commit comments