From f95ce4ea9b74e34caf6bbee9b41b3578c3d1906c Mon Sep 17 00:00:00 2001
From: Miha Muskinja <miha.muskinja@cern.ch>
Date: Thu, 4 Feb 2021 09:30:36 -0800
Subject: [PATCH] dynamically chose the sincos calculator

---
 .../GeoSpecialShapes/LArWheelCalculator.h              |  8 ++++++++
 .../GeoSpecialShapes/src/LArWheelCalculator.cxx        |  3 +++
 .../DistanceCalculatorSaggingOff.cxx                   | 10 +++++-----
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/DetectorDescription/GeoModel/GeoSpecialShapes/GeoSpecialShapes/LArWheelCalculator.h b/DetectorDescription/GeoModel/GeoSpecialShapes/GeoSpecialShapes/LArWheelCalculator.h
index 70faa362228e..0da3b1906837 100644
--- a/DetectorDescription/GeoModel/GeoSpecialShapes/GeoSpecialShapes/LArWheelCalculator.h
+++ b/DetectorDescription/GeoModel/GeoSpecialShapes/GeoSpecialShapes/LArWheelCalculator.h
@@ -126,6 +126,9 @@ class LArWheelCalculator
     std::pair<int, int> GetPhiGapAndSide(const CLHEP::Hep3Vector &p) const;
     double AmplitudeOfSurface(const CLHEP::Hep3Vector& P, int side, int fan_number) const;
 
+    /// Set the sincos calculator
+    // void SetVectorizedSincos() {m_sincos_calculator = &m_vsincos_par.eval;};
+
     /// @}
 
   private:
@@ -216,6 +219,11 @@ class LArWheelCalculator
 #if HAVE_VECTOR_SIZE_ATTRIBUTE
     vsincos_par m_vsincos_par{};
 #endif
+
+  private:
+    typedef void (LArWheelCalculator::*SincosCalculator)(const double, double &, double &) const;
+    SincosCalculator m_sincos_calculator;
+    void EvalSincos(const double P, double &x, double &y) const {(this->*m_sincos_calculator)(P, x, y);};
 };
 
 #ifndef XAOD_STANDALONE
diff --git a/DetectorDescription/GeoModel/GeoSpecialShapes/src/LArWheelCalculator.cxx b/DetectorDescription/GeoModel/GeoSpecialShapes/src/LArWheelCalculator.cxx
index 11a481c860f3..cec1e276735f 100644
--- a/DetectorDescription/GeoModel/GeoSpecialShapes/src/LArWheelCalculator.cxx
+++ b/DetectorDescription/GeoModel/GeoSpecialShapes/src/LArWheelCalculator.cxx
@@ -443,6 +443,9 @@ LArWheelCalculator::LArWheelCalculator(LArG4::LArWheelCalculator_t a_wheelType,
      fclose(O);
      exit(0);
   */
+
+   // set the sincos calculator
+   m_sincos_calculator = &LArWheelCalculator::parameterized_sincos;
 }
 
 /* converts module gap number into wheel gap number */
diff --git a/DetectorDescription/GeoModel/GeoSpecialShapes/src/LArWheelCalculator_Impl/DistanceCalculatorSaggingOff.cxx b/DetectorDescription/GeoModel/GeoSpecialShapes/src/LArWheelCalculator_Impl/DistanceCalculatorSaggingOff.cxx
index 06239cc8c1f4..0163f1ba9442 100644
--- a/DetectorDescription/GeoModel/GeoSpecialShapes/src/LArWheelCalculator_Impl/DistanceCalculatorSaggingOff.cxx
+++ b/DetectorDescription/GeoModel/GeoSpecialShapes/src/LArWheelCalculator_Impl/DistanceCalculatorSaggingOff.cxx
@@ -48,7 +48,7 @@ namespace LArWheelCalculator_Impl
     const double cos_a = scalpha.cs, sin_a = scalpha.sn;
 #else // parameterized sine
     double cos_a, sin_a;
-    lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
+    lwc()->EvalSincos(P.y(), sin_a, cos_a);
 #endif
     // determination of the nearest quarter-wave number
     int nqwave = (z < 0.) ? 0 : int(z / lwc()->m_QuarterWaveLength);
@@ -160,7 +160,7 @@ namespace LArWheelCalculator_Impl
     double cos_a = scalpha.cs, sin_a = scalpha.sn;
 #else // parameterized sine
     double cos_a, sin_a;
-    lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
+    lwc()->EvalSincos(P.y(), sin_a, cos_a);
 #endif
 
     bool sqw = false;
@@ -251,7 +251,7 @@ namespace LArWheelCalculator_Impl
     const double cos_a = scalpha.cs, sin_a = scalpha.sn;
 #else // parameterized sine
     double cos_a, sin_a;
-    lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
+    lwc()->EvalSincos(P.y(), sin_a, cos_a);
 #endif
 
     int nqwave;
@@ -339,7 +339,7 @@ namespace LArWheelCalculator_Impl
     double cos_a = scalpha.cs, sin_a = scalpha.sn;
 #else // parameterized sine
     double cos_a, sin_a;
-    lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
+    lwc()->EvalSincos(P.y(), sin_a, cos_a);
 #endif
 
     bool sqw = false;
@@ -434,7 +434,7 @@ namespace LArWheelCalculator_Impl
     // parameterized sine
 #else
     double cos_a, sin_a;
-    lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
+    lwc()->EvalSincos(P.y(), sin_a, cos_a);
 #endif
 
     // determination of the nearest quarter-wave number
-- 
GitLab