From 6b5d49fa7345b0363ac8662d2ed74889c0e24ea7 Mon Sep 17 00:00:00 2001
From: Vakho Tsulaia <vakhtang.tsulaia@cern.ch>
Date: Fri, 22 Oct 2021 02:15:51 +0200
Subject: [PATCH] Migrated L1CaloHVDummyContainers to reading
 CaloDetDescrManager from the Condition Store

Part of the ongoing migration of all clients of the CaloDetDescrManager
---
 .../L1CaloHVDummyContainers.h                 | 17 ++++--
 .../src/L1CaloHVDummyContainers.cxx           | 60 ++++++++-----------
 2 files changed, 35 insertions(+), 42 deletions(-)

diff --git a/Trigger/TrigT1/TrigT1CaloCalibUtils/TrigT1CaloCalibUtils/L1CaloHVDummyContainers.h b/Trigger/TrigT1/TrigT1CaloCalibUtils/TrigT1CaloCalibUtils/L1CaloHVDummyContainers.h
index debc9c659057..c7d557a329af 100644
--- a/Trigger/TrigT1/TrigT1CaloCalibUtils/TrigT1CaloCalibUtils/L1CaloHVDummyContainers.h
+++ b/Trigger/TrigT1/TrigT1CaloCalibUtils/TrigT1CaloCalibUtils/L1CaloHVDummyContainers.h
@@ -1,11 +1,13 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef L1CALOHVDUMMYCONTAINERS_H
 #define L1CALOHVDUMMYCONTAINERS_H
 
 #include "AthenaBaseComps/AthAlgorithm.h"
+#include "CaloDetDescr/CaloDetDescrManager.h"
+#include "StoreGate/ReadCondHandleKey.h"
 
 #include <string>
 
@@ -14,7 +16,6 @@ class CaloIdManager;
 class CaloCell_ID;
 class CaloDetDescriptor;
 class CaloDetDescrElement;
-class CaloDetDescrManager;
 
 /**
  * This algorithms creates dummy containers so HV job will run without data.
@@ -28,9 +29,9 @@ class L1CaloHVDummyContainers : public AthAlgorithm
     L1CaloHVDummyContainers(const std::string& name, ISvcLocator *pSvcLocator);
     virtual ~L1CaloHVDummyContainers();
 
-    StatusCode initialize();
-    StatusCode execute();
-    StatusCode finalize();
+    virtual StatusCode initialize() override;
+    virtual StatusCode execute() override;
+    virtual StatusCode finalize() override;
 
  private:
     std::string m_triggerTowerCollectionName;
@@ -38,7 +39,11 @@ class L1CaloHVDummyContainers : public AthAlgorithm
 
     const CaloIdManager* m_caloMgr;
     const CaloCell_ID* m_caloCellHelper;
-    const CaloDetDescrManager* m_caloDetDescrMgr;
+    SG::ReadCondHandleKey<CaloDetDescrManager> m_caloMgrKey { this
+	, "CaloDetDescrManager"
+	, "CaloDetDescrManager"
+	, "SG Key for CaloDetDescrManager in the Condition Store" };
+
 
     bool m_firstEvent;
 };
diff --git a/Trigger/TrigT1/TrigT1CaloCalibUtils/src/L1CaloHVDummyContainers.cxx b/Trigger/TrigT1/TrigT1CaloCalibUtils/src/L1CaloHVDummyContainers.cxx
index 01330b0a27e8..61bebf346b53 100644
--- a/Trigger/TrigT1/TrigT1CaloCalibUtils/src/L1CaloHVDummyContainers.cxx
+++ b/Trigger/TrigT1/TrigT1CaloCalibUtils/src/L1CaloHVDummyContainers.cxx
@@ -12,7 +12,6 @@
 #include "CaloEvent/CaloCellContainer.h"
 #include "CaloDetDescr/CaloDetDescriptor.h"
 #include "CaloDetDescr/CaloDetDescrElement.h"
-#include "CaloDetDescr/CaloDetDescrManager.h"
 #include "CaloIdentifier/CaloCell_ID.h"
 #include "CaloIdentifier/CaloIdManager.h"
 
@@ -20,9 +19,8 @@ L1CaloHVDummyContainers::L1CaloHVDummyContainers(const std::string& name, ISvcLo
   : AthAlgorithm(name, pSvcLocator),
     m_triggerTowerCollectionName("TriggerTowers"),
     m_caloCellContainerName("AllCalo"),
-    m_caloMgr(0),
-    m_caloCellHelper(0),
-    m_caloDetDescrMgr(0),
+    m_caloMgr(nullptr),
+    m_caloCellHelper(nullptr),
     m_firstEvent(true)
 {
     declareProperty("TriggerTowerCollectionName", m_triggerTowerCollectionName);
@@ -35,34 +33,24 @@ L1CaloHVDummyContainers::~L1CaloHVDummyContainers()
 
 StatusCode L1CaloHVDummyContainers::initialize()
 {
-    StatusCode sc;
-
-    sc = detStore()->retrieve(m_caloMgr);
-    if (sc.isFailure()) {
-        msg(MSG::ERROR) << "Cannot retrieve CaloMgr" << endmsg;
-	return sc;
-    }
-    else {
-        m_caloCellHelper = m_caloMgr->getCaloCell_ID();
-	if ( !m_caloCellHelper ) {
-	    msg(MSG::ERROR) << "Cannot retrieve CaloCell_ID" << endmsg;
-	    return StatusCode::FAILURE;
-        }
-    }
-    sc = detStore()->retrieve(m_caloDetDescrMgr);
-    if (sc.isFailure()) {
-        msg(MSG::ERROR) << "Cannot retrieve CaloDetDescrMgr" << endmsg;
-	return sc;
-    }
-
-    return StatusCode::SUCCESS;
+  ATH_CHECK(detStore()->retrieve(m_caloMgr));
+  m_caloCellHelper = m_caloMgr->getCaloCell_ID();
+  if ( !m_caloCellHelper ) {
+    ATH_MSG_ERROR("Cannot retrieve CaloCell_ID");
+    return StatusCode::FAILURE;
+  }
+  ATH_CHECK(m_caloMgrKey.initialize());
+
+  return StatusCode::SUCCESS;
 }
 
 StatusCode L1CaloHVDummyContainers::execute()
 {
     if (m_firstEvent) {
 
-	StatusCode sc;
+      SG::ReadCondHandle<CaloDetDescrManager> caloMgrHandle{m_caloMgrKey};
+      ATH_CHECK(caloMgrHandle.isValid());
+      const CaloDetDescrManager* caloDetDescrMgr = *caloMgrHandle;
 
         // Create dummy TriggerTower collection
 	TriggerTowerCollection* ttCol = new TriggerTowerCollection();
@@ -85,7 +73,7 @@ StatusCode L1CaloHVDummyContainers::execute()
                 }
             }
         }
-	msg(MSG::INFO) << "Size of TriggerTowerCollection is " << ttCol->size() << endmsg;
+	ATH_MSG_INFO("Size of TriggerTowerCollection is " << ttCol->size());
 	
 	// Create dummy CaloCellCollection
 	CaloCellContainer* ccCol = new CaloCellContainer();
@@ -95,35 +83,35 @@ StatusCode L1CaloHVDummyContainers::execute()
 	std::vector<Identifier>::const_iterator cellEnd(m_caloCellHelper->cell_end(CaloCell_ID::LAREM));
 	for (; cellItr != cellEnd; ++cellItr) {
 	    CaloCell* cell = new CaloCell();
-	    cell->set(m_caloDetDescrMgr->get_element(*cellItr), *cellItr);
+	    cell->set(caloDetDescrMgr->get_element(*cellItr), *cellItr);
 	    ccCol->push_back(cell);
         }
         cellItr = m_caloCellHelper->cell_begin(CaloCell_ID::LARHEC);
 	cellEnd = m_caloCellHelper->cell_end(CaloCell_ID::LARHEC);
 	for (; cellItr != cellEnd; ++cellItr) {
 	    CaloCell* cell = new CaloCell();
-	    cell->set(m_caloDetDescrMgr->get_element(*cellItr), *cellItr);
+	    cell->set(caloDetDescrMgr->get_element(*cellItr), *cellItr);
 	    ccCol->push_back(cell);
         }
 	cellItr = m_caloCellHelper->cell_begin(CaloCell_ID::LARFCAL);
 	cellEnd = m_caloCellHelper->cell_end(CaloCell_ID::LARFCAL);
 	for (; cellItr != cellEnd; ++cellItr) {
 	    CaloCell* cell = new CaloCell();
-	    cell->set(m_caloDetDescrMgr->get_element(*cellItr), *cellItr);
+	    cell->set(caloDetDescrMgr->get_element(*cellItr), *cellItr);
 	    ccCol->push_back(cell);
         }
-	msg(MSG::INFO) << "Size of CaloCellContainer is " << ccCol->size() << endmsg;
+	ATH_MSG_INFO("Size of CaloCellContainer is " << ccCol->size());
 
 	// Save in StoreGate
-	sc = evtStore()->record(ttCol, m_triggerTowerCollectionName);
+	StatusCode sc = evtStore()->record(ttCol, m_triggerTowerCollectionName);
 	if (sc.isFailure()) {
-	    msg(MSG::ERROR) << "Failed to store TriggerTowerCollection in StoreGate" << endmsg;
-	    return sc;
+	  ATH_MSG_ERROR("Failed to store TriggerTowerCollection in StoreGate");
+	  return sc;
         }
 	sc = evtStore()->record(ccCol, m_caloCellContainerName);
 	if (sc.isFailure()) {
-	    msg(MSG::ERROR) << "Failed to store CaloCellContainer in StoreGate" << endmsg;
-	    return sc;
+	  ATH_MSG_ERROR("Failed to store CaloCellContainer in StoreGate");
+	  return sc;
         }
 
 	m_firstEvent = false;
-- 
GitLab