From 2fb5d4bee2c2f6d9ad2110308e620441a0515c09 Mon Sep 17 00:00:00 2001
From: Alexandru Bercuci <abercuci@niham.nipne.ro>
Date: Tue, 6 Dec 2022 11:56:07 +0200
Subject: [PATCH] add GetSize accessor to account for signal count in TRD2D

---
 core/data/trd/CbmTrdCluster.cxx | 19 +++++++++++++++++++
 core/data/trd/CbmTrdCluster.h   |  1 +
 2 files changed, 20 insertions(+)

diff --git a/core/data/trd/CbmTrdCluster.cxx b/core/data/trd/CbmTrdCluster.cxx
index 702c915246..3def998b2b 100644
--- a/core/data/trd/CbmTrdCluster.cxx
+++ b/core/data/trd/CbmTrdCluster.cxx
@@ -128,6 +128,25 @@ int32_t CbmTrdCluster::IsChannelInRange(int32_t ch) const
   return 0;
 }
 
+//____________________________________________________________________
+uint16_t CbmTrdCluster::GetSize() const
+{
+  uint16_t size(0);
+  if (HasFaspDigis()) {
+    size = GetNCols() << 1;
+    if (HasOpenStart()) size--;
+    if (HasOpenStop()) size--;
+    if (size <= 0) {
+      LOG(warn) << GetName() << "::GetSize: Fasp cluster meta-info corrupt.";
+      std::cout << ToString();
+      return 0;
+    }
+  }
+  else
+    size = GetNCols();
+  return size;
+}
+
 //____________________________________________________________________
 bool CbmTrdCluster::Merge(CbmTrdCluster* second, bool typ)
 {
diff --git a/core/data/trd/CbmTrdCluster.h b/core/data/trd/CbmTrdCluster.h
index a597001142..0ce0b3dc41 100644
--- a/core/data/trd/CbmTrdCluster.h
+++ b/core/data/trd/CbmTrdCluster.h
@@ -69,6 +69,7 @@ public:
   uint16_t GetNRows() const { return fNRows & 0x1f; }
   uint16_t GetEndCh() const { return fStartCh + fNCols - 1; }
   uint16_t GetRow() const { return GetNRows(); }
+  uint16_t GetSize() const;
   uint16_t GetStartCh() const { return fStartCh; }
   uint32_t GetStartTime() const { return fStartTime; }
   bool HasFaspDigis() const { return TESTBIT(fNRows, kFasp); }
-- 
GitLab