Making the online QA manager capable to work in multi-threaded regime
Once the event reconstruction in the online processing runs in multi-threaded regime, the framework creates multiple instances of the corresponding QA classes. In each QA class, the histograms are stored in the shared qa::Data object. So, the shared qa::Data object contains copies of the histograms from each thread, which are then sent to the histogram server in the same time. Such behaviour may overload the histogram server and lead to undefined behaviour.
In this merge request, pointers to multiple qa::Data were added to the qa::Manager class:
std::shared_ptr<Data> fData: single-threaded instance of theqa::Datastd::vector<std::shared_ptr<Data>> fDataThreads: instances of theqa::Datafor the QA-tasks, which are executed in parallel.
Selection of the particular instance of the std::shared_ptr<Data> is important at the creation stage of a given QA module (qa::TaskHeader base class). At this point, the QA-manager returns a pointer to the current std::shared_ptr<Data>, which will then be used by the QA module for its entire lifetime.
To select the instance of the std::shared_ptr<Data> inside the QA manager, one has to call qa::Manager::SwitchToThread(int iThread) at the point, before the instances of the QA modules are created for a given thread. After the loop over threads at the initialization stage, one should call the
qa::Manager::SwitchToSingleThread() function to set back the instance to single-threaded processing.
At the point, when the histograms are sent to the histogram server, or stored in the output, the histograms of the different threads are summed into the ones, stored in fDataThreads[0], if multi-threaded regime is enabled. The histogramms in the other qa::Data instances are reset.