Fill histograms in parallel and write them on file.
The simplest meaningful possible example which shows ROOT thread awareness.
const UInt_t nNumbers = 20000000U;
{
auto workItem = [](
UInt_t workerID) {
TFile f(
Form(
"myFile_mt001_%u.root", workerID),
"RECREATE");
TH1F h(
Form(
"myHisto_%u", workerID),
"The Histogram", 64, -4, 4);
for (
UInt_t i = 0; i < nNumbers; ++i) {
h.Fill(workerRndm.Gaus());
}
};
std::vector<std::thread> workers;
for (
auto workerID :
ROOT::
TSeqI(nWorkers)) {
workers.emplace_back(workItem, workerID);
}
for (auto &&worker : workers)
worker.join();
return 0;
}
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
1-D histogram with a float per channel (see TH1 documentation)}
Random number generator class based on M.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
void EnableThreadSafety()
Enable support for multi-threading within the ROOT code in particular, enables the global mutex to ma...
- Date
- January 2016
- Author
- Danilo Piparo
Definition in file mt001_fillHistos.C.