diff --git a/GaudiAlg/src/lib/TupleDecorator.cpp b/GaudiAlg/src/lib/TupleDecorator.cpp index 47e7d9076cbd5f5f874c06e776a10c43b6f1b80a..3bc1b14fc8c628485733aef58ed4b94d298716a1 100644 --- a/GaudiAlg/src/lib/TupleDecorator.cpp +++ b/GaudiAlg/src/lib/TupleDecorator.cpp @@ -8,11 +8,6 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \***********************************************************************************/ -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// Coming from ROOT GenVector -# pragma warning( disable : 1572 ) -#endif // ============================================================================ // Include files // ============================================================================ diff --git a/GaudiAlg/tests/qmtest/refs/HistoEx2.pyref b/GaudiAlg/tests/qmtest/refs/HistoEx2.pyref index 6a60d9f559c9add3b51dfe28bd1fefa2dd2b27b1..6d0fea43d32a7d02064801a86798b578ec5eeef2 100644 --- a/GaudiAlg/tests/qmtest/refs/HistoEx2.pyref +++ b/GaudiAlg/tests/qmtest/refs/HistoEx2.pyref @@ -158,27 +158,27 @@ RndmGenSvc INFO Using Random engine:HepRndm::Engine<CLHEP::RanluxEngin | id : x vs y (profile) | - 4 ++----+----+----+----+----+----+----+----+----+----+ + 1 ++----+----+----+----+----+----+----+----+----+----+ |. . . . . | . . . . | |. . . . . | . . . . | |. . . . . | . . . . | |. . . . . | . . . . | - 1.5 +.........................+........................+ + 0.75 +.........................+........................+ |. . . . . | . . . . | |. . . . . | . . . . | - 0 I-+IIII**I***+I-*II-II-*--*III--**-*-*I-**III-I*II*I-->* - * |****I.*III***I******.**I*****I.*I*I**II*****I**I**| - -1 +.........................+................I......I+ |. . . . . | . . . . | |. . . . . | . . . . | + 0.5 +.........................+........................+ |. . . . . | . . . . | |. . . . . | . . . . | - -3.5 +.........................+........................+ - |. . . . . | . . . . | - |. . . . . | . . . . | - |. . . . . | . . . . | - |. . . . . | . . . . | - -6 ++----+----+----+----+----+----+----+----+----+----+ + |. I . . . | . . . . | + |. I . . . | . . . . | + 0.25 +.....I...................+.....................I..+ + |. I* . . . | . . I . I. I | + |.I II II . . I | I I . I . I. I | + |.I II III.I I . I I | I* I I. II . I.II | I + |III *I III.I I I I * I |I II * I. *I . *.I* | * + 0 I-+IIIII+I***+I-*II-II-I--*III--*I-I-*I-I*III-IIIIII-->I U N O D V diff --git a/GaudiAud/src/ProcStats.cpp b/GaudiAud/src/ProcStats.cpp index 27ac5c6b36ff4d15009593f81e5018e23ae1ba1e..08102f5c0439a33fb1c9f0bffb454420cd106e78 100644 --- a/GaudiAud/src/ProcStats.cpp +++ b/GaudiAud/src/ProcStats.cpp @@ -305,12 +305,11 @@ bool ProcStats::fetch( procInfo& f ) { #else f.vsize = 0; f.rss = 0; + return false; #endif // __linux__ or __APPLE__ - const bool rc = !( m_curr == f ); - m_curr.rss = f.rss; m_curr.vsize = f.vsize; - return rc; + return true; } diff --git a/GaudiAud/src/ProcStats.h b/GaudiAud/src/ProcStats.h index 22cf61a6080814ff0a45f4091dcd2e6008014897..b94ac0f34f85fe98f0f1290a0d5bc92d0a19a266 100644 --- a/GaudiAud/src/ProcStats.h +++ b/GaudiAud/src/ProcStats.h @@ -30,21 +30,6 @@ struct procInfo { procInfo() = default; procInfo( double sz, double rss_sz ) : vsize( sz ), rss( rss_sz ) {} - bool operator==( const procInfo& p ) const { -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -# pragma warning( push ) -# pragma warning( disable : 1572 ) -#endif - - return ( vsize == p.vsize && rss == p.rss ); - -#ifdef __ICC -// re-enable icc remark #1572 -# pragma warning( pop ) -#endif - } - // see proc(4) man pages for units and a description double vsize{ 0 }; // in MB (used to be in pages?) double rss{ 0 }; // in MB (used to be in pages?) diff --git a/GaudiCommonSvc/src/HistogramSvc/H1D.cpp b/GaudiCommonSvc/src/HistogramSvc/H1D.cpp index e8b4be233b38389f4771fa93c458a972d114ed7d..a11d4e0bbde2655f3815a654b966eac1d084daf7 100644 --- a/GaudiCommonSvc/src/HistogramSvc/H1D.cpp +++ b/GaudiCommonSvc/src/HistogramSvc/H1D.cpp @@ -125,22 +125,17 @@ bool Gaudi::Histogram1D::setBinContents( int i, int entries, double height, doub return true; } -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// The comparison are meant -# pragma warning( push ) -# pragma warning( disable : 1572 ) -#endif bool Gaudi::Histogram1D::setRms( double rms ) { m_rep->SetEntries( m_sumEntries ); std::vector<double> stat( 11 ); // sum weights stat[0] = sumBinHeights(); stat[1] = 0; - if ( equivalentBinEntries() != 0 ) stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries(); + if ( abs( equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() ) + stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries(); stat[2] = m_sumwx; double mean = 0; - if ( sumBinHeights() != 0 ) mean = m_sumwx / sumBinHeights(); + if ( abs( sumBinHeights() ) > std::numeric_limits<double>::epsilon() ) mean = m_sumwx / sumBinHeights(); stat[3] = ( mean * mean + rms * rms ) * sumBinHeights(); m_rep->PutStats( &stat.front() ); return true; @@ -155,7 +150,8 @@ bool Gaudi::Histogram1D::setStatistics( int allEntries, double eqBinEntries, dou stat[0] = sumBinHeights(); // sum weights **2 stat[1] = 0; - if ( eqBinEntries != 0 ) stat[1] = ( sumBinHeights() * sumBinHeights() ) / eqBinEntries; + if ( abs( eqBinEntries ) > std::numeric_limits<double>::epsilon() ) + stat[1] = ( sumBinHeights() * sumBinHeights() ) / eqBinEntries; // sum weights * x stat[2] = mean * sumBinHeights(); // sum weight * x **2 @@ -167,7 +163,7 @@ bool Gaudi::Histogram1D::setStatistics( int allEntries, double eqBinEntries, dou bool Gaudi::Histogram1D::fill( double x, double weight ) { // avoid race conditions when filling the histogram auto guard = std::scoped_lock{ m_fillSerialization }; - ( weight == 1. ) ? m_rep->Fill( x ) : m_rep->Fill( x, weight ); + m_rep->Fill( x, weight ); return true; } @@ -192,7 +188,8 @@ void Gaudi::Histogram1D::copyFromAida( const AIDA::IHistogram1D& h ) { double sumw = h.sumBinHeights(); // sumw2 double sumw2 = 0; - if ( h.equivalentBinEntries() != 0 ) sumw2 = ( sumw * sumw ) / h.equivalentBinEntries(); + if ( abs( h.equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() ) + sumw2 = ( sumw * sumw ) / h.equivalentBinEntries(); double sumwx = h.mean() * h.sumBinHeights(); double sumwx2 = ( h.mean() * h.mean() + h.rms() * h.rms() ) * h.sumBinHeights(); @@ -215,11 +212,6 @@ void Gaudi::Histogram1D::copyFromAida( const AIDA::IHistogram1D& h ) { m_rep->PutStats( &stat.front() ); } -#ifdef __ICC -// re-enable icc remark #1572 -# pragma warning( pop ) -#endif - StreamBuffer& Gaudi::Histogram1D::serialize( StreamBuffer& s ) { // DataObject::serialize(s); std::string title; diff --git a/GaudiCommonSvc/src/HistogramSvc/H2D.cpp b/GaudiCommonSvc/src/HistogramSvc/H2D.cpp index 5841f9d3832819df95922f4b8269788ba5642bd5..3033d1d99ad5aff0fa0e5101527b69239283562a 100644 --- a/GaudiCommonSvc/src/HistogramSvc/H2D.cpp +++ b/GaudiCommonSvc/src/HistogramSvc/H2D.cpp @@ -173,16 +173,10 @@ bool Gaudi::Histogram2D::reset() { return Base::reset(); } -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// The comparison are meant -# pragma warning( push ) -# pragma warning( disable : 1572 ) -#endif bool Gaudi::Histogram2D::fill( double x, double y, double weight ) { // avoid race conditiosn when filling the histogram auto guard = std::scoped_lock{ m_fillSerialization }; - ( weight == 1. ) ? m_rep->Fill( x, y ) : m_rep->Fill( x, y, weight ); + m_rep->Fill( x, y, weight ); return true; } @@ -191,14 +185,17 @@ bool Gaudi::Histogram2D::setRms( double rmsX, double rmsY ) { std::vector<double> stat( 11 ); stat[0] = sumBinHeights(); stat[1] = 0; - if ( equivalentBinEntries() != 0 ) stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries(); + if ( abs( equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() ) + stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries(); stat[2] = m_sumwx; - double meanX = 0; - if ( sumBinHeights() != 0 ) meanX = m_sumwx / sumBinHeights(); - stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights(); stat[4] = m_sumwy; + double meanX = 0; double meanY = 0; - if ( sumBinHeights() != 0 ) meanY = m_sumwy / sumBinHeights(); + if ( abs( sumBinHeights() ) > std::numeric_limits<double>::epsilon() ) { + meanX = m_sumwx / sumBinHeights(); + meanY = m_sumwy / sumBinHeights(); + } + stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights(); stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights(); stat[6] = 0; m_rep->PutStats( &stat.front() ); @@ -231,7 +228,8 @@ void Gaudi::Histogram2D::copyFromAida( const IHistogram2D& h ) { // statistics double sumw = h.sumBinHeights(); double sumw2 = 0; - if ( h.equivalentBinEntries() != 0 ) sumw2 = ( sumw * sumw ) / h.equivalentBinEntries(); + if ( abs( h.equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() ) + sumw2 = ( sumw * sumw ) / h.equivalentBinEntries(); double sumwx = h.meanX() * h.sumBinHeights(); double sumwx2 = ( h.meanX() * h.meanX() + h.rmsX() * h.rmsX() ) * h.sumBinHeights(); double sumwy = h.meanY() * h.sumBinHeights(); @@ -255,8 +253,3 @@ void Gaudi::Histogram2D::copyFromAida( const IHistogram2D& h ) { std::array<double, 11> stat = { { sumw, sumw2, sumwx, sumwx2, sumwy, sumwy2, sumwxy } }; m_rep->PutStats( stat.data() ); } - -#ifdef __ICC -// re-enable icc remark #1572 -# pragma warning( pop ) -#endif diff --git a/GaudiCommonSvc/src/HistogramSvc/H3D.cpp b/GaudiCommonSvc/src/HistogramSvc/H3D.cpp index 67a350987869b60bb2215347411e3ccde9587cf7..c6f7f79492b4c76833047ef7c08b7fd01f666388 100644 --- a/GaudiCommonSvc/src/HistogramSvc/H3D.cpp +++ b/GaudiCommonSvc/src/HistogramSvc/H3D.cpp @@ -131,34 +131,30 @@ void* Gaudi::Histogram3D::cast( const std::string& className ) const { return nullptr; } -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// The comparison are meant -# pragma warning( push ) -# pragma warning( disable : 1572 ) -#endif bool Gaudi::Histogram3D::setRms( double rmsX, double rmsY, double rmsZ ) { m_rep->SetEntries( m_sumEntries ); std::vector<double> stat( 11 ); // sum weights stat[0] = sumBinHeights(); stat[1] = 0; - if ( equivalentBinEntries() != 0 ) stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries(); + if ( abs( equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() ) + stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries(); stat[2] = m_sumwx; - double meanX = 0; - if ( sumBinHeights() != 0 ) meanX = m_sumwx / sumBinHeights(); - stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights(); stat[4] = m_sumwy; - double meanY = 0; - if ( sumBinHeights() != 0 ) meanY = m_sumwy / sumBinHeights(); - stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights(); stat[6] = 0; stat[7] = m_sumwz; + double meanX = 0; + double meanY = 0; double meanZ = 0; - if ( sumBinHeights() != 0 ) meanZ = m_sumwz / sumBinHeights(); + if ( abs( sumBinHeights() ) > std::numeric_limits<double>::epsilon() ) { + meanX = m_sumwx / sumBinHeights(); + meanY = m_sumwy / sumBinHeights(); + meanZ = m_sumwz / sumBinHeights(); + } + stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights(); + stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights(); stat[8] = ( meanZ * meanZ + rmsZ * rmsZ ) * sumBinHeights(); // do not need to use sumwxy sumwxz and sumwyz - m_rep->PutStats( &stat.front() ); return true; } @@ -198,7 +194,8 @@ void Gaudi::Histogram3D::copyFromAida( const AIDA::IHistogram3D& h ) { // statistics double sumw = h.sumBinHeights(); double sumw2 = 0; - if ( h.equivalentBinEntries() != 0 ) sumw2 = ( sumw * sumw ) / h.equivalentBinEntries(); + if ( abs( h.equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() ) + sumw2 = ( sumw * sumw ) / h.equivalentBinEntries(); double sumwx = h.meanX() * h.sumBinHeights(); double sumwx2 = ( h.meanX() * h.meanX() + h.rmsX() * h.rmsX() ) * h.sumBinHeights(); double sumwy = h.meanY() * h.sumBinHeights(); @@ -243,8 +240,3 @@ void Gaudi::Histogram3D::copyFromAida( const AIDA::IHistogram3D& h ) { stat[10] = sumwyz; m_rep->PutStats( &stat.front() ); } - -#ifdef __ICC -// re-enable icc remark #1572 -# pragma warning( pop ) -#endif diff --git a/GaudiCommonSvc/src/HistogramSvc/P1D.cpp b/GaudiCommonSvc/src/HistogramSvc/P1D.cpp index 603369da0ea235d5e0c8339567d39fdd7572f832..2917d14e5c0fd361d4dbaf99db1dadd136ffc0dc 100644 --- a/GaudiCommonSvc/src/HistogramSvc/P1D.cpp +++ b/GaudiCommonSvc/src/HistogramSvc/P1D.cpp @@ -111,14 +111,9 @@ bool Gaudi::Profile1D::setBinContents( int i, int entries, double height, double return true; } -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// The comparison is correct -# pragma warning( disable : 1572 ) -#endif bool Gaudi::Profile1D::fill( double x, double y, double weight ) { // avoid race conditions when filling the profile auto guard = std::scoped_lock{ m_fillSerialization }; - ( weight == 1. ) ? m_rep->Fill( x, y ) : m_rep->Fill( x, y, weight ); + m_rep->Fill( x, y, weight ); return true; } diff --git a/GaudiExamples/src/IO/EvtCollectionSelector.cpp b/GaudiExamples/src/IO/EvtCollectionSelector.cpp index 9f0034dc87406638d028c6e63380cd9971dbb29e..633eeb90181549b33c6985d9c07c2a72aef20224 100644 --- a/GaudiExamples/src/IO/EvtCollectionSelector.cpp +++ b/GaudiExamples/src/IO/EvtCollectionSelector.cpp @@ -103,7 +103,9 @@ namespace Gaudi { std::cout << std::endl << System::typeinfoName( typeid( *this ) ) << "\t -> Momenta(Fix): "; for ( int i = 0; i < std::min( 5, n ); ++i ) { std::cout << "[" << i << "]=" << m_trkMomFixed[i] << " "; } for ( int i = 5; i < 99; ++i ) { - if ( m_trkMomFixed[i] != 0.f ) { std::cout << "[" << i << "]= Error in Fixed momentum" << std::endl; } + if ( abs( m_trkMomFixed[i] ) > std::numeric_limits<float>::epsilon() ) { + std::cout << "[" << i << "]= Error in Fixed momentum" << std::endl; + } } #endif std::cout << std::endl; diff --git a/GaudiExamples/src/Properties/PropertyAlg.cpp b/GaudiExamples/src/Properties/PropertyAlg.cpp index 8c057ddb585441dd3dc5e17c81102ef024adc5ee..ca2dcc974ff9a4281393c680488c21d960eeb564 100644 --- a/GaudiExamples/src/Properties/PropertyAlg.cpp +++ b/GaudiExamples/src/Properties/PropertyAlg.cpp @@ -20,10 +20,12 @@ #include "PropertyAlg.h" -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -# pragma warning( disable : 1572 ) -#endif +namespace { + // idea coming from The art of computer programming by Knuth + constexpr bool essentiallyEqual( double const a, double const b ) { + return std::abs( a - b ) <= std::min( std::abs( a ), std::abs( b ) ) * std::numeric_limits<double>::epsilon(); + } +} // namespace // Read Handler //------------------------------------------------------------------------------ @@ -133,7 +135,7 @@ StatusCode PropertyAlg::initialize() { auto& doublearray = u_doublearray.value(); for ( unsigned int i = 0; i < doublearrayunits.size(); i++ ) { - if ( doublearrayunits[i] != doublearray[i] ) { + if ( !essentiallyEqual( doublearrayunits[i], doublearray[i] ) ) { error() << format( "DoubleArrayWithUnits[%d] = %g and should be %g", i, doublearrayunits[i], doublearray[i] ) << endmsg; } else { diff --git a/GaudiHive/src/CPUCruncher.cpp b/GaudiHive/src/CPUCruncher.cpp index d7f6ffe12456ac08d9b3358928735a8acf1b5f51..2e10d1d518df2ec3988e44a6f21e43ffb0f6777f 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 ( m_sleepFraction != 0.0f ) setBlocking( true ); + if ( abs( m_sleepFraction ) > std::numeric_limits<float>::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 @@ -140,7 +140,7 @@ StatusCode CPUCruncher::execute() // the execution of the algorithm do { unif1 = getUnifRandom( seed ); unif2 = getUnifRandom( seed ); - } while ( unif1 == 0. ); + } while ( unif1 < std::numeric_limits<double>::epsilon() ); const double normal = sqrt( -2. * log( unif1 ) ) * cos( 2 * M_PI * unif2 ); diff --git a/GaudiKernel/include/Gaudi/Accumulators.h b/GaudiKernel/include/Gaudi/Accumulators.h index 43befc4262dc16ad4662ce02c668d783be163a32..78794c31fa496df43fea4d13523dd941212e10fb 100644 --- a/GaudiKernel/include/Gaudi/Accumulators.h +++ b/GaudiKernel/include/Gaudi/Accumulators.h @@ -341,7 +341,9 @@ namespace Gaudi::Accumulators { using typename BaseValueHandler<Arithmetic, atomicity::full>::InternalType; static constexpr OutputType DefaultValue() { return Arithmetic{}; } static void merge( InternalType& a, Arithmetic b ) noexcept { - if ( DefaultValue() == b ) return; // avoid atomic operation if b is "0" + if constexpr ( !std::is_floating_point_v<Arithmetic> ) { // avoid comparisons for floating points + if ( DefaultValue() == b ) return; // avoid atomic operation if b is "0" + } if constexpr ( has_fetch_add_v<InternalType> ) { a.fetch_add( b, std::memory_order_relaxed ); } else { diff --git a/GaudiKernel/include/Gaudi/BaseSink.h b/GaudiKernel/include/Gaudi/BaseSink.h index fd3f876d672bf8640c935a518618bb3db936c1bf..612c60a31cd0be9c6f2e2d694aa833289462a716 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() != 0 ) { + if ( m_autoFlushPeriod.value() > std::numeric_limits<double>::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/include/GaudiKernel/HistoDef.h b/GaudiKernel/include/GaudiKernel/HistoDef.h index 4ed5413a92e60813d192a9b482c606e34809dc73..38e8e26f88d4fd4b1045c6fe9751ed21f25f7de6 100644 --- a/GaudiKernel/include/GaudiKernel/HistoDef.h +++ b/GaudiKernel/include/GaudiKernel/HistoDef.h @@ -88,10 +88,6 @@ namespace Gaudi { // ======================================================================== /// ordering operator (to please BoundedVerifier) friend bool operator<( const Histo1DDef& left, const Histo1DDef& right ); - /// equality operator - friend bool operator==( const Histo1DDef& left, const Histo1DDef& right ); - /// non-equality - friend bool operator!=( const Histo1DDef& left, const Histo1DDef& right ); // ======================================================================== /// the streamer operator for class Gaudi::Histo1DDef friend std::ostream& operator<<( std::ostream& o, const Gaudi::Histo1DDef& histo ); diff --git a/GaudiKernel/include/GaudiKernel/Plane3DTypes.h b/GaudiKernel/include/GaudiKernel/Plane3DTypes.h index 730fd60967a604625d20140c639876118929ce65..d657ca5c622121d1b3e52374640ef5aaa51336b5 100644 --- a/GaudiKernel/include/GaudiKernel/Plane3DTypes.h +++ b/GaudiKernel/include/GaudiKernel/Plane3DTypes.h @@ -8,32 +8,10 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \***********************************************************************************/ +#pragma once -//--------------------------------------------------------------------------------- -/** @file Plane3DTypes.h - * - * 3D plane typedefs - * - * @author Juan PALACIOS - * @date 2005-11-21 - */ -//--------------------------------------------------------------------------------- - -#ifndef GAUDIKERNEL_PLANE3DTYPES_H -#define GAUDIKERNEL_PLANE3DTYPES_H 1 - -#ifdef __INTEL_COMPILER // Disable ICC remark from Math headers -# pragma warning( push ) -# pragma warning( disable : 1572 ) // Floating-point equality and inequality comparisons are unreliable -#endif - -// Include files #include "Math/Plane3D.h" -#ifdef __INTEL_COMPILER -# pragma warning( pop ) -#endif - /** @namespace Gaudi * * General Gaudi namespace @@ -42,10 +20,5 @@ * @date 2005-11-21 */ namespace Gaudi { - - // NB : Please remember to give a simple doxygen comment for each tyedef - typedef ROOT::Math::Plane3D Plane3D; ///< 3D plane (double) } // namespace Gaudi - -#endif // KERNEL_PLANE3DTYPES_H diff --git a/GaudiKernel/include/GaudiKernel/StatEntity.h b/GaudiKernel/include/GaudiKernel/StatEntity.h index a1a99144baf7b6c6ca7c7ca477015fd66988748c..7575c537509f20025b88627dfbc7b6624d02c0c3 100644 --- a/GaudiKernel/include/GaudiKernel/StatEntity.h +++ b/GaudiKernel/include/GaudiKernel/StatEntity.h @@ -119,7 +119,8 @@ public: template <typename stream> stream& printImpl( stream& o, bool tableFormat, std::string_view name, bool flag, std::string_view fmtHead ) const { if ( flag && effCounter( name ) && 0 <= eff() && 0 <= effErr() && sum() <= nEntries() && - ( 0 == min() || 1 == min() ) && ( 0 == max() || 1 == max() ) ) { + ( essentiallyEqual( min(), 0 ) || essentiallyEqual( min(), 1 ) ) && + ( essentiallyEqual( max(), 0 ) || essentiallyEqual( max(), 1 ) ) ) { // efficiency printing if ( tableFormat ) { if ( name.empty() ) { @@ -191,4 +192,9 @@ public: j, { { { { "nEntries", "sum" }, "sum2" }, "min", "max" }, { "nTrueEntries", "nFalseEntries" } } ) ); return res; } + +private: + static constexpr bool essentiallyEqual( double const a, double const b ) { + return std::abs( a - b ) <= std::max( std::abs( a ), std::abs( b ) ) * std::numeric_limits<double>::epsilon(); + } }; diff --git a/GaudiKernel/include/GaudiKernel/Transform3DTypes.h b/GaudiKernel/include/GaudiKernel/Transform3DTypes.h index 0bf6e462060606d905d16a28aee3a377ca56366b..c9829284dff4dca180e98981f2bae2427a86af6c 100644 --- a/GaudiKernel/include/GaudiKernel/Transform3DTypes.h +++ b/GaudiKernel/include/GaudiKernel/Transform3DTypes.h @@ -8,24 +8,7 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \***********************************************************************************/ - -//--------------------------------------------------------------------------------- -/** @file Transform3DTypes.h - * - * 3D transformation typedefs - * - * @author Juan PALACIOS - * @date 2005-11-21 - */ -//--------------------------------------------------------------------------------- - -#ifndef GAUDIKERNEL_TRANSFORM3DTYPES_H -#define GAUDIKERNEL_TRANSFORM3DTYPES_H 1 - -#ifdef __INTEL_COMPILER // Disable ICC remark from Math headers -# pragma warning( push ) -# pragma warning( disable : 1572 ) // Floating-point equality and inequality comparisons are unreliable -#endif +#pragma once // Include files #include "Math/AxisAngle.h" @@ -38,10 +21,6 @@ #include "Math/Transform3D.h" #include "Math/Vector3D.h" -#ifdef __INTEL_COMPILER -# pragma warning( pop ) -#endif - /** @namespace Gaudi * * General Gaudi namespace @@ -50,9 +29,6 @@ * @date 2005-11-21 */ namespace Gaudi { - - // NB : Please remember to give a simple doxygen comment for each tyedef - typedef ROOT::Math::Rotation3D Rotation3D; ///< 3D rotation typedef ROOT::Math::EulerAngles EulerAngles; ///< 3D Euler Angles typedef ROOT::Math::Quaternion Quaternion; ///< 3D Quaternion @@ -63,5 +39,3 @@ namespace Gaudi { typedef ROOT::Math::Transform3D Transform3D; ///< General 3D transformation (rotation+translation) typedef ROOT::Math::XYZVector TranslationXYZ; ///< 3D translation } // namespace Gaudi - -#endif // EVENT_TRANSFORM3DTYPES_H diff --git a/GaudiKernel/src/Lib/HistoDef.cpp b/GaudiKernel/src/Lib/HistoDef.cpp index 5b0b033ebdeac402eb88049aea15bca21d34a296..09106c18c2f149f2e920d21627f42cfcbae7e150 100644 --- a/GaudiKernel/src/Lib/HistoDef.cpp +++ b/GaudiKernel/src/Lib/HistoDef.cpp @@ -60,26 +60,6 @@ namespace Gaudi { return std::tie( left.m_title, left.m_low, left.m_high, left.m_bins ) < std::tie( right.m_title, right.m_low, right.m_high, right.m_bins ); } -// ============================================================================ -// equality operator -// ============================================================================ -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -# pragma warning( push ) -# pragma warning( disable : 1572 ) -#endif - bool operator==( const Gaudi::Histo1DDef& left, const Gaudi::Histo1DDef& right ) { - return std::tie( left.m_title, left.m_low, left.m_high, left.m_bins ) == - std::tie( right.m_title, right.m_low, right.m_high, right.m_bins ); - } -#ifdef __ICC -// re-enable icc remark #1572 -# pragma warning( pop ) -#endif - // ============================================================================ - // non-equality - // ============================================================================ - bool operator!=( const Gaudi::Histo1DDef& left, const Gaudi::Histo1DDef& right ) { return !( left == right ); } // ============================================================================ // the streamer operator for class Gaudi::Histo1DDef // ============================================================================ diff --git a/GaudiKernel/tests/src/CounterSerializationTest.cpp b/GaudiKernel/tests/src/CounterSerializationTest.cpp index 6a8a7460b9ff208ff851182b2cd9407ddb4eaaa2..1045cdadc0c2c1fb8cbc71c667f81c12e793da3e 100644 --- a/GaudiKernel/tests/src/CounterSerializationTest.cpp +++ b/GaudiKernel/tests/src/CounterSerializationTest.cpp @@ -12,12 +12,9 @@ #if __has_include( <catch2/catch.hpp>) // Catch2 v2 # include <catch2/catch.hpp> -namespace Catch { - using Detail::Approx; -} #else // Catch2 v3 -# include <catch2/catch_approx.hpp> +# include <catch2/catch_matchers_floating_point.hpp> # include <catch2/catch_template_test_macros.hpp> # include <catch2/catch_test_macros.hpp> #endif @@ -99,12 +96,12 @@ namespace { void check_details( const nlohmann::json& j, bool empty ) const { if ( empty ) { CHECK( j["nEntries"].get<unsigned long>() == 0 ); - CHECK( j["sum"].get<double>() == 0 ); - CHECK( j["mean"].get<double>() == 0 ); + REQUIRE_THAT( j["sum"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + REQUIRE_THAT( j["mean"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); } else { CHECK( j["nEntries"].get<unsigned long>() == 3 ); - CHECK( j["sum"].get<double>() == 60 ); - CHECK( j["mean"].get<double>() == 20 ); + REQUIRE_THAT( j["sum"].get<double>(), Catch::Matchers::WithinRel( 60, 1.e-4 ) ); + REQUIRE_THAT( j["mean"].get<double>(), Catch::Matchers::WithinRel( 20, 1.e-4 ) ); } } }; @@ -118,16 +115,16 @@ namespace { void check_details( const nlohmann::json& j, bool empty ) const { if ( empty ) { CHECK( j["nEntries"].get<unsigned long>() == 0 ); - CHECK( j["sum"].get<double>() == 0 ); - CHECK( j["mean"].get<double>() == 0 ); - CHECK( j["sum2"].get<double>() == 0 ); - CHECK( j["standard_deviation"].get<double>() == 0 ); + REQUIRE_THAT( j["sum"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + REQUIRE_THAT( j["mean"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + REQUIRE_THAT( j["sum2"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + REQUIRE_THAT( j["standard_deviation"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); } else { CHECK( j["nEntries"].get<unsigned long>() == 3 ); - CHECK( j["sum"].get<double>() == 60 ); - CHECK( j["mean"].get<double>() == 20 ); - CHECK( j["sum2"].get<double>() == 1400 ); - CHECK( j["standard_deviation"].get<double>() == Catch::Approx( 8.164966 ) ); + REQUIRE_THAT( j["sum"].get<double>(), Catch::Matchers::WithinRel( 60, 1.e-4 ) ); + REQUIRE_THAT( j["mean"].get<double>(), Catch::Matchers::WithinRel( 20, 1.e-4 ) ); + REQUIRE_THAT( j["sum2"].get<double>(), Catch::Matchers::WithinRel( 1400, 1.e-4 ) ); + REQUIRE_THAT( j["standard_deviation"].get<double>(), Catch::Matchers::WithinRel( 8.164966, 1.e-4 ) ); } } }; @@ -141,20 +138,20 @@ namespace { void check_details( const nlohmann::json& j, bool empty ) const { if ( empty ) { CHECK( j["nEntries"].get<unsigned long>() == 0 ); - CHECK( j["sum"].get<double>() == 0 ); - CHECK( j["mean"].get<double>() == 0 ); - CHECK( j["sum2"].get<double>() == 0 ); - CHECK( j["standard_deviation"].get<double>() == 0 ); - // CHECK( j["min"].get<double>() == 0 ); - // CHECK( j["max"].get<double>() == 0 ); + REQUIRE_THAT( j["sum"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + REQUIRE_THAT( j["mean"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + REQUIRE_THAT( j["sum2"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + REQUIRE_THAT( j["standard_deviation"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + // REQUIRE_THAT( j["min"].get<double>(), Catch::Matchers::WithinAbs(0, 1.e-4 ) ); + // REQUIRE_THAT( j["max"].get<double>(), Catch::Matchers::WithinAbs(0, 1.e-4 ) ); } else { CHECK( j["nEntries"].get<unsigned long>() == 3 ); - CHECK( j["sum"].get<double>() == 60 ); - CHECK( j["mean"].get<double>() == 20 ); - CHECK( j["sum2"].get<double>() == 1400 ); - CHECK( j["standard_deviation"].get<double>() == Catch::Approx( 8.164966 ) ); - CHECK( j["min"].get<double>() == 10 ); - CHECK( j["max"].get<double>() == 30 ); + REQUIRE_THAT( j["sum"].get<double>(), Catch::Matchers::WithinRel( 60, 1.e-4 ) ); + REQUIRE_THAT( j["mean"].get<double>(), Catch::Matchers::WithinRel( 20, 1.e-4 ) ); + REQUIRE_THAT( j["sum2"].get<double>(), Catch::Matchers::WithinRel( 1400, 1.e-4 ) ); + REQUIRE_THAT( j["standard_deviation"].get<double>(), Catch::Matchers::WithinRel( 8.164966, 1.e-4 ) ); + REQUIRE_THAT( j["min"].get<double>(), Catch::Matchers::WithinRel( 10, 1.e-4 ) ); + REQUIRE_THAT( j["max"].get<double>(), Catch::Matchers::WithinRel( 30, 1.e-4 ) ); } } }; @@ -169,16 +166,16 @@ namespace { void check_details( const nlohmann::json& j, bool empty ) const { if ( empty ) { CHECK( j["nEntries"].get<unsigned long>() == 0 ); - CHECK( j["nTrueEntries"].get<double>() == 0 ); - CHECK( j["nFalseEntries"].get<double>() == 0 ); - // CHECK( j["efficiency"].get<double>() == 0 ); - // CHECK( j["efficiencyErr"].get<double>() == 0 ); + REQUIRE_THAT( j["nTrueEntries"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + REQUIRE_THAT( j["nFalseEntries"].get<double>(), Catch::Matchers::WithinAbs( 0, 1.e-4 ) ); + // REQUIRE_THAT( j["efficiency"].get<double>(), Catch::Matchers::WithinAbs(0, 1.e-4 ) ); + // REQUIRE_THAT( j["efficiencyErr"].get<double>(), Catch::Matchers::WithinAbs(0, 1.e-4 ) ); } else { CHECK( j["nEntries"].get<unsigned long>() == 10 ); - CHECK( j["nTrueEntries"].get<double>() == 5 ); - CHECK( j["nFalseEntries"].get<double>() == 5 ); - CHECK( j["efficiency"].get<double>() == 0.5 ); - CHECK( j["efficiencyErr"].get<double>() == Catch::Approx( 0.158114 ) ); + REQUIRE_THAT( j["nTrueEntries"].get<double>(), Catch::Matchers::WithinRel( 5, 1.e-4 ) ); + REQUIRE_THAT( j["nFalseEntries"].get<double>(), Catch::Matchers::WithinRel( 5, 1.e-4 ) ); + REQUIRE_THAT( j["efficiency"].get<double>(), Catch::Matchers::WithinRel( 0.5, 1.e-4 ) ); + REQUIRE_THAT( j["efficiencyErr"].get<double>(), Catch::Matchers::WithinRel( 0.158114, 1.e-4 ) ); } } }; diff --git a/GaudiKernel/tests/src/RootHistogramUtilsUnitTest.cpp b/GaudiKernel/tests/src/RootHistogramUtilsUnitTest.cpp index 80bdb136df9ab27aea2ae118c413fa5645823ccc..2339ceec9a33eac3218fe031f664a4b282577698 100644 --- a/GaudiKernel/tests/src/RootHistogramUtilsUnitTest.cpp +++ b/GaudiKernel/tests/src/RootHistogramUtilsUnitTest.cpp @@ -150,8 +150,8 @@ BOOST_AUTO_TEST_CASE( test_prof2D_to_json ) { namespace { void checkAxis( TAxis axis, int nbins, double min, double max, std::string title ) { BOOST_CHECK( axis.GetNbins() == nbins ); - BOOST_CHECK( axis.GetXmin() == min ); - BOOST_CHECK( axis.GetXmax() == max ); + BOOST_CHECK_CLOSE( axis.GetXmin(), min, 1.e-4 ); + BOOST_CHECK_CLOSE( axis.GetXmax(), max, 1.e-4 ); BOOST_CHECK( axis.GetTitle() == title ); } } // namespace @@ -180,14 +180,14 @@ BOOST_AUTO_TEST_CASE( test_json_to_histo1D ) { BOOST_CHECK( fullDir == "dir/subdir" ); BOOST_CHECK( strcmp( histo.GetTitle(), "MyNiceTitle" ) == 0 ); BOOST_CHECK( histo.GetDimension() == 1 ); - BOOST_CHECK( histo.GetEntries() == 6 ); + BOOST_CHECK_CLOSE( histo.GetEntries(), 6, 1.e-4 ); checkAxis( *histo.GetXaxis(), 16, -4.5, 12.5, "MyNiceAxisTitle" ); - BOOST_CHECK( histo.GetBinContent( 0 ) == 1.0 ); - BOOST_CHECK( histo.GetBinContent( 1 ) == 0.0 ); - BOOST_CHECK( histo.GetBinContent( 5 ) == 5.0 ); - BOOST_CHECK( histo.GetBinError( 0 ) == 1.0 ); - BOOST_CHECK( histo.GetBinError( 1 ) == 0.0 ); - BOOST_CHECK( histo.GetBinError( 5 ) == std::sqrt( 5.0 ) ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 0 ), 1.0, 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinContent( 1 ), 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 5 ), 5.0, 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinError( 0 ), 1.0, 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinError( 1 ), 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinError( 5 ), std::sqrt( 5.0 ), 1.e-4 ); } BOOST_AUTO_TEST_CASE( test_json_to_histo2D ) { @@ -206,15 +206,15 @@ BOOST_AUTO_TEST_CASE( test_json_to_histo2D ) { BOOST_CHECK( fullDir == "dir/subdir" ); BOOST_CHECK( strcmp( histo.GetTitle(), "MyNiceTitle" ) == 0 ); BOOST_CHECK( histo.GetDimension() == 2 ); - BOOST_CHECK( histo.GetEntries() == 6 ); + BOOST_CHECK_CLOSE( histo.GetEntries(), 6, 1.e-4 ); checkAxis( *histo.GetXaxis(), 2, -1.0, 1.0, "MyNiceAxisTitle" ); checkAxis( *histo.GetYaxis(), 2, 3.0, 5.0, "" ); - BOOST_CHECK( histo.GetBinContent( 0 ) == 1.0 ); - BOOST_CHECK( histo.GetBinContent( 1 ) == 0.0 ); - BOOST_CHECK( histo.GetBinContent( 5 ) == 5.0 ); - BOOST_CHECK( histo.GetBinError( 0 ) == 1.0 ); - BOOST_CHECK( histo.GetBinError( 1 ) == 0.0 ); - BOOST_CHECK( histo.GetBinError( 5 ) == std::sqrt( 5.0 ) ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 0 ), 1.0, 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinContent( 1 ), 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 5 ), 5.0, 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinError( 0 ), 1.0, 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinError( 1 ), 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinError( 5 ), std::sqrt( 5.0 ), 1.e-4 ); } BOOST_AUTO_TEST_CASE( test_json_to_histo3D ) { @@ -236,16 +236,16 @@ BOOST_AUTO_TEST_CASE( test_json_to_histo3D ) { BOOST_CHECK( fullDir == "dir/subdir" ); BOOST_CHECK( strcmp( histo.GetTitle(), "MyNiceTitle" ) == 0 ); BOOST_CHECK( histo.GetDimension() == 3 ); - BOOST_CHECK( histo.GetEntries() == 6 ); + BOOST_CHECK_CLOSE( histo.GetEntries(), 6, 1.e-4 ); checkAxis( *histo.GetXaxis(), 2, -1.0, 1.0, "MyNiceAxisTitle" ); checkAxis( *histo.GetYaxis(), 2, 3.0, 5.0, "" ); checkAxis( *histo.GetZaxis(), 1, -4.0, -2.0, "" ); - BOOST_CHECK( histo.GetBinContent( 0 ) == 1.0 ); - BOOST_CHECK( histo.GetBinContent( 1 ) == 0.0 ); - BOOST_CHECK( histo.GetBinContent( 21 ) == 5.0 ); - BOOST_CHECK( histo.GetBinError( 0 ) == 1.0 ); - BOOST_CHECK( histo.GetBinError( 1 ) == 0.0 ); - BOOST_CHECK( histo.GetBinError( 21 ) == std::sqrt( 5.0 ) ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 0 ), 1.0, 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinContent( 1 ), 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 21 ), 5.0, 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinError( 0 ), 1.0, 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinError( 1 ), 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinError( 21 ), std::sqrt( 5.0 ), 1.e-4 ); } BOOST_AUTO_TEST_CASE( test_json_to_prof1D ) { @@ -263,21 +263,21 @@ BOOST_AUTO_TEST_CASE( test_json_to_prof1D ) { BOOST_CHECK( fullDir == "dir/subdir" ); BOOST_CHECK( strcmp( histo.GetTitle(), "MyNiceTitle" ) == 0 ); BOOST_CHECK( histo.GetDimension() == 1 ); - BOOST_CHECK( histo.GetEntries() == 6 ); + BOOST_CHECK_CLOSE( histo.GetEntries(), 6, 1.e-4 ); checkAxis( *histo.GetXaxis(), 2, -0.5, 1.5, "MyNiceAxisTitle" ); auto* sumw2 = histo.GetSumw2(); - BOOST_CHECK( histo.GetBinEntries( 0 ) == 1.0 ); - BOOST_CHECK( histo.GetBinContent( 0 ) == 2.0 ); - BOOST_CHECK( sumw2->At( 0 ) == 4.0 ); - BOOST_CHECK( histo.GetBinError( 0 ) == 0.0 ); - BOOST_CHECK( histo.GetBinEntries( 1 ) == 5.0 ); - BOOST_CHECK( histo.GetBinContent( 1 ) == 3.0 ); - BOOST_CHECK( sumw2->At( 1 ) == 55.0 ); - BOOST_CHECK( histo.GetBinError( 1 ) == std::sqrt( 0.4 ) ); - BOOST_CHECK( histo.GetBinEntries( 2 ) == 0.0 ); - BOOST_CHECK( histo.GetBinContent( 2 ) == 0.0 ); - BOOST_CHECK( sumw2->At( 2 ) == 0.0 ); - BOOST_CHECK( histo.GetBinError( 2 ) == 0.0 ); + BOOST_CHECK_CLOSE( histo.GetBinEntries( 0 ), 1.0, 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 0 ), 2.0, 1.e-4 ); + BOOST_CHECK_CLOSE( sumw2->At( 0 ), 4.0, 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinError( 0 ), 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinEntries( 1 ), 5.0, 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 1 ), 3.0, 1.e-4 ); + BOOST_CHECK_CLOSE( sumw2->At( 1 ), 55.0, 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinError( 1 ), std::sqrt( 0.4 ), 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinEntries( 2 ), 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinContent( 2 ), 1.e-4 ); + BOOST_CHECK_SMALL( sumw2->At( 2 ), 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinError( 2 ), 1.e-4 ); } BOOST_AUTO_TEST_CASE( test_json_to_prof2D ) { @@ -312,20 +312,20 @@ BOOST_AUTO_TEST_CASE( test_json_to_prof2D ) { BOOST_CHECK( fullDir == "dir/subdir" ); BOOST_CHECK( strcmp( histo.GetTitle(), "MyNiceTitle" ) == 0 ); BOOST_CHECK( histo.GetDimension() == 2 ); - BOOST_CHECK( histo.GetEntries() == 6 ); + BOOST_CHECK_CLOSE( histo.GetEntries(), 6, 1.e-4 ); checkAxis( *histo.GetXaxis(), 2, -0.5, 1.5, "MyNiceAxisTitle" ); checkAxis( *histo.GetYaxis(), 2, 2.5, 4.5, "" ); auto* sumw2 = histo.GetSumw2(); - BOOST_CHECK( histo.GetBinEntries( 0 ) == 1.0 ); - BOOST_CHECK( histo.GetBinContent( 0 ) == 2.0 ); - BOOST_CHECK( sumw2->At( 0 ) == 4.0 ); - BOOST_CHECK( histo.GetBinError( 0 ) == 0.0 ); - BOOST_CHECK( histo.GetBinEntries( 5 ) == 5.0 ); - BOOST_CHECK( histo.GetBinContent( 5 ) == 3.0 ); - BOOST_CHECK( sumw2->At( 5 ) == 55.0 ); - BOOST_CHECK( histo.GetBinError( 5 ) == std::sqrt( 0.4 ) ); - BOOST_CHECK( histo.GetBinEntries( 2 ) == 0.0 ); - BOOST_CHECK( histo.GetBinContent( 2 ) == 0.0 ); - BOOST_CHECK( sumw2->At( 2 ) == 0.0 ); - BOOST_CHECK( histo.GetBinError( 2 ) == 0.0 ); + BOOST_CHECK_CLOSE( histo.GetBinEntries( 0 ), 1.0, 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 0 ), 2.0, 1.e-4 ); + BOOST_CHECK_CLOSE( sumw2->At( 0 ), 4.0, 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinError( 0 ), 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinEntries( 5 ), 5.0, 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinContent( 5 ), 3.0, 1.e-4 ); + BOOST_CHECK_CLOSE( sumw2->At( 5 ), 55.0, 1.e-4 ); + BOOST_CHECK_CLOSE( histo.GetBinError( 5 ), std::sqrt( 0.4 ), 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinEntries( 2 ), 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinContent( 2 ), 1.e-4 ); + BOOST_CHECK_SMALL( sumw2->At( 2 ), 1.e-4 ); + BOOST_CHECK_SMALL( histo.GetBinError( 2 ), 1.e-4 ); } diff --git a/GaudiKernel/tests/src/parsers.cpp b/GaudiKernel/tests/src/parsers.cpp index 060bc4fdd274f850644c56aa89d5f5919a855ee4..0c6982ad587f03103dd9ce2f69c27c8d9b179540 100644 --- a/GaudiKernel/tests/src/parsers.cpp +++ b/GaudiKernel/tests/src/parsers.cpp @@ -73,20 +73,20 @@ BOOST_AUTO_TEST_CASE( test_RealGrammar ) { { double result; BOOST_CHECK( parse( result, "1.5E2" ) ); - BOOST_CHECK( result == 150 ); + BOOST_CHECK_CLOSE( result, 150, 1.e-4 ); } { float result; BOOST_CHECK( parse( result, "1.5E2" ) ); - BOOST_CHECK( result == 150 ); + BOOST_CHECK_CLOSE( result, 150, 1.e-4 ); } { // test bug GAUDI-1121 float result; BOOST_CHECK( parse( result, "-10000000000.0" ) ); - BOOST_CHECK( result == -1.E10 ); + BOOST_CHECK_CLOSE( result, -1.E10, 1.e-4 ); } } @@ -114,17 +114,17 @@ BOOST_AUTO_TEST_CASE( test_VectorGramar ) { std::vector<std::vector<double>> result; BOOST_CHECK( parse( result, "[[1, 2]/* Test comments */,[3]]" ) ); BOOST_CHECK( result.size() == 2 ); - BOOST_CHECK( result[0][0] == 1 ); - BOOST_CHECK( result[0][1] == 2 ); - BOOST_CHECK( result[1][0] == 3 ); + BOOST_CHECK_CLOSE( result[0][0], 1, 1.e-4 ); + BOOST_CHECK_CLOSE( result[0][1], 2, 1.e-4 ); + BOOST_CHECK_CLOSE( result[1][0], 3, 1.e-4 ); } { std::vector<double> result; BOOST_CHECK( parse( result, "[1.1, 2.2 ]" ) ); BOOST_CHECK( result.size() == 2 ); - BOOST_CHECK( result[0] == 1.1 ); - BOOST_CHECK( result[1] == 2.2 ); + BOOST_CHECK_CLOSE( result[0], 1.1, 1.e-4 ); + BOOST_CHECK_CLOSE( result[1], 2.2, 1.e-4 ); } /*{ std::set<double> result; @@ -146,8 +146,8 @@ BOOST_AUTO_TEST_CASE( test_VectorGramar ) { BOOST_AUTO_TEST_CASE( test_PairGramar ) { std::pair<double, double> result; BOOST_CHECK( parse( result, "(10.1, 10)" ) ); - BOOST_CHECK( result.first == 10.1 ); - BOOST_CHECK( result.second == 10 ); + BOOST_CHECK_CLOSE( result.first, 10.1, 1.e-4 ); + BOOST_CHECK_CLOSE( result.second, 10, 1.e-4 ); } BOOST_AUTO_TEST_CASE( test_MapGramar ) { @@ -178,7 +178,7 @@ BOOST_AUTO_TEST_CASE( test_MapGramar ) { BOOST_CHECK( parse( result, "{'key':[10.0,20.0]}" ) ); BOOST_CHECK( result.size() == 1 ); BOOST_CHECK( result["key"].size() == 2 ); - BOOST_CHECK( result["key"][0] == 10 ); + BOOST_CHECK_CLOSE( result["key"][0], 10, 1.e-4 ); } { @@ -186,27 +186,27 @@ BOOST_AUTO_TEST_CASE( test_MapGramar ) { BOOST_CHECK( parse( result, "{'key':10, 'key1'=20}" ) ); BOOST_CHECK( result.size() == 2 ); Gaudi::StringKey key = std::string( "key" ); - BOOST_CHECK( result.at( key ) == 10 ); + BOOST_CHECK_CLOSE( result.at( key ), 10, 1.e-4 ); key = std::string( "key1" ); - BOOST_CHECK( result.at( key ) == 20 ); + BOOST_CHECK_CLOSE( result.at( key ), 20, 1.e-4 ); } } BOOST_AUTO_TEST_CASE( test_Pnt3DTypes ) { Gaudi::XYZPoint result; BOOST_CHECK( parse( result, "(px:10.0, py:11.0, pZ:12.0)" ) ); - BOOST_CHECK( result.X() == 10.0 ); - BOOST_CHECK( result.Y() == 11.0 ); - BOOST_CHECK( result.Z() == 12.0 ); + BOOST_CHECK_CLOSE( result.X(), 10.0, 1.e-4 ); + BOOST_CHECK_CLOSE( result.Y(), 11.0, 1.e-4 ); + BOOST_CHECK_CLOSE( result.Z(), 12.0, 1.e-4 ); } BOOST_AUTO_TEST_CASE( test_Pnt4DTypes ) { Gaudi::LorentzVector result; BOOST_CHECK( parse( result, "(px:10.0, py:11.0, pZ:12.0;100.0)" ) ); - BOOST_CHECK( result.X() == 10.0 ); - BOOST_CHECK( result.Y() == 11.0 ); - BOOST_CHECK( result.Z() == 12.0 ); - BOOST_CHECK( result.T() == 100.0 ); + BOOST_CHECK_CLOSE( result.X(), 10.0, 1.e-4 ); + BOOST_CHECK_CLOSE( result.Y(), 11.0, 1.e-4 ); + BOOST_CHECK_CLOSE( result.Z(), 12.0, 1.e-4 ); + BOOST_CHECK_CLOSE( result.T(), 100.0, 1.e-4 ); } BOOST_AUTO_TEST_CASE( test_HistoTypes ) { @@ -214,8 +214,8 @@ BOOST_AUTO_TEST_CASE( test_HistoTypes ) { Gaudi::Histo1DDef result; BOOST_CHECK( parse( result, "('test', 1.0,2.0, 100)" ) ); BOOST_CHECK( result.title() == "test" ); - BOOST_CHECK( result.lowEdge() == 1.0 ); - BOOST_CHECK( result.highEdge() == 2.0 ); + BOOST_CHECK_CLOSE( result.lowEdge(), 1.0, 1.e-4 ); + BOOST_CHECK_CLOSE( result.highEdge(), 2.0, 1.e-4 ); BOOST_CHECK( result.bins() == 100 ); } @@ -223,8 +223,8 @@ BOOST_AUTO_TEST_CASE( test_HistoTypes ) { Gaudi::Histo1DDef result; BOOST_CHECK( parse( result, "(1.0,2.0, 'test', 100)" ) ); BOOST_CHECK( result.title() == "test" ); - BOOST_CHECK( result.lowEdge() == 1.0 ); - BOOST_CHECK( result.highEdge() == 2.0 ); + BOOST_CHECK_CLOSE( result.lowEdge(), 1.0, 1.e-4 ); + BOOST_CHECK_CLOSE( result.highEdge(), 2.0, 1.e-4 ); BOOST_CHECK( result.bins() == 100 ); } } diff --git a/GaudiPartProp/src/ParticlePropertySvc.cpp b/GaudiPartProp/src/ParticlePropertySvc.cpp index 495b2216d6d45109bf752ffeb4d2410feaa5155e..c9fab16ada03276ddc7d4fe5089755a78869aa71 100644 --- a/GaudiPartProp/src/ParticlePropertySvc.cpp +++ b/GaudiPartProp/src/ParticlePropertySvc.cpp @@ -8,33 +8,29 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \***********************************************************************************/ -// ============================================================================ -// Include files -// ============================================================================ -// STD&STL -// ============================================================================ #include "boost/algorithm/string/classification.hpp" #include "boost/algorithm/string/split.hpp" #include "boost/algorithm/string/trim.hpp" #include <cctype> #include <fstream> namespace ba = boost::algorithm; -// ============================================================================ -// GaudiKernel -// ============================================================================ + #include "GaudiKernel/IFileAccess.h" #include "GaudiKernel/ISvcLocator.h" #include "GaudiKernel/MsgStream.h" #include "GaudiKernel/ParticleProperty.h" #include "GaudiKernel/PhysicalConstants.h" #include "GaudiKernel/System.h" -// ============================================================================ -// #include "GaudiKernel/ToStream.h" -// ============================================================================ -// Local -// ============================================================================ + #include "ParticlePropertySvc.h" -// ============================================================================ + +namespace { + // idea coming from The art of computer programming by Knuth + constexpr bool essentiallyEqual( double const a, double const b ) { + return std::abs( a - b ) <= std::min( std::abs( a ), std::abs( b ) ) * std::numeric_limits<double>::epsilon(); + } +} // namespace + namespace Gaudi { /** Instantiation of a static factory class used by clients to create * instances of this service @@ -370,13 +366,7 @@ namespace Gaudi { // return StatusCode::SUCCESS; } -// ============================================================================ -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// The comparison are meant -# pragma warning( push ) -# pragma warning( disable : 1572 ) -#endif + // ============================================================================ bool ParticlePropertySvc::diff( const ParticleProperty* o, const ParticleProperty* n, const MSG::Level l ) const { // if ( o == n ) { return false; } @@ -405,15 +395,15 @@ namespace Gaudi { result = true; log << " PYID:" << o->pythiaID() << "/" << n->pythiaID() << "'"; } - if ( o->charge() != n->charge() ) { + if ( essentiallyEqual( o->charge(), n->charge() ) ) { result = true; log << " Q:" << o->charge() << "/" << n->charge() << "'"; } - if ( o->mass() != n->mass() ) { + if ( essentiallyEqual( o->mass(), n->mass() ) ) { result = true; log << " M:" << o->mass() << "/" << n->mass() << "'"; } - if ( o->lifetime() != n->lifetime() ) { + if ( essentiallyEqual( o->lifetime(), n->lifetime() ) ) { result = true; log << " T:" << o->lifetime() << "/" << n->lifetime() << "'"; } @@ -421,7 +411,7 @@ namespace Gaudi { result = true; log << " EvtGen:" << o->evtGenName() << "/" << n->evtGenName() << "'"; } - if ( o->maxWidth() != n->maxWidth() ) { + if ( essentiallyEqual( o->maxWidth(), n->maxWidth() ) ) { result = true; log << " WMAX:" << o->maxWidth() << "/" << n->maxWidth() << "'"; } @@ -430,10 +420,6 @@ namespace Gaudi { return result; } } // namespace Gaudi -#ifdef __ICC -// re-enable icc remark #1572 -# pragma warning( pop ) -#endif // ============================================================================ // The END // ============================================================================ diff --git a/GaudiSvc/src/CPUCrunchSvc/CPUCrunchSvc.cpp b/GaudiSvc/src/CPUCrunchSvc/CPUCrunchSvc.cpp index 2f189321904d0c02297dffff14a52ced5fdc7ea3..6012aa7a703522d366962f124b9e583f9808b4bb 100644 --- a/GaudiSvc/src/CPUCrunchSvc/CPUCrunchSvc.cpp +++ b/GaudiSvc/src/CPUCrunchSvc/CPUCrunchSvc.cpp @@ -23,6 +23,13 @@ DECLARE_COMPONENT( CPUCrunchSvc ) #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) #define VERBOSE_MSG ON_VERBOSE verbose() +namespace { + // idea coming from The art of computer programming by Knuth + constexpr bool essentiallyEqual( double const a, double const b ) { + return std::abs( a - b ) <= std::min( std::abs( a ), std::abs( b ) ) * std::numeric_limits<double>::epsilon(); + } +} // namespace + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ CPUCrunchSvc::CPUCrunchSvc( const std::string& name, ISvcLocator* svc ) : base_class( name, svc ) {} @@ -101,7 +108,7 @@ void CPUCrunchSvc::calibrate() { } } } - if ( m_corrFact != 1. ) { + if ( essentiallyEqual( m_corrFact, 1. ) ) { debug() << "Adjusting times with correction factor " << m_corrFact.value() << endmsg; for ( auto& t : m_times_vect ) { t = t * m_corrFact; } } diff --git a/GaudiSvc/src/RndmGenSvc/HepRndmGenerators.cpp b/GaudiSvc/src/RndmGenSvc/HepRndmGenerators.cpp index befaceb29303b38ef1d95efb98c62f90f4745109..807fd6c3423808fe53181dbd81434c7e4fba9f36 100644 --- a/GaudiSvc/src/RndmGenSvc/HepRndmGenerators.cpp +++ b/GaudiSvc/src/RndmGenSvc/HepRndmGenerators.cpp @@ -326,12 +326,6 @@ namespace HepRndm { double shoot() const override { return m_generator->shoot( m_hepEngine ); } }; -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// The comparison is meant -# pragma warning( push ) -# pragma warning( disable : 1572 ) -#endif // Specialized shoot function template <> double Generator<Rndm::GaussianTail>::shoot() const { @@ -365,15 +359,11 @@ namespace HepRndm { do { // v = gsl_rng_uniform (r); v = RandFlat::shoot( m_hepEngine ); - } while ( v == 0.0 ); + } while ( std::abs( v ) < std::numeric_limits<double>::epsilon() * m_specs->cut() ); x = sqrt( s * s - 2 * log( v ) ); } while ( x * u > s ); return x * sigma; } -#ifdef __ICC -// re-enable icc remark #1572 -# pragma warning( pop ) -#endif } } // namespace HepRndm diff --git a/GaudiUtils/include/GaudiUtils/HistoDump.h b/GaudiUtils/include/GaudiUtils/HistoDump.h index 787b1a7f41dc2f44406fff2ad72c27777748054c..bdf82b2d16acb3d3f4d130ac27310c63fee51f52 100644 --- a/GaudiUtils/include/GaudiUtils/HistoDump.h +++ b/GaudiUtils/include/GaudiUtils/HistoDump.h @@ -8,49 +8,24 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \***********************************************************************************/ -#ifndef GAUDIUTILS_HISTODUMP_H -#define GAUDIUTILS_HISTODUMP_H 1 -// ============================================================================ -// Include files -// ============================================================================ -// STD & STL -// ============================================================================ -#include <string> -// ============================================================================ -// GaudiKernel -// ============================================================================ +#pragma once + #include "GaudiKernel/Kernel.h" -// ============================================================================ -/// forward declarations: -// ============================================================================ + +#include <string> + namespace AIDA { class IHistogram1D; // AIDA class IProfile1D; // AIDA } // namespace AIDA -// ============================================================================ + class TH1; // ROOT class TProfile; // ROOT -// ============================================================================ + namespace Gaudi { - // ========================================================================== namespace Utils { - // ======================================================================== namespace Histos { - // ====================================================================== - /** dump the text representation of the histogram - * @param histo (INPUT) the histogram - * @param stream (OUTUT) the stream - * @param width (INPUT) the maximal column width - * @param height (INPUT) the proposed column height - * @param errors (INPUT) print/plot errors - * @return the stream - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2009-09-19 - */ - GAUDI_API - std::ostream& histoDump_( const AIDA::IHistogram1D* histo, std::ostream& stream, const std::size_t width = 80, - const std::size_t height = 50, const bool errors = false ); - // ====================================================================== + /** dump the text representation of the histogram * @param histo (INPUT) the histogram * @param width (INPUT) the maximal column width @@ -63,21 +38,7 @@ namespace Gaudi { GAUDI_API std::string histoDump( const AIDA::IHistogram1D* histo, const std::size_t width = 80, const std::size_t height = 50, const bool errors = false ); - // ====================================================================== - /** dump the text representation of 1D-profile - * @param histo (INPUT) the 1D-profile - * @param stream (OUTUT) the stream - * @param width (INPUT) the maximal column width - * @param height (INPUT) the proposed column height - * @param spread (INPUT) print/plot spread/rms ? - * @return the stream - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2009-09-19 - */ - GAUDI_API - std::ostream& histoDump_( const AIDA::IProfile1D* histo, std::ostream& stream, const std::size_t width = 80, - const std::size_t height = 50, const bool spread = true ); - // ==================================================================== + /** dump the text representation of the 1D-profile * @param histo (INPUT) the histogram * @param width (INPUT) the maximal column width @@ -90,21 +51,7 @@ namespace Gaudi { GAUDI_API std::string histoDump( const AIDA::IProfile1D* histo, const std::size_t width = 80, const std::size_t height = 50, const bool spread = true ); - // ====================================================================== - /** dump the text representation of the Profile - * @param histo (INPUT) the histogram - * @param stream (OUTUT) the stream - * @param width (INPUT) the maximal column width - * @param height (INPUT) the proposed coulmn height - * @param spread (INPUT) print/plot rms versus erorr - * @return the stream - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2009-09-19 - */ - GAUDI_API - std::ostream& histoDump_( const TProfile* histo, std::ostream& stream, const std::size_t width = 80, - const std::size_t height = 50 ); - // ==================================================================== + /** dump the text representation of the histogram * @param histo (INPUT) the histogram * @param width (INPUT) the maximal column width @@ -116,21 +63,7 @@ namespace Gaudi { */ GAUDI_API std::string histoDump( const TProfile* histo, const std::size_t width = 80, const std::size_t height = 50 ); - // ==================================================================== - /** dump the text representation of the histogram - * @param histo (INPUT) the histogram - * @param stream (OUTUT) the stream - * @param width (INPUT) the maximal column width - * @param height (INPUT) the proposed coulmn height - * @param errors (INPUT) print/plot errors - * @return the stream - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2009-09-19 - */ - GAUDI_API - std::ostream& histoDump_( const TH1* histo, std::ostream& stream, const std::size_t width = 80, - const std::size_t height = 50, const bool errors = false ); - // ==================================================================== + /** dump the text representation of the histogram * @param histo (INPUT) the histogram * @param width (INPUT) the maximal column width @@ -143,13 +76,8 @@ namespace Gaudi { GAUDI_API std::string histoDump( const TH1* histo, const std::size_t width = 80, const std::size_t height = 50, const bool errors = false ); - // ====================================================================== } // namespace Histos - // ======================================================================== + } // namespace Utils - // ========================================================================== + } // end of namespace Gaudi -// ============================================================================ -// The END -// ============================================================================ -#endif // GAUDIUTILS_HISTODUMP_H diff --git a/GaudiUtils/src/Lib/HistoDump.cpp b/GaudiUtils/src/Lib/HistoDump.cpp index c222767a94666aa647fc8f53d7457905cee90a2f..d66e87a1dfba3880ce1808f3fd765ef398b0afbe 100644 --- a/GaudiUtils/src/Lib/HistoDump.cpp +++ b/GaudiUtils/src/Lib/HistoDump.cpp @@ -12,9 +12,6 @@ // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits // TODO: To be removed, since it comes from ROOT TMathBase.h # pragma warning( disable : 2259 ) -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// The comparison are meant -# pragma warning( disable : 1572 ) #endif #ifdef WIN32 // Disable warning @@ -44,6 +41,12 @@ // ============================================================================ namespace { + + // idea coming from The art of computer programming by Knuth + constexpr bool essentiallyEqual( double const a, double const b ) { + return std::abs( a - b ) <= std::min( std::abs( a ), std::abs( b ) ) * std::numeric_limits<double>::epsilon(); + } + // ========================================================================== /** @struct Histo * helper structure to keep the representation of the histogram @@ -255,10 +258,10 @@ namespace { * @date 2009-09-19 */ std::pair<double, int> decompose( double v ) { - if ( 0 == v ) { + if ( abs( v ) < std::numeric_limits<double>::epsilon() ) { return { 0.0, 0 }; } // RETURN - else if ( 1 == v ) { + else if ( essentiallyEqual( 1.0, v ) ) { return { 1.0, 0 }; } // RETURN else if ( 0 > v ) { @@ -302,12 +305,7 @@ namespace { * @date 2009-09-19 */ inline double rValMax( double v ) { - if ( 0 == v ) { - return 0; - } // RETURN - else if ( 0 > v ) { - return -1 * rValMin( -v ); - } // RETURN + if ( 0 > v ) { return -1 * rValMin( -v ); } // RETURN // decompose the double value into decimal significand and mantissa std::pair<double, int> r = decompose( v ); // @@ -321,12 +319,7 @@ namespace { * @date 2009-09-19 */ inline double rValMin( double v ) { - if ( 0 == v ) { - return 0; - } // RETURN - else if ( 0 > v ) { - return -1 * rValMax( -v ); - } // RETURN + if ( 0 > v ) { return -1 * rValMax( -v ); } // RETURN // decompose the double value into decimal significand and mantissa std::pair<double, int> r = decompose( v ); const double f = std::floor( 20 * r.first ) / 2; // - 1 ; @@ -373,8 +366,8 @@ namespace { * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl * @date 2009-09-19 */ - std::ostream& dumpText( const Histo& histo, const std::size_t width, const std::size_t height, const bool errors, - std::ostream& stream ) { + std::ostringstream& dumpText( const Histo& histo, const std::size_t width, const std::size_t height, + const bool errors, std::ostringstream& stream ) { if ( 40 > width ) { return dumpText( histo, 40, height, errors, stream ); } if ( 200 < width ) { return dumpText( histo, 200, height, errors, stream ); } if ( 150 < height ) { return dumpText( histo, width, 150, errors, stream ); } @@ -392,7 +385,7 @@ namespace { double yMax = std::max( rValMax( histo.maxY( errors ) ), 0.0 ); double yMin = std::min( rValMin( histo.minY( errors ) ), 0.0 ); - if ( yMin == yMax ) { yMax = yMin + 1; } + if ( essentiallyEqual( yMin, yMax ) ) { yMax = yMin + 1; } /// try to define the proper "Y-binning" std::pair<double, int> r = decompose( yMax - yMin ); double _ny = std::ceil( 10 * r.first ); // 1 <= ny < 10 @@ -556,25 +549,27 @@ namespace { return stream; // RETURN } } // namespace + // ============================================================================ /* dump the text representation of the histogram - * @param histo (INPUT) the histogram - * @param stream (OUTUT) the stream - * @param width (INPUT) the maximal column width + * @param histo the histogram + * @param stream the stream + * @param width the maximal column width * @param height (INPUT) the proposed coulmn height * @param errors (INPUT) print/plot errors - * @return the stream + * @param erorrs print/plot errors * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl * @date 2009-09-19 */ // ============================================================================ -std::ostream& Gaudi::Utils::Histos::histoDump_( const AIDA::IHistogram1D* histo, std::ostream& stream, - const std::size_t width, const std::size_t height, const bool errors ) { +std::string Gaudi::Utils::Histos::histoDump( const AIDA::IHistogram1D* histo, const std::size_t width, + const std::size_t height, const bool errors ) { + std::ostringstream stream; stream << std::endl; - if ( !histo ) { return stream; } // RETURN + if ( !histo ) { return stream.str(); } // RETURN Histo hist; StatusCode sc = _getHisto( histo, hist ); - if ( sc.isFailure() ) { return stream; } // RETURN + if ( sc.isFailure() ) { return stream.str(); } // RETURN stream << fmt::format( R"( Histo TES : "{}" Histo Title : "{}" @@ -607,45 +602,25 @@ std::ostream& Gaudi::Utils::Histos::histoDump_( const AIDA::IHistogram1D* histo, stream << '\n'; } - return dumpText( hist, width, height, errors, stream ); + return dumpText( hist, width, height, errors, stream ).str(); } -// ============================================================================ -/* dump the text representation of the histogram + +/* dump the text representation of the 1D-profile * @param histo the histogram * @param stream the stream * @param width the maximal column width * @param height (INPUT) the proposed coulmn height - * @param errors (INPUT) print/plot errors - * @param erorrs print/plot errors * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl * @date 2009-09-19 */ -// ============================================================================ -std::string Gaudi::Utils::Histos::histoDump( const AIDA::IHistogram1D* histo, const std::size_t width, - const std::size_t height, const bool errors ) { +std::string Gaudi::Utils::Histos::histoDump( const AIDA::IProfile1D* histo, const std::size_t width, + const std::size_t height, const bool spread ) { std::ostringstream stream; - histoDump_( histo, stream, width, height, errors ); - return stream.str(); -} -// ============================================================================ -/* dump the text representation of the 1D-profile - * @param histo (INPUT) the profile - * @param stream (OUTUT) the stream - * @param width (INPUT) the maximal column width - * @param height (INPUT) the proposed coulmn height - * @param spread (INPUT) plot spread/error? - * @return the stream - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2009-09-19 - */ -// ============================================================================ -std::ostream& Gaudi::Utils::Histos::histoDump_( const AIDA::IProfile1D* histo, std::ostream& stream, - const std::size_t width, const std::size_t height, const bool spread ) { stream << std::endl; - if ( !histo ) { return stream; } // RETURN + if ( !histo ) { return stream.str(); } // RETURN Histo hist; StatusCode sc = _getHisto( histo, hist, spread ); - if ( sc.isFailure() ) { return stream; } // RETURN + if ( sc.isFailure() ) { return stream.str(); } // RETURN stream << fmt::format( R"( Histo TES : "{}" Histo Title : "{}" @@ -673,45 +648,28 @@ std::ostream& Gaudi::Utils::Histos::histoDump_( const AIDA::IProfile1D* histo, s stream << std::endl; } - return dumpText( hist, width, height, true, stream ); + return dumpText( hist, width, height, true, stream ).str(); } -// ============================================================================ -/* dump the text representation of the 1D-profile - * @param histo the histogram - * @param stream the stream - * @param width the maximal column width - * @param height (INPUT) the proposed coulmn height - * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl - * @date 2009-09-19 - */ -// ============================================================================ -std::string Gaudi::Utils::Histos::histoDump( const AIDA::IProfile1D* histo, const std::size_t width, - const std::size_t height, const bool spread ) { - std::ostringstream stream; - histoDump_( histo, stream, width, height, spread ); - return stream.str(); -} -// ============================================================================ + /* dump the text representation of the histogram * @param histo (INPUT) the histogram - * @param stream (OUTUT) the stream * @param width (INPUT) the maximal column width * @param errors (INPUT) print/plot errors - * @return the stream + * @return string representation of the histogram * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl * @date 2009-09-19 */ -// ============================================================================ -std::ostream& Gaudi::Utils::Histos::histoDump_( const TH1* histo, std::ostream& stream, const std::size_t width, - const std::size_t height, const bool errors ) { +std::string Gaudi::Utils::Histos::histoDump( const TH1* histo, const std::size_t width, const std::size_t height, + const bool errors ) { const TProfile* profile = dynamic_cast<const TProfile*>( histo ); - if ( profile ) { return histoDump_( profile, stream, width, height ); } + if ( profile ) { return histoDump( profile, width, height ); } // + std::ostringstream stream; stream << std::endl; - if ( !histo ) { return stream; } // RETURN + if ( !histo ) { return stream.str(); } // RETURN Histo hist; StatusCode sc = _getHisto( histo, hist ); - if ( sc.isFailure() ) { return stream; } // RETURN + if ( sc.isFailure() ) { return stream.str(); } // RETURN stream << fmt::format( R"( Histo Name : "{}" Histo Title : "{}" @@ -732,26 +690,25 @@ std::ostream& Gaudi::Utils::Histos::histoDump_( const TH1* histo, std::ostream& histo->GetBinContent( histo->GetNbinsX() + 1 ), histo->GetEffectiveEntries(), histo->Integral() ); - return dumpText( hist, width, height, errors, stream ); + return dumpText( hist, width, height, errors, stream ).str(); } -// ============================================================================ + /* dump the text representation of the histogram * @param histo (INPUT) the histogram - * @param stream (OUTUT) the stream * @param width (INPUT) the maximal column width * @param errors (INPUT) print/plot errors - * @return the stream + * @return string representation of the histogram * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl * @date 2009-09-19 */ -// ============================================================================ -std::ostream& Gaudi::Utils::Histos::histoDump_( const TProfile* histo, std::ostream& stream, const std::size_t width, - const std::size_t height ) { +std::string Gaudi::Utils::Histos::histoDump( const TProfile* histo, const std::size_t width, + const std::size_t height ) { + std::ostringstream stream; stream << std::endl; - if ( !histo ) { return stream; } // RETURN + if ( !histo ) { return stream.str(); } // RETURN Histo hist; StatusCode sc = _getHisto( histo, hist, true ); - if ( sc.isFailure() ) { return stream; } // RETURN + if ( sc.isFailure() ) { return stream.str(); } // RETURN stream << fmt::format( R"( Profile Name : "{}" Profile Title : "{}" @@ -769,42 +726,5 @@ std::ostream& Gaudi::Utils::Histos::histoDump_( const TProfile* histo, std::ostr histo->GetEntries(), histo->GetBinContent( 0 ), histo->GetBinContent( histo->GetNbinsX() + 1 ), histo->Integral() ); - return dumpText( hist, width, height, true, stream ); + return dumpText( hist, width, height, true, stream ).str(); } -// ============================================================================ -/* dump the text representation of the histogram - * @param histo (INPUT) the histogram - * @param width (INPUT) the maximal column width - * @param errors (INPUT) print/plot errors - * @return string representation of the histogram - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2009-09-19 - */ -// ============================================================================ -std::string Gaudi::Utils::Histos::histoDump( const TH1* histo, const std::size_t width, const std::size_t height, - const bool errors ) { - std::ostringstream stream; - histoDump_( histo, stream, width, height, errors ); - return stream.str(); -} -// ============================================================================ -/* dump the text representation of the histogram - * @param histo (INPUT) the histogram - * @param width (INPUT) the maximal column width - * @param errors (INPUT) print/plot errors - * @return string representation of the histogram - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2009-09-19 - */ -// ============================================================================ -std::string Gaudi::Utils::Histos::histoDump( const TProfile* histo, const std::size_t width, - const std::size_t height ) { - std::ostringstream stream; - histoDump_( histo, stream, width, height ); - return stream.str(); -} -// ============================================================================ - -// ============================================================================ -// The END -// ============================================================================ diff --git a/GaudiUtils/src/Lib/HistoStats.cpp b/GaudiUtils/src/Lib/HistoStats.cpp index 21f4c99e679e3694c45538a42be9d89acbe78103..c88e6cd45aff5700c828b4cae69ff40134750255 100644 --- a/GaudiUtils/src/Lib/HistoStats.cpp +++ b/GaudiUtils/src/Lib/HistoStats.cpp @@ -8,13 +8,6 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \***********************************************************************************/ -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// The comparisons are meant -# pragma warning( disable : 1572 ) -#endif -// ============================================================================ -// Include files // ============================================================================ // STD & STL // ============================================================================ @@ -99,7 +92,7 @@ namespace { weight += yBin; result += yBin * std::pow( xBin - value, order ); } - if ( 0 != weight ) { result /= weight; } + if ( weight > std::numeric_limits<double>::epsilon() ) { result /= weight; } return result; } // ============================================================================ @@ -282,9 +275,8 @@ namespace { double _overflowIntegralFrac( const HISTO* histo ) { if ( !histo ) { return s_bad; } // RETURN const auto overflow = histo->binHeight( AIDA::IAxis::OVERFLOW_BIN ); - if ( 0 == overflow ) { return 0; } // RETURN - const auto all = histo->sumAllBinHeights(); - if ( 0 == all ) { return 0; } // "CONVENTION?" RETURN + const auto all = histo->sumAllBinHeights(); + if ( all < std::numeric_limits<double>::epsilon() ) { return 0; } // "CONVENTION?" RETURN // return (double)overflow / (double)all; } @@ -295,9 +287,8 @@ namespace { double _underflowIntegralFrac( const HISTO* histo ) { if ( !histo ) { return s_bad; } // RETURN const auto underflow = histo->binHeight( AIDA::IAxis::UNDERFLOW_BIN ); - if ( 0 == underflow ) { return 0; } // RETURN - const auto all = histo->sumAllBinHeights(); - if ( 0 == all ) { return 0; } // "CONVENTION?" RETURN + const auto all = histo->sumAllBinHeights(); + if ( all < std::numeric_limits<double>::epsilon() ) { return 0; } // "CONVENTION?" RETURN // return (double)underflow / (double)all; } @@ -345,7 +336,7 @@ namespace { if ( !histo ) { return s_bad; } // RETURN // const auto all = histo->sumAllBinHeights(); - if ( 0 == all ) { return s_bad; } // RETURN + if ( all < std::numeric_limits<double>::epsilon() ) { return s_bad; } // RETURN const auto overflow = histo->binHeight( AIDA::IAxis::OVERFLOW_BIN ); const auto oErr = histo->binError( AIDA::IAxis::OVERFLOW_BIN ); if ( 0 > oErr ) { return s_bad; } // RETURN @@ -366,7 +357,7 @@ namespace { if ( !histo ) { return s_bad; } // RETURN // const auto all = histo->sumAllBinHeights(); - if ( 0 == all ) { return s_bad; } // RETURN + if ( all < std::numeric_limits<double>::epsilon() ) { return s_bad; } // RETURN const auto underflow = histo->binHeight( AIDA::IAxis::UNDERFLOW_BIN ); const auto oErr = histo->binError( AIDA::IAxis::UNDERFLOW_BIN ); if ( 0 > oErr ) { return s_bad; } // RETURN diff --git a/PartPropSvc/src/PartPropSvc.cpp b/PartPropSvc/src/PartPropSvc.cpp index 56bcd11e2ab20840d1aa93c77c2af7e8c114cc3a..9d32155726db77e28e049eb9a1cb7ba1f9837033 100644 --- a/PartPropSvc/src/PartPropSvc.cpp +++ b/PartPropSvc/src/PartPropSvc.cpp @@ -8,12 +8,6 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \***********************************************************************************/ -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// TODO: should be removed because come from HepPDT -# pragma warning( disable : 1572 ) -#endif - // Include files #include "GaudiKernel/ISvcLocator.h" #include "GaudiKernel/MsgStream.h" diff --git a/RootHistCnv/src/RCWNTupleCnv.cpp b/RootHistCnv/src/RCWNTupleCnv.cpp index 7b023cf3139666eee5ff2b69124c0963cb79abe2..c3c6a099e90cc89144ddf2676270630c121e661b 100644 --- a/RootHistCnv/src/RCWNTupleCnv.cpp +++ b/RootHistCnv/src/RCWNTupleCnv.cpp @@ -121,13 +121,8 @@ namespace { } if ( it->hasIndex() || it->length() > 1 ) { desc += ']'; } - if ( it->range().lower() != it->range().min() && it->range().upper() != it->range().max() ) { - lowerRange = it->range().lower(); - upperRange = it->range().upper(); - } else { - lowerRange = 0; - upperRange = -1; - } + lowerRange = it->range().lower(); + upperRange = it->range().upper(); desc += typ; size += item_size * dimension; } @@ -340,17 +335,12 @@ StatusCode RootHistCnv::RCWNTupleCnv::load( TTree* tree, INTuple*& refpObject ) int itemSize; item = nullptr; - // TLeaf* tl = (TLeaf*)tobj; TLeaf* tl = dynamic_cast<TLeaf*>( tobj ); - if ( tl ) { - itemName = tl->GetName(); - } else { + if ( !tl ) { log << MSG::ERROR << "cannot dynamic cast to TLeaf" << endmsg; + return StatusCode::FAILURE; } - - // char* buf_pos = (char*)tl->GetValuePointer(); - // cout << " " << itemName << " " << blockName << " " - // << (void*)buf_pos; + itemName = tl->GetName(); if ( blockName != "" ) { log << MSG::DEBUG << "loading NTuple item " << blockName << "/" << itemName; @@ -359,15 +349,14 @@ StatusCode RootHistCnv::RCWNTupleCnv::load( TTree* tree, INTuple*& refpObject ) } int arraySize{ 0 }; - TLeaf* indexLeaf = ( tl ? tl->GetLeafCounter( arraySize ) : nullptr ); + TLeaf* indexLeaf = tl->GetLeafCounter( arraySize ); if ( arraySize == 0 ) { log << MSG::ERROR << "TLeaf counter size = 0. This should not happen!" << endmsg; } if ( indexLeaf ) { // index Arrays and Matrices - indexName = indexLeaf->GetName(); - // indexRange = tl->GetNdata(); + indexName = indexLeaf->GetName(); indexRange = indexLeaf->GetMaximum(); itemSize = indexRange * tl->GetLenType() * arraySize; @@ -392,9 +381,6 @@ StatusCode RootHistCnv::RCWNTupleCnv::load( TTree* tree, INTuple*& refpObject ) log << endmsg; - // cout << " index: " << indexName << endl; - - // size = tl->GetNdata() * tl->GetLenType(); size = itemSize; totsize += size; @@ -414,7 +400,7 @@ StatusCode RootHistCnv::RCWNTupleCnv::load( TTree* tree, INTuple*& refpObject ) max = tli->GetMaximum(); } - item = createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup ); + item = createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup, hasRange ); } else { long min = 0, max = 0; if ( hasRange ) { @@ -422,7 +408,7 @@ StatusCode RootHistCnv::RCWNTupleCnv::load( TTree* tree, INTuple*& refpObject ) max = tli->GetMaximum(); } - item = createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup ); + item = createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup, hasRange ); } } else { log << MSG::ERROR << "cannot dynamic cast to TLeafI" << endmsg; @@ -442,7 +428,7 @@ StatusCode RootHistCnv::RCWNTupleCnv::load( TTree* tree, INTuple*& refpObject ) log << MSG::ERROR << "cannot dynamic cast to TLeafF" << endmsg; } - item = createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup ); + item = createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup, hasRange ); // Double } else if ( tobj->IsA()->InheritsFrom( "TLeafD" ) ) { @@ -458,7 +444,7 @@ StatusCode RootHistCnv::RCWNTupleCnv::load( TTree* tree, INTuple*& refpObject ) log << MSG::ERROR << "cannot dynamic cast to TLeafD" << endmsg; } - item = createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup ); + item = createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup, hasRange ); } else { log << MSG::ERROR << "Uknown data type" << endmsg; diff --git a/RootHistCnv/src/RNTupleCnv.cpp b/RootHistCnv/src/RNTupleCnv.cpp index 40bdfe052573727e9ac1d44c1609a5dfedd0d4be..2e3a066e8e1290d44dbf35e1028b2c89e4c6d0f4 100644 --- a/RootHistCnv/src/RNTupleCnv.cpp +++ b/RootHistCnv/src/RNTupleCnv.cpp @@ -25,12 +25,6 @@ // Root #include "TTree.h" -#ifdef __ICC -// disable icc remark #1572: floating-point equality and inequality comparisons are unreliable -// they are intended -# pragma warning( disable : 1572 ) -#endif - //----------------------------------------------------------------------------- // // Implementation of class : RootHistCnv::RNTupleCnv @@ -263,13 +257,13 @@ bool RootHistCnv::parseName( const std::string& full, std::string& blk, std::str #define INSTANTIATE( TYP ) \ template INTupleItem* createNTupleItem<TYP>( std::string itemName, std::string blockName, std::string index_name, \ int indexRange, int arraySize, TYP minimum, TYP maximum, \ - INTuple* tuple ) + INTuple* tuple, bool hasRange ) namespace RootHistCnv { template <class TYP> INTupleItem* createNTupleItem( std::string itemName, std::string blockName, std::string indexName, int indexRange, - int arraySize, TYP min, TYP max, INTuple* ntup ) { + int arraySize, TYP min, TYP max, INTuple* ntup, bool hasRange ) { std::string varName; if ( blockName != "" ) { @@ -281,7 +275,7 @@ namespace RootHistCnv { TYP null = 0; INTupleItem* col = nullptr; - if ( min == 0 && max == 0 ) { + if ( !hasRange ) { min = NTuple::Range<TYP>::min(); max = NTuple::Range<TYP>::max(); } diff --git a/RootHistCnv/src/RNTupleCnv.h b/RootHistCnv/src/RNTupleCnv.h index 3451a1b5a6667232a8c87f72bce84c26028e79bb..97632e9904d21bfc8c37993b74fa2203de624e14 100644 --- a/RootHistCnv/src/RNTupleCnv.h +++ b/RootHistCnv/src/RNTupleCnv.h @@ -69,7 +69,7 @@ namespace RootHistCnv { /// Add an item of a given type to the N tuple template <class TYP> INTupleItem* createNTupleItem( std::string itemName, std::string blockName, std::string indexName, int indexRange, - int arraySize, TYP minimum, TYP maximum, INTuple* tuple ); + int arraySize, TYP minimum, TYP maximum, INTuple* tuple, bool hasRange ); bool parseName( const std::string& full, std::string& blk, std::string& var );