From f695a6512e911e181a981b065c734d21d1e89665 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Fri, 9 Dec 2022 13:20:18 +0100
Subject: [PATCH] L1: L1NaN.h was replaced with L1Undef.h

---
 reco/L1/CMakeLists.txt                  |  1 -
 reco/L1/L1Algo/L1CaTrackFinderSlice.cxx |  8 ++-
 reco/L1/L1Algo/L1Constants.h            |  5 +-
 reco/L1/L1Algo/L1Material.h             |  7 +--
 reco/L1/L1Algo/L1NaN.h                  | 76 -------------------------
 reco/L1/L1Algo/L1SimdSerializer.h       | 10 ++--
 reco/L1/L1Algo/L1UMeasurementInfo.cxx   |  2 +
 reco/L1/L1Algo/L1UMeasurementInfo.h     |  5 +-
 reco/L1/L1Algo/L1XYMeasurementInfo.h    |  9 ++-
 9 files changed, 26 insertions(+), 97 deletions(-)
 delete mode 100644 reco/L1/L1Algo/L1NaN.h

diff --git a/reco/L1/CMakeLists.txt b/reco/L1/CMakeLists.txt
index b08d0a4afe..bbb0e86c29 100644
--- a/reco/L1/CMakeLists.txt
+++ b/reco/L1/CMakeLists.txt
@@ -206,7 +206,6 @@ install(FILES CbmL1Counters.h
   L1Algo/L1ObjectInitController.h
   L1Algo/L1Constants.h
   L1Algo/L1Utils.h
-  L1Algo/L1NaN.h
   L1Algo/L1SimdSerializer.h
   L1Algo/L1TrackPar.h
   L1Algo/L1Track.h
diff --git a/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx b/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx
index 9f211669b3..09002f5a78 100644
--- a/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx
+++ b/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx
@@ -516,8 +516,12 @@ inline void L1Algo::findTripletsStep0(  // input
   const L1Station& stam = fParameters.GetStation(iStaM);
   const L1Station& star = fParameters.GetStation(iStaR);
 
-  L1HitIndex_t hitsl_2[fvec::size()] {L1NaN::SetNaN<L1HitIndex_t>()};
-  L1HitIndex_t hitsm_2_tmp[fvec::size()] {L1NaN::SetNaN<L1HitIndex_t>()};
+  std::array<L1HitIndex_t, fvec::size()> hitsl_2     = {};
+  std::array<L1HitIndex_t, fvec::size()> hitsm_2_tmp = {};
+
+  std::fill(hitsl_2.begin(), hitsl_2.end(), undef::kU32);
+  std::fill(hitsm_2_tmp.begin(), hitsm_2_tmp.end(), undef::kU32);
+
   L1TrackPar L1TrackPar_0;
   // SG!! to avoid nans in unfilled part
   //TODO: SG: investigate, it changes the results !!
diff --git a/reco/L1/L1Algo/L1Constants.h b/reco/L1/L1Algo/L1Constants.h
index 4917146e0b..af74194f3a 100644
--- a/reco/L1/L1Algo/L1Constants.h
+++ b/reco/L1/L1Algo/L1Constants.h
@@ -12,7 +12,10 @@
 #ifndef L1Constants_h
 #define L1Constants_h 1
 
-#include "L1NaN.h"
+#include "CaSimd.h"
+using cbm::algo::ca::fmask;
+using cbm::algo::ca::fscal;  // TODO: remove "using" from headers
+using cbm::algo::ca::fvec;   // TODO: remove "using" from headers
 
 /// Namespace contains compile-time constants definition for the L1 tracking algorithm
 namespace L1Constants
diff --git a/reco/L1/L1Algo/L1Material.h b/reco/L1/L1Algo/L1Material.h
index 1727d3c363..3dcf4924a6 100644
--- a/reco/L1/L1Algo/L1Material.h
+++ b/reco/L1/L1Algo/L1Material.h
@@ -13,7 +13,6 @@
 #include <vector>
 
 #include "L1Def.h"
-#include "L1NaN.h"
 #include "L1SimdSerializer.h"
 #include "L1Undef.h"
 
@@ -54,13 +53,13 @@ public:
   float GetRadThickScal(float x, float y) const;
 
   /// Gets material thickness in units of X0 in (x,y) point of the station
-  /// fvec type can be float, that is why "Vec" and "Scal" specifications
+  /// cbm::algo::ca::fvec type can be float, that is why "Vec" and "Scal" specifications
   /// \param x  X coordinate of the point [cm] (SIMDized vector)
   /// \param y  Y coordinate of the point [cm] (SIMDized veotor)
-  fvec GetRadThickVec(fvec x, fvec y) const;
+  cbm::algo::ca::fvec GetRadThickVec(cbm::algo::ca::fvec x, cbm::algo::ca::fvec y) const;
 
   /// Checks, if the fields are NaN
-  bool IsNaN() const { return L1NaN::IsNaN(fNbins) || L1NaN::IsNaN(fRmax) || L1NaN::IsNaN(fFactor); }
+  bool IsNaN() const { return undef::IsUndefined(fNbins) || undef::IsUndefined(fRmax) || undef::IsUndefined(fFactor); }
 
   /// Verifies class invariant consistency
   void CheckConsistency() const;
diff --git a/reco/L1/L1Algo/L1NaN.h b/reco/L1/L1Algo/L1NaN.h
deleted file mode 100644
index 129cd32ca0..0000000000
--- a/reco/L1/L1Algo/L1NaN.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
-   SPDX-License-Identifier: GPL-3.0-only
-   Authors: Sergei Zharko [committer] */
-
-/***************************************************************************************************
- * @file   L1NaN.h
- * @brief  Definition of setters and checkers for NaN values
- * @since  21.06.2022
- * @author S.Zharko <s.zharko@gsi.de>
- ***************************************************************************************************/
-
-#ifndef L1NaN_h
-#define L1NaN_h 1
-
-#include <limits>
-#include <type_traits>
-
-#include <cmath>
-
-#include "CaSimd.h"
-#include "L1Def.h"
-
-using cbm::algo::ca::fmask;
-using cbm::algo::ca::fscal;  // TODO: remove "using" from headers
-using cbm::algo::ca::fvec;   // TODO: remove "using" from headers
-
-/// Namespace L1NaN defines functions to set variables to NaN and check wether they are NaN or not
-///
-namespace L1NaN
-{
-  /// Returns NaN value for a floating point variable
-  template<typename T, typename std::enable_if<std::is_floating_point<T>::value, T>::type* = nullptr>
-  constexpr auto SetNaN()
-  {
-    return std::numeric_limits<T>::signaling_NaN();
-  }
-
-  /// Returns MaN value for an intergral variable
-  template<typename T,
-           typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bool>::value, T>::type* = nullptr>
-  constexpr auto SetNaN()
-  {
-    return T(-1);  // -1 for signed integers and MAX_INT for unsigned integers
-  }
-
-  /// Returns MaN value for fvec variable
-  template<typename T, typename std::enable_if<std::is_same<T, fvec>::value, T>::type* = nullptr>
-  constexpr auto SetNaN()
-  {
-    return fvec(SetNaN<fscal>());
-  }
-
-  /// Checks, if the floating point variable is NaN
-  template<typename T, typename std::enable_if<std::is_floating_point<T>::value, T>::type* = nullptr>
-  bool IsNaN(T value)
-  {
-    return std::isnan(value);
-  }
-
-  /// Checks, if the integral variable is NaN
-  template<typename T,
-           typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bool>::value, T>::type* = nullptr>
-  bool IsNaN(T value)
-  {
-    return T(-1) == value;
-  }
-
-  /// Checks, if the fvec variable is NaN
-  template<typename T, typename std::enable_if<std::is_same<T, fvec>::value, T>::type* = nullptr>
-  bool IsNaN(T value)
-  {
-    return isnan(value).isNotEmpty();  // NOTE: Here we consider fvec a NaN if at least one of its words is NaN
-  }
-};  // namespace L1NaN
-
-#endif  // L1NaN_h
diff --git a/reco/L1/L1Algo/L1SimdSerializer.h b/reco/L1/L1Algo/L1SimdSerializer.h
index a78dbf9c72..79505b8125 100644
--- a/reco/L1/L1Algo/L1SimdSerializer.h
+++ b/reco/L1/L1Algo/L1SimdSerializer.h
@@ -22,23 +22,23 @@ namespace boost
   namespace serialization
   {
     template<class Archive>
-    void save(Archive& ar, const fvec& vect, unsigned int)
+    void save(Archive& ar, const cbm::algo::ca::fvec& vect, unsigned int)
     {
       ar << vect[0];
     }
 
     template<class Archive>
-    void load(Archive& ar, fvec& vect, unsigned int)
+    void load(Archive& ar, cbm::algo::ca::fvec& vect, unsigned int)
     {
-      fscal buffer;
+      cbm::algo::ca::fscal buffer;
       ar >> buffer;
-      for (size_t i = 0; i < fvec::size(); ++i) {
+      for (size_t i = 0; i < cbm::algo::ca::fvec::size(); ++i) {
         vect[i] = buffer;
       }
     }
 
     template<class Archive>
-    void serialize(Archive& ar, fvec& vect, const unsigned int version)
+    void serialize(Archive& ar, cbm::algo::ca::fvec& vect, const unsigned int version)
     {
       split_free(ar, vect, version);
     }
diff --git a/reco/L1/L1Algo/L1UMeasurementInfo.cxx b/reco/L1/L1Algo/L1UMeasurementInfo.cxx
index a8e45ad248..3fc58dd95a 100644
--- a/reco/L1/L1Algo/L1UMeasurementInfo.cxx
+++ b/reco/L1/L1Algo/L1UMeasurementInfo.cxx
@@ -7,6 +7,8 @@
 #include <iomanip>
 #include <sstream>
 
+using namespace cbm::algo::ca;
+
 //----------------------------------------------------------------------------------------------------------------------
 //
 std::string L1UMeasurementInfo::ToString(int indentLevel) const
diff --git a/reco/L1/L1Algo/L1UMeasurementInfo.h b/reco/L1/L1Algo/L1UMeasurementInfo.h
index 51e05f7040..bb1b775469 100644
--- a/reco/L1/L1Algo/L1UMeasurementInfo.h
+++ b/reco/L1/L1Algo/L1UMeasurementInfo.h
@@ -8,7 +8,6 @@
 #include <string>
 
 #include "L1Def.h"
-#include "L1NaN.h"
 #include "L1SimdSerializer.h"
 #include "L1Undef.h"
 #include "L1Utils.h"
@@ -16,8 +15,8 @@
 class L1UMeasurementInfo {
 
 public:
-  fvec cos_phi = undef::kFvc;
-  fvec sin_phi = undef::kFvc;
+  cbm::algo::ca::fvec cos_phi = undef::kFvc;
+  cbm::algo::ca::fvec sin_phi = undef::kFvc;
 
   /// String representation of class contents
   /// \param indentLevel      number of indent characters in the output
diff --git a/reco/L1/L1Algo/L1XYMeasurementInfo.h b/reco/L1/L1Algo/L1XYMeasurementInfo.h
index aa48af6501..41a82401be 100644
--- a/reco/L1/L1Algo/L1XYMeasurementInfo.h
+++ b/reco/L1/L1Algo/L1XYMeasurementInfo.h
@@ -8,15 +8,14 @@
 #include <string>
 
 #include "L1Def.h"
-#include "L1NaN.h"
 #include "L1SimdSerializer.h"
 #include "L1Undef.h"
 
 class L1XYMeasurementInfo {
 public:
-  fvec C00 = undef::kFvc;
-  fvec C10 = undef::kFvc;
-  fvec C11 = undef::kFvc;
+  cbm::algo::ca::fvec C00 = undef::kFvc;
+  cbm::algo::ca::fvec C10 = undef::kFvc;
+  cbm::algo::ca::fvec C11 = undef::kFvc;
 
   /// Consistency checker
   void CheckConsistency() const;
@@ -26,7 +25,7 @@ public:
   std::string ToString(int indentLevel = 0) const;
 
   /// Checks, if the fields are NaN
-  bool IsNaN() const { return L1NaN::IsNaN(C00) || L1NaN::IsNaN(C10) || L1NaN::IsNaN(C11); }
+  bool IsNaN() const { return undef::IsUndefined(C00) || undef::IsUndefined(C10) || undef::IsUndefined(C11); }
 
   /// Serialization function
   friend class boost::serialization::access;
-- 
GitLab