From a23d4057a5ee104b2ae4a156883b7ea3fc16937a Mon Sep 17 00:00:00 2001
From: Rafal Bielski <rafal.bielski@cern.ch>
Date: Tue, 25 May 2021 22:18:43 +0200
Subject: [PATCH 1/2] TrigT1TGC: Fix missing data handle migration in
 LVL1TGCTrigger

---
 Trigger/TrigT1/TrigT1TGC/TrigT1TGC/LVL1TGCTrigger.h |  2 ++
 Trigger/TrigT1/TrigT1TGC/src/LVL1TGCTrigger.cxx     | 10 +++++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/Trigger/TrigT1/TrigT1TGC/TrigT1TGC/LVL1TGCTrigger.h b/Trigger/TrigT1/TrigT1TGC/TrigT1TGC/LVL1TGCTrigger.h
index 2da3574a105f..1c1522d83d05 100644
--- a/Trigger/TrigT1/TrigT1TGC/TrigT1TGC/LVL1TGCTrigger.h
+++ b/Trigger/TrigT1/TrigT1TGC/TrigT1TGC/LVL1TGCTrigger.h
@@ -36,6 +36,7 @@
 
 #include "TrigT1TGC/TGCArguments.h"
 #include "MuonDigitContainer/TgcDigitContainer.h"
+#include "MuonRDO/TgcRdoContainer.h"
 
 // Tile-Muon
 #include "TileEvent/TileMuContainer.h"
@@ -180,6 +181,7 @@ namespace LVL1TGCTrigger {
     TGCArguments m_tgcArgs;
     TGCArguments* tgcArgs();
 
+    SG::ReadHandleKey<TgcRdoContainer> m_keyTgcRdo{this,"InputRDO","TGCRDO","Location of TgcRdoContainer"};
     SG::ReadHandleKey<TgcDigitContainer> m_keyTgcDigit{this,"InputData_perEvent","TGC_DIGITS","Location of TgcDigitContainer"};
     SG::ReadHandleKey<TileMuonReceiverContainer> m_keyTileMu{this,"TileMuRcv_Input","TileMuRcvCnt","Location of TileMuonReceiverContainer"};
     SG::ReadHandleKey<Muon::NSW_TrigRawDataContainer> m_keyNSWTrigOut{this,"NSWTrigger_Input","NSWTRGRDO","Location of NSW_TrigRawDataContainer"};
diff --git a/Trigger/TrigT1/TrigT1TGC/src/LVL1TGCTrigger.cxx b/Trigger/TrigT1/TrigT1TGC/src/LVL1TGCTrigger.cxx
index ca058158562c..f600e824aa54 100644
--- a/Trigger/TrigT1/TrigT1TGC/src/LVL1TGCTrigger.cxx
+++ b/Trigger/TrigT1/TrigT1TGC/src/LVL1TGCTrigger.cxx
@@ -38,7 +38,6 @@
 #include "MuonDigitContainer/TgcDigitContainer.h"
 #include "MuonDigitContainer/TgcDigitCollection.h"
 #include "MuonDigitContainer/TgcDigit.h"
-#include "MuonRDO/TgcRdoContainer.h"
 
 
 #include "MuonRDO/NSW_TrigRawData.h"
@@ -119,6 +118,7 @@ namespace LVL1TGCTrigger {
     ATH_CHECK(getCabling());
 
     // read and write handle key
+    ATH_CHECK(m_keyTgcRdo.initialize());
     ATH_CHECK(m_keyTgcDigit.initialize());
     ATH_CHECK(m_keyTileMu.initialize());
     ATH_CHECK(m_keyNSWTrigOut.initialize(tgcArgs()->USE_NSW())); // to be updated once the Run 3 CondDb becomes available (should be automatically configured by db info)
@@ -180,10 +180,9 @@ namespace LVL1TGCTrigger {
     
     // TgcRdo
     m_tgcrdo.clear();
-    const TgcRdoContainer * rdoCont;
-    StatusCode sc = evtStore()->retrieve( rdoCont, "TGCRDO" );
-    if (sc.isFailure()) {
-      ATH_MSG_WARNING("Cannot retrieve TgcRdoContainer with key=TGCRDO");
+    SG::ReadHandle<TgcRdoContainer> rdoCont(m_keyTgcRdo);
+    if (!rdoCont.isValid()) {
+      ATH_MSG_WARNING("Cannot retrieve TgcRdoContainer with key=" << m_keyTgcRdo.key());
       return StatusCode::SUCCESS;
     }
     if (rdoCont->size()>0) {
@@ -216,6 +215,7 @@ namespace LVL1TGCTrigger {
     }
     
     // process one by one
+    StatusCode sc = StatusCode::SUCCESS;
     for (int bc=TgcDigit::BC_PREVIOUS; bc<=TgcDigit::BC_NEXT; bc++){
       sc = StatusCode::SUCCESS;
       
-- 
GitLab


From 915833fe71d9bc71f16403220774c6bb584e8999 Mon Sep 17 00:00:00 2001
From: Rafal Bielski <rafal.bielski@cern.ch>
Date: Tue, 25 May 2021 22:25:31 +0200
Subject: [PATCH 2/2] TrigT1Muctpi: Fix missing data handle migration in
 L1Muctpi

---
 .../TrigT1Muctpi/src/Algorithms/L1Muctpi.cxx  | 36 ++++++++++---------
 .../TrigT1Muctpi/src/Algorithms/L1Muctpi.h    | 14 ++++++--
 2 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/Trigger/TrigT1/TrigT1Muctpi/src/Algorithms/L1Muctpi.cxx b/Trigger/TrigT1/TrigT1Muctpi/src/Algorithms/L1Muctpi.cxx
index a1afbac51e2b..bb6480994ec3 100644
--- a/Trigger/TrigT1/TrigT1Muctpi/src/Algorithms/L1Muctpi.cxx
+++ b/Trigger/TrigT1/TrigT1Muctpi/src/Algorithms/L1Muctpi.cxx
@@ -25,7 +25,6 @@
 #include "TrigT1Interfaces/MuCTPICTP.h"
 #include "TrigT1Interfaces/MuCTPIToRoIBSLink.h"
 #include "TrigT1Interfaces/TrigT1StoreGateKeys.h"
-#include "TrigT1Interfaces/NimCTP.h"
 
 
 // Inlcudes for the MuCTPI simulation
@@ -71,7 +70,6 @@ LVL1MUCTPI::L1Muctpi::L1Muctpi( const std::string& name, ISvcLocator* pSvcLocato
    declareProperty( "AODLocID", m_aodLocId = m_DEFAULT_AODLocID );
    declareProperty( "RDOLocID", m_rdoLocId = m_DEFAULT_RDOLocID );
 
-   declareProperty( "L1TopoOutputLocID", m_l1topoOutputLocId = LVL1MUCTPI::DEFAULT_MuonL1TopoLocation);
    // The LUTs can be huge, so the default is to turn their printing off:
    declareProperty( "DumpLUT", m_dumpLut = false );
    
@@ -80,7 +78,6 @@ LVL1MUCTPI::L1Muctpi::L1Muctpi( const std::string& name, ISvcLocator* pSvcLocato
  
    // Declare the properties of the NIM output creation:
    declareProperty( "DoNIMOutput", m_doNimOutput = false );
-   declareProperty( "NIMOutputLocID", m_nimOutputLocId = LVL1::DEFAULT_NimCTPLocation );
    declareProperty( "NIMBarrelBit", m_nimBarrelBit = 0,
                     "Bit on the NIM input of the CTP, showing that there was at least "
                     "one barrel candidate in the event" );
@@ -124,6 +121,9 @@ LVL1MUCTPI::L1Muctpi::initialize()
    ATH_CHECK( m_rdoOutputLocId.initialize( SG::AllowEmpty ) );
    ATH_CHECK( m_muctpi2CtpKey.initialize( SG::AllowEmpty ) );
    ATH_CHECK( m_muctpi2RoibKey.initialize( SG::AllowEmpty ) );
+   ATH_CHECK( m_nimctpKey.initialize( SG::AllowEmpty ) );
+   ATH_CHECK( m_topoOutputLocId.initialize( SG::AllowEmpty ) );
+   ATH_CHECK( m_topoOutputOffsetLocId.initialize( SG::AllowEmpty ) );
 
 
    // Now this is a tricky part. We have to force the message logging of the
@@ -244,7 +244,7 @@ LVL1MUCTPI::L1Muctpi::initialize()
    if( m_doNimOutput ) {
       ATH_MSG_INFO( "NIM output for CTP will be created" );
       ATH_MSG_DEBUG( "SG key for the NIM object will be: "
-                     << m_nimOutputLocId );
+                     << m_nimctpKey.key() );
       // A small sanity check:
       if( m_nimBarrelBit == m_nimEndcapBit ) {
          REPORT_ERROR( StatusCode::FAILURE )
@@ -720,33 +720,35 @@ LVL1MUCTPI::L1Muctpi::saveOutput(int bcidOffset)
             cw1|=nimEndcapBitMask;
          }
 
-         //constructing NimCTP object 
-         LVL1::NimCTP* nim = new LVL1::NimCTP( 0, cw1, 0 );
-
-         // Save it into StoreGate:
-         if( evtStore()->contains< LVL1::NimCTP >( m_nimOutputLocId ) ) {
-            ATH_MSG_ERROR("NimCTP object already in store gate. This should not happen!");
-            return StatusCode::FAILURE;
-         }
-         CHECK( evtStore()->record( nim, m_nimOutputLocId ) );
+         // Construct and save NimCTP object
+         auto nim = SG::makeHandle(m_nimctpKey);
+         CHECK(nim.record(std::make_unique<LVL1::NimCTP>(0, cw1, 0)));
       }
 
       // get outputs for L1Topo and store into Storegate
       ATH_MSG_DEBUG("Getting the output for L1Topo");
       LVL1::MuCTPIL1Topo l1topoCandidates = m_theMuctpi->getL1TopoData();
-      LVL1::MuCTPIL1Topo* l1topo = new LVL1::MuCTPIL1Topo(l1topoCandidates.getCandidates());
-      CHECK( evtStore()->record( l1topo, m_l1topoOutputLocId ) );
+      auto l1topo = SG::makeHandle(m_topoOutputLocId);
+      CHECK(l1topo.record(std::make_unique<LVL1::MuCTPIL1Topo>(l1topoCandidates.getCandidates())));
       //      std::cout << "TW: ALG central slice: offset: " <<  bcidOffset << "  location: " << m_l1topoOutputLocId << std::endl;
       //      l1topo->print();
    }
 
    /// if we have a bcid offset, then just get the topo output and put it on storegate
    if (bcidOffset  != 0) {
+      auto getHandleKey = [this](const int bcidOffset) -> SG::WriteHandleKey<LVL1::MuCTPIL1Topo>* {
+         for (SG::VarHandleKey* key : m_topoOutputOffsetLocId.keys()) {
+            if (key->key() == m_topoOutputLocId.key()+std::to_string(bcidOffset)) {
+               return dynamic_cast<SG::WriteHandleKey<LVL1::MuCTPIL1Topo>*>(key);
+            }
+         }
+         return nullptr;
+      };
       ATH_MSG_DEBUG("Getting the output for L1Topo for BCID slice");
       LVL1::MuCTPIL1Topo l1topoCandidatesBC = m_theMuctpi->getL1TopoData();
-      LVL1::MuCTPIL1Topo* l1topoBC = new LVL1::MuCTPIL1Topo(l1topoCandidatesBC.getCandidates());
+      auto l1topoBC = SG::makeHandle(*getHandleKey(bcidOffset));
+      CHECK(l1topoBC.record(std::make_unique<LVL1::MuCTPIL1Topo>(l1topoCandidatesBC.getCandidates())));
       l1topoBC->setBcidOffset(bcidOffset);
-      CHECK( evtStore()->record( l1topoBC, m_l1topoOutputLocId+std::to_string(bcidOffset) ) );
       // std::cout << "TW: slice: offset: " <<  bcidOffset << "  location: " 
       //		<< m_l1topoOutputLocId+std::to_string(bcidOffset) << std::endl;
       // l1topoBC->print();
diff --git a/Trigger/TrigT1/TrigT1Muctpi/src/Algorithms/L1Muctpi.h b/Trigger/TrigT1/TrigT1Muctpi/src/Algorithms/L1Muctpi.h
index 7ae73273ab3d..ac432a79f5e6 100644
--- a/Trigger/TrigT1/TrigT1Muctpi/src/Algorithms/L1Muctpi.h
+++ b/Trigger/TrigT1/TrigT1Muctpi/src/Algorithms/L1Muctpi.h
@@ -22,6 +22,8 @@
 #include "StoreGate/WriteHandleKey.h"
 #include "TrigT1Result/MuCTPI_RDO.h"
 #include "TrigT1Interfaces/Lvl1MuCTPIInput.h"
+#include "TrigT1Interfaces/MuCTPIL1Topo.h"
+#include "TrigT1Interfaces/NimCTP.h"
 
 // Forward declaration(s):
 namespace TrigConf {
@@ -117,6 +119,16 @@ namespace LVL1MUCTPI {
      SG::WriteHandleKey<LVL1::MuCTPICTP> m_muctpi2CtpKey { this, "CTPOutputLocID", LVL1MUCTPI::DEFAULT_MuonCTPLocation, "Output to CTPO" };
      SG::WriteHandleKey<MuCTPI_RDO> m_rdoOutputLocId{this, "RDOOutputLocID", "MUCTPI_RDO", "Location of MUCTPI RDOs"};
      SG::WriteHandleKey<L1MUINT::MuCTPIToRoIBSLink> m_muctpi2RoibKey { this, "MuCTPISLinkLocation", LVL1MUCTPI::DEFAULT_MuonRoIBLocation, "StoreGate location for outpput to RoIBuilder" };
+     SG::WriteHandleKey<LVL1::NimCTP> m_nimctpKey { this, "NIMOutputLocID", LVL1::DEFAULT_NimCTPLocation, "StoreGate location for output LVL1::NimCTP" };
+     SG::WriteHandleKey<LVL1::MuCTPIL1Topo> m_topoOutputLocId{this, "L1TopoOutputLocID", LVL1MUCTPI::DEFAULT_MuonL1TopoLocation, "Output to L1Topo"};
+     SG::WriteHandleKeyArray<LVL1::MuCTPIL1Topo> m_topoOutputOffsetLocId{this, "L1TopoOutputOffsetLocID",
+        {  // Corresponds to m_bcidOffsetList
+           LVL1MUCTPI::DEFAULT_MuonL1TopoLocation+"-2",
+           LVL1MUCTPI::DEFAULT_MuonL1TopoLocation+"-1",
+           LVL1MUCTPI::DEFAULT_MuonL1TopoLocation+"1",
+           LVL1MUCTPI::DEFAULT_MuonL1TopoLocation+"2"
+        },
+        "Output to L1Topo for offset BCIDs"};
 
 
       // These properties control the way the overlap handling functions:
@@ -138,7 +150,6 @@ namespace LVL1MUCTPI {
       std::string m_aodLocId;
       std::string m_rdoLocId;
       // std::string m_roiOutputLocId;
-      std::string m_l1topoOutputLocId;
       // std::string m_tgcLocId;
       // std::string m_rpcLocId;
 
@@ -152,7 +163,6 @@ namespace LVL1MUCTPI {
 
       // Properties controlling the NIM outputs provided by the simulation
       bool m_doNimOutput;
-      std::string m_nimOutputLocId;
       unsigned int m_nimBarrelBit;
       unsigned int m_nimEndcapBit;
       
-- 
GitLab