From 6da8158de1ddde3855023c6b4a894de053fd0fab Mon Sep 17 00:00:00 2001
From: Pascal Raisig <praisig@ikf.uni-frankfurt.de>
Date: Thu, 22 Jul 2021 13:34:30 +0200
Subject: [PATCH] Introduce a CbmSourceType flag

Since, the FairSource::Source_Type setting changes the behavior on the reading of the first Timeslice, its usage is for the time being removed. Therefore, a CbmSourceType enum is introduced which handles now the switch between data reading from online and offline sources.
---
 macro/run/run_unpack_online.C     |  2 +-
 macro/run/run_unpack_tsa.C        |  1 +
 reco/steer/CbmSourceTsArchive.cxx | 10 +++++++---
 reco/steer/CbmSourceTsArchive.h   | 27 ++++++++++++++++++++++++---
 4 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/macro/run/run_unpack_online.C b/macro/run/run_unpack_online.C
index 9147cfe159..f7761d3c04 100644
--- a/macro/run/run_unpack_online.C
+++ b/macro/run/run_unpack_online.C
@@ -118,7 +118,7 @@ void run_unpack_online(std::string publisher = "localhost", Int_t serverHttpPort
 
   // -----   CbmSourceTsArchive   -------------------------------------------
   auto source = new CbmSourceTsArchive(publisher.data());
-  source->SetSourceType(Source_Type::kONLINE);
+  source->SetCbmSourceType(CbmSourceTsArchive::eCbmSourceType::kOnline);
   auto unpack = source->GetRecoUnpack();
   unpack->SetUnpackConfig(trdconfig);
   // ------------------------------------------------------------------------
diff --git a/macro/run/run_unpack_tsa.C b/macro/run/run_unpack_tsa.C
index 45d3e1f2d1..d391221afa 100644
--- a/macro/run/run_unpack_tsa.C
+++ b/macro/run/run_unpack_tsa.C
@@ -177,6 +177,7 @@ void run_unpack_tsa(std::string infile = "test.tsa", UInt_t runid = 0, const cha
 
   // -----   CbmSourceTsArchive   -------------------------------------------
   auto source = new CbmSourceTsArchive(infile.data());
+  source->SetCbmSourceType(CbmSourceTsArchive::eCbmSourceType::kOffline);
   auto unpack = source->GetRecoUnpack();
   if (psdconfig) unpack->SetUnpackConfig(psdconfig);
   if (richconfig) unpack->SetUnpackConfig(richconfig);
diff --git a/reco/steer/CbmSourceTsArchive.cxx b/reco/steer/CbmSourceTsArchive.cxx
index 6018c4e166..90fa59a0f9 100644
--- a/reco/steer/CbmSourceTsArchive.cxx
+++ b/reco/steer/CbmSourceTsArchive.cxx
@@ -47,8 +47,10 @@ void CbmSourceTsArchive::Close()
 Bool_t CbmSourceTsArchive::Init()
 {
 
-  switch (fSourceType) {
-    case Source_Type::kONLINE: {
+  switch (fCbmSourceType) {
+    // Use again when kFILE does not skipp the first TS by default anymore
+    // case Source_Type::kONLINE: {
+    case eCbmSourceType::kOnline: {
       // Create a ";" separated string with all host/port combinations
       // Build a semicolon-separated list of file names for TimesliceMultiInputArchive
       string fileList;
@@ -70,7 +72,9 @@ Bool_t CbmSourceTsArchive::Init()
       }
       break;
     }
-    case Source_Type::kFILE: {
+    // Se above
+    // case Source_Type::kFILE: {
+    case eCbmSourceType::kOffline: {
       // Return error for empty file list and an offline run
       if (fFileNames.empty()) return kFALSE;
 
diff --git a/reco/steer/CbmSourceTsArchive.h b/reco/steer/CbmSourceTsArchive.h
index 8a835eb066..bf1677a5f3 100644
--- a/reco/steer/CbmSourceTsArchive.h
+++ b/reco/steer/CbmSourceTsArchive.h
@@ -29,6 +29,16 @@
 class CbmSourceTsArchive : public FairSource {
 
 public:
+  /**
+   * @brief Enum for switch of source type
+   * @remark This is a temporary fix as long as in the original FairSource::Source_Type kFILE leads to skipping the first Timeslice
+  */
+  enum class eCbmSourceType : uint16_t
+  {
+    kOnline = 0,  // Use when running with an online source (published data)
+    kOffline      // Use when running with tsa files as source
+  };
+
   /** @brief Constructor
    ** @param fileName  Name of (single) input file.
    **
@@ -60,10 +70,15 @@ public:
 
 
   /** @brief Source type
-   ** @return kFILE
+   ** @return FairSource::Source_Type
    **/
   virtual Source_Type GetSourceType() { return fSourceType; }
 
+  /** @brief Get the Cbm Source type
+   ** @return eCbmSourceType
+   **/
+  eCbmSourceType GetCbmSourceType() { return fCbmSourceType; }
+
   /**
    * @brief Get the Reco Unpack
    * Access the CbmRecoUnpack class to add unpacker configs
@@ -100,6 +115,9 @@ public:
   /** @brief Set the Source Type @param type */
   void SetSourceType(Source_Type type) { fSourceType = type; }
 
+  /** @brief Set the Cbm Source Type @param type @remark temporary fix see enum */
+  void SetCbmSourceType(eCbmSourceType type) { fCbmSourceType = type; }
+
 private:
   /** List of input file names **/
   std::vector<std::string> fFileNames = {};
@@ -107,8 +125,11 @@ private:
   /** @brief Amount of Timeslices buffered before the publisher starts dropping new ones, if the old are not digested yet.*/
   std::uint32_t fHighWaterMark = 1;
 
-  /** @brief type of source that is currently used */
-  Source_Type fSourceType = Source_Type::kFILE;
+  /** @brief type of source that is currently used @remark currently we use kONLINE as default, since, kFILE skipps the first TS probably due to obsolete reasons (to be checked PR072021) */
+  Source_Type fSourceType = Source_Type::kONLINE;
+
+  /** @brief type of source that is currently used in the CBM definition @remark temprorary fix for the issue described in the comments of the enum */
+  eCbmSourceType fCbmSourceType = eCbmSourceType::kOffline;
 
   /** Time-slice source interface **/
   fles::TimesliceSource* fTsSource = nullptr;  //!
-- 
GitLab