From 8b2f627a5e39bccc981a45a3c92b5b41deb93a3b Mon Sep 17 00:00:00 2001
From: Stewart Martin-Haugh <smh@cern.ch>
Date: Wed, 29 Apr 2020 11:22:20 +0200
Subject: [PATCH] Move Run2CPMTowerMaker to DataHandles

---
 .../TrigT1CaloSim/Run2CPMTowerMaker.h         | 14 ++--
 .../TrigT1CaloSim/src/Run2CPMTowerMaker.cxx   | 65 ++++---------------
 2 files changed, 20 insertions(+), 59 deletions(-)

diff --git a/Trigger/TrigT1/TrigT1CaloSim/TrigT1CaloSim/Run2CPMTowerMaker.h b/Trigger/TrigT1/TrigT1CaloSim/TrigT1CaloSim/Run2CPMTowerMaker.h
index 1b6d2605e8f3..052dc928f5b6 100644
--- a/Trigger/TrigT1/TrigT1CaloSim/TrigT1CaloSim/Run2CPMTowerMaker.h
+++ b/Trigger/TrigT1/TrigT1CaloSim/TrigT1CaloSim/Run2CPMTowerMaker.h
@@ -13,17 +13,18 @@
 
 // STL
 #include <string>
-#include <vector>
 
 // Athena/Gaudi
 #include "AthenaBaseComps/AthAlgorithm.h"
-#include "GaudiKernel/ServiceHandle.h"
-#include "AthContainers/DataVector.h"
 #include "GaudiKernel/ToolHandle.h"
+#include "StoreGate/ReadHandleKey.h"
+#include "StoreGate/WriteHandleKey.h"
 #include "xAODTrigL1Calo/CPMTowerContainer.h"
 #include "xAODTrigL1Calo/CPMTowerAuxContainer.h"
 #include "xAODTrigL1Calo/TriggerTowerContainer.h"
 
+#include "TrigT1Interfaces/TrigT1CaloDefs.h"
+
 #include "TrigT1CaloToolInterfaces/IL1CPMTowerTools.h"
 
 
@@ -54,7 +55,6 @@ class Run2CPMTowerMaker : public AthAlgorithm
 {
   typedef xAOD::CPMTowerContainer     CPMTCollection;
   typedef xAOD::CPMTowerAuxContainer  CPMTAuxCollection;
-  typedef xAOD::TriggerTowerContainer TTCollection;
  public:
 
   //-------------------------
@@ -80,10 +80,10 @@ class Run2CPMTowerMaker : public AthAlgorithm
 
    ToolHandle<LVL1::IL1CPMTowerTools> m_CPMTowerTool;
 
-  /** location of TriggerTowers in TES */
-  std::string m_triggerTowerLocation;
   /** locations within the TES to store collections of JEs*/
-  std::string   m_cpmTowerLocation ;
+  SG::ReadHandleKey<xAOD::TriggerTowerContainer> m_triggerTowerKey{this, "TriggerTowerLocation", TrigT1CaloDefs::xAODTriggerTowerLocation};
+  SG::WriteHandleKey<CPMTCollection>             m_cpmTowerKey{this, "CPMTowerLocation", TrigT1CaloDefs::CPMTowerLocation};
+
 
 };
 
diff --git a/Trigger/TrigT1/TrigT1CaloSim/src/Run2CPMTowerMaker.cxx b/Trigger/TrigT1/TrigT1CaloSim/src/Run2CPMTowerMaker.cxx
index c31525a96458..cd725bf50516 100644
--- a/Trigger/TrigT1/TrigT1CaloSim/src/Run2CPMTowerMaker.cxx
+++ b/Trigger/TrigT1/TrigT1CaloSim/src/Run2CPMTowerMaker.cxx
@@ -13,46 +13,24 @@
 
 // This algorithm includes
 #include "TrigT1CaloSim/Run2CPMTowerMaker.h"
-#include "TrigT1Interfaces/TrigT1CaloDefs.h"
 #include "TrigT1CaloEvent/CPMTower_ClassDEF.h"
 
 
 
 namespace LVL1 {
 
-/** This is the constructor for JEMaker and is where you define the relevant
-    parameters.
-    Currently these are :
-    - "TriggerTowerLocation" : the location of the jes in Storegate You shouldn't have to touch this.
-    - "CPMTowerLocation" : the location of the CPMT in StoreGate. You shouldn't have to touch this.
-
-  Alter the values of these in jobOptions.txt
-*/
-  
 Run2CPMTowerMaker::Run2CPMTowerMaker( const std::string& name, ISvcLocator* pSvcLocator ) 
   : AthAlgorithm( name, pSvcLocator ), 
-    m_CPMTowerTool("LVL1::L1CPMTowerTools/L1CPMTowerTools")
-{
-  m_triggerTowerLocation     = TrigT1CaloDefs::xAODTriggerTowerLocation;
-  m_cpmTowerLocation         = TrigT1CaloDefs::CPMTowerLocation;
-
-  // This is how you declare the parameters to Gaudi so that
-  // they can be over-written via the job options file
-
-  declareProperty( "TriggerTowerLocation", m_triggerTowerLocation ) ;
-  declareProperty( "CPMTowerLocation", m_cpmTowerLocation ) ;
-}
+    m_CPMTowerTool("LVL1::L1CPMTowerTools/L1CPMTowerTools") {}
   
 
   /** the initialise() method is called at the start of processing, so we set up any histograms
       etc. here*/
 StatusCode Run2CPMTowerMaker::initialize()
 {
-  // We must here instantiate items which can only be made after
-  // any job options have been set
-
-  ATH_MSG_INFO ( "Initialising" ) ;
   ATH_CHECK( m_CPMTowerTool.retrieve() );
+  ATH_CHECK(m_triggerTowerKey.initialize());
+  ATH_CHECK(m_cpmTowerKey.initialize());
   return StatusCode::SUCCESS ;
 }
 
@@ -80,26 +58,19 @@ There is so little to do that this routine does it all itself:
 StatusCode Run2CPMTowerMaker::execute( )
 {
   ATH_MSG_DEBUG ( "Executing" ) ;
-  ATH_MSG_DEBUG  ( "looking for trigger towers at "
-                   << m_triggerTowerLocation ) ;
 				      
   // Vectors to store CPMTs in
-  CPMTCollection*    vectorOfCPMTs = new  CPMTCollection;
-  CPMTAuxCollection* cpmtAuxVector = new  CPMTAuxCollection;
-  vectorOfCPMTs->setStore(cpmtAuxVector);
+  auto CPMTs = SG::makeHandle(m_cpmTowerKey);
+  auto vectorOfCPMTs = std::make_unique<CPMTCollection>();
+  auto cpmtAuxVector = std::make_unique<CPMTAuxCollection>();
+  vectorOfCPMTs->setStore(cpmtAuxVector.get());
   
   // Retrieve TriggerTowers from StoreGate 
-  if (evtStore()->contains<xAOD::TriggerTowerContainer>(m_triggerTowerLocation)) {
-    const DataVector<xAOD::TriggerTower>* vectorOfTTs;
-    StatusCode sc = evtStore()->retrieve(vectorOfTTs, m_triggerTowerLocation);
-    if (sc.isSuccess()) {
-      // Fill a DataVector of CPMTowers using L1CPMTowerTools
-      m_CPMTowerTool->makeCPMTowers(vectorOfTTs, vectorOfCPMTs, true);
-      ATH_MSG_DEBUG( vectorOfCPMTs->size()<<" CPMTowers have been generated") ;
-    }
-    else ATH_MSG_WARNING("Failed to retrieve TriggerTowers from " << m_triggerTowerLocation );
-  }
-  else ATH_MSG_WARNING("No TriggerTowerContainer at " << m_triggerTowerLocation );
+  auto vectorOfTTs = SG::makeHandle(m_triggerTowerKey);
+  ATH_CHECK(vectorOfTTs.isValid());
+  // Fill a DataVector of CPMTowers using L1CPMTowerTools
+  m_CPMTowerTool->makeCPMTowers(vectorOfTTs.get(), vectorOfCPMTs.get(), true);
+  ATH_MSG_DEBUG( vectorOfCPMTs->size()<<" CPMTowers have been generated") ;
 
   if (msgLvl(MSG::DEBUG)) {
     ATH_MSG_DEBUG ( "Formed " << vectorOfCPMTs->size() << " CPM Towers " )  ;
@@ -109,18 +80,8 @@ StatusCode Run2CPMTowerMaker::execute( )
       ATH_MSG_DEBUG("CPMT has coords (" << (*itCPMT)->eta() <<", "<< (*itCPMT)->phi() << ") and energies : "
           << (*itCPMT)->emEnergy() <<", "<< (*itCPMT)->hadEnergy() <<" (Em,Had)" );
   }
-      
-  // Finally, store CPMTs and we are done
-  CHECK( evtStore()->record( cpmtAuxVector, m_cpmTowerLocation + "Aux." ) );
-  CHECK( evtStore()->record( vectorOfCPMTs, m_cpmTowerLocation ) );
-  
-  // Report success for debug purposes
-  ATH_MSG_DEBUG("Stored CPM Towers in TES at "<< m_cpmTowerLocation );
-
+  ATH_CHECK(CPMTs.record(std::move(vectorOfCPMTs), std::move(cpmtAuxVector)));
   
-  // Report success in any case, or else job will terminate
-  vectorOfCPMTs=0;
-  cpmtAuxVector=0;
   return StatusCode::SUCCESS;
   
 }//end execute
-- 
GitLab