Fill the same TNtuple from different threads.
This tutorial illustrates the basics of how it's possible with ROOT to write simultaneously to a single output file using TBufferMerger.
void mt103_fillNtupleFromMultipleThreads()
{
const size_t nEntries = 65535;
const size_t nWorkers = 4;
const size_t nEventsPerWorker = nEntries / nWorkers;
auto fileName = "mt103_fillNtupleFromMultipleThreads.root";
auto work_function = [&](int seed) {
auto f = merger.GetFile();
TNtuple ntrand(
"ntrand",
"Random Numbers",
"r");
ntrand.Fill(rnd.Gaus());
};
std::vector<std::thread> workers;
workers.emplace_back(work_function, i + 1);
for (auto &&worker : workers)
worker.join();
}
TBufferMerger is a class to facilitate writing data in parallel from multiple threads,...
A pseudo container class which is a generator of indices.
A simple TTree restricted to a list of float variables only.
This is the base class for the ROOT Random number generators.
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
- Date
- May 2017
- Author
- Guilherme Amadio
Definition in file mt103_fillNtupleFromMultipleThreads.C.