From 3f2669f98f0fa00a7bd643fcd3e57d523b0b3ab2 Mon Sep 17 00:00:00 2001
From: Vakho Tsulaia <vakhtang.tsulaia@cern.ch>
Date: Thu, 28 Oct 2021 02:43:26 +0200
Subject: [PATCH] Fixed the access to CaloDetDescrManager in TBRec

1. Switched TBCellContainerFillerTool to reading CaloDetDescrManager from
the Condition Store
2. Dropped the redundant dependency on CaloDetDescrManager from
TBClusterMaker, TBECLArRawChannelBuilder and TBEMECXTalkToyModel.
Instead they now retrieve CaloCell ID helpers directly from the
Detector Store

This is part of the ongoing migration of all clients of CaloDetDescrManager
---
 .../TBRec/src/TBCellContainerFillerTool.cxx   | 46 +++++++++----------
 .../TBRec/src/TBCellContainerFillerTool.h     | 18 +++++---
 TestBeam/TBRec/src/TBClusterMaker.cxx         | 13 +-----
 TestBeam/TBRec/src/TBClusterMaker.h           |  7 ---
 .../TBRec/src/TBECLArRawChannelBuilder.cxx    |  9 ++--
 TestBeam/TBRec/src/TBECLArRawChannelBuilder.h |  2 -
 TestBeam/TBRec/src/TBEMECXTalkToyModel.cxx    |  5 +-
 TestBeam/TBRec/src/TBEMECXTalkToyModel.h      |  6 +--
 8 files changed, 41 insertions(+), 65 deletions(-)

diff --git a/TestBeam/TBRec/src/TBCellContainerFillerTool.cxx b/TestBeam/TBRec/src/TBCellContainerFillerTool.cxx
index d6f2fbee0c18..3854a23b9ecb 100644
--- a/TestBeam/TBRec/src/TBCellContainerFillerTool.cxx
+++ b/TestBeam/TBRec/src/TBCellContainerFillerTool.cxx
@@ -14,9 +14,7 @@ TBCellContainerFillerTool::TBCellContainerFillerTool(
 			     const std::string& type, 
 			     const std::string& name, 
 			     const IInterface* parent)
-  :base_class (type, name, parent) ,
-   m_theCaloDDM(0), m_theCaloCCIDM(0), m_onlineHelper(0),
-   m_hashMax(0)
+  :base_class (type, name, parent)
 { 
 }
 
@@ -25,10 +23,9 @@ TBCellContainerFillerTool::TBCellContainerFillerTool(
 
 StatusCode TBCellContainerFillerTool::initialize()
 {
+  ATH_CHECK(m_caloMgrKey.initialize());
   // Cache pointers:
-
-  m_theCaloDDM = CaloDetDescrManager::instance() ;
-  m_theCaloCCIDM   = m_theCaloDDM->getCaloCell_ID() ;
+  ATH_CHECK(detStore()->retrieve(m_theCaloCCIDM, "CaloCell_ID"));
 
   m_hashMax = m_theCaloCCIDM->calo_cell_hash_max();
 
@@ -39,9 +36,12 @@ StatusCode TBCellContainerFillerTool::initialize()
 
 StatusCode
 TBCellContainerFillerTool::process (CaloCellContainer* theCont,
-                                    const EventContext& /*ctx*/) const
+                                    const EventContext& ctx) const
 {
-	
+  SG::ReadCondHandle<CaloDetDescrManager> caloMgrHandle{m_caloMgrKey,ctx};
+  ATH_CHECK(caloMgrHandle.isValid());
+  const CaloDetDescrManager* caloMgr = *caloMgrHandle;
+
   StatusCode returnSc = StatusCode::SUCCESS ;
 
   unsigned int index = 0;
@@ -68,23 +68,23 @@ TBCellContainerFillerTool::process (CaloCellContainer* theCont,
     const CaloCell * theCell = theCont->findCell(IdentifierHash(theHash)) ;
     CaloCell *nCell;
     if(!theCell) {
-       Identifier cellid = m_theCaloCCIDM->cell_id(theHash);
-       HWIdentifier chid = m_onlineHelper->channel_Id(m_theCaloCCIDM->calo_cell_hash(cellid));
-       if(!chid.get_identifier32().get_compact()) continue;
-          const CaloDetDescrElement* cDDE = m_theCaloDDM->get_element(cellid);
-          if(!cDDE) { continue; }
-          if(cDDE->is_lar_hec())
-             nCell = new CaloCell(cDDE,0.,0.,0.,CaloGain::LARMEDIUMGAIN);
-          else
-             nCell = new CaloCell(cDDE,0.,0.,0.,CaloGain::LARHIGHGAIN);
-          ATH_MSG_VERBOSE ( "Adding 0. energy cell: " << m_theCaloCCIDM->cell_id(theHash));
-          theCont->push_back(nCell);
-          ++added;
-//       }
+      Identifier cellid = m_theCaloCCIDM->cell_id(theHash);
+      HWIdentifier chid = m_onlineHelper->channel_Id(m_theCaloCCIDM->calo_cell_hash(cellid));
+      if(!chid.get_identifier32().get_compact()) continue;
+      const CaloDetDescrElement* cDDE = caloMgr->get_element(cellid);
+      if(!cDDE) continue;
+      if(cDDE->is_lar_hec()) {
+	nCell = new CaloCell(cDDE,0.,0.,0.,CaloGain::LARMEDIUMGAIN);
+      }
+      else {
+	nCell = new CaloCell(cDDE,0.,0.,0.,CaloGain::LARHIGHGAIN);
+      }
+      ATH_MSG_VERBOSE ( "Adding 0. energy cell: " << m_theCaloCCIDM->cell_id(theHash));
+      theCont->push_back(nCell);
+      ++added;
     } 
   }
-
-//  theCont->updateCaloIterators();
+  
   theCont->order();
   
   return returnSc ;
diff --git a/TestBeam/TBRec/src/TBCellContainerFillerTool.h b/TestBeam/TBRec/src/TBCellContainerFillerTool.h
index d1a25d1dac57..a1d1c507b98d 100644
--- a/TestBeam/TBRec/src/TBCellContainerFillerTool.h
+++ b/TestBeam/TBRec/src/TBCellContainerFillerTool.h
@@ -1,17 +1,17 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef TBREC_TBCELLCONTAINERFILLERTOOL_H
 #define TBREC_TBCELLCONTAINERFILLERTOOL_H
 
 #include "AthenaBaseComps/AthAlgTool.h"
-//#include "CaloUtils/ICaloCellMakerTool.h"
 #include "CaloInterface/ICaloCellMakerTool.h"
 #include "GaudiKernel/ToolHandle.h"
+#include "CaloDetDescr/CaloDetDescrManager.h"
+#include "StoreGate/ReadCondHandleKey.h"
 
 class MsgStream;
-class CaloDetDescrManager;
 class CaloCell_ID;
 class LArOnlineID;
 
@@ -30,10 +30,14 @@ class TBCellContainerFillerTool
                                     const EventContext& ctx) const override;
 
     private:
-        const CaloDetDescrManager *m_theCaloDDM;
-        const CaloCell_ID * m_theCaloCCIDM;
-        const LArOnlineID* m_onlineHelper;
-        unsigned int m_hashMax;
+	SG::ReadCondHandleKey<CaloDetDescrManager> m_caloMgrKey { this
+	    , "CaloDetDescrManager"
+	    , "CaloDetDescrManager"
+	    , "SG Key for CaloDetDescrManager in the Condition Store" };
+
+        const CaloCell_ID * m_theCaloCCIDM{nullptr};
+        const LArOnlineID* m_onlineHelper{nullptr};
+        unsigned int m_hashMax{0};
 };
 
 #endif
diff --git a/TestBeam/TBRec/src/TBClusterMaker.cxx b/TestBeam/TBRec/src/TBClusterMaker.cxx
index ee9b09ee12d5..8cc2d93dfce1 100644
--- a/TestBeam/TBRec/src/TBClusterMaker.cxx
+++ b/TestBeam/TBRec/src/TBClusterMaker.cxx
@@ -5,13 +5,10 @@
 #include "TBClusterMaker.h"
 
 #include "CLHEP/Units/SystemOfUnits.h"
-#include "CaloDetDescr/CaloDetDescrManager.h"
 #include "CaloGeoHelpers/CaloPhiRange.h"
 
 #include "CaloEvent/CaloCell.h"
 #include "CaloEvent/CaloCellContainer.h"
-//#include "CaloEvent/CaloCluster.h"
-//#include "CaloEvent/CaloClusterContainer.h"
 #include "xAODCaloEvent/CaloClusterContainer.h"
 #include "xAODCaloEvent/CaloClusterKineHelper.h"
 #include "CaloGeoHelpers/proxim.h"
@@ -30,7 +27,6 @@ TBClusterMaker::TBClusterMaker(const std::string& type,
     m_deltaR(0.02),
     m_maxIter(4),
     m_CellEnergyInADC(false),
-    m_calo_DDM(0),
     m_calo_id(0)
 {
   // CaloCell Container Name
@@ -56,9 +52,6 @@ TBClusterMaker::TBClusterMaker(const std::string& type,
   // Cluster \f$ \phi \f$) from JO file
   declareProperty("phiCluster",m_phi0=99.);
 
-  //m_numCluIterationsConverged = 0;
-  //m_numCluIterationsNonConverged = 0;
-  //m_numSeedCellNotFound = 0;
 }
 ////////////////////
 // Initialization //
@@ -69,10 +62,8 @@ StatusCode TBClusterMaker::initialize(){
   MsgStream log(msgSvc(), name());
   log << MSG::INFO << "in initialize()" << endmsg;
 
-  // Get pointer to detector manager and CaloCell_ID:
-  m_calo_DDM  = CaloDetDescrManager::instance(); 
-  m_calo_id   = m_calo_DDM->getCaloCell_ID();
-
+  // Get pointer to CaloCell_ID:
+  ATH_CHECK(detStore()->retrieve(m_calo_id, "CaloCell_ID"));
   ATH_CHECK( m_elecNoiseKey.initialize() );
 
   // setup calorimeter module and sampling lookup tables
diff --git a/TestBeam/TBRec/src/TBClusterMaker.h b/TestBeam/TBRec/src/TBClusterMaker.h
index e59ac188bc5b..caf074d8b51b 100644
--- a/TestBeam/TBRec/src/TBClusterMaker.h
+++ b/TestBeam/TBRec/src/TBClusterMaker.h
@@ -16,7 +16,6 @@
  * Like all other cluster maker tools this class derives from
  * CaloClusterMakerTool.  */
 
-class CaloDetDescrManager; 
 class CaloDetDescrElement;
 
 #include "CaloIdentifier/CaloCell_ID.h"
@@ -85,13 +84,7 @@ class TBClusterMaker: public AthAlgTool, virtual public CaloClusterCollectionPro
   /** True if cell enrgy is in ADC counts, default = FALSE **/
   bool m_CellEnergyInADC;
 
-  /** Counters */
-  //int m_numSeedCellNotFound;
-  //int m_numCluIterationsConverged;
-  //int m_numCluIterationsNonConverged;
-
   /** Services */
-  const CaloDetDescrManager* m_calo_DDM;
   const CaloCell_ID* m_calo_id;
 
   SG::ReadCondHandleKey<CaloNoise> m_elecNoiseKey
diff --git a/TestBeam/TBRec/src/TBECLArRawChannelBuilder.cxx b/TestBeam/TBRec/src/TBECLArRawChannelBuilder.cxx
index 23cf839c6264..e31ed4163a87 100644
--- a/TestBeam/TBRec/src/TBECLArRawChannelBuilder.cxx
+++ b/TestBeam/TBRec/src/TBECLArRawChannelBuilder.cxx
@@ -3,14 +3,12 @@
 */
 
 #include "TBECLArRawChannelBuilder.h"
-#include "CaloDetDescr/CaloDetDescrManager.h"
 #include "CaloIdentifier/CaloCell_ID.h"
 
 #include "LArRawEvent/LArDigitContainer.h"
 #include "TBEvent/TBPhase.h"
 
 #include "LArElecCalib/ILArPedestal.h"
-//#include "LArElecCalib/ILArRamp.h"
 #include "LArElecCalib/ILArOFC.h"
 #include "LArElecCalib/ILArShape.h"
 #include "LArElecCalib/ILArGlobalTimeOffset.h"
@@ -30,7 +28,6 @@ TBECLArRawChannelBuilder::TBECLArRawChannelBuilder (const std::string& name, ISv
   AthAlgorithm(name, pSvcLocator),
   m_onlineHelper(0),
   m_calo_id(0),
-  m_calo_dd_man(0),
   m_DataLocation("FREE"),
   m_ChannelContainerName("LArRawChannels"),
   m_useTDC(false),
@@ -102,9 +99,9 @@ StatusCode TBECLArRawChannelBuilder::initialize(){
 
   if (!m_useRamp)
   {
-    // pointer to detector manager:
-    ATH_CHECK( detStore()->retrieve (m_calo_dd_man, "CaloMgr") );
-    m_calo_id   = m_calo_dd_man->getCaloCell_ID();
+    // pointer to CaloCell ID helper:
+    ATH_CHECK( detStore()->retrieve (m_calo_id, "CaloCell_ID") );
+    
     for (int i=0; i<30; i++) {
       m_adc2mev[i] = 0;
       if (i == 6)  m_adc2mev[i] = 0.041*637;    // EMEC2
diff --git a/TestBeam/TBRec/src/TBECLArRawChannelBuilder.h b/TestBeam/TBRec/src/TBECLArRawChannelBuilder.h
index 8361f92cb761..06e06576adf8 100644
--- a/TestBeam/TBRec/src/TBECLArRawChannelBuilder.h
+++ b/TestBeam/TBRec/src/TBECLArRawChannelBuilder.h
@@ -21,7 +21,6 @@
 #include "LArElecCalib/ILArHVScaleCorr.h"
 
 class CaloCell_ID;
-class CaloDetDescrManager;
 
 class TBECLArRawChannelBuilder : public AthAlgorithm
 {
@@ -35,7 +34,6 @@ private:
   //Services & Tools 
   const LArOnlineID* m_onlineHelper;
   const CaloCell_ID* m_calo_id;
-  const CaloDetDescrManager* m_calo_dd_man; 
 
   SG::ReadCondHandleKey<LArOnOffIdMapping>  m_cablingKey {this,"keyCabling", "LArOnOffIdMap", "Input key for Id mapping"} ;
   SG::ReadCondHandleKey<ILArHVScaleCorr> m_offlineHVScaleCorrKey{this, "keyOfflineHVCorr", "LArHVScaleCorrRecomputed","Key for LArHVScaleCorr"};
diff --git a/TestBeam/TBRec/src/TBEMECXTalkToyModel.cxx b/TestBeam/TBRec/src/TBEMECXTalkToyModel.cxx
index 7a6c424c1379..e9e782b36986 100644
--- a/TestBeam/TBRec/src/TBEMECXTalkToyModel.cxx
+++ b/TestBeam/TBRec/src/TBEMECXTalkToyModel.cxx
@@ -23,7 +23,6 @@ PURPOSE:  A simple toy model to simulate longitudinal cross-talk
 
 #include "CaloDetDescr/CaloDetDescrElement.h"
 #include "CaloIdentifier/CaloCell_ID.h"
-#include "CaloDetDescr/CaloDetDescrManager.h"
 
 /////////////////////////////////////////////////////////////////////
 // CONSTRUCTOR:
@@ -35,7 +34,6 @@ TBEMECXTalkToyModel::TBEMECXTalkToyModel(
 			     const IInterface* parent)
   :base_class (type, name, parent),
    m_caloSelection(false),
-   m_calo_dd_man(nullptr),
    m_calo_id(nullptr)
 {
   declareProperty("CaloNums",m_caloNums);
@@ -84,8 +82,7 @@ StatusCode TBEMECXTalkToyModel::initialize()
     }
   }
 
-  m_calo_dd_man = CaloDetDescrManager::instance(); 
-  m_calo_id = m_calo_dd_man->getCaloCell_ID();	
+  ATH_CHECK(detStore()->retrieve(m_calo_id,"CaloCell_ID"));
 
   ATH_MSG_VERBOSE ("XTalkScaleLong     = " << m_xtalkScaleLong);
   ATH_MSG_VERBOSE ("XTalkScaleEta      = " << m_xtalkScaleEta);
diff --git a/TestBeam/TBRec/src/TBEMECXTalkToyModel.h b/TestBeam/TBRec/src/TBEMECXTalkToyModel.h
index f1eeaa487e36..713fe611ac5c 100644
--- a/TestBeam/TBRec/src/TBEMECXTalkToyModel.h
+++ b/TestBeam/TBRec/src/TBEMECXTalkToyModel.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef TBREC_TBEMECXTALKTOYMODEL_H
@@ -12,9 +12,6 @@
 #include "GaudiKernel/ToolHandle.h"
 #include "CaloIdentifier/CaloCell_ID.h"
 
-class CaloDetDescrManager;
-
-
 class TBEMECXTalkToyModel
   : public extends<AthAlgTool, ICaloCellMakerTool>
 {
@@ -37,7 +34,6 @@ public:
 
   bool m_caloSelection ;
 
-  const CaloDetDescrManager * m_calo_dd_man;
   const CaloCell_ID * m_calo_id;
 
 
-- 
GitLab