From 904f8f7d3081bb56d7250480a98f4d0cc58a209d Mon Sep 17 00:00:00 2001
From: Dave Casper <dcasper@uci.edu>
Date: Thu, 6 Jan 2022 03:54:11 -0800
Subject: [PATCH] Use cable mapping DB for raw Tracker data

---
 .../FaserAuthentication/data/dblookup.xml     |  4 +
 .../python/FaserByteStreamCnvSvcConfig.py     |  4 +
 .../ISCT_CableMappingTool.h                   | 37 ++++++++
 .../python/FaserSCT_CableMappingConfig.py     | 27 ++++++
 .../src/FaserSCT_CableMappingTool.cxx         | 89 +++++++++++++++++++
 .../src/FaserSCT_CableMappingTool.h           | 62 +++++++++++++
 .../FaserSCT_ConditionsTools_entries.cxx      |  2 +
 .../TrackerByteStream/CMakeLists.txt          |  2 +-
 .../python/TrackerByteStreamConfig.py         |  5 +-
 .../src/TrackerByteStreamCnv.cxx              |  7 +-
 .../src/TrackerByteStreamCnv.h                |  2 +
 .../src/TrackerDataDecoderTool.cxx            | 18 ++--
 .../src/TrackerDataDecoderTool.h              |  4 +-
 13 files changed, 253 insertions(+), 10 deletions(-)
 create mode 100644 Tracker/TrackerConditions/FaserSCT_ConditionsTools/FaserSCT_ConditionsTools/ISCT_CableMappingTool.h
 create mode 100644 Tracker/TrackerConditions/FaserSCT_ConditionsTools/python/FaserSCT_CableMappingConfig.py
 create mode 100644 Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_CableMappingTool.cxx
 create mode 100644 Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_CableMappingTool.h

diff --git a/Database/ConnectionManagement/FaserAuthentication/data/dblookup.xml b/Database/ConnectionManagement/FaserAuthentication/data/dblookup.xml
index 5b309fd7..ca007cb7 100644
--- a/Database/ConnectionManagement/FaserAuthentication/data/dblookup.xml
+++ b/Database/ConnectionManagement/FaserAuthentication/data/dblookup.xml
@@ -21,5 +21,9 @@
  <service name="sqlite_file:///cvmfs/faser.cern.ch/repo/sw/database/DBRelease/current/sqlite200/ALLP200.db" accessMode="read" />
 </logicalservice>
 
+<logicalservice name="COOLONL_SCT">
+   <service name="sqlite_file:data/sqlite200/CABP200.db" accessMode="read" />
+   <service name="sqlite_file:///cvmfs/faser.cern.ch/repo/sw/database/DBRelease/current/sqlite200/CABP200.db" accessMode="read" />
+</logicalservice>
 
 </servicelist>
diff --git a/Event/FaserByteStreamCnvSvc/python/FaserByteStreamCnvSvcConfig.py b/Event/FaserByteStreamCnvSvc/python/FaserByteStreamCnvSvcConfig.py
index e2315ae1..5da32c10 100644
--- a/Event/FaserByteStreamCnvSvc/python/FaserByteStreamCnvSvcConfig.py
+++ b/Event/FaserByteStreamCnvSvc/python/FaserByteStreamCnvSvcConfig.py
@@ -50,6 +50,10 @@ def FaserByteStreamCnvSvcCfg(configFlags, **kwargs):
     from WaveByteStream.WaveByteStreamConfig import WaveByteStreamCfg
     result.merge(WaveByteStreamCfg(configFlags))
 
+# Configure TrackerByteStream converter
+    from TrackerByteStream.TrackerByteStreamConfig import TrackerByteStreamCfg
+    result.merge(TrackerByteStreamCfg(configFlags))
+
 # Load ByteStreamEventStorageInputSvc
     bsInputSvc = CompFactory.FaserByteStreamInputSvc
     result.addService(bsInputSvc(name = "FaserByteStreamInputSvc"))
diff --git a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/FaserSCT_ConditionsTools/ISCT_CableMappingTool.h b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/FaserSCT_ConditionsTools/ISCT_CableMappingTool.h
new file mode 100644
index 00000000..e3472b21
--- /dev/null
+++ b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/FaserSCT_ConditionsTools/ISCT_CableMappingTool.h
@@ -0,0 +1,37 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS and FAsER collaborations
+*/
+
+/** @file ISCT_CableMappingTool.h Interface file for SCT_CableMappingTool.
+ */
+
+// Multiple inclusion protection
+#ifndef ISCT_CABLE_MAPPING_TOOL
+#define ISCT_CABLE_MAPPING_TOOL
+
+//STL includes
+#include <vector>
+
+//Gaudi Includes
+#include "GaudiKernel/IAlgTool.h"
+#include "GaudiKernel/EventContext.h"
+
+class ISCT_CableMappingTool: virtual public IAlgTool {
+
+ public:
+  
+  //----------Public Member Functions----------//
+  // Structors
+  virtual ~ISCT_CableMappingTool() = default; //!< Destructor
+
+  /// Creates the InterfaceID and interfaceID() method
+  DeclareInterfaceID(ISCT_CableMappingTool, 1, 0);
+
+  // Methods to return cable-mapping data 
+  virtual std::map<int, std::pair<int,int> > getCableMapping(const EventContext& ctx) const = 0;
+  virtual std::map<int, std::pair<int,int> > getCableMapping(void) const = 0;
+
+};
+
+//---------------------------------------------------------------------- 
+#endif // ISCT_CABLE_MAPPING_TOOL
diff --git a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/python/FaserSCT_CableMappingConfig.py b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/python/FaserSCT_CableMappingConfig.py
new file mode 100644
index 00000000..4e4a2642
--- /dev/null
+++ b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/python/FaserSCT_CableMappingConfig.py
@@ -0,0 +1,27 @@
+"""Define methods to configure FaserSCT_CableMapping
+
+Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+"""
+from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
+from AthenaConfiguration.ComponentFactory import CompFactory
+from IOVDbSvc.IOVDbSvcConfig import addFolders
+FaserSCT_CableMappingTool=CompFactory.FaserSCT_CableMappingTool
+
+def FaserSCT_CableMappingToolCfg(flags, name="CableMappingTool", **kwargs):
+    """Return a configured FaserSCT_CableMappingTool"""
+    return FaserSCT_CableMappingTool(name, **kwargs)
+
+def FaserSCT_CableMappingCfg(flags, **kwargs):
+    """Return configured ComponentAccumulator and tool for FaserSCT_CableMapping
+
+    CableMappingTool may be provided in kwargs
+    """
+    acc = ComponentAccumulator()
+    # tool = kwargs.get("CableMappingTool", FaserSCT_CableMappingToolCfg(flags))
+    # folder arguments
+    dbInstance = kwargs.get("dbInstance", "SCT_ONL")
+    dbFolder = kwargs.get("dbFolder", "/SCT/DAQ/CableMapping")
+    acc.merge(addFolders(flags, dbFolder, dbInstance, className="CondAttrListCollection"))
+    # acc.addPublicTool(tool)
+    return acc
+
diff --git a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_CableMappingTool.cxx b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_CableMappingTool.cxx
new file mode 100644
index 00000000..9260ec31
--- /dev/null
+++ b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_CableMappingTool.cxx
@@ -0,0 +1,89 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS and FASER collaborations
+*/
+
+/** @file FaserSCT_CableMappingTool.cxx Implementation file for FaserSCT_CableMappingTool.
+    @author Dave Casper (06/01/22)
+*/
+
+#include "FaserSCT_CableMappingTool.h"
+
+// Include Athena stuff
+
+//----------------------------------------------------------------------
+FaserSCT_CableMappingTool::FaserSCT_CableMappingTool (const std::string& type, const std::string& name, const IInterface* parent) :
+  base_class(type, name, parent)
+{
+}
+
+//----------------------------------------------------------------------
+StatusCode 
+FaserSCT_CableMappingTool::initialize() {
+  // Read Cond Handle Key
+
+  ATH_CHECK(m_readKey.initialize());
+
+  return StatusCode::SUCCESS;
+} // FaserSCT_CableMappingTool::initialize()
+
+//----------------------------------------------------------------------
+StatusCode
+FaserSCT_CableMappingTool::finalize() {
+  // Print where you are
+  return StatusCode::SUCCESS;
+} // FaserSCT_CableMappingTool::finalize()
+
+//----------------------------------------------------------------------
+std::map<int, std::pair<int, int> >
+FaserSCT_CableMappingTool::getCableMapping(const EventContext& ctx) const {
+  // Print where you are
+  ATH_MSG_DEBUG("in getCableMapping()");
+  std::map<int, std::pair<int, int> > mappingData;
+
+  // Read Cond Handle
+  SG::ReadCondHandle<CondAttrListCollection> readHandle{m_readKey, ctx};
+  const CondAttrListCollection* readCdo{*readHandle}; 
+  if (readCdo==nullptr) {
+    ATH_MSG_FATAL("Null pointer to the read conditions object");
+    return mappingData;
+  }
+  // Get the validitiy range
+  EventIDRange rangeW;
+  if (not readHandle.range(rangeW)) {
+    ATH_MSG_FATAL("Failed to retrieve validity range for " << readHandle.key());
+    return mappingData;
+  }
+  ATH_MSG_INFO("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdo->size()= " << readCdo->size());
+  ATH_MSG_INFO("Range of input is " << rangeW);
+  
+  // Read mapping info
+  std::string stationParam{"station"};
+  std::string planeParam{"plane"};
+  CondAttrListCollection::const_iterator attrList{readCdo->begin()};
+  CondAttrListCollection::const_iterator end{readCdo->end()};
+  // CondAttrListCollection doesn't support C++11 type loops, no generic 'begin'
+  for (; attrList!=end; ++attrList) {
+    // A CondAttrListCollection is a map of ChanNum and AttributeList
+    CondAttrListCollection::ChanNum channelNumber{attrList->first};
+    const CondAttrListCollection::AttributeList &payload{attrList->second};
+    if (payload.exists(stationParam) and not payload[stationParam].isNull() and 
+        payload.exists(planeParam) and not payload[planeParam].isNull()) 
+    {
+      int stationVal{payload[stationParam].data<int>()};
+      int planeVal  {payload[planeParam].data<int>()};
+      if (stationVal < 0 || planeVal < 0) continue;  // Don't include invalid entries
+      mappingData.emplace(std::make_pair(channelNumber, std::make_pair(stationVal, planeVal)));
+    } else {
+      ATH_MSG_WARNING(stationParam << " and/or " << planeParam << " does not exist for ChanNum " << channelNumber);
+    }
+  }
+
+  return mappingData;
+} //FaserSCT_ReadCalibChipDataTool::getNPtGainData()
+
+std::map<int, std::pair<int, int> >
+FaserSCT_CableMappingTool::getCableMapping(void) const {
+  const EventContext& ctx{Gaudi::Hive::currentContext()};
+  return getCableMapping(ctx);
+}
+
diff --git a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_CableMappingTool.h b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_CableMappingTool.h
new file mode 100644
index 00000000..b2cf0076
--- /dev/null
+++ b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_CableMappingTool.h
@@ -0,0 +1,62 @@
+// -*- C++ -*-
+
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS and CERN collaborations
+*/
+
+/** @file FaserSCT_CableMappingTool.h Header file for FaserSCT_CableMappingTool.
+    @author Dave Casper, 06/01/22
+*/
+
+// Multiple inclusion protection
+#ifndef FASERSCT_CABLE_MAPPING_TOOL
+#define FASERSCT_CABLE_MAPPING_TOOL
+
+// Include interface class
+#include "AthenaBaseComps/AthAlgTool.h"
+#include "FaserSCT_ConditionsTools/ISCT_CableMappingTool.h"
+
+// Include Athena stuff
+#include "AthenaPoolUtilities/CondAttrListCollection.h"
+#include "StoreGate/ReadCondHandleKey.h"
+
+#include "GaudiKernel/ICondSvc.h"
+#include "Gaudi/Property.h"
+
+// #include "FaserSCT_ConditionsData/FaserSCT_ConditionsParameters.h"
+// #include "FaserSCT_ConditionsData/FaserSCT_GainCalibData.h"
+// #include "FaserSCT_ConditionsData/FaserSCT_NoiseCalibData.h"
+
+// Include Gaudi classes
+#include "GaudiKernel/EventContext.h"
+
+/** This class contains a Tool that reads SCT cable mapping data and makes it available to 
+    other algorithms. The current implementation reads the data from a COOL database. 
+*/
+
+class FaserSCT_CableMappingTool: public extends<AthAlgTool, ISCT_CableMappingTool> {
+
+ public:
+  //----------Public Member Functions----------//
+  // Structors
+  FaserSCT_CableMappingTool(const std::string& type, const std::string& name, const IInterface* parent); //!< Constructor
+  virtual ~FaserSCT_CableMappingTool() = default; //!< Destructor
+
+  // Standard Gaudi functions
+  virtual StatusCode initialize() override; //!< Gaudi initialiser
+  virtual StatusCode finalize() override; //!< Gaudi finaliser
+
+  // Methods to return calibration data
+  virtual std::map<int, std::pair<int, int> > getCableMapping(const EventContext& ctx) const override;
+  virtual std::map<int, std::pair<int, int> > getCableMapping(void) const override;
+
+ private:
+  // Read Cond Handle
+  SG::ReadCondHandleKey<CondAttrListCollection> m_readKey{this, "ReadKey", "/SCT/DAQ/CableMapping", "Key of input cabling folder"};
+
+  ServiceHandle<ICondSvc> m_condSvc{this, "CondSvc", "CondSvc"};
+
+};
+
+//---------------------------------------------------------------------- 
+#endif // FASERSCT_CABLE_MAPPING_TOOL
diff --git a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/components/FaserSCT_ConditionsTools_entries.cxx b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/components/FaserSCT_ConditionsTools_entries.cxx
index 5cf6ed93..cae3df3c 100644
--- a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/components/FaserSCT_ConditionsTools_entries.cxx
+++ b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/components/FaserSCT_ConditionsTools_entries.cxx
@@ -19,6 +19,7 @@
 #include "../FaserSCT_SiliconConditionsTool.h"
 // #include "../SCT_StripVetoTool.h"
 // #include "../SCT_TdaqEnabledTool.h"
+#include "../FaserSCT_CableMappingTool.h"
 
 // DECLARE_COMPONENT( SCT_ByteStreamErrorsTool )
 // DECLARE_COMPONENT( SCT_ChargeTrappingTool )
@@ -41,3 +42,4 @@ DECLARE_COMPONENT( FaserSCT_ReadCalibChipDataTool )
 DECLARE_COMPONENT( FaserSCT_SiliconConditionsTool )
 // DECLARE_COMPONENT( SCT_StripVetoTool )
 // DECLARE_COMPONENT( SCT_TdaqEnabledTool )
+DECLARE_COMPONENT( FaserSCT_CableMappingTool )
\ No newline at end of file
diff --git a/Tracker/TrackerEventCnv/TrackerByteStream/CMakeLists.txt b/Tracker/TrackerEventCnv/TrackerByteStream/CMakeLists.txt
index 2ae44b44..37ed9323 100644
--- a/Tracker/TrackerEventCnv/TrackerByteStream/CMakeLists.txt
+++ b/Tracker/TrackerEventCnv/TrackerByteStream/CMakeLists.txt
@@ -8,7 +8,7 @@ atlas_subdir( TrackerByteStream )
 atlas_add_component( TrackerByteStream
                      src/*.cxx src/*.h
                      src/components/*.cxx
-                     LINK_LIBRARIES AthenaKernel GaudiKernel StoreGateLib FaserByteStreamCnvSvcBaseLib FaserEventStorageLib TrackerRawData TrackerReadoutGeometry TrackerIdentifier EventFormats
+                     LINK_LIBRARIES AthenaKernel GaudiKernel StoreGateLib FaserByteStreamCnvSvcBaseLib FaserEventStorageLib TrackerRawData TrackerReadoutGeometry TrackerIdentifier EventFormats FaserSCT_ConditionsToolsLib
                      PRIVATE_LINK_LIBRARIES AthenaBaseComps )
 
 
diff --git a/Tracker/TrackerEventCnv/TrackerByteStream/python/TrackerByteStreamConfig.py b/Tracker/TrackerEventCnv/TrackerByteStream/python/TrackerByteStreamConfig.py
index 06e02977..f1945e30 100644
--- a/Tracker/TrackerEventCnv/TrackerByteStream/python/TrackerByteStreamConfig.py
+++ b/Tracker/TrackerEventCnv/TrackerByteStream/python/TrackerByteStreamConfig.py
@@ -2,8 +2,11 @@
 
 #from AthenaConfiguration.ComponentFactory import CompFactory
 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
+from FaserSCT_ConditionsTools.FaserSCT_CableMappingConfig import FaserSCT_CableMappingCfg
+# from FaserSCT_ConditionsTools.FaserSCT_DCSConditionsConfig import FaserSCT_DCSConditionsCfg
 
 def TrackerByteStreamCfg(configFlags, **kwargs):
-    acc = ComponentAccumulator()
+    acc = FaserSCT_CableMappingCfg(configFlags, **kwargs)
+    # tool = acc.popToolsAndMerge(acc)
 
     return acc
\ No newline at end of file
diff --git a/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerByteStreamCnv.cxx b/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerByteStreamCnv.cxx
index 8a82d3cd..575bd046 100644
--- a/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerByteStreamCnv.cxx
+++ b/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerByteStreamCnv.cxx
@@ -26,6 +26,7 @@ TrackerByteStreamCnv::TrackerByteStreamCnv(ISvcLocator* svcloc)
   : Converter(storageType(), classID(), svcloc)
   , AthMessaging(svcloc != nullptr ? msgSvc() : nullptr, "TrackerByteStreamCnv")
   , m_tool("TrackerDataDecoderTool")
+  , m_mappingTool("FaserSCT_CableMappingTool")
   , m_rdpSvc("FaserROBDataProviderSvc", "TrackerByteStreamCnv")
   , m_detStoreSvc("StoreGateSvc/DetectorStore", "TrackerByteStreamCnv")
 {
@@ -46,6 +47,7 @@ StatusCode TrackerByteStreamCnv::initialize()
   CHECK(Converter::initialize());
   CHECK(m_rdpSvc.retrieve());
   CHECK(m_tool.retrieve());
+  CHECK(m_mappingTool.retrieve());
 
   ATH_CHECK(m_detStoreSvc.retrieve());
   ATH_CHECK(m_detStoreSvc->retrieve(m_sctID, "FaserSCT_ID"));
@@ -94,9 +96,12 @@ StatusCode TrackerByteStreamCnv::createObj(IOpaqueAddress* pAddr, DataObject*& p
   FaserSCT_RDO_Container* cont = new FaserSCT_RDO_Container(max);
   ATH_MSG_DEBUG("New FaserSCT_RDO_Container created of size="<<cont->size());
 
+  auto mapping = m_mappingTool->getCableMapping();
+  ATH_MSG_ALWAYS("Cable mapping contains " << mapping.size() << " entries");
+  
   // Convert raw data into this container
 
-  CHECK( m_tool->convert(re, cont, key) );
+  CHECK( m_tool->convert(re, cont, key, mapping) );
   
   pObj = SG::asStorable(cont);
 
diff --git a/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerByteStreamCnv.h b/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerByteStreamCnv.h
index 212257de..de0095b6 100644
--- a/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerByteStreamCnv.h
+++ b/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerByteStreamCnv.h
@@ -14,6 +14,7 @@
 
 #include "AthenaBaseComps/AthMessaging.h"
 #include "FaserByteStreamCnvSvcBase/FaserByteStreamAddress.h"
+#include "FaserSCT_ConditionsTools/ISCT_CableMappingTool.h"
 
 class TrackerDataDecoderTool;
 class IFaserROBDataProviderSvc;
@@ -40,6 +41,7 @@ public:
   
 private:
   ToolHandle<TrackerDataDecoderTool>      m_tool;
+  ToolHandle<ISCT_CableMappingTool>       m_mappingTool;
   ServiceHandle<IFaserROBDataProviderSvc> m_rdpSvc;
   ServiceHandle<StoreGateSvc>             m_detStoreSvc;
   const FaserSCT_ID*                      m_sctID{nullptr};
diff --git a/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerDataDecoderTool.cxx b/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerDataDecoderTool.cxx
index e3c2b07f..9971d029 100644
--- a/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerDataDecoderTool.cxx
+++ b/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerDataDecoderTool.cxx
@@ -46,7 +46,7 @@ TrackerDataDecoderTool::initialize()
   ATH_CHECK(detStore()->retrieve(m_sctID, "FaserSCT_ID"));
 
   auto first_wafer = m_sctID->wafer_begin();
-  m_trb0Station = m_sctID->station(*first_wafer);
+  // m_trb0Station = m_sctID->station(*first_wafer);
 
   m_sctContext = m_sctID->wafer_context();
   m_phiReversed.resize(m_sctID->wafer_hash_max(), false);
@@ -80,7 +80,8 @@ TrackerDataDecoderTool::finalize()
 StatusCode
 TrackerDataDecoderTool::convert(const DAQFormats::EventFull* re, 
     FaserSCT_RDO_Container* container,
-    std::string key)
+    std::string key,
+    const std::map<int, std::pair<int, int> >& cableMapping)
 {
   ATH_MSG_DEBUG("TrackerDataDecoderTool::convert()");
 
@@ -116,10 +117,17 @@ TrackerDataDecoderTool::convert(const DAQFormats::EventFull* re,
     if ((frag->source_id()&0xFFFF0000) != DAQFormats::SourceIDs::TrackerSourceID) continue;
     ATH_MSG_DEBUG("Fragment:\n" << *frag);
     uint32_t trb = frag->source_id() & 0x0000FFFF;
+    if (cableMapping.count(trb) == 0)
+    {
+      ATH_MSG_ERROR("Invalid trb number " << trb << " not in mapping DB");
+      return StatusCode::FAILURE;
+    }
     // FIXME: 1 by default; needs to be 0 for IFT
-    int station = m_trb0Station + trb / TrackerDataFragment::PLANES_PER_STATION; 
-    int plane = trb % TrackerDataFragment::PLANES_PER_STATION;
-    
+    // int station = m_trb0Station + trb / TrackerDataFragment::PLANES_PER_STATION; 
+    // int plane = trb % TrackerDataFragment::PLANES_PER_STATION;
+    int station = cableMapping.at(trb).first;
+    int plane   = cableMapping.at(trb).second;
+
     // Exceptions are a no-no in Athena/Calypso, so catch any thrown by faser-common
     try
     {
diff --git a/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerDataDecoderTool.h b/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerDataDecoderTool.h
index 1d9507c2..32b42ced 100644
--- a/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerDataDecoderTool.h
+++ b/Tracker/TrackerEventCnv/TrackerByteStream/src/TrackerDataDecoderTool.h
@@ -31,7 +31,7 @@ class TrackerDataDecoderTool : public AthAlgTool {
   virtual StatusCode initialize();
   virtual StatusCode finalize();
 
-  StatusCode convert(const DAQFormats::EventFull* re, FaserSCT_RDO_Container* cont, std::string key);
+  StatusCode convert(const DAQFormats::EventFull* re, FaserSCT_RDO_Container* cont, std::string key, const std::map<int, std::pair<int, int> >& cableMapping);
 
 private:
   const FaserSCT_ID*                      m_sctID{nullptr};
@@ -42,7 +42,7 @@ private:
                                                         {7, 2, 5, 0, 3, 6, 1, 4}, 
                                                         "Mapping from online to offline module numbers" };
   
-  Gaudi::Property<uint32_t>               m_trb0Station { this, "Trb0StationNumber", 1, "Station number for TRB #0" };
+  // Gaudi::Property<uint32_t>               m_trb0Station { this, "Trb0StationNumber", 1, "Station number for TRB #0" };
 };
 
 #endif  /* TRACKERBYTESTREAM_TRACKERDATADECODERTOOL_H */
-- 
GitLab