From 0f87a54d612a82bfe5425087ef26600ddce807c0 Mon Sep 17 00:00:00 2001
From: P-A Loizeau <p.-a.loizeau@gsi.de>
Date: Mon, 18 Nov 2024 16:13:12 +0100
Subject: [PATCH] Bugfix in BMON and TOF online unpacker: time offset was
 stored as unsigned int!

---
 algo/detectors/bmon/ReadoutConfig.cxx | 4 ++--
 algo/detectors/bmon/ReadoutConfig.h   | 6 +++---
 algo/detectors/bmon/UnpackMS.h        | 2 +-
 algo/detectors/tof/Unpack.cxx         | 2 +-
 algo/detectors/tof/UnpackMS.h         | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/algo/detectors/bmon/ReadoutConfig.cxx b/algo/detectors/bmon/ReadoutConfig.cxx
index dc8c325b6e..6e6e97f141 100644
--- a/algo/detectors/bmon/ReadoutConfig.cxx
+++ b/algo/detectors/bmon/ReadoutConfig.cxx
@@ -63,9 +63,9 @@ namespace cbm::algo::bmon
 
 
   // ---  Mapping (equimentId, elink) -> time offset  -------------------------------------
-  int64_t ReadoutConfig::TimeOffsetMap(uint16_t equipmentId, uint16_t elinkId)
+  int32_t ReadoutConfig::TimeOffsetMap(uint16_t equipmentId, uint16_t elinkId)
   {
-    int64_t result = 0;
+    int32_t result = 0;
     auto equipIter = fTimeOffsetMap.find(equipmentId);
     if (equipIter != fTimeOffsetMap.end()) {
       if (elinkId < equipIter->second.size()) {
diff --git a/algo/detectors/bmon/ReadoutConfig.h b/algo/detectors/bmon/ReadoutConfig.h
index a4048bde5c..13133d6b3b 100644
--- a/algo/detectors/bmon/ReadoutConfig.h
+++ b/algo/detectors/bmon/ReadoutConfig.h
@@ -23,7 +23,7 @@ namespace cbm::algo::bmon
       i32 rpcType;
       i32 rpcSide;
       i32 nRPC;
-      i64 timeOffset;
+      i32 timeOffset;
 
       CBM_YAML_PROPERTIES(
         yaml::Property(&CROB::moduleId, "moduleId", "Unique ID of module the CROB resides in"),
@@ -93,12 +93,12 @@ namespace cbm::algo::bmon
      ** @param elink       Elink number within component
      ** @return Time Offset
      */
-    int64_t TimeOffsetMap(uint16_t equipId, uint16_t elink);
+    int32_t TimeOffsetMap(uint16_t equipId, uint16_t elink);
 
    private:
     // --- Bmon elink time offsets
     // --- Map index: (equipment, elink), map value: (time offset)
-    std::map<uint16_t, std::vector<uint64_t>> fTimeOffsetMap = {};
+    std::map<uint16_t, std::vector<int32_t>> fTimeOffsetMap = {};
 
     // --- Bmon readout map
     // --- Map index: (equipment, elink, channel), map value: (TOF address)
diff --git a/algo/detectors/bmon/UnpackMS.h b/algo/detectors/bmon/UnpackMS.h
index 8ba772dbb7..4930ab2ac3 100644
--- a/algo/detectors/bmon/UnpackMS.h
+++ b/algo/detectors/bmon/UnpackMS.h
@@ -27,7 +27,7 @@ namespace cbm::algo::bmon
    **/
   struct UnpackElinkPar {
     std::vector<uint32_t> fChannelUId;  ///< CbmBmonAddress for different channels
-    uint64_t fTimeOffset = 0.;          ///< Time calibration parameter
+    int32_t fTimeOffset = 0.;           ///< Time calibration parameter
   };
 
 
diff --git a/algo/detectors/tof/Unpack.cxx b/algo/detectors/tof/Unpack.cxx
index 1969e4e6a1..3f6dbb2d5d 100644
--- a/algo/detectors/tof/Unpack.cxx
+++ b/algo/detectors/tof/Unpack.cxx
@@ -11,7 +11,7 @@ using fles::Subsystem;
 
 Unpack::Unpack(const ReadoutConfig& readout) : fReadout(readout)
 {
-  constexpr i64 SystemTimeOffset = 40;
+  constexpr i32 SystemTimeOffset = 40;
   constexpr u8 SystemVersion     = 0x00;
 
   auto equipIdsTof = fReadout.GetEquipmentIds();
diff --git a/algo/detectors/tof/UnpackMS.h b/algo/detectors/tof/UnpackMS.h
index 591a4deee1..6f41bd674e 100644
--- a/algo/detectors/tof/UnpackMS.h
+++ b/algo/detectors/tof/UnpackMS.h
@@ -27,7 +27,7 @@ namespace cbm::algo::tof
    **/
   struct UnpackElinkPar {
     std::vector<uint32_t> fChannelUId;  ///< CbmTofAddress for different channels
-    uint64_t fTimeOffset = 0.;          ///< Time calibration parameter
+    int32_t fTimeOffset = 0.;           ///< Time calibration parameter
   };
 
   /** @struct UnpackPar
-- 
GitLab