From 62d69b8626111a6d9e670bac0f70ff5fbc9aaa9c Mon Sep 17 00:00:00 2001
From: Marco Clemencic <marco.clemencic@cern.ch>
Date: Wed, 20 Mar 2024 14:33:42 +0100
Subject: [PATCH] Avoid implicit conversion from float to double

Force the operands to either double or float depending on what required fewer modifications.
---
 GaudiAud/src/AlgTimingAuditor.cpp                       | 4 ++--
 GaudiCommonSvc/src/DataSvc/EvtStoreSvc.cpp              | 2 +-
 GaudiHive/src/CPUCruncher.cpp                           | 4 ++--
 GaudiHive/src/CPUCruncher.h                             | 4 ++--
 GaudiKernel/include/Gaudi/BaseSink.h                    | 2 +-
 GaudiKernel/tests/src/test_GaudiTiming.cpp              | 4 ++--
 GaudiTestSuite/src/FunctionalAlgorithms/transformer.cpp | 2 +-
 GaudiTestSuite/src/IO/WriteAlg.cpp                      | 6 +++---
 RootCnv/src/RootNTupleCnv.cpp                           | 4 ++--
 9 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/GaudiAud/src/AlgTimingAuditor.cpp b/GaudiAud/src/AlgTimingAuditor.cpp
index 3ef1e10e47..c91c82cfaa 100644
--- a/GaudiAud/src/AlgTimingAuditor.cpp
+++ b/GaudiAud/src/AlgTimingAuditor.cpp
@@ -89,7 +89,7 @@ struct AlgTimingAuditor final : extends<Auditor, IIncidentListener> {
       const auto count      = m_eventLoopStats.count;
       const auto total_time = m_eventLoopStats.total_time;
       info() << fmt::format( "{:<30.30} | {:9.4} | {:9} | {:9.4}", "EVENT LOOP",
-                             count ? ms( total_time ).count() / count : 0., count, s( total_time ).count() )
+                             count ? ms( total_time ).count() / count : 0.f, count, s( total_time ).count() )
              << endmsg;
     }
     std::vector<std::pair<std::string, std::size_t>> offsets{ begin( m_offsets ), end( m_offsets ) };
@@ -99,7 +99,7 @@ struct AlgTimingAuditor final : extends<Auditor, IIncidentListener> {
       const auto  count         = m_stats[offset].count;
       const auto  total_time    = m_stats[offset].total_time;
       info() << fmt::format( "{:<30.30} | {:9.4} | {:9} | {:9.4}", indented_name,
-                             count ? ms( total_time ).count() / count : 0., count, s( total_time ).count() )
+                             count ? ms( total_time ).count() / count : 0.f, count, s( total_time ).count() )
              << endmsg;
     }
     info() << "-------------------------------------------------------------------" << endmsg;
diff --git a/GaudiCommonSvc/src/DataSvc/EvtStoreSvc.cpp b/GaudiCommonSvc/src/DataSvc/EvtStoreSvc.cpp
index 18f29cfb78..a1564a790f 100644
--- a/GaudiCommonSvc/src/DataSvc/EvtStoreSvc.cpp
+++ b/GaudiCommonSvc/src/DataSvc/EvtStoreSvc.cpp
@@ -396,7 +396,7 @@ public:
   }
   StatusCode finalize() override {
     if ( m_printPoolStats ) {
-      info() << "Mean memory pool usage: " << float( 1e-3f * m_usedPoolSize.mean() ) << " KiB serving "
+      info() << "Mean memory pool usage: " << float( 1e-3f * float( m_usedPoolSize.mean() ) ) << " KiB serving "
              << float( m_servedPoolAllocations.mean() ) << " allocations from " << float( m_usedPoolAllocations.mean() )
              << " to produce " << float( m_storeEntries.mean() ) << " entries in " << float( m_storeBuckets.mean() )
              << " buckets" << endmsg;
diff --git a/GaudiHive/src/CPUCruncher.cpp b/GaudiHive/src/CPUCruncher.cpp
index 3a9133b654..eef4e81d9e 100644
--- a/GaudiHive/src/CPUCruncher.cpp
+++ b/GaudiHive/src/CPUCruncher.cpp
@@ -59,7 +59,7 @@ StatusCode CPUCruncher::initialize() {
   }
 
   // if an algorithm was setup to sleep, for whatever period, it effectively models CPU-blocking behavior
-  if ( std::abs( m_sleepFraction ) > std::numeric_limits<float>::epsilon() ) setBlocking( true );
+  if ( std::abs( m_sleepFraction ) > std::numeric_limits<double>::epsilon() ) setBlocking( true );
 
   // This is a bit ugly. There is no way to declare a vector of DataObjectHandles, so
   // we need to wait until initialize when we've read in the input and output key
@@ -108,7 +108,7 @@ StatusCode CPUCruncher::execute() // the execution of the algorithm
 
   if ( m_loader && !m_declAugmented ) declareRuntimeRequestedOutputs();
 
-  float crunchtime;
+  double crunchtime;
 
   if ( m_local_rndm_gen ) {
     /* This will disappear with a thread safe random number generator service.
diff --git a/GaudiHive/src/CPUCruncher.h b/GaudiHive/src/CPUCruncher.h
index 3341657964..b8ccd61c56 100644
--- a/GaudiHive/src/CPUCruncher.h
+++ b/GaudiHive/src/CPUCruncher.h
@@ -70,8 +70,8 @@ private:
   Gaudi::Property<bool>         m_local_rndm_gen{ this, "localRndm", true,
                                           "Decide if the local random generator is to be used" };
   Gaudi::Property<unsigned int> m_rwRepetitions{ this, "RwRepetitions", 1, "Increase access to the WB" };
-  Gaudi::Property<float>        m_sleepFraction{
-      this, "SleepFraction", 0.0f,
+  Gaudi::Property<double>       m_sleepFraction{
+      this, "SleepFraction", 0.0,
       "Fraction of time, between 0 and 1, when an algorithm is actually sleeping instead of crunching" };
   Gaudi::Property<bool>         m_invertCFD{ this, "InvertDecision", false, "Invert control flow decision." };
   Gaudi::Property<unsigned int> m_failNEvents{ this, "FailNEvents", 0, "Return FAILURE on every Nth event" };
diff --git a/GaudiKernel/include/Gaudi/BaseSink.h b/GaudiKernel/include/Gaudi/BaseSink.h
index 9e7d0eb010..de6c59add0 100644
--- a/GaudiKernel/include/Gaudi/BaseSink.h
+++ b/GaudiKernel/include/Gaudi/BaseSink.h
@@ -74,7 +74,7 @@ namespace Gaudi::Monitoring {
         // promise needs to be recreated in case of a restart
         m_flushThreadStop = std::promise<void>{};
         // enable periodic output file flush if requested
-        if ( m_autoFlushPeriod.value() > std::numeric_limits<double>::epsilon() ) {
+        if ( m_autoFlushPeriod.value() > std::numeric_limits<float>::epsilon() ) {
           m_flushThread = std::thread{ [this, flushStop = m_flushThreadStop.get_future()]() {
             using namespace std::chrono_literals;
             while ( flushStop.wait_for( m_autoFlushPeriod.value() * 1s ) == std::future_status::timeout ) {
diff --git a/GaudiKernel/tests/src/test_GaudiTiming.cpp b/GaudiKernel/tests/src/test_GaudiTiming.cpp
index 31c4cb4a22..45edf58ec9 100644
--- a/GaudiKernel/tests/src/test_GaudiTiming.cpp
+++ b/GaudiKernel/tests/src/test_GaudiTiming.cpp
@@ -108,8 +108,8 @@ namespace GaudiKernelTest {
       CPPUNIT_ASSERT_EQUAL( ( t1 - t0 ).elapsedTime<System::Sec>(), 1LL );
 
       // This should result in non-zero user and kernel times
-      t0      = System::getProcessTime();
-      float x = 1.5;
+      t0       = System::getProcessTime();
+      double x = 1.5;
 
       // this variable is only needed to ensure that the timed loop
       // takes a measurable time
diff --git a/GaudiTestSuite/src/FunctionalAlgorithms/transformer.cpp b/GaudiTestSuite/src/FunctionalAlgorithms/transformer.cpp
index 1710955eba..7f86b886d9 100644
--- a/GaudiTestSuite/src/FunctionalAlgorithms/transformer.cpp
+++ b/GaudiTestSuite/src/FunctionalAlgorithms/transformer.cpp
@@ -25,7 +25,7 @@ namespace Gaudi {
       Gaudi::TestSuite::MyTrack::Selection
       operator()( const Gaudi::Range_<Gaudi::TestSuite::MyTrack::ConstVector>& in_tracks ) const override {
         Gaudi::TestSuite::MyTrack::Selection out_tracks;
-        out_tracks.insert( in_tracks.begin(), in_tracks.end(), []( const MyTrack* t ) { return t->px() >= 10.; } );
+        out_tracks.insert( in_tracks.begin(), in_tracks.end(), []( const MyTrack* t ) { return t->px() >= 10.f; } );
         return out_tracks;
       }
     };
diff --git a/GaudiTestSuite/src/IO/WriteAlg.cpp b/GaudiTestSuite/src/IO/WriteAlg.cpp
index a873d03d93..6e8c47c2bd 100644
--- a/GaudiTestSuite/src/IO/WriteAlg.cpp
+++ b/GaudiTestSuite/src/IO/WriteAlg.cpp
@@ -162,11 +162,11 @@ StatusCode WriteAlg::execute() {
   }
   // Now connect vertices and tracks
   for ( MyTrackVector::iterator k = myTracks->begin(); k != myTracks->end(); ++k ) {
-    int       org    = (int)( rndmflat() * float( m ) );
+    int       org    = (int)( rndmflat() * double( m ) );
     MyVertex* orgVtx = *( myVertices->begin() + org );
     ( *k )->setOriginVertex( orgVtx );
-    int dec1 = (int)( rndmflat() * float( m ) );
-    int dec2 = (int)( rndmflat() * float( m ) );
+    int dec1 = (int)( rndmflat() * double( m ) );
+    int dec2 = (int)( rndmflat() * double( m ) );
     int tmp  = dec1;
     dec1     = ( tmp < dec2 ) ? tmp : dec2;
     dec2     = ( tmp > dec2 ) ? tmp : dec2;
diff --git a/RootCnv/src/RootNTupleCnv.cpp b/RootCnv/src/RootNTupleCnv.cpp
index 3582d61c7e..b473388535 100644
--- a/RootCnv/src/RootNTupleCnv.cpp
+++ b/RootCnv/src/RootNTupleCnv.cpp
@@ -299,7 +299,7 @@ StatusCode RootNTupleCnv::i__updateObjRoot( RootAddress* rpA, INTuple* tupl, TTr
         for ( ; ipar[1] < last; ++ipar[1] ) { // loop on all selected entries
           tree->LoadTree( ipar[1] );
           rpA->select->GetNdata();
-          if ( fabs( rpA->select->EvalInstance( 0 ) ) > std::numeric_limits<float>::epsilon() ) { break; }
+          if ( fabs( rpA->select->EvalInstance( 0 ) ) > std::numeric_limits<double>::epsilon() ) { break; }
           log() << MSG::DEBUG << par[0] << "/" << par[1] << " SKIP Entry: " << ipar[1] << endmsg;
         }
       }
@@ -733,7 +733,7 @@ StatusCode RootNTupleCnv::i__updateObjPool( RootAddress* rpA, INTuple* tupl, TTr
         for ( ; ipar[1] < last; ++ipar[1] ) {
           tree->LoadTree( ipar[1] );
           rpA->select->GetNdata();
-          if ( fabs( rpA->select->EvalInstance( 0 ) ) > std::numeric_limits<float>::epsilon() ) { break; }
+          if ( fabs( rpA->select->EvalInstance( 0 ) ) > std::numeric_limits<double>::epsilon() ) { break; }
           log() << MSG::DEBUG << par[0] << "/" << par[1] << " SKIP Entry: " << ipar[1] << endmsg;
         }
       }
-- 
GitLab