Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:34

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 ISEQUENCERTIMERTOOL_H
0012 #define ISEQUENCERTIMERTOOL_H 1
0013 
0014 // from Gaudi
0015 #include "GaudiKernel/IAlgTool.h"
0016 
0017 /** @class ISequencerTimerTool ISequencerTimerTool.h
0018  *  Implements the time measurement inside a sequencer
0019  *
0020  *  @author Olivier Callot
0021  *  @date   2004-05-19
0022  */
0023 
0024 class GAUDI_API ISequencerTimerTool : public virtual IAlgTool {
0025 
0026 public:
0027   using IAlgTool::name;
0028   using IAlgTool::start;
0029   using IAlgTool::stop;
0030 
0031 public:
0032   /// InterfaceID
0033   DeclareInterfaceID( ISequencerTimerTool, 3, 0 );
0034 
0035   /** add a timer entry with the specified name **/
0036   virtual int addTimer( const std::string& name ) = 0;
0037 
0038   /** Increase the indentation of the name **/
0039   virtual void increaseIndent() = 0;
0040 
0041   /** Decrease the indentation of the name **/
0042   virtual void decreaseIndent() = 0;
0043 
0044   /** start the counter, i.e. register the current time **/
0045   virtual void start( int index ) = 0;
0046 
0047   /** stop the counter, return the elapsed time **/
0048   virtual double stop( int index ) = 0;
0049 
0050   /** returns the name of the counter **/
0051   virtual const std::string& name( int index ) = 0;
0052 
0053   /** returns the last measured time time **/
0054   virtual double lastTime( int index ) = 0;
0055 
0056   /** returns the index of the counter with that name, or -1 **/
0057   virtual int indexByName( const std::string& name ) = 0;
0058 
0059   /** returns the flag telling that global timing is wanted **/
0060   virtual bool globalTiming() = 0;
0061 
0062   /** prepares and saves the timing histograms **/
0063   virtual void saveHistograms() = 0;
0064 
0065   /**
0066    * * @brief Start timer by index. The timer stops on destruction of returned object.
0067    *
0068    *       * @param index: index in list of timers.
0069    *       * @param enable: only if true actually perform any timing
0070    *       * @return opaque type whose scope determines what is timed
0071    */
0072   [[nodiscard]] auto scopedTimer( int index, bool enable = true ) {
0073     class Ret {
0074       ISequencerTimerTool* tool;
0075       int                  index;
0076 
0077     public:
0078       Ret( ISequencerTimerTool* tool, int index ) : tool{ tool }, index{ index } {
0079         if ( tool ) tool->start( index );
0080       }
0081       ~Ret() { reset(); }
0082       void reset() {
0083         if ( tool ) tool->stop( index );
0084       }
0085     };
0086     return Ret{ enable ? this : nullptr, index };
0087   }
0088 };
0089 
0090 #endif // ISEQUENCERTIMERTOOL_H