From 4ec5693dc51e7e5f95934ba9a3defbedf8ec347d Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Mon, 18 Feb 2019 19:45:39 +0000
Subject: [PATCH] Add mutex or atomic to mutable data members of SCT classes
 (ATLASRECTS-4557)

---
 .../SCT_CalibAlgs/SCTCalibWriteTool.h         |  5 ++--
 .../SCT_CalibAlgs/src/SCTCalibWriteTool.cxx   |  7 +++---
 .../SCT_CalibAlgs/src/SCT_CalibEventInfo.h    | 12 +++++-----
 .../SCT_CalibAlgs/src/SCT_CalibLbTool.h       |  9 +++----
 .../src/SCT_ByteStreamErrorsTool.cxx          | 10 ++++++--
 .../SCT_Cabling/src/SCT_CablingTool.cxx       | 24 +++----------------
 .../SCT_Cabling/src/SCT_CablingTool.h         |  9 -------
 .../src/SCT_FillCablingFromCoraCool.h         |  5 ++--
 .../SCT_Cabling/src/SCT_FillCablingFromText.h |  5 ++--
 .../SCT_Digitization/src/SCT_FrontEnd.cxx     |  3 +++
 .../SCT_Digitization/src/SCT_FrontEnd.h       |  6 ++++-
 .../src/SCTRawDataProviderTool.cxx            |  4 ++--
 .../CompetingSCT_ClustersOnTrack.h            |  9 +++----
 .../src/CompetingSCT_ClustersOnTrack.cxx      |  9 ++-----
 .../InDetRIO_OnTrack/SiClusterOnTrack.h       |  6 +++--
 .../src/PixelClusterOnTrack.cxx               |  2 +-
 .../src/SCT_ClusterOnTrack.cxx                |  3 +--
 .../InDetRIO_OnTrack/src/SiClusterOnTrack.cxx | 12 +++++-----
 18 files changed, 61 insertions(+), 79 deletions(-)

diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteTool.h
index 112f7b3f505..a8fc81f48c3 100644
--- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteTool.h
+++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteTool.h
@@ -37,6 +37,7 @@
 #include <map>
 #include <set>
 #include <list>
+#include <mutex>
 
 //forward declarations
 class IdentifierHash;
@@ -177,6 +178,7 @@ class SCTCalibWriteTool : public AthAlgTool {
       static std::string s_LAFolderName;
 
       // cache for the Collections, access by foldername
+      mutable std::mutex m_mutex;
       mutable std::map<const std::string, const CondAttrListCollection*>  m_attrListCollectionMap;
       CondAttrListCollection*      m_attrListColl;
       CondAttrListCollection*      m_attrListColl_deadStrip;
@@ -223,9 +225,6 @@ class SCTCalibWriteTool : public AthAlgTool {
       bool                         m_BSErrRecorded;
       bool                         m_LARecorded;
       const SCT_ID*                m_pHelper;
-      // FIXME: this caches only the last call of getList.
-      // creating a hash of _all_ calls may be faster, but wastes a lot of memory
-      mutable std::string          m_currentDefectList;
 };
 
 inline const InterfaceID & SCTCalibWriteTool::interfaceID() {
diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteTool.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteTool.cxx
index 8adefbf3fb0..3748c82e541 100644
--- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteTool.cxx
+++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteTool.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 /**
@@ -59,6 +59,7 @@ SCTCalibWriteTool::SCTCalibWriteTool(const std::string& type, const std::string&
    AthAlgTool(type, name, parent),
    m_detStore(0),
    m_eventInfoKey(std::string("ByteStreamEventInfo")),
+   m_mutex(),
    m_attrListColl(0),
    m_attrListColl_deadStrip(0),
    m_attrListColl_deadChip(0),
@@ -93,8 +94,7 @@ SCTCalibWriteTool::SCTCalibWriteTool(const std::string& type, const std::string&
    m_RawOccuRecorded(false),
    m_BSErrRecorded(false),
    m_LARecorded(false),
-   m_pHelper(0),
-   m_currentDefectList("")
+   m_pHelper(0)
 {
    declareProperty("WriteCondObjs",        m_writeCondObjs);
    declareProperty("RegisterIOV",          m_regIOV);
@@ -514,6 +514,7 @@ SCTCalibWriteTool::createListLA(const Identifier& wafer_id,const SCT_ID* sctId,c
 
 const CondAttrListCollection*
 SCTCalibWriteTool::getAttrListCollectionByFolder(const string& foldername) const {
+   std::lock_guard<std::mutex> lock(m_mutex);
    // trying to find the pointer in the hashmap
    // if it exists, return it, otherwise put it in.
    const CondAttrListCollection* nullPtr(0);
diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.h
index d69448fdf75..54d44636ff0 100644
--- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.h
+++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.h
@@ -10,12 +10,12 @@
 
 #ifndef SCT_CalibEventInfo_h
 #define SCT_CalibEventInfo_h
-//#include "AthenaBaseComps/AthService.h"    //baseclass
-//#include "GaudiKernel/ServiceHandle.h"     //member
+
 #include "AthenaBaseComps/AthAlgTool.h"
 #include "GaudiKernel/ToolHandle.h"     //member
 
 #include "SCT_CalibAlgs/ISCT_CalibEvtInfo.h"
+#include <atomic>
 #include <string>
 
 class StatusCode;
@@ -74,10 +74,10 @@ class SCT_CalibEventInfo: public extends<AthAlgTool, ISCT_CalibEvtInfo>
       std::string m_source;
 
       //
-      mutable int m_runNumber;
-      mutable int m_lumiBlock;
-      mutable int m_timeStamp;
-      mutable int m_bunchCrossing;
+      mutable std::atomic_int m_runNumber;
+      mutable std::atomic_int m_lumiBlock;
+      mutable std::atomic_int m_timeStamp;
+      mutable std::atomic_int m_bunchCrossing;
       int  m_counter;
       std::string toUtc(const int timestamp) const;
 };
diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.h
index 55fbc61e725..e3eee1990eb 100644
--- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.h
+++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.h
@@ -11,9 +11,6 @@
 #ifndef SCT_CalibLbTool_h
 #define SCT_CalibLbTool_h
 
-//STL includes
-#include <string>
-
 //Athena includes
 #include "AthenaBaseComps/AthAlgTool.h"
 #include "StoreGate/StoreGateSvc.h"
@@ -28,6 +25,10 @@
 //local includes
 #include "SCT_CalibAlgs/ISCT_CalibHistoTool.h"
 
+//STL includes
+#include <atomic>
+#include <string>
+
 //fwd declarations
 
 namespace InDetDD {
@@ -72,7 +73,7 @@ class SCT_CalibLbTool : public extends<AthAlgTool, ISCT_CalibHistoTool>
       VecInt *m_sct_firstStrip;
       VecInt *m_sct_rdoGroupSize;
 
-      mutable int m_lumiBlock;
+      mutable std::atomic_int m_lumiBlock;
 
       //private use in this class
       int                m_LbRange;
diff --git a/InnerDetector/InDetConditions/SCT_ConditionsTools/src/SCT_ByteStreamErrorsTool.cxx b/InnerDetector/InDetConditions/SCT_ConditionsTools/src/SCT_ByteStreamErrorsTool.cxx
index 139b1301d70..2e7f2c46664 100644
--- a/InnerDetector/InDetConditions/SCT_ConditionsTools/src/SCT_ByteStreamErrorsTool.cxx
+++ b/InnerDetector/InDetConditions/SCT_ConditionsTools/src/SCT_ByteStreamErrorsTool.cxx
@@ -270,6 +270,7 @@ SCT_ByteStreamErrorsTool::getChip(const Identifier& stripId, const EventContext&
 
 void 
 SCT_ByteStreamErrorsTool::resetSets(const EventContext& ctx) const {
+  // Used in fillData and m_mutex is already locked.
 
   for (int errType{0}; errType<SCT_ByteStreamErrors::NUM_ERROR_TYPES; errType++) {
     m_bsErrors[errType][ctx.slot()].clear();
@@ -293,6 +294,7 @@ SCT_ByteStreamErrorsTool::getErrorSet(int errorType, const EventContext& ctx) co
       ATH_MSG_ERROR("fillData in getErrorSet fails");
     }
 
+    std::lock_guard<std::mutex> lock{m_mutex};
     return &m_bsErrors[errorType][ctx.slot()];
   }
   return nullptr;
@@ -316,13 +318,13 @@ SCT_ByteStreamErrorsTool::fillData(const EventContext& ctx) const {
   EventContext::ContextID_t slot{ctx.slot()};
   EventContext::ContextEvt_t evt{ctx.evt()};
   
+  std::lock_guard<std::mutex> lock{m_mutex};
+
   if (slot<m_cache.size() and m_cache[slot]==evt) {
     // Cache isvalid
     return StatusCode::SUCCESS;
   }
 
-  std::lock_guard<std::mutex> lock{m_mutex};
-
   static const EventContext::ContextEvt_t invalidValue{EventContext::INVALID_CONTEXT_EVT};  
   if (slot>=m_cache.size()) {
     m_cache.resize(slot+1, invalidValue); // Store invalid values in order to go to the next IF statement.
@@ -397,6 +399,8 @@ SCT_ByteStreamErrorsTool::fillData(const EventContext& ctx) const {
 
 void 
 SCT_ByteStreamErrorsTool::addError(const IdentifierHash& id, int errorType, const EventContext& ctx) const {
+  // Used in fillData and m_mutex is already locked.
+
   if (errorType>=0 and errorType<SCT_ByteStreamErrors::NUM_ERROR_TYPES) {
     m_bsErrors[errorType][ctx.slot()].insert(id);
   }
@@ -479,6 +483,7 @@ const std::map<Identifier, unsigned int>& SCT_ByteStreamErrorsTool::getTempMaske
     ATH_MSG_ERROR("fillData in getTempMaskedChips fails");
   }
 
+  std::lock_guard<std::mutex> lock{m_mutex};
   return m_tempMaskedChips[ctx.slot()];
 }
 
@@ -488,5 +493,6 @@ const std::map<Identifier, unsigned int>& SCT_ByteStreamErrorsTool::getAbcdError
     ATH_MSG_ERROR("fillData in getAbcdErrorChips fails");
   }
 
+  std::lock_guard<std::mutex> lock{m_mutex};
   return m_abcdErrorChips[ctx.slot()];
 }
diff --git a/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_CablingTool.cxx b/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_CablingTool.cxx
index 38c5c554382..4c012112c02 100644
--- a/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_CablingTool.cxx
+++ b/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_CablingTool.cxx
@@ -43,10 +43,7 @@ namespace {
 SCT_CablingTool::SCT_CablingTool(const std::string& type, const std::string& name, const IInterface* parent) :
   base_class(type, name, parent),
   m_idHelper{nullptr},
-  m_usingDatabase{true},
-  m_mutex{},
-  m_cache{},
-  m_condData{}
+  m_usingDatabase{true}
 {
   declareProperty("DataSource", m_cablingDataSource=defaultSource);
 }
@@ -263,21 +260,6 @@ SCT_CablingTool::getHashesForRod(std::vector<IdentifierHash>& usersVector, const
 
 const SCT_CablingData*
 SCT_CablingTool::getData(const EventContext& ctx) const {
-  static const EventContext::ContextEvt_t invalidValue{EventContext::INVALID_CONTEXT_EVT};
-  const EventContext::ContextID_t slot{ctx.slot()};
-  const EventContext::ContextEvt_t evt{ctx.evt()};
-  if (slot>=m_cache.size()) {
-    std::lock_guard<std::mutex> lock(m_mutex);
-    m_cache.resize(slot+1, invalidValue); // Store invalid values in order to go to the next IF statement.
-  }
-  if (m_cache[slot]!=evt) {
-    std::lock_guard<std::mutex> lock(m_mutex);
-    SG::ReadCondHandle<SCT_CablingData> condData{m_data};
-    if (not condData.isValid()) {
-      ATH_MSG_ERROR("Failed to get " << m_data.key());
-    }
-    m_condData.set(*condData);
-    m_cache[slot] = evt;
-  }
-  return m_condData.get();
+  SG::ReadCondHandle<SCT_CablingData> condData{m_data, ctx};
+  return condData.retrieve();
 }
diff --git a/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_CablingTool.h b/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_CablingTool.h
index e6cdf406892..2caac3dba33 100644
--- a/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_CablingTool.h
+++ b/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_CablingTool.h
@@ -20,11 +20,9 @@
 #include "StoreGate/ReadCondHandleKey.h"
 
 // Gaudi includes
-#include "GaudiKernel/ContextSpecificPtr.h"
 #include "GaudiKernel/EventContext.h"
 
 //STL includes
-#include <mutex>
 #include <string>
 #include <vector>
 
@@ -100,13 +98,6 @@ class SCT_CablingTool: public extends<AthAlgTool, ISCT_CablingTool> {
   const SCT_ID* m_idHelper; //!< helper for offlineId/hash conversions
   bool m_usingDatabase;
 
-  // Mutex to protect the contents.
-  mutable std::mutex m_mutex;
-  // Cache to store events for slots
-  mutable std::vector<EventContext::ContextEvt_t> m_cache;
-  // Pointer of SCT_CablingData
-  mutable Gaudi::Hive::ContextSpecificPtr<const SCT_CablingData> m_condData;
-
   const SCT_CablingData* getData(const EventContext& ctx) const;
 };
 
diff --git a/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_FillCablingFromCoraCool.h b/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_FillCablingFromCoraCool.h
index e3c753d36a8..8aaa2464e23 100644
--- a/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_FillCablingFromCoraCool.h
+++ b/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_FillCablingFromCoraCool.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef SCT_FillCablingFromCoraCool_H
@@ -20,6 +20,7 @@
 #include "AthenaPoolUtilities/CondAttrListVec.h"
 
 //STL includes
+#include <atomic>
 #include <string>
 
 //fwd declarations
@@ -79,7 +80,7 @@ private:
 
   bool insert(const IdentifierHash& hash, const SCT_OnlineId& onlineId, const SCT_SerialNumber& sn, SCT_CablingData& data) const;
 
-  mutable bool m_filled;
+  mutable std::atomic_bool m_filled;
   std::string m_source;
 };//end of class
 
diff --git a/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_FillCablingFromText.h b/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_FillCablingFromText.h
index 18d4702aeae..7ce6254126d 100644
--- a/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_FillCablingFromText.h
+++ b/InnerDetector/InDetDetDescr/SCT_Cabling/src/SCT_FillCablingFromText.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef SCT_FillCablingFromText_H
@@ -18,6 +18,7 @@
 #include "SCT_Cabling/ISCT_FillCabling.h"
 
 //STL includes
+#include <atomic>
 #include <string>
 
 //fwd declarations
@@ -72,7 +73,7 @@ class SCT_FillCablingFromText: public extends<AthAlgTool, ISCT_FillCabling> {
 
   bool insert(const IdentifierHash& hash, const SCT_OnlineId& onlineId, const SCT_SerialNumber& sn, SCT_CablingData& data) const;
 
-  mutable bool m_filled;
+  mutable std::atomic_bool m_filled;
   std::string m_source;
 };//end of class
 
diff --git a/InnerDetector/InDetDigitization/SCT_Digitization/src/SCT_FrontEnd.cxx b/InnerDetector/InDetDigitization/SCT_Digitization/src/SCT_FrontEnd.cxx
index e5a7317ffe4..cdb3a5401f6 100644
--- a/InnerDetector/InDetDigitization/SCT_Digitization/src/SCT_FrontEnd.cxx
+++ b/InnerDetector/InDetDigitization/SCT_Digitization/src/SCT_FrontEnd.cxx
@@ -30,6 +30,7 @@ using namespace InDetDD;
 // constructor
 SCT_FrontEnd::SCT_FrontEnd(const std::string& type, const std::string& name, const IInterface* parent)
   : AthAlgTool(type, name, parent),
+    m_mutex(),
     m_SCTdetMgr(nullptr),
     m_sct_id(nullptr) {
   declareInterface<ISCT_FrontEnd>(this);
@@ -593,6 +594,8 @@ StatusCode SCT_FrontEnd::randomNoise(SiChargedDiodeCollection& collection, const
 // (this could be moved elsewhere later) apply threshold do clustering
 // ----------------------------------------------------------------------
 void SCT_FrontEnd::process(SiChargedDiodeCollection& collection, CLHEP::HepRandomEngine * rndmEngine) const {
+  std::lock_guard<std::mutex> lock(m_mutex);
+
   // get SCT module side design and check it
   const SCT_ModuleSideDesign *p_design = dynamic_cast<const SCT_ModuleSideDesign*>(&(collection.design()));
 
diff --git a/InnerDetector/InDetDigitization/SCT_Digitization/src/SCT_FrontEnd.h b/InnerDetector/InDetDigitization/SCT_Digitization/src/SCT_FrontEnd.h
index 73e510cb778..9e2e6c60060 100644
--- a/InnerDetector/InDetDigitization/SCT_Digitization/src/SCT_FrontEnd.h
+++ b/InnerDetector/InDetDigitization/SCT_Digitization/src/SCT_FrontEnd.h
@@ -36,6 +36,9 @@
 // Gaudi
 #include "GaudiKernel/ToolHandle.h"
 
+// STL
+#include <mutex>
+
 class ISCT_Amp;
 class SCT_ID;
 
@@ -112,7 +115,8 @@ class  SCT_FrontEnd : public AthAlgTool, virtual public ISCT_FrontEnd {
   short m_data_readout_mode;                //!< To set the data read out mode
   bool m_useCalibData;                      //!< Flag to set the use of calibration data for noise, Gain,offset etc.
   mutable int m_strip_max;                  //!< For SLHC studies
- 
+
+  mutable std::mutex m_mutex;
   mutable std::vector<float> m_Offset;      //!< generate offset per channel
   mutable std::vector<float> m_GainFactor;  //!< generate gain per channel  (added to the gain per chip from calib data)
   mutable std::vector<float> m_NoiseFactor; //!< Kondo: 31/08/07 noise per channel (actually noise per chip from calib data)
diff --git a/InnerDetector/InDetEventCnv/SCT_RawDataByteStreamCnv/src/SCTRawDataProviderTool.cxx b/InnerDetector/InDetEventCnv/SCT_RawDataByteStreamCnv/src/SCTRawDataProviderTool.cxx
index 7b53401825c..0037d7fde39 100644
--- a/InnerDetector/InDetEventCnv/SCT_RawDataByteStreamCnv/src/SCTRawDataProviderTool.cxx
+++ b/InnerDetector/InDetEventCnv/SCT_RawDataByteStreamCnv/src/SCTRawDataProviderTool.cxx
@@ -47,6 +47,8 @@ StatusCode SCTRawDataProviderTool::convert(std::vector<const ROBFragment*>& vecR
   
   StatusCode sc{StatusCode::SUCCESS};
 
+  std::lock_guard<std::mutex> lock(m_mutex);
+
   // loop over the ROB fragments
 
   std::set<uint32_t> tmpROBIDSet;
@@ -79,9 +81,7 @@ StatusCode SCTRawDataProviderTool::convert(std::vector<const ROBFragment*>& vecR
     }
   }
 
-  m_mutex.lock();
   m_robIDSet.insert(tmpROBIDSet.begin(), tmpROBIDSet.end());
-  m_mutex.unlock();
 
   if (sc == StatusCode::FAILURE) {
     ATH_MSG_ERROR("There was a problem with SCT ByteStream conversion");
diff --git a/InnerDetector/InDetRecEvent/InDetCompetingRIOsOnTrack/InDetCompetingRIOsOnTrack/CompetingSCT_ClustersOnTrack.h b/InnerDetector/InDetRecEvent/InDetCompetingRIOsOnTrack/InDetCompetingRIOsOnTrack/CompetingSCT_ClustersOnTrack.h
index 6364b47fb98..45b1434dfa7 100755
--- a/InnerDetector/InDetRecEvent/InDetCompetingRIOsOnTrack/InDetCompetingRIOsOnTrack/CompetingSCT_ClustersOnTrack.h
+++ b/InnerDetector/InDetRecEvent/InDetCompetingRIOsOnTrack/InDetCompetingRIOsOnTrack/CompetingSCT_ClustersOnTrack.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -14,7 +14,7 @@
 #include "InDetRIO_OnTrack/SCT_ClusterOnTrack.h" // cannot fwd-declare because of covariant method
 
 #include <iosfwd>
-#include <mutex>
+#include <atomic>
 
 class MsgStream;
 
@@ -106,9 +106,7 @@ private:
 
 
     /** The global position */
-    mutable const Amg::Vector3D*        m_globalPosition;
-    /** Mutex to protect the global position */
-    mutable std::mutex m_mutex;
+    mutable std::atomic<const Amg::Vector3D*> m_globalPosition;
 
     /** The vector of contained InDet::SCT_ClusterOnTrack objects */
     std::vector<const InDet::SCT_ClusterOnTrack*>*   m_containedChildRots;
@@ -141,7 +139,6 @@ inline const InDet::SCT_ClusterOnTrack& CompetingSCT_ClustersOnTrack::rioOnTrack
 
 inline const Amg::Vector3D& CompetingSCT_ClustersOnTrack::globalPosition() const {
     if (m_globalPosition==nullptr) {
-        std::lock_guard<std::mutex> lock{m_mutex};
         m_globalPosition = associatedSurface().localToGlobal(localParameters());
     }
     return (*m_globalPosition);
diff --git a/InnerDetector/InDetRecEvent/InDetCompetingRIOsOnTrack/src/CompetingSCT_ClustersOnTrack.cxx b/InnerDetector/InDetRecEvent/InDetCompetingRIOsOnTrack/src/CompetingSCT_ClustersOnTrack.cxx
index 8c4eec43588..ac3bdd91975 100755
--- a/InnerDetector/InDetRecEvent/InDetCompetingRIOsOnTrack/src/CompetingSCT_ClustersOnTrack.cxx
+++ b/InnerDetector/InDetRecEvent/InDetCompetingRIOsOnTrack/src/CompetingSCT_ClustersOnTrack.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -19,7 +19,6 @@
 InDet::CompetingSCT_ClustersOnTrack::CompetingSCT_ClustersOnTrack():
         Trk::CompetingRIOsOnTrack(),
         m_globalPosition(nullptr),
-        m_mutex(),
         m_containedChildRots(0)
         //
         {}
@@ -28,7 +27,6 @@ InDet::CompetingSCT_ClustersOnTrack::CompetingSCT_ClustersOnTrack():
 InDet::CompetingSCT_ClustersOnTrack::CompetingSCT_ClustersOnTrack(const InDet::CompetingSCT_ClustersOnTrack& compROT) :
         Trk::CompetingRIOsOnTrack(compROT),
         m_globalPosition(compROT.m_globalPosition ? new Amg::Vector3D(*compROT.m_globalPosition) : nullptr),
-        m_mutex(),
         m_containedChildRots(0) {
     m_containedChildRots = new std::vector< const InDet::SCT_ClusterOnTrack* >;
     std::vector< const InDet::SCT_ClusterOnTrack* >::const_iterator rotIter = compROT.m_containedChildRots->begin();
@@ -46,7 +44,6 @@ InDet::CompetingSCT_ClustersOnTrack::CompetingSCT_ClustersOnTrack(
 ):
 Trk::CompetingRIOsOnTrack(assgnProb),
 m_globalPosition(nullptr),
-m_mutex(),
 m_containedChildRots(childrots)
 {
   // initialize local position and error matrix
@@ -68,17 +65,15 @@ InDet::CompetingSCT_ClustersOnTrack& InDet::CompetingSCT_ClustersOnTrack::operat
         for (; rotIter!=compROT.m_containedChildRots->end(); ++rotIter)
             m_containedChildRots->push_back((*rotIter)->clone());
 
-        std::lock_guard<std::mutex> lock{m_mutex};
         m_globalPosition     = compROT.m_globalPosition ? new Amg::Vector3D(*compROT.m_globalPosition) : nullptr;
     }
     return (*this);
 }
 
 InDet::CompetingSCT_ClustersOnTrack::~CompetingSCT_ClustersOnTrack() {
-   
-    delete m_globalPosition;
     clearChildRotVector();
     delete m_containedChildRots;
+    delete m_globalPosition;
 }
 
 void InDet::CompetingSCT_ClustersOnTrack::clearChildRotVector() {
diff --git a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/InDetRIO_OnTrack/SiClusterOnTrack.h b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/InDetRIO_OnTrack/SiClusterOnTrack.h
index 06e529f8e12..fc773dd6a15 100755
--- a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/InDetRIO_OnTrack/SiClusterOnTrack.h
+++ b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/InDetRIO_OnTrack/SiClusterOnTrack.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -12,6 +12,8 @@
 #include "TrkRIO_OnTrack/RIO_OnTrack.h"
 #include "Identifier/IdentifierHash.h"
 
+#include <atomic>
+
 class SiClusterOnTrackCnv_p1;
 
 namespace Trk 
@@ -101,7 +103,7 @@ namespace InDet {
       /** The IdentifierHash - probably not used*/
       IdentifierHash                      m_idDE;
       /** The global position */
-      mutable const Amg::Vector3D*  m_globalPosition;
+      mutable std::atomic<const Amg::Vector3D*> m_globalPosition;
       bool m_isbroad;
   };
 
diff --git a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/PixelClusterOnTrack.cxx b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/PixelClusterOnTrack.cxx
index 7df70ae4405..156d7287743 100755
--- a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/PixelClusterOnTrack.cxx
+++ b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/PixelClusterOnTrack.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
diff --git a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/SCT_ClusterOnTrack.cxx b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/SCT_ClusterOnTrack.cxx
index ee25b4ddc46..d1bcf1e158b 100755
--- a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/SCT_ClusterOnTrack.cxx
+++ b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/SCT_ClusterOnTrack.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -89,7 +89,6 @@ void InDet::SCT_ClusterOnTrack::setValues(const Trk::TrkDetElementBase* detEl, c
   
 const  Amg::Vector3D& InDet::SCT_ClusterOnTrack::globalPosition() const
   {
-  
    //checking whether the globalposition is available
    if(!m_globalPosition)
    {
diff --git a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/SiClusterOnTrack.cxx b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/SiClusterOnTrack.cxx
index 3da49587060..5aa45e5ddf1 100755
--- a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/SiClusterOnTrack.cxx
+++ b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/SiClusterOnTrack.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -47,7 +47,7 @@ InDet::SiClusterOnTrack::SiClusterOnTrack( const Trk::LocalParameters& locpars,
 // Destructor:
 InDet::SiClusterOnTrack::~SiClusterOnTrack()
 { 
-  delete m_globalPosition; 
+  delete m_globalPosition;
 }
 
 // Default constructor:
@@ -84,15 +84,15 @@ InDet::SiClusterOnTrack& InDet::SiClusterOnTrack::operator=( const SiClusterOnTr
 
 const Amg::Vector3D& InDet::SiClusterOnTrack::globalPosition() const
 { 
-    if (!m_globalPosition) m_globalPosition = associatedSurface().localToGlobal(localParameters());
-    return (*m_globalPosition); 
+   if (!m_globalPosition) m_globalPosition = associatedSurface().localToGlobal(localParameters());
+   return (*m_globalPosition);
 }
 
 MsgStream& InDet::SiClusterOnTrack::dump( MsgStream& sl ) const
 {
 
     sl << "SiClusterOnTrack {" << endmsg;
-    Trk::RIO_OnTrack::dump(sl); 
+    Trk::RIO_OnTrack::dump(sl);
 
     sl << "Global position (x,y,z) = (";
     this->globalPosition();
@@ -112,7 +112,7 @@ std::ostream& InDet::SiClusterOnTrack::dump( std::ostream& sl ) const
 {
     sl << "SiClusterOnTrack {"<<std::endl;
 
-    Trk::RIO_OnTrack::dump(sl); 
+    Trk::RIO_OnTrack::dump(sl);
 
     sl << "Global position (x,y,z) = (";
     this->globalPosition();
-- 
GitLab