Illustrate the usage of the TTreeProcessorMT::Process method.
Such method provides an implicit parallelisation of the reading and processing of a TTree. In particular, when invoking Process, the user provides a function that iterates on a subrange of the tree via a TTreeReader. Multiple tasks will be spawned, one for each sub-range, so that the processing of the tree is parallelised. Since two invocations of the user function can potentially run in parallel, the function code must be thread safe. The example also introduces a new class, ROOT::TThreadedObject, which makes objects thread private. With the help of this class, histograms can be filled safely inside the user function and then merged at the end to get the final result.
int imt101_parTreeProcessing()
{
int nthreads = 4;
auto myPtHist = ptHist.Get();
auto myPzHist = pzHist.Get();
auto myPxPyHist = pxpyHist.Get();
while (myReader.Next()) {
myPtHist->Fill(track.Pt(), 1. / track.Pt());
myPxPyHist->Fill(track.Px(), track.Py());
myPzHist->Fill(track.Pz());
}
}
};
tp.Process(myFunction);
auto ptHistMerged = ptHist.Merge();
auto pzHistMerged = pzHist.Merge();
auto pxpyHistMerged = pxpyHist.Merge();
return 0;
}
A wrapper to make object instances thread private, lazily.
A class to process the entries of a TTree in parallel.
An interface for reading values stored in ROOT columnar datasets.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
- Date
- 26/09/2016
- Author
- Enric Tejedor
Definition in file imt101_parTreeProcessing.C.