From 40dc7ac477f658fadf58f62e69fb6bb5747ae400 Mon Sep 17 00:00:00 2001
From: Dominik Smith <d.smith@gsi.de>
Date: Tue, 4 Jun 2024 15:20:41 +0200
Subject: [PATCH] Added YAML-configurable system offset TRD2D unpacker in
 cbm::algo.

---
 algo/detectors/trd2d/ReadoutConfig.h |  9 ++++++++-
 algo/detectors/trd2d/Unpack.cxx      | 11 +++++------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/algo/detectors/trd2d/ReadoutConfig.h b/algo/detectors/trd2d/ReadoutConfig.h
index 44df9ad798..0c2bdc7b1b 100644
--- a/algo/detectors/trd2d/ReadoutConfig.h
+++ b/algo/detectors/trd2d/ReadoutConfig.h
@@ -108,7 +108,13 @@ namespace cbm::algo::trd2d
     void InitChannelMap(
       const std::map<size_t, std::map<size_t, std::map<size_t, std::tuple<int32_t, bool, uint64_t>>>>& channelMap);
 
+    /** @brief Get system time offset **/
+    int64_t GetSystemTimeOffset() { return fSystemTimeOffset; };
+
    private:
+    // --- System time offset
+    int64_t fSystemTimeOffset = 0;
+
     // --- TRD2D readout map
     // --- Map index: (equipment), map value: (module id, crob id)
     std::map<uint16_t, CompMapping> fReadoutMap = {};  //!
@@ -117,7 +123,8 @@ namespace cbm::algo::trd2d
     // --- Map index: (equipment, asic, chan), map value: (pad address, mask flag, daq offset)
     std::map<uint16_t, std::vector<std::vector<ChanMapping>>> fChannelMap = {};  //!
 
-    CBM_YAML_PROPERTIES(yaml::Property(&ReadoutConfig::fReadoutMap, "readoutMap", "Maps equipment to module and CROB ID",
+    CBM_YAML_PROPERTIES(yaml::Property(&ReadoutConfig::fSystemTimeOffset, "timeOffset", "System time offset for TRD2D"),
+		    yaml::Property(&ReadoutConfig::fReadoutMap, "readoutMap", "Maps equipment to module and CROB ID",
                                     YAML::Hex),
                    yaml::Property(&ReadoutConfig::fChannelMap, "channelMap",
                                     "Maps equipment, ASIC and channel to pad address, R pairing flag and DAQ offset",
diff --git a/algo/detectors/trd2d/Unpack.cxx b/algo/detectors/trd2d/Unpack.cxx
index e12ef68aee..cc6b25977d 100644
--- a/algo/detectors/trd2d/Unpack.cxx
+++ b/algo/detectors/trd2d/Unpack.cxx
@@ -11,8 +11,7 @@ using fles::Subsystem;
 
 Unpack::Unpack(const ReadoutConfig& readout) : fReadout(readout)
 {
-  constexpr i64 SystemTimeOffset = -510;
-  constexpr u8 SystemVersion     = 0x02;
+  constexpr u8 SystemVersion = 0x02;
 
   // Create one algorithm per component for TRD and configure it with parameters
   auto equipIdsTrd2d = fReadout.GetEquipmentIds();
@@ -33,10 +32,10 @@ Unpack::Unpack(const ReadoutConfig& readout) : fReadout(readout)
         chanPar.fDaqOffset  = pars.daqOffset;     // Time calibration parameter
         asicPar.fChanParams.push_back(chanPar);
       }
-      auto comppars          = fReadout.CompMap(equip);
-      par.fSystemTimeOffset  = SystemTimeOffset;
-      par.fModId             = comppars.moduleId;
-      par.fCrobId            = comppars.crobId;
+      auto comppars         = fReadout.CompMap(equip);
+      par.fSystemTimeOffset = fReadout.GetSystemTimeOffset();
+      par.fModId            = comppars.moduleId;
+      par.fCrobId           = comppars.crobId;
       par.fAsicParams.push_back(asicPar);
     }
     auto algo                      = std::make_unique<UnpackMS>(par);
-- 
GitLab