Logo ROOT  
Reference Guide
mtbb001_fillHistos.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Fill histograms in parallel and write them on file.

This example expresses the parallelism of the mt001_fillHistos.C tutorial with multiprocessing techniques.

// Total amount of numbers
const UInt_t nNumbers = 20000000U;
// The number of workers
const UInt_t nThreads = 4U;
Int_t mtbb001_fillHistos()
// We define our work item
auto workItem = [](UInt_t workerID) {
// One generator, file and ntuple per worker
TRandom3 workerRndm(workerID); // Change the seed
TFile f(Form("myFile_mtbb001_%u.root", workerID), "RECREATE");
TH1F h(Form("myHisto_%u", workerID), "The Histogram", 64, -4, 4);
for (UInt_t i = 0; i < nNumbers; ++i) {
return 0;
// Create the pool of threads
ROOT::TThreadExecutor pool(nThreads);
// Fill the pool with work
pool.Map(workItem, ROOT::TSeqI(nThreads));
return 0;
#define f(i)
Definition: RSha256.hxx:104
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2456
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:67
This class provides a simple interface to execute the same task multiple times in parallel threads,...
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:577
Random number generator class based on M.
Definition: TRandom3.h:27
January 2016
Danilo Piparo

Definition in file mtbb001_fillHistos.C.