From 34c20beea894e633130057c0f13cb58720f13bf7 Mon Sep 17 00:00:00 2001
From: Vakho Tsulaia <vakhtang.tsulaia@cern.ch>
Date: Fri, 22 Oct 2021 07:07:46 +0200
Subject: [PATCH] Fixes in alignment condition algorithms

1. Pixel and SCT algorithms turned into AthAlgorithms to address ATLASRECTS-6553

2. TRT, LAr and Calo algorithms fixed by adding event context to the constructors
of condition handles
---
 .../CaloAlignmentAlgs/src/CaloAlignCondAlg.cxx      |  7 ++++---
 .../src/PixelAlignCondAlg.cxx                       |  5 +++--
 .../src/PixelAlignCondAlg.h                         |  6 +++---
 .../src/SCT_AlignCondAlg.cxx                        |  7 ++++---
 .../SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.h |  8 ++++----
 .../TRT_ConditionsAlgs/src/TRTAlignCondAlg.cxx      | 13 +++++++------
 .../LArAlignmentAlgs/src/LArAlignCondAlg.cxx        |  5 +++--
 7 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/Calorimeter/CaloAlignment/CaloAlignmentAlgs/src/CaloAlignCondAlg.cxx b/Calorimeter/CaloAlignment/CaloAlignmentAlgs/src/CaloAlignCondAlg.cxx
index 03b906f1634..52f677372e8 100644
--- a/Calorimeter/CaloAlignment/CaloAlignmentAlgs/src/CaloAlignCondAlg.cxx
+++ b/Calorimeter/CaloAlignment/CaloAlignmentAlgs/src/CaloAlignCondAlg.cxx
@@ -30,8 +30,9 @@ StatusCode CaloAlignCondAlg::initialize()
 
 StatusCode CaloAlignCondAlg::execute()
 {
+  const EventContext& ctx = Gaudi::Hive::currentContext();
   // ____________ Construct Write Cond Handle and check its validity ____________
-  SG::WriteCondHandle<CaloDetDescrManager> writeCaloMgrHandle{m_writeCaloMgrKey};
+  SG::WriteCondHandle<CaloDetDescrManager> writeCaloMgrHandle{m_writeCaloMgrKey,ctx};
   if (writeCaloMgrHandle.isValid()) {
     ATH_MSG_DEBUG("Found valid write handle");
     return StatusCode::SUCCESS;
@@ -41,7 +42,7 @@ StatusCode CaloAlignCondAlg::execute()
   // 1. GeoAlignmentStore
   const GeoAlignmentStore* geoAlign{nullptr};
   if(!m_readKeyGeoAlign.empty()) {
-    SG::ReadCondHandle<GeoAlignmentStore> readHandleGeoAlign{m_readKeyGeoAlign};
+    SG::ReadCondHandle<GeoAlignmentStore> readHandleGeoAlign{m_readKeyGeoAlign,ctx};
     ATH_CHECK(readHandleGeoAlign.isValid());
     ATH_MSG_DEBUG("Retrieved GeoAlignmentStore object form the Condition Store");
     writeCaloMgrHandle.addDependency(readHandleGeoAlign);
@@ -51,7 +52,7 @@ StatusCode CaloAlignCondAlg::execute()
   // 2. CaloCellPositionShift
   const CaloRec::CaloCellPositionShift* cellPosShift{nullptr};
   if(!m_readKeyCellPosShift.empty()) {
-    SG::ReadCondHandle<CaloRec::CaloCellPositionShift> readHandleCellPosShift{m_readKeyCellPosShift};
+    SG::ReadCondHandle<CaloRec::CaloCellPositionShift> readHandleCellPosShift{m_readKeyCellPosShift,ctx};
     ATH_CHECK(readHandleCellPosShift.isValid());
     ATH_MSG_DEBUG("Retrieved CaloRec::CaloCellPositionShift object form the Condition Store");
     writeCaloMgrHandle.addDependency(readHandleCellPosShift);
diff --git a/InnerDetector/InDetConditions/PixelConditionsAlgorithms/src/PixelAlignCondAlg.cxx b/InnerDetector/InDetConditions/PixelConditionsAlgorithms/src/PixelAlignCondAlg.cxx
index 6f68f62d894..9f475f22e47 100644
--- a/InnerDetector/InDetConditions/PixelConditionsAlgorithms/src/PixelAlignCondAlg.cxx
+++ b/InnerDetector/InDetConditions/PixelConditionsAlgorithms/src/PixelAlignCondAlg.cxx
@@ -10,7 +10,7 @@
 #include <memory>
 
 PixelAlignCondAlg::PixelAlignCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
-  : ::AthReentrantAlgorithm(name, pSvcLocator)
+  : ::AthAlgorithm(name, pSvcLocator)
 {
 }
 
@@ -41,10 +41,11 @@ StatusCode PixelAlignCondAlg::initialize()
   return StatusCode::SUCCESS;
 }
 
-StatusCode PixelAlignCondAlg::execute(const EventContext& ctx) const
+StatusCode PixelAlignCondAlg::execute()
 {
   ATH_MSG_DEBUG("execute " << name());
 
+  const EventContext& ctx = Gaudi::Hive::currentContext();
   // ____________ Construct Write Cond Handle and check its validity ____________
   SG::WriteCondHandle<GeoAlignmentStore> writeHandle{m_writeKey, ctx};
 
diff --git a/InnerDetector/InDetConditions/PixelConditionsAlgorithms/src/PixelAlignCondAlg.h b/InnerDetector/InDetConditions/PixelConditionsAlgorithms/src/PixelAlignCondAlg.h
index f90f3670993..def54ed8f7f 100644
--- a/InnerDetector/InDetConditions/PixelConditionsAlgorithms/src/PixelAlignCondAlg.h
+++ b/InnerDetector/InDetConditions/PixelConditionsAlgorithms/src/PixelAlignCondAlg.h
@@ -7,7 +7,7 @@
 #ifndef PIXELCONDITIONSALGORITHMS_PIXELALIGNCONDALG_H
 #define PIXELCONDITIONSALGORITHMS_PIXELALIGNCONDALG_H
 
-#include "AthenaBaseComps/AthReentrantAlgorithm.h"
+#include "AthenaBaseComps/AthAlgorithm.h"
 #include "StoreGate/ReadCondHandleKey.h"
 #include "StoreGate/WriteCondHandleKey.h"
 
@@ -21,14 +21,14 @@ namespace InDetDD {
   class PixelDetectorManager;
 }
 
-class PixelAlignCondAlg : public AthReentrantAlgorithm
+class PixelAlignCondAlg : public AthAlgorithm
 {
  public:
   PixelAlignCondAlg(const std::string& name, ISvcLocator* pSvcLocator);
   virtual ~PixelAlignCondAlg() override = default;
 
   virtual StatusCode initialize() override;
-  virtual StatusCode execute(const EventContext& ctx) const override;
+  virtual StatusCode execute() override;
 
  private:
   BooleanProperty m_useDynamicAlignFolders{
diff --git a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.cxx b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.cxx
index 02dbd7cd174..ae6907ac837 100644
--- a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.cxx
+++ b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.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
 */
 
 #include "SCT_AlignCondAlg.h"
@@ -10,7 +10,7 @@
 #include <memory>
 
 SCT_AlignCondAlg::SCT_AlignCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
-  : ::AthReentrantAlgorithm(name, pSvcLocator)
+  : ::AthAlgorithm(name, pSvcLocator)
   , m_writeKey{"SCTAlignmentStore", "SCTAlignmentStore"}
   , m_DetManagerName("SCT")
 {
@@ -44,10 +44,11 @@ StatusCode SCT_AlignCondAlg::initialize()
   return StatusCode::SUCCESS;
 }
 
-StatusCode SCT_AlignCondAlg::execute(const EventContext& ctx) const
+StatusCode SCT_AlignCondAlg::execute()
 {
   ATH_MSG_DEBUG("execute " << name());
 
+  const EventContext& ctx = Gaudi::Hive::currentContext();
   // ____________ Construct Write Cond Handle and check its validity ____________
   SG::WriteCondHandle<GeoAlignmentStore> writeHandle{m_writeKey, ctx};
 
diff --git a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.h b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.h
index fb2097449ab..9911ceaf279 100644
--- a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.h
+++ b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.h
@@ -1,13 +1,13 @@
 // -*- C++ -*-
 
 /*
-  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 SCT_CONDITIONSALGORITHMS_SCT_ALIGNCONDALG_H
 #define SCT_CONDITIONSALGORITHMS_SCT_ALIGNCONDALG_H
 
-#include "AthenaBaseComps/AthReentrantAlgorithm.h"
+#include "AthenaBaseComps/AthAlgorithm.h"
 #include "StoreGate/ReadCondHandleKey.h"
 #include "StoreGate/WriteCondHandleKey.h"
 
@@ -36,14 +36,14 @@ namespace InDetDD {
 // However, we cannot give non-const pointer for SiDetectorElement
 // in SCT_DetectorManager in the above chain.
 
-class SCT_AlignCondAlg : public AthReentrantAlgorithm
+class SCT_AlignCondAlg : public AthAlgorithm
 {
  public:
   SCT_AlignCondAlg(const std::string& name, ISvcLocator* pSvcLocator);
   virtual ~SCT_AlignCondAlg() override = default;
 
   virtual StatusCode initialize() override;
-  virtual StatusCode execute(const EventContext& ctx) const override;
+  virtual StatusCode execute() override;
   virtual StatusCode finalize() override;
 
  private:
diff --git a/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTAlignCondAlg.cxx b/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTAlignCondAlg.cxx
index 3175f724d51..2252e85aed9 100644
--- a/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTAlignCondAlg.cxx
+++ b/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTAlignCondAlg.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
 */
 
 
@@ -58,9 +58,10 @@ StatusCode TRTAlignCondAlg::execute()
 {
   ATH_MSG_DEBUG("execute " << name());
 
+  const EventContext& ctx = Gaudi::Hive::currentContext();
   // ____________ Construct Write Cond Handles and check their validity ____________
-  SG::WriteCondHandle<GeoAlignmentStore> writeHandle{m_writeKeyAlignStore};
-  SG::WriteCondHandle<InDetDD::TRT_DetElementContainer> writeHandleDetElCont{m_writeKeyDetElCont};
+  SG::WriteCondHandle<GeoAlignmentStore> writeHandle{m_writeKeyAlignStore,ctx};
+  SG::WriteCondHandle<InDetDD::TRT_DetElementContainer> writeHandleDetElCont{m_writeKeyDetElCont,ctx};
 
   if (writeHandleDetElCont.isValid()) {
     ATH_MSG_DEBUG("CondHandle " << writeHandleDetElCont.fullKey() << " is already valid."
@@ -95,7 +96,7 @@ StatusCode TRTAlignCondAlg::execute()
     // 1. Dynamic folders
 
     // ** Global
-    SG::ReadCondHandle<CondAttrListCollection> readHandleDynamicGlobal{m_readKeyDynamicGlobal};
+    SG::ReadCondHandle<CondAttrListCollection> readHandleDynamicGlobal{m_readKeyDynamicGlobal,ctx};
     // Get CDO and store it into container
     const CondAttrListCollection* readCdoDynamicGlobal{*readHandleDynamicGlobal};
     if(readCdoDynamicGlobal==nullptr) {
@@ -111,7 +112,7 @@ StatusCode TRTAlignCondAlg::execute()
     }
 
     // ** Regular
-    SG::ReadCondHandle<AlignableTransformContainer> readHandleDynamicRegular{m_readKeyDynamicRegular};
+    SG::ReadCondHandle<AlignableTransformContainer> readHandleDynamicRegular{m_readKeyDynamicRegular,ctx};
     // Get CDO and store it into container
     const AlignableTransformContainer* readCdoDynamicRegular{*readHandleDynamicRegular};
     if(readCdoDynamicRegular==nullptr) {
@@ -131,7 +132,7 @@ StatusCode TRTAlignCondAlg::execute()
   }
   else {
     // 2. Regular folder
-    SG::ReadCondHandle<AlignableTransformContainer> readHandleRegular{m_readKeyRegular};
+    SG::ReadCondHandle<AlignableTransformContainer> readHandleRegular{m_readKeyRegular,ctx};
     // Get CDO and store it into container
     const AlignableTransformContainer* readCdoRegular{*readHandleRegular};
     if(readCdoRegular==nullptr) {
diff --git a/LArCalorimeter/LArAlignment/LArAlignmentAlgs/src/LArAlignCondAlg.cxx b/LArCalorimeter/LArAlignment/LArAlignmentAlgs/src/LArAlignCondAlg.cxx
index c2867823e63..59ab3c7744b 100644
--- a/LArCalorimeter/LArAlignment/LArAlignmentAlgs/src/LArAlignCondAlg.cxx
+++ b/LArCalorimeter/LArAlignment/LArAlignmentAlgs/src/LArAlignCondAlg.cxx
@@ -28,15 +28,16 @@ StatusCode LArAlignCondAlg::initialize()
 
 StatusCode LArAlignCondAlg::execute()
 {
+  const EventContext& ctx = Gaudi::Hive::currentContext();
   // ____________ Construct Write Cond Handle and check its validity ____________
-  SG::WriteCondHandle<GeoAlignmentStore> writeGeoAlignHandle{m_writeGeoAlignKey};
+  SG::WriteCondHandle<GeoAlignmentStore> writeGeoAlignHandle{m_writeGeoAlignKey,ctx};
   if (writeGeoAlignHandle.isValid()) {
     ATH_MSG_DEBUG("Found valid write handle");
     return StatusCode::SUCCESS;
   }
   
   // ____________ Get Read Cond Object ____________
-  SG::ReadCondHandle<DetCondKeyTrans> readLArAlignHandle{m_readLArAlignKey};
+  SG::ReadCondHandle<DetCondKeyTrans> readLArAlignHandle{m_readLArAlignKey,ctx};
   ATH_CHECK(readLArAlignHandle.isValid());
   ATH_MSG_DEBUG("Retrieved DetCondKeyTrans object form the Condition Store");
   writeGeoAlignHandle.addDependency(readLArAlignHandle);
-- 
GitLab