From 628cb9ca993ceda8cab75603313d5c865fbef9bb Mon Sep 17 00:00:00 2001
From: scott snyder <sss@karma>
Date: Mon, 7 Sep 2020 15:09:43 -0400
Subject: [PATCH] TRT_GeoModel: Thread-safety cleanups.

Const consistency.
Remove most ATLAS_NOT_THREAD_SAFE annotations (except for registerCallback).
Remove use of static data.
---
 .../src/TRTDetectorFactory_Full.cxx           | 34 +++++++++----------
 .../src/TRTDetectorFactory_Full.h             |  6 ++--
 .../src/TRT_DetDescrDB_ParameterInterface.cxx |  2 +-
 .../src/TRT_DetDescrDB_ParameterInterface.h   |  2 +-
 .../TRT_GeoModel/src/TRT_DetectorTool.cxx     |  2 +-
 5 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.cxx b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.cxx
index 3ced1b74b7ca..d48ccba8a08d 100755
--- a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.cxx
+++ b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.cxx
@@ -2287,7 +2287,7 @@ GeoPhysVol * TRTDetectorFactory_Full::makeStraw( double& activeGasZPosition, boo
 ///////////////////////////////// makeStrawPlane /////////////////////////////////
 //
 //GeoFullPhysVol * TRTDetectorFactory_Full::makeStrawPlane(size_t w) const {
-GeoFullPhysVol * TRTDetectorFactory_Full::makeStrawPlane(size_t w, ActiveGasMixture gasMixture) const {
+GeoFullPhysVol * TRTDetectorFactory_Full::makeStrawPlane(size_t w, ActiveGasMixture gasMixture) {
   // -----------------------------------------------------------------------------------//
   //                                                                                    //
   // There are twelve straw planes; however there are only two kinds, one for sector    //
@@ -2295,29 +2295,29 @@ GeoFullPhysVol * TRTDetectorFactory_Full::makeStrawPlane(size_t w, ActiveGasMixt
   // In order to economize, we shall only create two planes.                            //
   // -----------------------------------------------------------------------------------//
 
-  static GeoFullPhysVol *type1Plane=nullptr, *type2Plane=nullptr, *type1PlaneAr=nullptr, *type2PlaneAr=nullptr, *type1PlaneKr=nullptr, *type2PlaneKr=nullptr;
   size_t nstraws=0;
 
   //A and B wheels have similar straw planes, but the C wheels are different.
   //  const size_t firstIndexOfC = 15; //hardcoded
   const size_t firstIndexOfC = 14; //hardcoded
 
-  GeoFullPhysVol *&cur_type1Plane = (gasMixture == GM_KRYPTON) ? type1PlaneKr :
-                                    (gasMixture == GM_ARGON  ) ? type1PlaneAr :
-                                                                 type1Plane;
-  GeoFullPhysVol *&cur_type2Plane = (gasMixture == GM_KRYPTON) ? type2PlaneKr :
-                                    (gasMixture == GM_ARGON  ) ? type2PlaneAr :
-                                                                 type2Plane;
+  unsigned iplane = 0;
+  if (gasMixture == GM_ARGON) {
+    iplane = 1;
+  }
+  else if (gasMixture == GM_KRYPTON) {
+    iplane = 2;
+  }
 
   if (w>=firstIndexOfC) {
-    if (cur_type2Plane!=nullptr) {
-      return cur_type2Plane;
+    if (m_type2Planes[iplane] != nullptr) {
+      return m_type2Planes[iplane];
     }
     nstraws=m_data->endcapNumberOfStrawsInStrawLayer_CWheels;
   } 
   else {
-    if (cur_type1Plane!=nullptr) {
-      return cur_type1Plane;
+    if (m_type1Planes[iplane] != nullptr) {
+      return m_type1Planes[iplane];
     }
     nstraws=m_data->endcapNumberOfStrawsInStrawLayer_AWheels;
     //Check here that (m_data->endcapNumberOfStrawsInStrawLayer_AWheels == m_data->endcapNumberOfStrawsInStrawLayer_BWheels) !!
@@ -2415,15 +2415,13 @@ GeoFullPhysVol * TRTDetectorFactory_Full::makeStrawPlane(size_t w, ActiveGasMixt
   GeoPhysVol *pWire = new GeoPhysVol(lWire);
   pStraw->add(pWire);
 
-  // Look above *type2Plane=nullptr
-  if (w>=firstIndexOfC && type2Plane!=nullptr) {
-    cur_type2Plane=pStrawPlane;
-    return cur_type2Plane;
+  if (w>=firstIndexOfC) {
+    m_type2Planes[iplane] = pStrawPlane;
   }
   else {
-    cur_type1Plane=pStrawPlane;
-    return cur_type1Plane;
+    m_type1Planes[iplane] = pStrawPlane;
   }
+  return pStrawPlane;
 
 }
 
diff --git a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.h b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.h
index eed23fcd1885..aabed98257ae 100755
--- a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.h
+++ b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.h
@@ -29,7 +29,7 @@ class GeoFullPhysVol;
 class TRTParameterInterface;
 class InDetMaterialManager;
 
-class ATLAS_NOT_THREAD_SAFE TRTDetectorFactory_Full : public InDetDD::DetectorFactoryBase  { // Static variables are used.
+class TRTDetectorFactory_Full : public InDetDD::DetectorFactoryBase  {
 
  public:
   
@@ -88,7 +88,7 @@ class ATLAS_NOT_THREAD_SAFE TRTDetectorFactory_Full : public InDetDD::DetectorFa
   //GeoPhysVol * makeStraw( double& activeGasZPosition, bool hasLargeDeadRegion=false ) const;
   GeoPhysVol * makeStraw( double& activeGasZPosition, bool hasLargeDeadRegion=false, ActiveGasMixture gasMixture = GM_XENON) const;
   //GeoFullPhysVol  *makeStrawPlane( size_t w ) const;
-  GeoFullPhysVol  *makeStrawPlane( size_t w , ActiveGasMixture gasMixture = GM_XENON) const;
+  GeoFullPhysVol  *makeStrawPlane( size_t w , ActiveGasMixture gasMixture = GM_XENON);
 
   // private member data:
   InDetDD::TRT_DetectorManager * m_detectorManager;
@@ -105,6 +105,8 @@ class ATLAS_NOT_THREAD_SAFE TRTDetectorFactory_Full : public InDetDD::DetectorFa
   bool m_doKrypton;
   bool m_useDynamicAlignFolders;
 
+  GeoFullPhysVol* m_type1Planes[3] = {nullptr, nullptr, nullptr};
+  GeoFullPhysVol* m_type2Planes[3] = {nullptr, nullptr, nullptr};
 };
 
 #endif // TRTDetectorFactory_Full_h
diff --git a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetDescrDB_ParameterInterface.cxx b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetDescrDB_ParameterInterface.cxx
index 02fd09c0bb6a..65baba4b4caa 100755
--- a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetDescrDB_ParameterInterface.cxx
+++ b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetDescrDB_ParameterInterface.cxx
@@ -53,7 +53,7 @@ TRT_DetDescrDB_ParameterInterface::~TRT_DetDescrDB_ParameterInterface() {
 }
 
 //_________________________________________________________________________________________
-void TRT_DetDescrDB_ParameterInterface::SetValues ATLAS_NOT_THREAD_SAFE () { // Thread unsafe AthenaComps::rdbAccessSvc const method is used.
+void TRT_DetDescrDB_ParameterInterface::SetValues() {
 
   /////////////////////////////////////////////////////////////////////////////////////////
   //                                 Initialize Services                                 //
diff --git a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetDescrDB_ParameterInterface.h b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetDescrDB_ParameterInterface.h
index 7d294887ce1e..f28529a3f1dd 100755
--- a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetDescrDB_ParameterInterface.h
+++ b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetDescrDB_ParameterInterface.h
@@ -23,7 +23,7 @@ public:
 
    
   // Only allowed constructor
-  TRT_DetDescrDB_ParameterInterface(InDetDD::AthenaComps * athenaComps) ATLAS_CTORDTOR_NOT_THREAD_SAFE; // Thread unsafe SetValues method is used.
+  TRT_DetDescrDB_ParameterInterface(InDetDD::AthenaComps * athenaComps);
 
   ~TRT_DetDescrDB_ParameterInterface();
   // delete copy c'tor
diff --git a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetectorTool.cxx b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetectorTool.cxx
index b14adda18339..ffe15af57e62 100755
--- a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetectorTool.cxx
+++ b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetectorTool.cxx
@@ -68,7 +68,7 @@ TRT_DetectorTool::~TRT_DetectorTool()
 
 //////////////  Create the Detector Node corresponding to this tool //////////////
 //
-StatusCode TRT_DetectorTool::create ATLAS_NOT_THREAD_SAFE () // Thread unsafe TRTDetectorFactory_Full class is used.
+StatusCode TRT_DetectorTool::create()
 { 
 
   // Get the detector configuration.
-- 
GitLab