#include "TMVA/Timer.h"
#include "Riostream.h"
#ifndef ROOT_TMVA_Config
#include "TMVA/Config.h"
#endif
#ifndef ROOT_TMVA_Tools
#include "TMVA/Tools.h"
#endif
const TString TMVA::Timer::fgClassName = "Timer";
const Int_t   TMVA::Timer::fgNbins     = 24;  
using TMVA::Tools::Color;
ClassImp(TMVA::Timer)
TMVA::Timer::Timer( const char* prefix, Bool_t colourfulOutput )
   : fNcounts        ( 0 ),
     fPrefix         ( Timer::fgClassName ),
     fColourfulOutput( colourfulOutput )
{
   
   if (prefix == "") fPrefix = Timer::fgClassName;
   else              fPrefix = prefix;
   fLogger = new MsgLogger( fPrefix.Data() );
   Reset();
}
TMVA::Timer::Timer( Int_t ncounts, const char* prefix, Bool_t colourfulOutput  )
   : fNcounts        ( ncounts ),
     fColourfulOutput( colourfulOutput )
{
   
   
   
   
   if (prefix == "") fPrefix = Timer::fgClassName;
   else              fPrefix = prefix;
   fLogger = new MsgLogger( fPrefix.Data() );
   Reset();
}
TMVA::Timer::~Timer( void )
{
   
   delete fLogger;
}
void TMVA::Timer::Init( Int_t ncounts )
{
   
   fNcounts = ncounts;  
   Reset();
}
void TMVA::Timer::Reset( void )
{
   
   TStopwatch::Start( kTRUE );
}
Double_t TMVA::Timer::ElapsedSeconds( void ) 
{
   
   Double_t rt = TStopwatch::RealTime(); TStopwatch::Start( kFALSE );
   return rt;
}
TString TMVA::Timer::GetElapsedTime( Bool_t Scientific ) 
{
   
   return SecToText( ElapsedSeconds(), Scientific );
}
TString TMVA::Timer::GetLeftTime( Int_t icounts ) 
{
   
   Double_t leftTime = ( icounts <= 0 ? -1 :
                         icounts > fNcounts ? -1 :
                         Double_t(fNcounts - icounts)/Double_t(icounts)*ElapsedSeconds() );
   return SecToText( leftTime, kFALSE );
}
void TMVA::Timer::DrawProgressBar() 
{
   
   fNcounts++;
   if (fNcounts == 1) {
      clog << fLogger->GetPrintedSource();
      clog << "Please wait ";
   }
   clog << "." << flush;
}
void TMVA::Timer::DrawProgressBar( TString theString ) 
{
   
   clog << fLogger->GetPrintedSource();
   clog << Color("white_on_green") << Color("dyellow") << "[" << Color("reset");
   clog << Color("white_on_green") << Color("dyellow") << theString << Color("reset");
   clog << Color("white_on_green") << Color("dyellow") << "]" << Color("reset");
   clog << "\r" << flush; 
}
void TMVA::Timer::DrawProgressBar( Int_t icounts ) 
{
   
   
   
   if (icounts > fNcounts-1) icounts = fNcounts-1;
   if (icounts < 0         ) icounts = 0;
   Int_t ic = Int_t(Float_t(icounts)/Float_t(fNcounts)*fgNbins);
   clog << fLogger->GetPrintedSource();
   if (fColourfulOutput) clog << Color("white_on_green") << Color("dyellow") << "[" << Color("reset");
   else                  clog << "[";
   for (Int_t i=0; i<ic; i++) {
      if (fColourfulOutput) clog << Color("white_on_green") << Color("dyellow") << ">" << Color("reset"); 
      else                  clog << ">";
   }
   for (Int_t i=ic+1; i<fgNbins; i++) {
      if (fColourfulOutput) clog << Color("white_on_green") << Color("dyellow") << "." << Color("reset"); 
      else                  clog << ".";
   }
   if (fColourfulOutput) clog << Color("white_on_green") << Color("dyellow") << "]" << Color("reset");
   else                  clog << "]" ;
   
   if (fColourfulOutput) {
      clog << Color("reset") << " " ;
      clog << "(" << Color("dred") << Int_t((100*(icounts+1))/Float_t(fNcounts)) << "%" << Color("reset")
               << ", " 
               << "time left: "
               << this->GetLeftTime( icounts ) << Color("reset") << ") ";
   }
   else {
      clog << "] " ;
      clog << "(" << Int_t((100*(icounts+1))/Float_t(fNcounts)) << "%" 
               << ", " << "time left: " << this->GetLeftTime( icounts ) << ") ";
   }
   clog << "\r" << flush; 
}
TString TMVA::Timer::SecToText( Double_t seconds, Bool_t Scientific ) const
{
   
   TString out = "";
   if      (Scientific    ) out = Form( "%.3g sec", seconds );
   else if (seconds <  0  ) out = "unknown";
   else if (seconds <= 300) out = Form( "%i sec", Int_t(seconds) );
   else {
      if (seconds > 3600) {
         Int_t h = Int_t(seconds/3600);
         if (h <= 1) out = Form( "%i hr : ", h );
         else        out = Form( "%i hrs : ", h );
      
         seconds = Int_t(seconds)%3600;
      }
      Int_t m = Int_t(seconds/60);
      if (m <= 1) out += Form( "%i min", m );
      else        out += Form( "%i mins", m );
   }
   return (fColourfulOutput) ? Color("dred") + out + Color("reset") : out;
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.