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) {
TNtuple ntrand(
"ntrand",
"Random Numbers",
"r");
for (
auto i :
ROOT::TSeqI(nEntries)) ntrand.Fill(rnd.Gaus());
};
std::vector<std::thread> workers;
workers.emplace_back(work_function, i+1);
for (auto &&worker : workers) worker.join();
}
- Author
- Guilherme Amadio
Definition in file mt103_fillNtupleFromMultipleThreads.C.