72#define STDERR_FILENO 2
85 :
Timer(0, prefix, colourfulOutput)
96 : fNcounts ( ncounts ),
97 fPrefix ( strcmp(prefix,
"")==0?
Timer::fgClassName:
TString(prefix) ),
98 fColourfulOutput( colourfulOutput ),
99 fPreviousProgress(-1),
100 fOutputToFile(!isatty(STDERR_FILENO)),
101 fProgressBarStringLength (0),
102 fLogger ( new
MsgLogger( fPrefix.Data() ) )
129 fPreviousProgress = -1;
130 fPreviousTimeEstimate.Clear();
147 return SecToText( ElapsedSeconds(), Scientific );
155 Double_t leftTime = ( icounts <= 0 ? -1 :
156 icounts > fNcounts ? -1 :
159 return SecToText( leftTime,
kFALSE );
167 fProgressBarStringLength = 0;
170 std::clog << fLogger->GetPrintedSource();
171 std::clog <<
"Please wait ";
174 std::clog <<
"." << std::flush;
183 std::clog << fLogger->GetPrintedSource();
191 for (
int i = fProgressBarStringLength; i < theString.
Length (); ++i)
193 std::clog <<
"\r" << std::flush;
194 fProgressBarStringLength = theString.
Length ();
203 if (!
gConfig().DrawProgressBar())
return;
206 if (icounts > fNcounts-1) icounts = fNcounts-1;
207 if (icounts < 0 ) icounts = 0;
210 auto timeLeft = this->GetLeftTime( icounts );
213 if (ic == fPreviousProgress && timeLeft == fPreviousTimeEstimate && icounts != fNcounts-1)
return;
216 if (ic != fPreviousProgress) {
217 std::clog <<
Int_t((100*(icounts+1))/
Float_t(fNcounts)) <<
"%, time left: " << timeLeft << std::endl;
218 fPreviousProgress = ic;
222 fPreviousProgress = ic;
223 fPreviousTimeEstimate = timeLeft;
225 std::clog << fLogger->GetPrintedSource();
227 else std::clog <<
"[";
228 for (
Int_t i=0; i<ic; i++) {
230 else std::clog <<
">";
232 for (
Int_t i=ic+1; i<fgNbins; i++) {
234 else std::clog <<
".";
237 else std::clog <<
"]" ;
240 if (fColourfulOutput) {
249 std::clog <<
"(" <<
Int_t((100*(icounts+1))/
Float_t(fNcounts)) <<
"%"
250 <<
", " <<
"time left: " << timeLeft <<
") ";
253 std::clog <<
"[" << comment <<
"] ";
255 std::clog <<
"\r" << std::flush;
265 else if (seconds < 0 ) out =
"unknown";
268 if (seconds > 3600) {
273 seconds =
Int_t(seconds)%3600;
int Int_t
Signed integer 4 bytes (int)
float Float_t
Float 4 bytes (float)
double Double_t
Double 8 bytes.
ostringstream derivative to redirect and format output
Timing information for training and evaluation of MVA methods.
Bool_t fColourfulOutput
flag for use of colors
Double_t ElapsedSeconds(void)
computes elapsed tim in seconds
static const Int_t fgNbins
number of bins in progress bar
void DrawProgressBar(void)
draws the progressbar
TString SecToText(Double_t, Bool_t) const
pretty string output
TString GetLeftTime(Int_t icounts)
returns pretty string with time left
Timer(const char *prefix="", Bool_t colourfulOutput=kTRUE)
constructor
void Reset(void)
resets timer
virtual ~Timer(void)
destructor
static const TString fgClassName
used for output
TString GetElapsedTime(Bool_t Scientific=kTRUE)
returns pretty string with elapsed time
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.