From 14b91c5d30d1ce82d956e51eb46eeaf55ae1d0b9 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de>
Date: Mon, 6 May 2024 15:47:31 +0000
Subject: [PATCH] online: Fix NaNs in monitoring.

---
 algo/global/Reco.cxx | 22 +++++++++++-----------
 algo/global/Reco.h   |  2 ++
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/algo/global/Reco.cxx b/algo/global/Reco.cxx
index fdb86d5df2..b98a217a02 100644
--- a/algo/global/Reco.cxx
+++ b/algo/global/Reco.cxx
@@ -478,7 +478,7 @@ void Reco::QueueTofCalibMetrics(const tof::CalibrateMonitorData& mon)
   GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
                            {
                              {"tofCalibTimeTotal", mon.fTime.wall()},
-                             {"tofCalibThroughput", mon.fTime.throughput()},
+                             {"tofCalibThroughput", FilterNan(mon.fTime.throughput())},
                              {"tofCalibNumDigisIn", mon.fNumDigis},
                              {"tofCalibUnknownRPC", mon.fDigiCalibUnknownRPC},
                            });
@@ -519,16 +519,16 @@ void Reco::QueueEvbuildMetrics(const evbuild::EventbuildChainMonitorData& mon)
   double totalSelectionRatio = nDigisTotal > 0 ? double(nDigisInEventsTotal) / nDigisTotal : 0;
   GetMonitor().QueueMetric("cbmreco", tags,
                            {{"digiTriggerTimeTotal", mon.digiMultTrigger.time.wall()},
-                            {"digiTriggerThroughput", mon.digiMultTrigger.time.throughput()},
+                            {"digiTriggerThroughput", FilterNan(mon.digiMultTrigger.time.throughput())},
                             {"hitTriggerTimeTotal", mon.hitMultTrigger.time.wall()},
-                            {"hitTriggerThroughput", mon.hitMultTrigger.time.throughput()},
+                            {"hitTriggerThroughput", FilterNan(mon.hitMultTrigger.time.throughput())},
                             {"v0TriggerNumTrackPairs", mon.v0Trigger.numTrackPairs},
                             {"v0TriggerNumTrackPairsCoinc", mon.v0Trigger.numTrackPairsAfterTimeCut},
                             {"v0TriggerErrTracksUnsorted", mon.v0Trigger.errTracksUnsorted},
                             {"v0TriggerTimeTotal", mon.v0Trigger.time.wall()},
-                            {"v0TriggerThroughput", mon.v0Trigger.time.throughput()},
+                            {"v0TriggerThroughput", FilterNan(mon.v0Trigger.time.throughput())},
                             {"eventbuildTimeTotal", mon.evbuild.time.wall()},
-                            {"eventbuildThroughput", mon.evbuild.time.throughput()},
+                            {"eventbuildThroughput", FilterNan(mon.evbuild.time.throughput())},
                             {"numTrigger", mon.digiMultTrigger.nTriggers},
                             {"numEvents", mon.evbuild.nEvents},
                             {"totalEvSelectionRatio", totalSelectionRatio}});
@@ -556,12 +556,12 @@ void Reco::QueueProcessingMetrics(const ProcessingMonitor& mon)
   }
 
   MetricFieldSet fields = {
-    {"processingTimeTotal", mon.time.wall()},   {"processingThroughput", mon.time.throughput()},
-    {"caRecoTimeTotal", mon.timeCA.wall()},     {"caRecoThroughput", mon.timeCA.throughput()},
-    {"trdRecoTimeTotal", mon.timeTRD.wall()},   {"trdRecoThroughput", mon.timeTRD.throughput()},
-    {"tofRecoTimeTotal", mon.timeTOF.wall()},   {"tofRecoThroughput", mon.timeTOF.throughput()},
-    {"stsRecoTimeTotal", mon.timeSTS.wall()},   {"stsRecoThroughput", mon.timeSTS.throughput()},
-    {"unpackTimeTotal", mon.timeUnpack.wall()}, {"unpackThroughput", mon.timeUnpack.throughput()}};
+    {"processingTimeTotal", mon.time.wall()},   {"processingThroughput", FilterNan(mon.time.throughput())},
+    {"caRecoTimeTotal", mon.timeCA.wall()},     {"caRecoThroughput", FilterNan(mon.timeCA.throughput())},
+    {"trdRecoTimeTotal", mon.timeTRD.wall()},   {"trdRecoThroughput", FilterNan(mon.timeTRD.throughput())},
+    {"tofRecoTimeTotal", mon.timeTOF.wall()},   {"tofRecoThroughput", FilterNan(mon.timeTOF.throughput())},
+    {"stsRecoTimeTotal", mon.timeSTS.wall()},   {"stsRecoThroughput", FilterNan(mon.timeSTS.throughput())},
+    {"unpackTimeTotal", mon.timeUnpack.wall()}, {"unpackThroughput", FilterNan(mon.timeUnpack.throughput())}};
 
   if (mon.tsDelta) {
     fields.emplace_back("tsDelta", *mon.tsDelta);
diff --git a/algo/global/Reco.h b/algo/global/Reco.h
index 0b8483d57f..0496e3b3cf 100644
--- a/algo/global/Reco.h
+++ b/algo/global/Reco.h
@@ -150,6 +150,8 @@ namespace cbm::algo
     // Tracking
     std::unique_ptr<TrackingChain> fTracking;
 
+    static double FilterNan(double x) { return std::isnan(x) || std::isinf(x) ? 0. : x; }
+
     void Validate(const Options& opts);
 
     template<class Unpacker>
-- 
GitLab