Back to home page

EIC code displayed by LXR

 
 

    


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

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 GAUDI_LOCKEDCHRONO_H
0012 #define GAUDI_LOCKEDCHRONO_H 1
0013 // ===========================================================================
0014 // Include files
0015 // ===========================================================================
0016 // GaudiKernel
0017 // ===========================================================================
0018 #include "GaudiKernel/ChronoEntity.h"
0019 // ===========================================================================
0020 namespace Gaudi {
0021   // =========================================================================
0022   namespace Utils {
0023     // =======================================================================
0024     /** @class LockedChrono
0025      *
0026      *  Helper object, useful for measurement of CPU-performance
0027      *  of highly-recursive structures, e.g. Data-On-Demand service,
0028      *  complex algorithms, etc...
0029      *
0030      *  @code
0031      *
0032      *  class MyClass ...
0033      *  {
0034      *
0035      *  public:
0036      *
0037      *  void doSomethingRecursive() const
0038      *    {
0039      *      ...
0040      *      LockedChrono timer ( m_chrono , m_lock ) ;
0041      *      ...
0042      *      // some direct or indirect recursive call:
0043      *      if ( ... ) { doSomethingRecursive () ; }
0044      *      ...
0045      *    }
0046      *
0047      *  private:
0048      *
0049      *     /// the lock
0050      *     mutable bool         m_lock   ;    // lock
0051      *     /// the actual timer
0052      *     mutable ChronoEntity m_chrono ;    // actual timer
0053      *
0054      *  };
0055      *  @endcode
0056      *
0057      *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
0058      *  @date   2009-08-10
0059      */
0060     class LockedChrono {
0061     public:
0062       // ======================================================================
0063       /// constructor from the actual timer: start the timer
0064       LockedChrono( ChronoEntity& c, bool& lock ) : m_timer( c ), m_locker( lock ) {
0065         if ( !lock ) {
0066           m_timer.start();
0067           m_locker = true;
0068           m_locked = true;
0069         }
0070       }
0071       /// destructor:
0072       ~LockedChrono() {
0073         if ( m_locked ) {
0074           m_timer.stop();
0075           m_locker = false;
0076         }
0077       }
0078       // ======================================================================
0079       /// no default constructor
0080       LockedChrono() = delete;
0081       // ======================================================================
0082     private:
0083       // ======================================================================
0084       /// the actual timer
0085       ChronoEntity& m_timer; // the actual timer
0086       /// the actual locker
0087       bool& m_locker; // the actual locker
0088       /// locked ?
0089       bool m_locked = false; //          locked ?
0090       // ======================================================================
0091     };
0092     // ========================================================================
0093   } // namespace Utils
0094   // ==========================================================================
0095 } //                                                     end of namespace Gaudi
0096 // ============================================================================
0097 // The END
0098 // ============================================================================
0099 #endif // GAUDI_LOCKEDCHRONO_H