From dabf5507a15d55abc31c983c4f10f652bca97780 Mon Sep 17 00:00:00 2001
From: Lucy Lewitt <lucy.lewitt@cern.ch>
Date: Thu, 14 Sep 2023 15:13:08 +0100
Subject: [PATCH 1/2] Use some calo helpers.

---
 .../egamma/egammaAlgs/src/egammaForwardBuilder.cxx         | 7 ++-----
 Reconstruction/egamma/egammaTools/src/EMClusterTool.cxx    | 4 +---
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/Reconstruction/egamma/egammaAlgs/src/egammaForwardBuilder.cxx b/Reconstruction/egamma/egammaAlgs/src/egammaForwardBuilder.cxx
index 3d415104545a..ed9b2ecf9d42 100644
--- a/Reconstruction/egamma/egammaAlgs/src/egammaForwardBuilder.cxx
+++ b/Reconstruction/egamma/egammaAlgs/src/egammaForwardBuilder.cxx
@@ -8,6 +8,7 @@
 #include "xAODCaloEvent/CaloClusterAuxContainer.h"
 #include "xAODCaloEvent/CaloCluster.h"
 #include "CaloDetDescr/CaloDetDescrManager.h"
+#include "CaloUtils/CaloClusterStoreHelper.h"
 
 #include "xAODEgamma/ElectronContainer.h"
 #include "xAODEgamma/ElectronAuxContainer.h"
@@ -97,11 +98,7 @@ StatusCode egammaForwardBuilder::execute(const EventContext& ctx) const
     ctx
   );
 
-  ATH_CHECK(outClusterContainer.record(
-    std::make_unique<xAOD::CaloClusterContainer>(),
-    std::make_unique<xAOD::CaloClusterAuxContainer>()
-  ));
-
+  CaloClusterStoreHelper::AddContainerWriteHandle(outClusterContainer);
   SG::WriteHandle<CaloClusterCellLinkContainer> outClusterContainerCellLink(
     m_outClusterContainerCellLinkKey,
     ctx
diff --git a/Reconstruction/egamma/egammaTools/src/EMClusterTool.cxx b/Reconstruction/egamma/egammaTools/src/EMClusterTool.cxx
index 093e390672eb..8b97e3306cde 100644
--- a/Reconstruction/egamma/egammaTools/src/EMClusterTool.cxx
+++ b/Reconstruction/egamma/egammaTools/src/EMClusterTool.cxx
@@ -54,9 +54,7 @@ EMClusterTool::contExecute(const EventContext& ctx,
   SG::WriteHandle<xAOD::CaloClusterContainer> outputClusterContainer(
     m_outputClusterContainerKey, ctx);
 
-  ATH_CHECK(outputClusterContainer.record(
-    std::make_unique<xAOD::CaloClusterContainer>(),
-    std::make_unique<xAOD::CaloClusterAuxContainer>()));
+  CaloClusterStoreHelper::AddContainerWriteHandle(outputClusterContainer);
 
   SG::WriteHandle<CaloClusterCellLinkContainer> outputClusterContainerCellLink(
     m_outputClusterContainerCellLinkKey, ctx);
-- 
GitLab


From e4df484ca342a498a11d837d6a6a82085019a589 Mon Sep 17 00:00:00 2001
From: Lucy Lewitt <lucy.lewitt@cern.ch>
Date: Thu, 14 Sep 2023 15:50:09 +0100
Subject: [PATCH 2/2] Add ATH_CHECK and use helper function in supercluster
 builrders as well.

---
 .../egamma/egammaAlgs/src/egammaForwardBuilder.cxx     |  2 +-
 .../egammaAlgs/src/egammaSuperClusterBuilder.cxx       | 10 ++++------
 .../egammaAlgs/src/electronSuperClusterBuilder.cxx     |  9 +++------
 .../egammaAlgs/src/photonSuperClusterBuilder.cxx       |  9 +++------
 .../egamma/egammaTools/src/EMClusterTool.cxx           |  2 +-
 5 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/Reconstruction/egamma/egammaAlgs/src/egammaForwardBuilder.cxx b/Reconstruction/egamma/egammaAlgs/src/egammaForwardBuilder.cxx
index ed9b2ecf9d42..5c8ec70badd0 100644
--- a/Reconstruction/egamma/egammaAlgs/src/egammaForwardBuilder.cxx
+++ b/Reconstruction/egamma/egammaAlgs/src/egammaForwardBuilder.cxx
@@ -98,7 +98,7 @@ StatusCode egammaForwardBuilder::execute(const EventContext& ctx) const
     ctx
   );
 
-  CaloClusterStoreHelper::AddContainerWriteHandle(outClusterContainer);
+  ATH_CHECK(CaloClusterStoreHelper::AddContainerWriteHandle(outClusterContainer));
   SG::WriteHandle<CaloClusterCellLinkContainer> outClusterContainerCellLink(
     m_outClusterContainerCellLinkKey,
     ctx
diff --git a/Reconstruction/egamma/egammaAlgs/src/egammaSuperClusterBuilder.cxx b/Reconstruction/egamma/egammaAlgs/src/egammaSuperClusterBuilder.cxx
index 7c1b7db9df26..fe3b528e647c 100644
--- a/Reconstruction/egamma/egammaAlgs/src/egammaSuperClusterBuilder.cxx
+++ b/Reconstruction/egamma/egammaAlgs/src/egammaSuperClusterBuilder.cxx
@@ -5,6 +5,7 @@
 #include "egammaSuperClusterBuilder.h"
 
 #include "CaloDetDescr/CaloDetDescrManager.h"
+#include "CaloUtils/CaloClusterStoreHelper.h"
 #include "StoreGate/ReadHandle.h"
 #include "StoreGate/WriteHandle.h"
 #include "xAODCaloEvent/CaloCluster.h"
@@ -62,10 +63,9 @@ egammaSuperClusterBuilder::execute(const EventContext& ctx) const
   // Have to register cluster container in order to properly get cluster links.
   SG::WriteHandle<xAOD::CaloClusterContainer> outputClusterContainer(
     m_outputegammaSuperClustersKey, ctx);
-  ATH_CHECK(outputClusterContainer.record(
-    std::make_unique<xAOD::CaloClusterContainer>(),
-    std::make_unique<xAOD::CaloClusterAuxContainer>()));
 
+  ATH_CHECK(CaloClusterStoreHelper::AddContainerWriteHandle(outputClusterContainer));
+  
   // Create the new egamma Super Cluster based EgammaRecContainer
   SG::WriteHandle<EgammaRecContainer> newEgammaRecs(
     m_egammaSuperRecCollectionKey, ctx);
@@ -78,9 +78,7 @@ egammaSuperClusterBuilder::execute(const EventContext& ctx) const
   std::optional<SG::WriteHandle<xAOD::CaloClusterContainer>> precorrClustersH;
   if (!m_precorrClustersKey.empty()) {
     precorrClustersH.emplace(m_precorrClustersKey, ctx);
-    ATH_CHECK(precorrClustersH->record(
-      std::make_unique<xAOD::CaloClusterContainer>(),
-      std::make_unique<xAOD::CaloClusterAuxContainer>()));
+    ATH_CHECK(CaloClusterStoreHelper::AddContainerWriteHandle(*precorrClustersH));
     precorrClustersH->ptr()->reserve(inputSize);
   }
 
diff --git a/Reconstruction/egamma/egammaAlgs/src/electronSuperClusterBuilder.cxx b/Reconstruction/egamma/egammaAlgs/src/electronSuperClusterBuilder.cxx
index 94375edd0593..d29beba6c154 100644
--- a/Reconstruction/egamma/egammaAlgs/src/electronSuperClusterBuilder.cxx
+++ b/Reconstruction/egamma/egammaAlgs/src/electronSuperClusterBuilder.cxx
@@ -5,6 +5,7 @@
 #include "electronSuperClusterBuilder.h"
 //
 #include "CaloDetDescr/CaloDetDescrManager.h"
+#include "CaloUtils/CaloClusterStoreHelper.h"
 #include "xAODCaloEvent/CaloCluster.h"
 #include "xAODCaloEvent/CaloClusterAuxContainer.h"
 #include "xAODEgamma/Egamma.h"
@@ -70,9 +71,7 @@ electronSuperClusterBuilder::execute(const EventContext& ctx) const
   SG::WriteHandle<xAOD::CaloClusterContainer> outputClusterContainer(
     m_outputElectronSuperClustersKey, ctx);
 
-  ATH_CHECK(outputClusterContainer.record(
-    std::make_unique<xAOD::CaloClusterContainer>(),
-    std::make_unique<xAOD::CaloClusterAuxContainer>()));
+  ATH_CHECK(CaloClusterStoreHelper::AddContainerWriteHandle(outputClusterContainer));
 
   // Create the new Electron Super Cluster based EgammaRecContainer
   SG::WriteHandle<EgammaRecContainer> newEgammaRecs(
@@ -86,9 +85,7 @@ electronSuperClusterBuilder::execute(const EventContext& ctx) const
   std::optional<SG::WriteHandle<xAOD::CaloClusterContainer>> precorrClustersH;
   if (!m_precorrClustersKey.empty()) {
     precorrClustersH.emplace(m_precorrClustersKey, ctx);
-    ATH_CHECK(precorrClustersH->record(
-      std::make_unique<xAOD::CaloClusterContainer>(),
-      std::make_unique<xAOD::CaloClusterAuxContainer>()));
+    ATH_CHECK(CaloClusterStoreHelper::AddContainerWriteHandle(*precorrClustersH));
     precorrClustersH->ptr()->reserve(inputSize);
   }
 
diff --git a/Reconstruction/egamma/egammaAlgs/src/photonSuperClusterBuilder.cxx b/Reconstruction/egamma/egammaAlgs/src/photonSuperClusterBuilder.cxx
index ed5be9f3ae36..606fc85d745c 100644
--- a/Reconstruction/egamma/egammaAlgs/src/photonSuperClusterBuilder.cxx
+++ b/Reconstruction/egamma/egammaAlgs/src/photonSuperClusterBuilder.cxx
@@ -5,6 +5,7 @@
 #include "photonSuperClusterBuilder.h"
 
 #include "CaloDetDescr/CaloDetDescrManager.h"
+#include "CaloUtils/CaloClusterStoreHelper.h"
 #include "xAODCaloEvent/CaloCluster.h"
 #include "xAODCaloEvent/CaloClusterAuxContainer.h"
 #include "xAODEgamma/EgammaEnums.h"
@@ -62,9 +63,7 @@ photonSuperClusterBuilder::execute(const EventContext& ctx) const
   // Have to register cluster container in order to properly get cluster links.
   SG::WriteHandle<xAOD::CaloClusterContainer> outputClusterContainer(
     m_outputPhotonSuperClustersKey, ctx);
-  ATH_CHECK(outputClusterContainer.record(
-    std::make_unique<xAOD::CaloClusterContainer>(),
-    std::make_unique<xAOD::CaloClusterAuxContainer>()));
+  ATH_CHECK(CaloClusterStoreHelper::AddContainerWriteHandle(outputClusterContainer));
 
   // Create the new Photon Super Cluster based EgammaRecContainer
   SG::WriteHandle<EgammaRecContainer> newEgammaRecs(
@@ -78,9 +77,7 @@ photonSuperClusterBuilder::execute(const EventContext& ctx) const
   std::optional<SG::WriteHandle<xAOD::CaloClusterContainer>> precorrClustersH;
   if (!m_precorrClustersKey.empty()) {
     precorrClustersH.emplace(m_precorrClustersKey, ctx);
-    ATH_CHECK(precorrClustersH->record(
-      std::make_unique<xAOD::CaloClusterContainer>(),
-      std::make_unique<xAOD::CaloClusterAuxContainer>()));
+    ATH_CHECK(CaloClusterStoreHelper::AddContainerWriteHandle(*precorrClustersH));
     precorrClustersH->ptr()->reserve(inputSize);
   }
 
diff --git a/Reconstruction/egamma/egammaTools/src/EMClusterTool.cxx b/Reconstruction/egamma/egammaTools/src/EMClusterTool.cxx
index 8b97e3306cde..8cc602c10c9f 100644
--- a/Reconstruction/egamma/egammaTools/src/EMClusterTool.cxx
+++ b/Reconstruction/egamma/egammaTools/src/EMClusterTool.cxx
@@ -54,7 +54,7 @@ EMClusterTool::contExecute(const EventContext& ctx,
   SG::WriteHandle<xAOD::CaloClusterContainer> outputClusterContainer(
     m_outputClusterContainerKey, ctx);
 
-  CaloClusterStoreHelper::AddContainerWriteHandle(outputClusterContainer);
+  ATH_CHECK(CaloClusterStoreHelper::AddContainerWriteHandle(outputClusterContainer));
 
   SG::WriteHandle<CaloClusterCellLinkContainer> outputClusterContainerCellLink(
     m_outputClusterContainerCellLinkKey, ctx);
-- 
GitLab