Multithreading for faster TTree->GetEntry

Hi, I want to boost the speed of TTree->GetEntry by using multiple threads. My machine has 12 workers and I want to use full of them.
My code usually goes like this:

TFile *f = new TFile(“file.root”);
TTree *t = (TTree *) f->Get(“tree”);
vector *x = 0;

TBranch *b = 0;
t->SetBranchAddress(“x”, &x, &b);

for (int i=0; iGetEntries(); i++){

Since there is massive number of entries in my root file, the for loop above takes a lot of time.
So I want to use 12 workers to boost the speed 12 times faster.
With python, I used to deal with this kind of problem using Pool of Multiprocessing.
But that method is not compatible with PyROOT.

I tried C++ version of multithreading with somewhat following:

TFile *f = new TFile(“file.root”);
TTree *t = (TTree *) f->Get(“tree”);
vector *x = 0;

auto foo = [](TTree *t, TBranch *b, vector *x, int entry1, int entry2){
t->SetBranchAddress(“x”, &x, &b);
for (int i=entry1; i<entry2; i++){

TBranch *b1 = 0;
TBranch *b2 = 0;
TBranch *b3 = 0;
TBranch *b4 = 0;
thread th1(foo, t, b1, 0, 99);
thread th2(foo, t, b2, 100, 199);
thread th3(foo, t, b3, 200, 299);
thread th4(foo, t, b4, 300, 399);


And it didn’t work.

Any ideas?? Please help me.

ROOT Version: 6.09/03
Platform: Linux
Compiler: Not Provided


TTree does not support multithreading out of the box. In order to analyse your data with all of your core you can use RDataFrame.
On the other hand this will require you moving to ROOT 6.14 at least.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.