From a279fa8b2c513698e490696531cebc0eb5db6703 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de>
Date: Mon, 19 Jun 2023 14:25:34 +0000
Subject: [PATCH] algo::Unpack: Add option to mask detectors.

---
 algo/unpack/Unpack.cxx      | 15 +++++++++++++--
 algo/unpack/Unpack.h        | 17 ++++++++++++++---
 algo/unpack/UnpackChain.cxx | 21 +++++++++++++++++++--
 3 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/algo/unpack/Unpack.cxx b/algo/unpack/Unpack.cxx
index 532fd7f490..b28d9f092a 100644
--- a/algo/unpack/Unpack.cxx
+++ b/algo/unpack/Unpack.cxx
@@ -28,6 +28,8 @@ namespace cbm::algo
       // System ID of current component
       const auto systemId = static_cast<fles::SubsystemIdentifier>(timeslice->descriptor(comp, 0).sys_id);
 
+      if (!DetectorEnabled(systemId)) continue;
+
       // Equipment ID of current component
       const uint16_t equipmentId = timeslice->descriptor(comp, 0).eq_id;
 
@@ -128,8 +130,18 @@ namespace cbm::algo
   // ----------------------------------------------------------------------------
 
   // -----   Initialisation   ---------------------------------------------------
-  bool Unpack::Init()
+  bool Unpack::Init(std::optional<std::vector<fles::SubsystemIdentifier>> subIds)
   {
+    if (!subIds) {
+      fSubIds = {
+        fles::SubsystemIdentifier::STS, fles::SubsystemIdentifier::MUCH, fles::SubsystemIdentifier::RPC,
+        fles::SubsystemIdentifier::T0,  fles::SubsystemIdentifier::TRD,  fles::SubsystemIdentifier::TRD2D,
+      };
+    }
+    else {
+      fSubIds = *subIds;
+    }
+
     // --- Common parameters for all components for STS
     uint32_t numChansPerAsicSts   = 128;  // R/O channels per ASIC for STS
     uint32_t numAsicsPerModuleSts = 16;   // Number of ASICs per module for STS
@@ -285,5 +297,4 @@ namespace cbm::algo
   }
   // ----------------------------------------------------------------------------
 
-
 } /* namespace cbm::algo */
diff --git a/algo/unpack/Unpack.h b/algo/unpack/Unpack.h
index 3071986f54..3a8ab29b4a 100644
--- a/algo/unpack/Unpack.h
+++ b/algo/unpack/Unpack.h
@@ -15,6 +15,7 @@
 #include "trd2d/Trd2dReadoutConfig.h"
 #include "trd2d/UnpackTrd2d.h"
 
+#include <optional>
 #include <sstream>
 #include <vector>
 
@@ -100,8 +101,16 @@ namespace cbm::algo
     /** @brief Parameters for RICH unpackers **/
     RichReadoutConfig fRichConfig {};
 
-    /** @brief Initialize unpackers and fill parameters from config objects **/
-    bool Init();
+    /** @brief Initialize unpackers and fill parameters from config objects
+     * @param subIds: vector of subsystem identifiers to unpack, default: all
+     * @see Init()
+     **/
+    bool Init(std::optional<std::vector<fles::SubsystemIdentifier>> subIds = {});
+
+    bool DetectorEnabled(fles::SubsystemIdentifier subId)
+    {
+      return std::find(fSubIds.begin(), fSubIds.end(), subId) != fSubIds.end();
+    }
 
   private:  // methods
     /** @brief Microslice loop **/
@@ -111,7 +120,9 @@ namespace cbm::algo
                 std::vector<MonitorData>* monitorMs, uint8_t sys_ver);
 
 
-  private:  // members
+  private:                                                // members
+    std::vector<fles::SubsystemIdentifier> fSubIds = {};  ///< Detector identifiers to unpack
+
     /** @brief STS unpackers **/
     std::map<uint16_t, UnpackSts> fAlgoSts = {};
 
diff --git a/algo/unpack/UnpackChain.cxx b/algo/unpack/UnpackChain.cxx
index 25b412ffd2..21e6742b60 100644
--- a/algo/unpack/UnpackChain.cxx
+++ b/algo/unpack/UnpackChain.cxx
@@ -7,8 +7,25 @@ using namespace cbm::algo;
 
 void UnpackChain::Init()
 {
-  bool ok = fUnpack.Init();
+  bool ok = fUnpack.Init(std::vector<fles::SubsystemIdentifier> {
+    fles::SubsystemIdentifier::STS,
+    // fles::SubsystemIdentifier::MUCH,
+    fles::SubsystemIdentifier::RPC, fles::SubsystemIdentifier::T0,
+    // fles::SubsystemIdentifier::TRD,
+    // fles::SubsystemIdentifier::TRD2D,
+  });
   if (!ok) throw std::runtime_error("Unpack::Init failed");
 }
 
-Unpack::resultType UnpackChain::Run(const fles::Timeslice& timeslice) { return fUnpack(&timeslice); }
+Unpack::resultType UnpackChain::Run(const fles::Timeslice& timeslice)
+{
+  auto result = fUnpack(&timeslice);
+
+  auto& digis = result.first.fData;
+
+  L_(info) << "Timeslice contains " << digis.fSts.Size() << " STS Digis";
+  L_(info) << "Timeslice contains " << digis.fTof.Size() << " TOF Digis";
+  L_(info) << "Timeslice contains " << digis.fT0.Size() << " RPC Digis";
+
+  return result;
+}
-- 
GitLab