From 1eb3d0b46b1642627c9d7dfb728a018ca9e837e4 Mon Sep 17 00:00:00 2001
From: Scott Snyder <scott.snyder@cern.ch>
Date: Wed, 15 Sep 2021 19:24:05 +0200
Subject: [PATCH] MuonCondData+MuonCondSvc: Enable thread-safety checking.

---
 .../MuonCondData/ATLAS_CHECK_THREAD_SAFETY          |  1 +
 .../MuonCondData/CscCondDataCollectionBase.h        |  9 +--------
 .../MuonCondSvc/MuonCondSvc/CscCoolStrSvc.h         |  5 +++--
 .../MuonCondSvc/src/CscCoolStrSvc.cxx               | 13 +++++++------
 4 files changed, 12 insertions(+), 16 deletions(-)
 create mode 100644 MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/ATLAS_CHECK_THREAD_SAFETY

diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/ATLAS_CHECK_THREAD_SAFETY b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/ATLAS_CHECK_THREAD_SAFETY
new file mode 100644
index 000000000000..20bfa081ecf8
--- /dev/null
+++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/ATLAS_CHECK_THREAD_SAFETY
@@ -0,0 +1 @@
+MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData
diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/CscCondDataCollectionBase.h b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/CscCondDataCollectionBase.h
index 41fe3500f0f1..89ac26a17d9a 100755
--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/CscCondDataCollectionBase.h
+++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/CscCondDataCollectionBase.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef CSCCONDDATACOLLECTIONBASE_H 
@@ -15,7 +15,6 @@
 **/
 
 #include "AthContainers/DataVector.h"
-#include "StoreGate/DataHandle.h"
 #include "AthenaPoolUtilities/CondAttrListCollection.h"
 #include "MuonCondData/CscCondData.h"
 
@@ -75,10 +74,6 @@ namespace MuonCalib {
       //Get size
       virtual size_t getSize() const = 0; 
 
-      const DataHandle<CondAttrListCollection> & atrcHandle() const {
-        return m_atrcHandle;
-      }
-
       //record an entry to the DataVector 
       virtual StatusCode recordFromSS(std::istringstream & ss, const unsigned int & index) = 0;
 
@@ -104,8 +99,6 @@ namespace MuonCalib {
 
       int m_numBits;
       int m_bitOffset;
-      
-      const DataHandle<CondAttrListCollection> m_atrcHandle;
   };
 
 
diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/CscCoolStrSvc.h b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/CscCoolStrSvc.h
index 2b90dca2e85e..1e693c1ea65e 100755
--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/CscCoolStrSvc.h
+++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/CscCoolStrSvc.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef MUONCONDSVC_CSCCOOLSTRSVC_H
@@ -181,7 +181,8 @@ namespace MuonCalib {
 
     /**Map is an easier way to reference parameters by name than the dbCache*/
     std::map<std::string, CscCondDataCollectionBase*> m_parNameMap;
-    std::map<std::string, CscCondDataCollectionBase*> m_parSGKeyMap;
+    std::map<std::string, std::pair<CscCondDataCollectionBase*,
+                                    const DataHandle<CondAttrListCollection> > > m_parSGKeyMap;
 
     const CscCondDataCollection<float>* m_rmsCondData;
     const CscCondDataCollection<float>* m_slopeCondData;
diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/CscCoolStrSvc.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/CscCoolStrSvc.cxx
index d84c5e0a3103..dc8919b6f9e5 100755
--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/CscCoolStrSvc.cxx
+++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/CscCoolStrSvc.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 //Service designed to read in calibration files to the cool database. Can also read them
@@ -326,7 +326,7 @@ namespace MuonCalib {
 
       //Store the pointers in maps for easy lookup later
       m_parNameMap[name] = coll;
-      m_parSGKeyMap[sgKey] = coll;
+      m_parSGKeyMap[sgKey].first = coll;
       
       if( name == "rms" ) m_rmsCondData = dynamic_cast<CscCondDataCollection<float>*>(coll);
       else if( m_pslopeFromDB && name == "pslope" ) m_slopeCondData = dynamic_cast<CscCondDataCollection<float>*>(coll);
@@ -340,7 +340,8 @@ namespace MuonCalib {
         if( !m_statusCondData ) ATH_MSG_WARNING("Wrong data type for status bit " << dataType);
       }else  ATH_MSG_WARNING("Data type not cached, a direct access should be provided " << name);
       
-      const DataHandle<CondAttrListCollection> & dataHandle = coll->atrcHandle();
+      
+      const DataHandle<CondAttrListCollection> & dataHandle = m_parSGKeyMap[sgKey].second;
 
       //Registering callback function. The callback funciton will now be called
       //whenever the parameter in question is altered. i.e. whenever it goes
@@ -804,7 +805,7 @@ namespace MuonCalib {
   {
     if(msgLvl(MSG::DEBUG)) ATH_MSG_DEBUG("Caching parameter " << parKey);
     ///*****//
-    std::map<std::string, CscCondDataCollectionBase*>::iterator collItr = m_parSGKeyMap.find(parKey);
+    auto collItr = m_parSGKeyMap.find(parKey);
 
     if(collItr == m_parSGKeyMap.end())
     {
@@ -813,7 +814,7 @@ namespace MuonCalib {
       return StatusCode::RECOVERABLE;
     }
 
-    CscCondDataCollectionBase * coll = dynamic_cast<CscCondDataCollectionBase *>( collItr->second);
+    CscCondDataCollectionBase * coll = dynamic_cast<CscCondDataCollectionBase *>( collItr->second.first);
 
     coll->reset(); //Clear vector and set to size dictated by maxIndex
 
@@ -823,7 +824,7 @@ namespace MuonCalib {
     const unsigned int & numCoolChannels = coll->getNumCoolChan();
 
 
-    const CondAttrListCollection * atrc = &*(coll->atrcHandle());
+    const CondAttrListCollection * atrc = &*(collItr->second.second);
 
     //now cycle through all chambers in database;
     unsigned int numCoolChannelsFound = 0;
-- 
GitLab