2424using ROOT ::Experimental ::RNTupleOpenSpec ;
2525using ROOT ::Experimental ::RNTupleProcessor ;
2626
27- const std ::string kMainNTupleName = "mainNTuple" ;
27+ const std ::string kPrimaryNTupleName = "mainNTuple" ;
2828const std ::string kMainNTuplePath = "main_ntuple.root" ;
2929const std ::string kAuxNTupleName = "auxNTuple" ;
3030const std ::string kAuxNTuplePath = "aux_ntuple.root" ;
3131
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.
3333constexpr int kNEvents = 10000 ;
3434
35- void WriteMain (std ::string_view ntupleName , std ::string_view ntupleFileName )
35+ void WritePrimary (std ::string_view ntupleName , std ::string_view ntupleFileName )
3636{
3737 auto model = ROOT ::RNTupleModel ::Create ();
3838
@@ -41,15 +41,15 @@ void WriteMain(std::string_view ntupleName, std::string_view ntupleFileName)
4141
4242 auto writer = ROOT ::RNTupleWriter ::Recreate (std ::move (model ), ntupleName , ntupleFileName );
4343
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.
4545 for (int i = 0 ; i < kNEvents ; i += 5 ) {
4646 * fldI = i ;
4747 * fldVpx = gRandom -> Gaus ();
4848
4949 writer -> Fill ();
5050 }
5151
52- std ::cout << "Wrote " << writer -> GetNEntries () << " to the main RNTuple" << std ::endl ;
52+ std ::cout << "Wrote " << writer -> GetNEntries () << " to the primary RNTuple" << std ::endl ;
5353}
5454
5555void WriteAux (std ::string_view ntupleName , std ::string_view ntupleFileName )
@@ -77,23 +77,25 @@ void Read()
7777 TH1F hPy ("h" , "This is the px + py distribution" , 100 , -4 , 4 );
7878 hPy .SetFillColor (48 );
7979
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.
8686 auto processor =
87- RNTupleProcessor ::CreateJoin ({kMainNTupleName , kMainNTuplePath }, {kAuxNTupleName , kAuxNTuplePath }, {"i" });
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" );
95-
96- hPy .Fill (px + py );
87+ RNTupleProcessor ::CreateJoin ({kPrimaryNTupleName , kMainNTuplePath }, {kAuxNTupleName , kAuxNTuplePath }, {"i" });
88+
89+ // Access to the processor's fields is done by first requesting them through RNTupleProcessor::RequestField(). The
90+ // returned value can be used to read the current entry's value for that particular field. Fields from the primary
91+ // ntuple are requested by their original name.
92+ auto px = processor -> RequestField < float > ("vpx" );
93+ // Fields from auxiliary ntuples are requested by prepending the name of the auxiliary ntuple.
94+ auto py = processor -> RequestField < float > (kAuxNTupleName + ".vpy" );
95+
96+ // The iterator value is the index of the current entry being processed. In this example, we don't use it.
97+ for (auto _ : * processor ) {
98+ hPy .Fill (* px + * py );
9799 }
98100
99101 std ::cout << "Processed a total of " << processor -> GetNEntriesProcessed () << " entries" << std ::endl ;
@@ -103,7 +105,7 @@ void Read()
103105
104106void ntpl015_processor_join ()
105107{
106- WriteMain ( kMainNTupleName , kMainNTuplePath );
108+ WritePrimary ( kPrimaryNTupleName , kMainNTuplePath );
107109 WriteAux (kAuxNTupleName , kAuxNTuplePath );
108110
109111 Read ();
0 commit comments