From 059c201a61d7befbca97d58b977a30e82e7ab95c Mon Sep 17 00:00:00 2001
From: Rafal Bielski <rafal.bielski@cern.ch>
Date: Thu, 20 Dec 2018 03:02:17 +0100
Subject: [PATCH] configure ROB IDs to be decoded from RoIBResultByteStreamTool
 properties

---
 .../RoIBResultByteStreamTool.h                |  72 ++++++-----
 .../src/RoIBResultByteStreamDecoderAlg.cxx    |   7 +
 .../src/RoIBResultByteStreamTool.cxx          | 120 ++++++------------
 .../TrigUpgradeTest/share/testHLT_MT.py       |   2 +
 4 files changed, 91 insertions(+), 110 deletions(-)

diff --git a/Trigger/TrigT1/TrigT1ResultByteStream/TrigT1ResultByteStream/RoIBResultByteStreamTool.h b/Trigger/TrigT1/TrigT1ResultByteStream/TrigT1ResultByteStream/RoIBResultByteStreamTool.h
index 3c6d086657e2..7de74751c3aa 100755
--- a/Trigger/TrigT1/TrigT1ResultByteStream/TrigT1ResultByteStream/RoIBResultByteStreamTool.h
+++ b/Trigger/TrigT1/TrigT1ResultByteStream/TrigT1ResultByteStream/RoIBResultByteStreamTool.h
@@ -65,39 +65,12 @@ public:
   /// Convert RoIBResult to ByteStream
   StatusCode convert( ROIB::RoIBResult* cont, RawEventWrite* re );
 
-private:
-  /// Object used in creating the RoI Builder ROB fragments
-  FullEventAssembler<L1SrcIdMap> m_fea;
+  /// Vector of ROB IDs corresponding to the modules configured for decoding
+  const std::vector<uint32_t>& configuredROBIds() const {return m_configuredROBIds;}
 
-  /// @name Properties holding module IDs for L1 RoI ROBs
-  /// @{
-  /// CTP Module ID to decode
-  Gaudi::Property<uint32_t> m_ctpModuleID {
-    this, "CTPModuleId", 1,
-    "Module ID of CTP ROB with RoI information"
-  };
-  /// MUCTPI Module ID to decode
-  Gaudi::Property<uint32_t> m_muCTPIModuleID {
-    this, "MUCTPIModuleId", 1,
-    "Module ID of MUCTPI ROB with RoI information"
-  };
-  /// Jet Module IDs to decode
-  Gaudi::Property<std::vector<uint32_t>> m_jetModuleID {
-    this, "JetModuleIds", {0xac, 0xad},
-    "Vector of module IDs of Jet RoI ROBs"
-  };
-  /// EM Module IDs to decode
-  Gaudi::Property<std::vector<uint32_t>> m_emModuleID {
-    this, "EMModuleIds", {0xa8, 0xa9, 0xaa, 0xab},
-    "Vector of module IDs of EM RoI ROBs"
-  };
-  /// L1Topo Module IDs to decode
-  Gaudi::Property<std::vector<uint32_t>> m_l1TopoModuleID {
-    this, "L1TopoModuleIds", {0x81,0x91},
-    "Vector of module IDs of L1Topo RoI ROBs"
-  };
-  /// @}
+private:
 
+  // ------------------------- Private types -----------------------------------
   /// Structure holding the status words and rob/rod error flags
   struct DataStatus {
     bool rob_error {false};
@@ -106,6 +79,7 @@ private:
     uint32_t status_info {0};
   };
 
+  // ------------------------- Private methods ---------------------------------
   /**
    * @brief Helper method to extract ROD header information
    * @in rob ROBFragment from which data are extracted
@@ -134,6 +108,42 @@ private:
    **/
   ROIB::Trailer roibTrailer(const DataStatus& dataStatus, const uint32_t dataSize) const;
 
+  // ------------------------- Properties --------------------------------------
+  /// @name Properties holding module IDs for L1 RoI ROBs
+  /// @{
+  /// CTP Module ID to decode
+  Gaudi::Property<uint16_t> m_ctpModuleID {
+    this, "CTPModuleId", 1,
+    "Module ID of CTP ROB with RoI information"
+  };
+  /// MUCTPI Module ID to decode
+  Gaudi::Property<uint16_t> m_muCTPIModuleID {
+    this, "MUCTPIModuleId", 1,
+    "Module ID of MUCTPI ROB with RoI information"
+  };
+  /// Jet Module IDs to decode
+  Gaudi::Property<std::vector<uint16_t>> m_jetModuleID {
+    this, "JetModuleIds", {0xac, 0xad},
+    "Vector of module IDs of Jet RoI ROBs"
+  };
+  /// EM Module IDs to decode
+  Gaudi::Property<std::vector<uint16_t>> m_emModuleID {
+    this, "EMModuleIds", {0xa8, 0xa9, 0xaa, 0xab},
+    "Vector of module IDs of EM RoI ROBs"
+  };
+  /// L1Topo Module IDs to decode
+  Gaudi::Property<std::vector<uint16_t>> m_l1TopoModuleID {
+    this, "L1TopoModuleIds", {0x81,0x91},
+    "Vector of module IDs of L1Topo RoI ROBs"
+  };
+  /// @}
+
+  // ------------------------- Other private members ---------------------------
+  /// Vector of ROB IDs corresponding to the modules configured for decoding
+  std::vector<uint32_t> m_configuredROBIds;
+  /// Object used in creating the RoI Builder ROB fragments
+  FullEventAssembler<L1SrcIdMap> m_fea;
+
 }; // class RoIBResultByteStreamTool
 
 // Implementation of the legacy template method has to be included in the header file to avoid linking errors
diff --git a/Trigger/TrigT1/TrigT1ResultByteStream/src/RoIBResultByteStreamDecoderAlg.cxx b/Trigger/TrigT1/TrigT1ResultByteStream/src/RoIBResultByteStreamDecoderAlg.cxx
index 4a1a1e935658..dd897f80df95 100644
--- a/Trigger/TrigT1/TrigT1ResultByteStream/src/RoIBResultByteStreamDecoderAlg.cxx
+++ b/Trigger/TrigT1/TrigT1ResultByteStream/src/RoIBResultByteStreamDecoderAlg.cxx
@@ -19,6 +19,13 @@ StatusCode RoIBResultByteStreamDecoderAlg::initialize() {
   ATH_CHECK(m_roibResultWHKey.initialize());
   ATH_CHECK(m_robDataProviderSvc.retrieve());
 
+  // Retrieve the list of ROB IDs to decode
+  m_robIdsToDecode = m_decoderTool->configuredROBIds();
+  ATH_MSG_DEBUG("List of ROB IDs to decode:");
+  for (const uint32_t robid : m_robIdsToDecode) {
+    ATH_MSG_DEBUG("   0x" << MSG::hex << robid << MSG::dec);
+  }
+
   return StatusCode::SUCCESS;
 }
 
diff --git a/Trigger/TrigT1/TrigT1ResultByteStream/src/RoIBResultByteStreamTool.cxx b/Trigger/TrigT1/TrigT1ResultByteStream/src/RoIBResultByteStreamTool.cxx
index 502102951ec1..b74bf3e2ba5c 100755
--- a/Trigger/TrigT1/TrigT1ResultByteStream/src/RoIBResultByteStreamTool.cxx
+++ b/Trigger/TrigT1/TrigT1ResultByteStream/src/RoIBResultByteStreamTool.cxx
@@ -58,89 +58,51 @@ RoIBResultByteStreamTool::~RoIBResultByteStreamTool() {
 }
 
 /**
- * The function initialises the base class.
+ * @brief Initialise the tool
+ *
+ * Fill the vector of configured ROB IDs and print the module IDs to debug message stream
  */
 StatusCode RoIBResultByteStreamTool::initialize() {
-
-  //
-  // Initialise the base class:
-  //
-  StatusCode sc = AlgTool::initialize();
-  if( sc.isFailure() ) {
-    return sc;
+  std::vector<eformat::helper::SourceIdentifier> configuredROBSIDs;
+  std::ostringstream str;
+  ATH_MSG_DEBUG("Configured module IDs for:");
+
+  // CTP
+  configuredROBSIDs.emplace_back(eformat::TDAQ_CTP, m_ctpModuleID);
+  ATH_MSG_DEBUG("   CTP                                  = 0x" << MSG::hex << m_ctpModuleID.value() << MSG::dec);
+
+  // MUCTPI
+  configuredROBSIDs.emplace_back(eformat::TDAQ_MUON_CTP_INTERFACE, m_muCTPIModuleID);
+  ATH_MSG_DEBUG("   muCTPi                               = 0x" << MSG::hex << m_muCTPIModuleID.value() << MSG::dec);
+
+  // Jet/Energy
+  str.str("");
+  for (const uint16_t module_id : m_jetModuleID) {
+    configuredROBSIDs.emplace_back(eformat::TDAQ_CALO_JET_PROC_ROI, module_id);
+    str << "0x" << std::hex << module_id << std::dec << " ";
   }
+  ATH_MSG_DEBUG("   Calorimeter Jet/Energy Processor RoI = " << str.str());
 
-  //
-  // Get ByteStreamAddressProviderSvc:
-  //
-  ServiceHandle< IProperty > p_ByteStreamAddressProviderSvc( "ByteStreamAddressProviderSvc", name() );
-  sc = p_ByteStreamAddressProviderSvc.retrieve();
-  if( sc.isFailure() ) {
-    ATH_MSG_ERROR("Can't get ByteStreamAddressProviderSvc");
-    return sc;
-  } else {
-    ATH_MSG_DEBUG("Connected to " << p_ByteStreamAddressProviderSvc.name());
-
-    UnsignedIntegerProperty ctpModuleID;
-    ctpModuleID.setName("CTPModuleID");
-    if (ctpModuleID.assign(p_ByteStreamAddressProviderSvc->getProperty("CTPModuleID"))) {
-      m_ctpModuleID = ctpModuleID.value() ;
-      ATH_MSG_DEBUG(" ---> getProperty('CTPModuleID')             = " << ctpModuleID);
-    } else {
-      ATH_MSG_WARNING(p_ByteStreamAddressProviderSvc.name() << "::getProperty('CTPModuleID') failed.");
-    }
-
-    UnsignedIntegerProperty muCTPIModuleID;
-    muCTPIModuleID.setName("MuCTPIModuleID");
-    if (muCTPIModuleID.assign(p_ByteStreamAddressProviderSvc->getProperty("MuCTPIModuleID"))) {
-      m_muCTPIModuleID = muCTPIModuleID.value() ;
-      ATH_MSG_DEBUG(" ---> getProperty('MuCTPIModuleID')          = " << muCTPIModuleID);
-    } else {
-      ATH_MSG_WARNING(p_ByteStreamAddressProviderSvc.name() << "::getProperty('MuCTPIModuleID') failed.");
-    }
-
-    UnsignedIntegerArrayProperty jetProcModuleID;
-    jetProcModuleID.setName("JetProcModuleID");
-    if (jetProcModuleID.assign(p_ByteStreamAddressProviderSvc->getProperty("JetProcModuleID"))) {
-      m_jetModuleID = jetProcModuleID.value() ;
-      ATH_MSG_DEBUG(" ---> getProperty('JetProcModuleID')         = " << jetProcModuleID);
-    } else {
-      ATH_MSG_WARNING(p_ByteStreamAddressProviderSvc.name() << "::getProperty('JetProcModuleID') failed.");
-    }
-
-    UnsignedIntegerArrayProperty caloClusterProcModuleID;
-    caloClusterProcModuleID.setName("CaloClusterProcModuleID");
-    if (caloClusterProcModuleID.assign(p_ByteStreamAddressProviderSvc->getProperty("CaloClusterProcModuleID"))) {
-      m_emModuleID = caloClusterProcModuleID.value() ;
-      ATH_MSG_DEBUG(" ---> getProperty('CaloClusterProcModuleID') = " << caloClusterProcModuleID);
-    } else {
-      ATH_MSG_WARNING(p_ByteStreamAddressProviderSvc.name() << "::getProperty('CaloClusterProcModuleID') failed.");
-    }
+  // EM/Tau
+  str.str("");
+  for (const uint16_t module_id : m_emModuleID) {
+    configuredROBSIDs.emplace_back(eformat::TDAQ_CALO_CLUSTER_PROC_ROI, module_id);
+    str << "0x" << std::hex << module_id << std::dec << " ";
+  }
+  ATH_MSG_DEBUG("   Calorimeter Cluster Processor RoI    = " << str.str());
 
-    UnsignedIntegerArrayProperty l1TopoModuleID;
-    l1TopoModuleID.setName("TopoProcModuleID");
-    if (l1TopoModuleID.assign(p_ByteStreamAddressProviderSvc->getProperty("TopoProcModuleID"))) {
-      m_l1TopoModuleID = l1TopoModuleID.value();
-      ATH_MSG_DEBUG(" ---> getProperty('TopoProcModuleID') = " << l1TopoModuleID);
-    } else {
-      ATH_MSG_WARNING(p_ByteStreamAddressProviderSvc.name() << "::getProperty('TopoProcModuleID') failed.");
-    }
+  // L1Topo
+  str.str("");
+  for (const uint16_t module_id : m_l1TopoModuleID) {
+    configuredROBSIDs.emplace_back(eformat::TDAQ_CALO_TOPO_PROC, module_id);
+    str << "0x" << std::hex << module_id << std::dec << " ";
   }
+  ATH_MSG_DEBUG("   L1Topo                               = " << str.str());
 
-  ATH_MSG_DEBUG(" -- Module IDs for: ");
-  ATH_MSG_DEBUG("    CTP                                  = 0x" <<MSG::hex<< m_ctpModuleID <<MSG::dec);
-  ATH_MSG_DEBUG("    muCTPi                               = 0x" <<MSG::hex<< m_muCTPIModuleID <<MSG::dec);
-  ATH_MSG_DEBUG("    Calorimeter Cluster Processor RoI    = 0x" <<MSG::hex<< m_emModuleID[0]
-     << ", 0x" << m_emModuleID[1] << ", 0x" << m_emModuleID[2] << ", 0x" << m_emModuleID[3] <<MSG::dec);
-  ATH_MSG_DEBUG("    Calorimeter Jet/Energy Processor RoI = 0x" <<MSG::hex<< m_jetModuleID[0]
-     << ", 0x" << m_jetModuleID[1] <<MSG::dec);
-
-  //  ATH_MSG_DEBUG("    L1Topo                               = 0x" <<MSG::hex<< m_l1TopoModuleID[0]     << ", 0x" <<  m_l1TopoModuleID[1] <<MSG::dec);
-  std::ostringstream topoModulesString;
-  for (unsigned int mid: m_l1TopoModuleID){
-    topoModulesString << L1Topo::formatHex4(mid) << " ";
+  // Fill the ROB ID vector
+  for (const auto& sid : configuredROBSIDs) {
+    m_configuredROBIds.push_back( sid.code() );
   }
-  ATH_MSG_DEBUG( "    L1Topo                               = " << topoModulesString.str());
 
   return StatusCode::SUCCESS;
 }
@@ -303,9 +265,9 @@ StatusCode RoIBResultByteStreamTool::convert(const std::vector<const OFFLINE_FRA
       ROIB::Trailer trailer = roibTrailer(status, content.size());
 
       // Extract the CTP version number
-			const uint32_t* rod;
-			robf.rod_start(rod);
-			unsigned int ctpVersionNumber = ((rod[CTPdataformat::Helper::FormatVersionPos] >> CTPdataformat::CTPFormatVersionShift) & CTPdataformat::CTPFormatVersionMask);
+      const uint32_t* rod;
+      robf.rod_start(rod);
+      unsigned int ctpVersionNumber = ((rod[CTPdataformat::Helper::FormatVersionPos] >> CTPdataformat::CTPFormatVersionShift) & CTPdataformat::CTPFormatVersionMask);
 
       // Create CTPResult object
       cTPResult = ROIB::CTPResult(ctpVersionNumber, header, trailer, content);
@@ -410,7 +372,7 @@ StatusCode RoIBResultByteStreamTool::convert(const std::vector<const OFFLINE_FRA
 
   } // End of loop over all ROB fragments
 
-  ATH_MSG_DEBUG("Building RoIBResult wit the following inputs:");
+  ATH_MSG_DEBUG("Building RoIBResult with the following inputs:");
   ATH_MSG_DEBUG("  CTP             - " << (cTPFound ? "found" : "not found"));
   ATH_MSG_DEBUG("  MUCTPI          - " << (muCTPIFound ? "found" : "not found"));
   ATH_MSG_DEBUG("  Jet/Energy[0/1] - " << (jetEnergyFound[0] ? "found" : "not found") << "/"
diff --git a/Trigger/TrigValidation/TrigUpgradeTest/share/testHLT_MT.py b/Trigger/TrigValidation/TrigUpgradeTest/share/testHLT_MT.py
index 83a8057e42fd..0a0b08a2ecb7 100644
--- a/Trigger/TrigValidation/TrigUpgradeTest/share/testHLT_MT.py
+++ b/Trigger/TrigValidation/TrigUpgradeTest/share/testHLT_MT.py
@@ -443,6 +443,8 @@ if opt.doL1Sim:
 
 if opt.doL1Unpacking:
     if globalflags.InputFormat.is_bytestream() or opt.doL1Sim:
+        from TrigT1ResultByteStream.TrigT1ResultByteStreamConf import RoIBResultByteStreamDecoderAlg
+        topSequence += RoIBResultByteStreamDecoderAlg() # creates RoIBResult (input for L1Decoder) from ByteStream
         from TrigUpgradeTest.TestUtils import L1DecoderTest
     #topSequence += L1DecoderTest(OutputLevel = opt.HLTOutputLevel)
         topSequence += L1DecoderTest(OutputLevel = DEBUG)
-- 
GitLab