const std::string kPrimaryNTupleName = "mainNTuple";
const std::string kMainNTuplePath = "main_ntuple.root";
const std::string kAuxNTupleName = "auxNTuple";
const std::string kAuxNTuplePath = "aux_ntuple.root";
constexpr int kNEvents = 10000;
void WritePrimary(std::string_view ntupleName, std::string_view ntupleFileName)
{
auto fldI = model->MakeField<std::uint32_t>("i");
auto fldVpx = model->MakeField<float>("vpx");
for (int i = 0; i < kNEvents; i += 5) {
*fldI = i;
}
std::cout <<
"Wrote " <<
writer->GetNEntries() <<
" to the primary RNTuple" << std::endl;
}
void WriteAux(std::string_view ntupleName, std::string_view ntupleFileName)
{
auto fldI = model->MakeField<std::uint32_t>("i");
auto fldVpy = model->MakeField<float>("vpy");
for (int i = 0; i < kNEvents; ++i) {
*fldI = i;
}
std::cout <<
"Wrote " <<
writer->GetNEntries() <<
" to the auxiliary RNTuple" << std::endl;
}
void Read()
{
auto c =
new TCanvas(
"c",
"RNTupleJoinProcessor Example", 200, 10, 700, 500);
TH1F hPy(
"h",
"This is the px + py distribution", 100, -4, 4);
hPy.SetFillColor(48);
auto processor =
RNTupleProcessor::CreateJoin({kPrimaryNTupleName, kMainNTuplePath}, {kAuxNTupleName, kAuxNTuplePath}, {"i"});
auto px = processor->RequestField<float>("vpx");
auto py = processor->RequestField<float>(kAuxNTupleName + ".vpy");
for (
auto _ : *processor) {
hPy.Fill(*px + *py);
}
std::cout << "Processed a total of " << processor->GetNEntriesProcessed() << " entries" << std::endl;
hPy.DrawCopy();
}
void ntpl015_processor_join()
{
WritePrimary(kPrimaryNTupleName, kMainNTuplePath);
WriteAux(kAuxNTupleName, kAuxNTuplePath);
Read();
}
Specification of the name and location of an RNTuple, used for creating a new RNTupleProcessor.
Interface for iterating over entries of vertically ("chained") and/or horizontally ("joined") combine...
static std::unique_ptr< RNTupleModel > Create()
static std::unique_ptr< RNTupleWriter > Recreate(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Creates an RNTupleWriter backed by storage, overwriting it if one with the same URI exists.
1-D histogram with a float per channel (see TH1 documentation)