Thread safe fill of same tree and histograms from different synchronized threads

Hi,

Introduction. I have written a presort c++ analysis library to our triggerless data-acquisition system (600+ channels). I would like to also use optionally Root histograms and trees there. The natural way to increase the throughput is to use a pipeline scheme. I’m using currently taskflow library. In that, there are many worker threads accessing the same resources but of course synchronizing the threads perfectly in between. So no two threads accessing the same resources at same time.

Question. Are the Root histograms and tree thread safe so that I can access those from fully synchronized different threads at different times i.e. with using mutexes or similar. I have to ask this since the Root object seem to have complicated states and they interact with other global objects behind the scenes. The question can be asked also differently: Are histograms or Tree having a thread local data?

Of course, I will create the histograms and trees in one thread before going to parallel pipeline and save histograms to root file after the execution of pipeline in one single thread. Filling copies of histograms and merging them afterwards is not working solution here due to long time correlations (i.e. data must be handled in time order).

Best wishes,
Jan

Welcome to the ROOT Forum! Maybe @moneta can hep

Individual objects of type TTree or TH1* (or TFile) can not n be accessed from multiple thread as the same time. However once you turn on thread support in ROOT (ROOT::EnableThreadSafety()) distinct objects of those types can be access concurrently.

I.e. what you described will work but you might also be able to achieve even better thread scaling by using (in some cases) distinct objects rather than sharing them with several thread (We also have an infrastructure (TBufferMerger) that allows the merging of concurrently produced TTree and TH*

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