From 959c14d1a5972a3d223a4c23a640949df83df0ba Mon Sep 17 00:00:00 2001
From: "P.-A. Loizeau" <p.-a.loizeau@gsi.de>
Date: Thu, 21 Jul 2022 17:51:08 +0200
Subject: [PATCH] In TOF unpacker algo, add count of hit message rejected due
 to bad epoch + final printout

---
 reco/detectors/tof/unpack/CbmTofUnpackAlgo.cxx | 13 +++++++++++++
 reco/detectors/tof/unpack/CbmTofUnpackAlgo.h   |  4 +++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/reco/detectors/tof/unpack/CbmTofUnpackAlgo.cxx b/reco/detectors/tof/unpack/CbmTofUnpackAlgo.cxx
index 74aa75f767..11b6466572 100644
--- a/reco/detectors/tof/unpack/CbmTofUnpackAlgo.cxx
+++ b/reco/detectors/tof/unpack/CbmTofUnpackAlgo.cxx
@@ -44,6 +44,14 @@ std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>*
   return &fParContVec;
 }
 
+// ---- finishDerived ----
+void CbmTofUnpackAlgo::finishDerived()
+{
+  LOG(info) << fName << std::endl                                  // Block clang format
+            << " " << fulBadEpochNb << " bad epochs" << std::endl  // Block clang format
+            << " " << fulBadEpochHitNb << " hit messages lost due to bad epochs";
+}
+
 // ---- init
 Bool_t CbmTofUnpackAlgo::init() { return kTRUE; }
 
@@ -264,6 +272,9 @@ bool CbmTofUnpackAlgo::unpack(const fles::Timeslice* ts, std::uint16_t icomp, UI
           /// Epoch OK
           ProcessHit(pMess[uIdx]);
         }
+        else {
+          ++fulBadEpochHitNb;
+        }
         break;
       }  // case critof001::MSG_HIT:
       case critof001::MSG_EPOCH: {
@@ -365,6 +376,7 @@ void CbmTofUnpackAlgo::ProcessEpoch(const critof001::Message& mess, uint32_t uMe
       fbLastEpochGood       = false;
       ulEpochNr             = ulMsStartInEpoch;
       fuProcEpochUntilError = 0;
+      ++fulBadEpochNb;
     }  // if( ulEpochNr != ulMsStartInEpoch )
     else {
       fbLastEpochGood = true;
@@ -383,6 +395,7 @@ void CbmTofUnpackAlgo::ProcessEpoch(const critof001::Message& mess, uint32_t uMe
     ulEpochNr             = (fulCurrentEpoch + 1) % critof001::kulEpochCycleEp;
     fbLastEpochGood       = false;
     fuProcEpochUntilError = 0;
+    ++fulBadEpochNb;
   }  // if( ( (fulCurrentEpoch + 1) % critof001::kuEpochCounterSz ) != ulEpochNr )
   else {
     fbLastEpochGood = true;
diff --git a/reco/detectors/tof/unpack/CbmTofUnpackAlgo.h b/reco/detectors/tof/unpack/CbmTofUnpackAlgo.h
index aa04de6a42..f4f7cd0ce3 100644
--- a/reco/detectors/tof/unpack/CbmTofUnpackAlgo.h
+++ b/reco/detectors/tof/unpack/CbmTofUnpackAlgo.h
@@ -102,7 +102,7 @@ protected:
   }
 
   /** @brief Function that allows special calls during Finish in the derived algos */
-  virtual void finishDerived() { return; }
+  void finishDerived();
 
   /**
    * @brief Initialisation at begin of run. Special inits of the derived algos.
@@ -204,6 +204,8 @@ private:
   bool fbBmonParMode                    = false;
   std::vector<bool> fvbMaskedComponents = {};
   bool fbLastEpochGood                  = false;
+  uint64_t fulBadEpochNb                = 0;
+  uint64_t fulBadEpochHitNb             = 0;
 
   /// Book-keeping members
   uint32_t fuProcEpochUntilError = 0;
-- 
GitLab