Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:00:28

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_CHRONO_H
0012 #define GAUDIKERNEL_CHRONO_H
0013 // ============================================================================
0014 // Include files
0015 // ============================================================================
0016 // STD& STL
0017 // ============================================================================
0018 #include <string>
0019 // ============================================================================
0020 // GaudiKernel
0021 // ============================================================================
0022 #include "GaudiKernel/ChronoEntity.h"
0023 #include "GaudiKernel/IChronoSvc.h"
0024 #include "GaudiKernel/Kernel.h"
0025 // ============================================================================
0026 /** @class Chrono GaudiKernel/Chrono.h
0027  *
0028  * A small utility class for chronometry of user codes
0029  * @see  ChronoEntity
0030  * @see IChronoSvc
0031  *
0032  * @author Vanya Belyaev
0033  * @date    Nov 26, 1999
0034  */
0035 class GAUDI_API Chrono {
0036 public:
0037   // =========================================================================
0038   /** Constructor from Chrono Service and the tag
0039    *
0040    *  @code
0041    *
0042    *  IChronoSvc* svc = ... ;
0043    *
0044    *  { // start the scope
0045    *    Chrono chrono ( svc , "some unique tag here" ) ;
0046    *
0047    *    for ( long i = 0 ; i < 10000000 ; ++i )
0048    *     {
0049    *        .. put some CPU-intensive computations here
0050    *     }
0051    *
0052    *  } // end of the scope, destroy chrono
0053    *
0054    *  @endcode
0055    *
0056    *  @param svc pointer to Chrono Service
0057    *  @param tag the unique tag
0058    */
0059   Chrono( IChronoSvc*        svc = nullptr,            // the service
0060           const std::string& tag = "CHRONO::UNNAMED" ) // the unique tag/name
0061   {
0062     if ( svc ) { m_chrono = svc->chronoStart( tag ); }
0063   }
0064 
0065   // =========================================================================
0066   /** Move Constructor
0067    **/
0068 
0069   Chrono( Chrono&& rhs ) {
0070     m_chrono     = rhs.m_chrono;
0071     rhs.m_chrono = nullptr;
0072   }
0073 
0074   // =========================================================================
0075   /** Constructor from Chrono Service and the tag
0076    *
0077    *  @code
0078    *
0079    *  IChronoSvc* svc = ... ;
0080    *
0081    *  { // start the scope
0082    *    Chrono chrono ( "some unique tag here" , svc ) ;
0083    *
0084    *    for ( long i = 0 ; i < 10000000 ; ++i )
0085    *     {
0086    *        .. put some CPU-intensive computations here
0087    *     }
0088    *
0089    *  } // end of the scope, destroy chrono
0090    *
0091    *  @endcode
0092    *
0093    *  @param tag the unique tag
0094    *  @param svc pointer to Chrono Service
0095    */
0096   Chrono( const std::string& tag, // the unique tag/name
0097           IChronoSvc*        svc )       // the service
0098   {
0099     if ( svc ) { m_chrono = svc->chronoStart( tag ); }
0100   }
0101   // =========================================================================
0102   /** Constructor from Chrono Object/Entity
0103    *
0104    *  @code
0105    *
0106    *  ChronoEntity* chronometer = ... ;
0107    *
0108    *  { // start the scope
0109    *    Chrono chrono ( chronometer ) ;
0110    *
0111    *    for ( long i = 0 ; i < 10000000 ; ++i )
0112    *     {
0113    *        .. put some CPU-intensive computations here
0114    *     }
0115    *
0116    *  } // end of the scope, destroy chrono
0117    *
0118    *  @endcode
0119    *
0120    *  @param c the pointer to Chrono Object/Entity
0121    */
0122   Chrono( ChronoEntity* c ) : m_chrono( c ) {
0123     if ( m_chrono ) { m_chrono->start(); }
0124   }
0125   // =========================================================================
0126   /** Constructor from Chrono Object/Entity
0127    *
0128    *  @code
0129    *
0130    *  ChronoEntity m_chrono = ... ;
0131    *
0132    *  { // start the scope
0133    *    Chrono chrono ( m_chrono ) ;
0134    *
0135    *    for ( long i = 0 ; i < 10000000 ; ++i )
0136    *     {
0137    *        .. put some CPU-intensive computations here
0138    *     }
0139    *
0140    *  } // end of the scope, destroy chrono
0141    *
0142    *  @endcode
0143    *
0144    *  @param c the reference to Chrono Object/Entity
0145    */
0146   Chrono( ChronoEntity& c ) : m_chrono( &c ) { m_chrono->start(); }
0147   // =========================================================================
0148   /// Destructor , stop the chrono
0149   ~Chrono() {
0150     if ( m_chrono ) { m_chrono->stop(); }
0151   }
0152   // =========================================================================
0153 private:
0154   // =========================================================================
0155   /// delete the copy constructor and assignment operators
0156   Chrono( const Chrono& )            = delete;
0157   Chrono& operator=( const Chrono& ) = delete;
0158   // =========================================================================
0159 private:
0160   // ==========================================================================
0161   /// The actual chronometer
0162   ChronoEntity* m_chrono = nullptr; // The actual chronometer
0163   // ==========================================================================
0164 };
0165 // ============================================================================
0166 // The END
0167 // ============================================================================
0168 #endif //  GAUDIKERNEL_CHRONO_H