Hi,
I am trying to build a threaded program that would basically fill histograms from quite a big number of different TTree’s (of drastically different size).
I’d like to use multithreading. The idea is to have two queues (based on the size of the trees) to feed a certain number of threads. I’ve come up with this attached example to test the basic concept of threaded TFile/TTree access. The code works fine some times, some times not. So please run it a couple of times if it doesn’t crash at first. One of the main errors I have is, with usually with >= 5 threads (the only parameter of the function)
R__unzip: error -5 in inflate (zlib)
Error in <TBasket::ReadBasketBuffers>: fNbytes = 27421, fKeylen = 73, fObjlen = 31924, noutot = 0, nout=0, nin=27348, nbuf=31924
Error in <TBranch::GetBasket>: File: f0.root at byte:210, branch:rnd0, entry:-1, badread=1, nerrors=1, basketnumber=0
R__unzip: error -5 in inflate (zlib)
Error in <TBasket::ReadBasketBuffers>: fNbytes = 27421, fKeylen = 73, fObjlen = 31924, noutot = 0, nout=0, nin=27348, nbuf=31924
Error in <TBranch::GetBasket>: File: f0.root at byte:210, branch:rnd0, entry:-1, badread=1, nerrors=2, basketnumber=0
which makes me think the issue is when I try to read the root files. So where should my locks go (hopefully they won’t defeat the purpose of threads). I am sure I miss some stuff (I’m new to threads).
Also, I tried at first to open the TFile/TTree in the individual threads, which lead to complete disaster. Therefore I now open my files before launching the threads (which ideally should close it once their job is done). While not most effective, I guess I could live with that. Does the current ROOT setup allow to run such a case ?
The attached code simply does generate TTrees and fills them randomly (works usually fine). Then, I try to read the files and extract the content in histograms. All this in threaded mode. This is supposed to mimic what I would like.
The code runs inside root as well as compiled with the usual g++ root-config --cflags --libs
-lThread root_threads_test.cxx
I’ve got the impression that running as ‘root file.cxx+’ is crashing less often than the g++ compiled one. Any reason for this to happen ?
Thanks for you help.
Karolos
P.S. I was unable to find a tutorial or something with what I’m trying to do.
root_thread_test.cxx (3.25 KB)