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");
for (
auto i :
ROOT::TSeqI(nEntries))
ntrand.Fill(rnd.Gaus());
};
std::vector<std::thread> workers;
for (
auto i :
ROOT::TSeqI(nWorkers))
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 simple TTree restricted to a list of float variables only.
This is the base class for the ROOT Random number generators.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
- Date
- May 2017
- Author
- Guilherme Amadio
Definition in file mt103_fillNtupleFromMultipleThreads.C.