From eb533670eb5b9029ec1730859731261245888abb Mon Sep 17 00:00:00 2001
From: Alison Elliot <alison.elliot@cern.ch>
Date: Wed, 20 Mar 2019 18:15:41 +0000
Subject: [PATCH] l1calo athenaMT migration to readhandles

---
 .../TrigT1CaloSim/Run2TriggerTowerMaker.h     | 10 ++---
 .../python/TrigT1CaloSimRun2Config.py         |  3 ++
 .../share/TrigT1CaloSimJobOptions_Run2.py     |  3 ++
 .../src/Run2TriggerTowerMaker.cxx             | 39 +++++++++++++------
 .../TrigT1Interfaces/TrigT1CaloDefs.h         |  1 +
 .../TrigT1Interfaces/src/TrigT1CaloDefs.cxx   |  1 +
 6 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/Trigger/TrigT1/TrigT1CaloSim/TrigT1CaloSim/Run2TriggerTowerMaker.h b/Trigger/TrigT1/TrigT1CaloSim/TrigT1CaloSim/Run2TriggerTowerMaker.h
index d94a92a38a2..f655f8c48a4 100755
--- a/Trigger/TrigT1/TrigT1CaloSim/TrigT1CaloSim/Run2TriggerTowerMaker.h
+++ b/Trigger/TrigT1/TrigT1CaloSim/TrigT1CaloSim/Run2TriggerTowerMaker.h
@@ -131,9 +131,6 @@ private:
   //Flag to enable zero suppression (makes algorithm simulation much faster
   bool m_ZeroSuppress;
 
-  // locations within the TES to store collections of Trigger Towers
-  std::string m_outputLocation;
-
   // require all calorimeters, or allow running with some missing?
   bool m_requireAllCalos;
 
@@ -269,9 +266,10 @@ private:
   SG::ReadHandleKey<xAOD::EventInfo> m_xaodevtKey;
   //  location of input TriggerTowers (for reprocessing)
   SG::ReadHandleKey<xAOD::TriggerTowerContainer> m_inputTTLocation;
-  // locations within the TES to store collections of Trigger Towers
-  //SG::WriteHandleKey<xAOD::TriggerTowerContainer> m_outputLocation;
-  //SG::WriteHandleKey<xAOD::TriggerTowerAuxContainer> m_outputAuxLocation;
+  // locations within StoreGate to store collections of Trigger Towers
+  SG::WriteHandleKey<xAOD::TriggerTowerContainer> m_outputLocation;
+  // locations within StoreGate to store collections of Trigger Towers for reprocessing
+  SG::WriteHandleKey<xAOD::TriggerTowerContainer> m_outputLocationRerun;
 
   // location of LAr TTL1 data
   SG::ReadHandleKey<LArTTL1Container> m_EmTTL1ContainerName;
diff --git a/Trigger/TrigT1/TrigT1CaloSim/python/TrigT1CaloSimRun2Config.py b/Trigger/TrigT1/TrigT1CaloSim/python/TrigT1CaloSimRun2Config.py
index 574d7211dc6..0afdb6d4bab 100644
--- a/Trigger/TrigT1/TrigT1CaloSim/python/TrigT1CaloSimRun2Config.py
+++ b/Trigger/TrigT1/TrigT1CaloSim/python/TrigT1CaloSimRun2Config.py
@@ -37,6 +37,9 @@ class Run2TriggerTowerMaker(Run2TriggerTowerMakerBase):
         super(Run2TriggerTowerMaker, self).__init__(name)
         self.CellType = 3 # TTL1 input
         self.ZeroSuppress = True
+
+        from SGComps.AddressRemappingSvc import addInputRename
+        addInputRename ( 'xAOD::TriggerTowerContainer', 'xAODTriggerTowers_rerun', 'xAODTriggerTowers')
         
         from AthenaCommon import CfgMgr
         from AthenaCommon.AppMgr import ToolSvc
diff --git a/Trigger/TrigT1/TrigT1CaloSim/share/TrigT1CaloSimJobOptions_Run2.py b/Trigger/TrigT1/TrigT1CaloSim/share/TrigT1CaloSimJobOptions_Run2.py
index 77a4e2bb8da..d4d3aa4a24c 100755
--- a/Trigger/TrigT1/TrigT1CaloSim/share/TrigT1CaloSimJobOptions_Run2.py
+++ b/Trigger/TrigT1/TrigT1CaloSim/share/TrigT1CaloSimJobOptions_Run2.py
@@ -22,6 +22,9 @@ job = AlgSequence()
 include('TrigT1CaloCalibConditions/L1CaloCalibConditionsMC_jobOptions.py')
 from TrigT1CaloSim.TrigT1CaloSimRun2Config import Run2TriggerTowerMaker25ns, Run2TriggerTowerMaker50ns
 
+from SGComps.AddressRemappingSvc import addInputRename
+addInputRename ( 'xAOD::TriggerTowerContainer', 'xAODTriggerTowers_rerun', 'xAODTriggerTowers')
+
 # try to determine wheter running with 25ns/50ns bunchspacing
 _bunchSpacing = None
 _doPC = True # do pedestal correction?
diff --git a/Trigger/TrigT1/TrigT1CaloSim/src/Run2TriggerTowerMaker.cxx b/Trigger/TrigT1/TrigT1CaloSim/src/Run2TriggerTowerMaker.cxx
index d8ee708a12e..916a73f1746 100755
--- a/Trigger/TrigT1/TrigT1CaloSim/src/Run2TriggerTowerMaker.cxx
+++ b/Trigger/TrigT1/TrigT1CaloSim/src/Run2TriggerTowerMaker.cxx
@@ -110,6 +110,7 @@ namespace LVL1 {
     declareProperty("RequireAllCalos",m_requireAllCalos=true,"Should EM,Had and Tile all be available?");
 
     declareProperty("TriggerTowerLocation", m_outputLocation= TrigT1CaloDefs::xAODTriggerTowerLocation);
+    declareProperty("TriggerTowerLocationRerun", m_outputLocationRerun = TrigT1CaloDefs::xAODTriggerTowerRerunLocation);
     declareProperty("CellType", m_cellType = TTL1);
 
     // ADC simulation
@@ -190,13 +191,26 @@ namespace LVL1 {
     ATH_CHECK(m_xaodevtKey.initialize());
 
     ATH_CHECK(m_inputTTLocation.initialize());
-    //ATH_CHECK(m_outputLocation.initialize());
-    //m_outputAuxLocation = m_outputAuxLocation.key() + "Aux.";
-    //ATH_CHECK(m_outputAuxLocation.initialize());
 
     ATH_CHECK(m_EmTTL1ContainerName.initialize());
     ATH_CHECK(m_HadTTL1ContainerName.initialize());
     ATH_CHECK(m_TileTTL1ContainerName.initialize());
+    ATH_CHECK(m_outputLocation.initialize());
+
+    ATH_CHECK(m_outputLocationRerun.initialize());
+    
+    //Rerun on trigger towers
+    if (m_cellType == TRIGGERTOWERS) {
+      renounce(m_EmTTL1ContainerName);
+      renounce(m_HadTTL1ContainerName);
+      renounce(m_TileTTL1ContainerName);
+      renounce(m_outputLocation);
+    }
+    //Start from RDO inputs
+    else if (m_cellType == TTL1) {
+      renounce(m_inputTTLocation);
+      renounce(m_outputLocationRerun);
+    }
 
     return StatusCode::SUCCESS;
   }
@@ -887,9 +901,6 @@ namespace LVL1 {
   StatusCode Run2TriggerTowerMaker::store()
   {
     ATH_MSG_DEBUG("Storing TTs in DataVector");
-    if(m_outputLocation.empty()) return StatusCode::SUCCESS;
-    //if(m_outputLocation.key().empty()) return StatusCode::SUCCESS;
-
     if(m_ZeroSuppress) {
       // remove trigger towers whose energy is 0
       m_xaodTowers->erase(std::remove_if(m_xaodTowers->begin(), m_xaodTowers->end(),
@@ -899,12 +910,16 @@ namespace LVL1 {
                           m_xaodTowers->end());
     }
 
-    CHECK(evtStore()->record(m_xaodTowers.release(), m_outputLocation));
-    CHECK(evtStore()->record(m_xaodTowersAux.release(), m_outputLocation+"Aux."));
-    //SG::WriteHandle<xAOD::TriggerTowerContainer> output(m_outputLocation);
-    //SG::WriteHandle<xAOD::TriggerTowerAuxContainer> outputAux(m_outputAuxLocation);
-    //CHECK(output.record(std::move(m_xaodTowers)));
-    //CHECK(outputAux.record(std::move(m_xaodTowersAux)));
+    
+
+    if (m_cellType == TRIGGERTOWERS) {
+      SG::WriteHandle<xAOD::TriggerTowerContainer> output(m_outputLocationRerun);
+      CHECK(output.record(std::move(m_xaodTowers), std::move(m_xaodTowersAux)));
+    }
+    else if (m_cellType == TTL1) {
+      SG::WriteHandle<xAOD::TriggerTowerContainer> output(m_outputLocation);
+      CHECK(output.record(std::move(m_xaodTowers), std::move(m_xaodTowersAux)));
+    }
 
     return StatusCode::SUCCESS;
   } // end of LVL1::Run2TriggerTowerMaker::store(){
diff --git a/Trigger/TrigT1/TrigT1Interfaces/TrigT1Interfaces/TrigT1CaloDefs.h b/Trigger/TrigT1/TrigT1Interfaces/TrigT1Interfaces/TrigT1CaloDefs.h
index 2b5ae2235d4..70337e3a7e9 100644
--- a/Trigger/TrigT1/TrigT1Interfaces/TrigT1Interfaces/TrigT1CaloDefs.h
+++ b/Trigger/TrigT1/TrigT1Interfaces/TrigT1Interfaces/TrigT1CaloDefs.h
@@ -34,6 +34,7 @@ public:
   
   static const std::string TriggerTowerLocation;
   static const std::string xAODTriggerTowerLocation;
+  static const std::string xAODTriggerTowerRerunLocation;
   static const std::string CPMTowerLocation;
   static const std::string JetElementLocation;
   
diff --git a/Trigger/TrigT1/TrigT1Interfaces/src/TrigT1CaloDefs.cxx b/Trigger/TrigT1/TrigT1Interfaces/src/TrigT1CaloDefs.cxx
index 0ea2624a6fe..9e8b04eced7 100644
--- a/Trigger/TrigT1/TrigT1Interfaces/src/TrigT1CaloDefs.cxx
+++ b/Trigger/TrigT1/TrigT1Interfaces/src/TrigT1CaloDefs.cxx
@@ -29,6 +29,7 @@ const std::string TrigT1CaloDefs::AtlfastCellContainerLocation="/Event/AtlfastCe
 
 const std::string TrigT1CaloDefs::TriggerTowerLocation="TriggerTowers";
 const std::string TrigT1CaloDefs::xAODTriggerTowerLocation="xAODTriggerTowers";
+const std::string TrigT1CaloDefs::xAODTriggerTowerRerunLocation="xAODTriggerTowers_rerun";
 const std::string TrigT1CaloDefs::JetElementLocation="JetElements";
 const std::string TrigT1CaloDefs::CPMTowerLocation="CPMTowers";
 
-- 
GitLab