|
61 | 61 | #include <map> |
62 | 62 | #include <vector> |
63 | 63 | #include <csignal> |
| 64 | +#include <mutex> |
64 | 65 |
|
65 | 66 | #ifdef ENABLE_UPGRADES |
66 | 67 | #include <ITS3Simulation/Detector.h> |
@@ -192,7 +193,7 @@ class O2HitMerger : public FairMQDevice |
192 | 193 | void fillBranch(int eventID, std::string const& name, T* ptr) |
193 | 194 | { |
194 | 195 | // fetch tree into which to fill |
195 | | - |
| 196 | + const std::lock_guard<std::mutex> lock(mMapsMtx); |
196 | 197 | auto iter = mEventToTTreeMap.find(eventID); |
197 | 198 | if (iter == mEventToTTreeMap.end()) { |
198 | 199 | { |
@@ -312,11 +313,11 @@ class O2HitMerger : public FairMQDevice |
312 | 313 | void cleanEvent(int eventID) |
313 | 314 | { |
314 | 315 | // remove tree for that eventID |
| 316 | + const std::lock_guard<std::mutex> lock(mMapsMtx); |
315 | 317 | delete mEventToTTreeMap[eventID]; |
316 | | - mEventToTTreeMap.erase(eventID); |
317 | | - // remove memfile |
318 | 318 | delete mEventToTMemFileMap[eventID]; |
319 | | - mEventToTMemFileMap.erase(eventID); |
| 319 | + mEventToTTreeMap.erase(eventID); |
| 320 | + mEventToTMemFileMap.erase(eventID); // remove memfile |
320 | 321 | } |
321 | 322 |
|
322 | 323 | template <typename T> |
@@ -648,7 +649,7 @@ class O2HitMerger : public FairMQDevice |
648 | 649 | std::unordered_map<int, TTree*> mEventToTTreeMap; //! in memory trees to collect / presort incoming data per event |
649 | 650 | std::unordered_map<int, TMemFile*> mEventToTMemFileMap; //! files associated to the TTrees |
650 | 651 | std::thread mMergerIOThread; //! a thread used to do hit merging and IO flushing asynchronously |
651 | | - |
| 652 | + std::mutex mMapsMtx; //! |
652 | 653 | int mEntries = 0; //! counts the number of entries in the branches |
653 | 654 | int mEventChecksum = 0; //! checksum for events |
654 | 655 | int mNExpectedEvents = 0; //! number of events that we expect to receive |
|
0 commit comments