constexpr int kNEvents = 10000;
void Write(std::string_view ntupleName, std::string_view fileName)
{
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");
for (int i = 0; i < kNEvents; ++i) {
fldVpx->clear();
fldVpy->clear();
fldVpz->clear();
for (int j = 0; j < *fldN; ++j) {
float px, py, pz;
pz = px * px + py * py;
fldVpx->emplace_back(px);
fldVpy->emplace_back(py);
fldVpz->emplace_back(pz);
}
}
}
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 processor = RNTupleProcessor::CreateChain(ntuples);
int prevProcessorNumber{-1};
auto px = processor->RequestField<std::vector<float>>("vpx");
for (auto idx : *processor) {
if (static_cast<int>(processor->GetCurrentProcessorNumber()) > prevProcessorNumber) {
prevProcessorNumber = processor->GetCurrentProcessorNumber();
std::cout << "Processing `ntuple" << prevProcessorNumber + 1 << "` (" << idx + 1
<< " total entries processed so far)" << std::endl;
}
}
}
std::cout << "Processed a total of " << processor->GetNEntriesProcessed() << " entries" << std::endl;
hPx.DrawCopy();
}
void ntpl012_processor_chain()
{
Write("ntuple1", "ntuple1.root");
Write("ntuple2", "ntuple2.root");
Write("ntuple3", "ntuple3.root");
std::vector<RNTupleOpenSpec> ntuples = {
{"ntuple1", "ntuple1.root"}, {"ntuple2", "ntuple2.root"}, {"ntuple3", "ntuple3.root"}};
Read(ntuples);
}
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)