00001 // @(#)root/tmva $Id: Timer.h 31458 2009-11-30 13:58:20Z stelzer $ 00002 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss 00003 00004 /********************************************************************************** 00005 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis * 00006 * Package: TMVA * 00007 * Class : Timer * 00008 * Web : http://tmva.sourceforge.net * 00009 * * 00010 * Description: * 00011 * Timing information for methods training * 00012 * * 00013 * Authors (alphabetical): * 00014 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland * 00015 * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland * 00016 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany * 00017 * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada * 00018 * * 00019 * Copyright (c) 2006: * 00020 * CERN, Switzerland * 00021 * MPI-K Heidelberg, Germany * 00022 * * 00023 * Redistribution and use in source and binary forms, with or without * 00024 * modification, are permitted according to the terms listed in LICENSE * 00025 * (http://tmva.sourceforge.net/LICENSE) * 00026 **********************************************************************************/ 00027 00028 #ifndef ROOT_TMVA_Timer 00029 #define ROOT_TMVA_Timer 00030 00031 ////////////////////////////////////////////////////////////////////////// 00032 // // 00033 // Timer // 00034 // // 00035 // Timing information for training and evaluation of MVA methods // 00036 // // 00037 ////////////////////////////////////////////////////////////////////////// 00038 00039 #ifndef ROOT_time 00040 #include "time.h" 00041 #endif 00042 #ifndef ROOT_TString 00043 #include "TString.h" 00044 #endif 00045 #ifndef ROOT_TStopwatch 00046 #include "TStopwatch.h" 00047 #endif 00048 00049 // ensure that clock_t is always defined 00050 #if defined(__SUNPRO_CC) && defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 == 500 ) 00051 #ifndef _CLOCK_T 00052 #define _CLOCK_T 00053 typedef long clock_t; // relative time in a specified resolution 00054 #endif /* ifndef _CLOCK_T */ 00055 00056 #endif // SUN and XOPENSOURCE=500 00057 00058 namespace TMVA { 00059 00060 class MsgLogger; 00061 00062 class Timer : public TStopwatch { 00063 00064 public: 00065 00066 Timer( const char* prefix = "", Bool_t colourfulOutput = kTRUE ); 00067 Timer( Int_t ncounts, const char* prefix = "", Bool_t colourfulOutput = kTRUE ); 00068 virtual ~Timer( void ); 00069 00070 void Init ( Int_t ncounts ); 00071 void Reset( void ); 00072 00073 // when the "Scientific" flag set, time is returned with subdecimals 00074 // for algorithm timing measurement 00075 TString GetElapsedTime ( Bool_t Scientific = kTRUE ); 00076 Double_t ElapsedSeconds ( void ); 00077 TString GetLeftTime ( Int_t icounts ); 00078 void DrawProgressBar( Int_t, const TString& comment = "" ); 00079 void DrawProgressBar( TString ); 00080 void DrawProgressBar( void ); 00081 00082 private: 00083 00084 TString SecToText ( Double_t, Bool_t ) const; 00085 00086 Int_t fNcounts; // reference number of "counts" 00087 TString fPrefix; // prefix for outputs 00088 Bool_t fColourfulOutput; // flag for use of colors 00089 00090 static const TString fgClassName; // used for output 00091 static const Int_t fgNbins; // number of bins in progress bar 00092 00093 mutable MsgLogger* fLogger; // the output logger 00094 MsgLogger& Log() const { return *fLogger; } 00095 00096 ClassDef(Timer,0) // Timing information for training and evaluation of MVA methods 00097 }; 00098 00099 } // namespace 00100 00101 #endif