From 0f27b07b1958f24b56fdad5e7f420026cad8e7d2 Mon Sep 17 00:00:00 2001
From: Goetz Gaycken <goetz.gaycken@cern.ch>
Date: Thu, 26 Nov 2020 17:52:46 +0100
Subject: [PATCH] Avoid an early creation of CaloDescriptors.

The CaloDescriptors must not be created before the alignment callback has been
fired, because the descriptors cache the alignment transform at construction
time.

The creation of CaloDescriptors is e.g. triggered by the retrieval of the
calorimeter detector description manager. To ensure that this happens after the
alignment callback they are not retrieved anymore during the initialization of
the calorimeter volume builders.
---
 .../LArTrackingGeometry/LArVolumeBuilder.h    |  6 +-----
 .../src/LArVolumeBuilder.cxx                  | 20 +++++++++----------
 .../src/TileVolumeBuilder.cxx                 |  6 +-----
 3 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/LArCalorimeter/LArTrackingGeometry/LArTrackingGeometry/LArVolumeBuilder.h b/LArCalorimeter/LArTrackingGeometry/LArTrackingGeometry/LArVolumeBuilder.h
index fed7a542037..daf517aad43 100755
--- a/LArCalorimeter/LArTrackingGeometry/LArTrackingGeometry/LArVolumeBuilder.h
+++ b/LArCalorimeter/LArTrackingGeometry/LArTrackingGeometry/LArVolumeBuilder.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -18,12 +18,9 @@
 // STL
 #include <vector>
 
-class LArDetectorManager;
-class CaloDepthTool;
 class GeoPVConstLink;
 
 namespace Trk {
-  class ILayerArrayCreator;
   class ITrackingVolumeHelper;
   class ITrackingVolumeCreator;
   class TrackingVolume;
@@ -102,7 +99,6 @@ namespace LAr {
 
       // ------------- private members -----------------------------------------
                                      
-      const LArDetectorManager*                         m_lArMgr;                     //!< Calo DetDescrMgr
       std::string                                       m_lArMgrLocation;             //!< Location of the CaloDetDescrMgr
                                                                                       
       ToolHandle<Trk::ITrackingVolumeHelper>            m_lArTrackingVolumeHelper;     //!< Helper Tool to create TrackingVolumes
diff --git a/LArCalorimeter/LArTrackingGeometry/src/LArVolumeBuilder.cxx b/LArCalorimeter/LArTrackingGeometry/src/LArVolumeBuilder.cxx
index 894ae8676d6..dc65355f37c 100755
--- a/LArCalorimeter/LArTrackingGeometry/src/LArVolumeBuilder.cxx
+++ b/LArCalorimeter/LArTrackingGeometry/src/LArVolumeBuilder.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -53,7 +53,6 @@ using Gaudi::Units::mm;
 // constructor
 LAr::LArVolumeBuilder::LArVolumeBuilder(const std::string& t, const std::string& n, const IInterface* p) :
   AthAlgTool(t,n,p),
-  m_lArMgr(0),
   m_lArMgrLocation("LArMgr"),
   m_lArTrackingVolumeHelper("Trk::TrackingVolumeHelper/LArTrackingVolumeHelper"),
   m_trackingVolumeCreator("Trk::CylinderVolumeCreator/TrackingVolumeCreator"),
@@ -96,11 +95,6 @@ LAr::LArVolumeBuilder::~ LArVolumeBuilder()
 // initialize
 StatusCode LAr::LArVolumeBuilder::initialize()
 {
-  // get LAr Detector Description Manager
-  if (detStore()->retrieve(m_lArMgr, m_lArMgrLocation).isFailure()) {
-    ATH_MSG_FATAL( "Could not get LArDetectorManager! Calo TrackingGeometry will not be built");
-    return StatusCode::FAILURE;
-  }
   
   // Retrieve the tracking volume helper   -------------------------------------------------    
   if (m_lArTrackingVolumeHelper.retrieve().isFailure())
@@ -156,12 +150,18 @@ const std::vector<const Trk::TrackingVolume*>* LAr::LArVolumeBuilder::trackingVo
   
   Trk::Material dummyMaterial;
 
+  // get LAr Detector Description Manager
+  const LArDetectorManager* lArMgr=nullptr;
+  if (detStore()->retrieve(lArMgr, m_lArMgrLocation).isFailure()) {
+    ATH_MSG_FATAL( "Could not get LArDetectorManager! Calo TrackingGeometry will not be built");
+  }
+
   // out of couriosity
-  unsigned int numTreeTops =  m_lArMgr->getNumTreeTops();
+  unsigned int numTreeTops =  lArMgr->getNumTreeTops();
   ATH_MSG_DEBUG( "Retrieved " << numTreeTops << " tree tops from the LArDetDescrManager. " );
   
   for (unsigned int itreetop = 0; itreetop<numTreeTops; ++itreetop){
-    PVConstLink currentVPhysVolLink   = m_lArMgr->getTreeTop(itreetop);
+    PVConstLink currentVPhysVolLink   = lArMgr->getTreeTop(itreetop);
     const GeoLogVol* currentLogVol = currentVPhysVolLink->getLogVol();
     
     unsigned int currentChilds = currentVPhysVolLink->getNChildVols();
@@ -1703,7 +1703,7 @@ const std::vector<const Trk::TrackingVolume*>* LAr::LArVolumeBuilder::trackingVo
    // ST this better to be done by CaloTrackingGeometry ( to glue with BeamPipe )
    // pass MBTS info to CaloTG 
   // MBTS
-  const PVConstLink topEC = m_lArMgr->getTreeTop(1U);
+  const PVConstLink topEC = lArMgr->getTreeTop(1U);
   Amg::Transform3D trIn= topEC->getX();   
   Amg::Transform3D tr2(trIn);   
   const PVConstLink mbts= getChild(topEC,"MBTS_mother",trIn);
diff --git a/TileCalorimeter/TileTrackingGeometry/src/TileVolumeBuilder.cxx b/TileCalorimeter/TileTrackingGeometry/src/TileVolumeBuilder.cxx
index 87580b73a77..ac5c69f1017 100755
--- a/TileCalorimeter/TileTrackingGeometry/src/TileVolumeBuilder.cxx
+++ b/TileCalorimeter/TileTrackingGeometry/src/TileVolumeBuilder.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -95,10 +95,6 @@ Tile::TileVolumeBuilder::~ TileVolumeBuilder()
 // initialize
 StatusCode Tile::TileVolumeBuilder::initialize()
 {
-  // Get the Calo geometry
-  StatusCode status = detStore()->retrieve(m_calo_dd);
-  if(status.isFailure()) return status;
-  
   // get Tile Detector Description Manager
   if (detStore()->retrieve(m_tileMgr, m_tileMgrLocation).isFailure()){  
     ATH_MSG_FATAL( "Could not get TileDetDescrManager! Tile TrackingVolumes will not be built" );
-- 
GitLab