66#define STDERR_FILENO 2
80 :
Timer(0, prefix, colourfulOutput)
91 : fNcounts ( ncounts ),
92 fPrefix ( strcmp(prefix,
"")==0?
Timer::fgClassName:
TString(prefix) ),
93 fColourfulOutput( colourfulOutput ),
94 fPreviousProgress(-1),
95 fOutputToFile(!isatty(STDERR_FILENO)),
96 fProgressBarStringLength (0),
97 fLogger ( new
MsgLogger( fPrefix.Data() ) )
124 fPreviousProgress = -1;
125 fPreviousTimeEstimate.Clear();
142 return SecToText( ElapsedSeconds(), Scientific );
150 Double_t leftTime = ( icounts <= 0 ? -1 :
151 icounts > fNcounts ? -1 :
154 return SecToText( leftTime,
kFALSE );
162 fProgressBarStringLength = 0;
165 std::clog << fLogger->GetPrintedSource();
166 std::clog <<
"Please wait ";
169 std::clog <<
"." << std::flush;
178 std::clog << fLogger->GetPrintedSource();
186 for (
int i = fProgressBarStringLength; i < theString.
Length (); ++i)
188 std::clog <<
"\r" << std::flush;
189 fProgressBarStringLength = theString.
Length ();
198 if (!
gConfig().DrawProgressBar())
return;
201 if (icounts > fNcounts-1) icounts = fNcounts-1;
202 if (icounts < 0 ) icounts = 0;
205 auto timeLeft = this->GetLeftTime( icounts );
208 if (ic == fPreviousProgress && timeLeft == fPreviousTimeEstimate && icounts != fNcounts-1)
return;
211 if (ic != fPreviousProgress) {
212 std::clog <<
Int_t((100*(icounts+1))/
Float_t(fNcounts)) <<
"%, time left: " << timeLeft << std::endl;
213 fPreviousProgress = ic;
217 fPreviousProgress = ic;
218 fPreviousTimeEstimate = timeLeft;
220 std::clog << fLogger->GetPrintedSource();
222 else std::clog <<
"[";
223 for (
Int_t i=0; i<ic; i++) {
225 else std::clog <<
">";
227 for (
Int_t i=ic+1; i<fgNbins; i++) {
229 else std::clog <<
".";
232 else std::clog <<
"]" ;
235 if (fColourfulOutput) {
244 std::clog <<
"(" <<
Int_t((100*(icounts+1))/
Float_t(fNcounts)) <<
"%"
245 <<
", " <<
"time left: " << timeLeft <<
") ";
248 std::clog <<
"[" << comment <<
"] ";
250 std::clog <<
"\r" << std::flush;
259 if (Scientific ) out =
Form(
"%.3g sec", seconds );
260 else if (seconds < 0 ) out =
"unknown";
261 else if (seconds <= 300) out =
Form(
"%i sec",
Int_t(seconds) );
263 if (seconds > 3600) {
265 if (
h <= 1) out =
Form(
"%i hr : ",
h );
266 else out =
Form(
"%i hrs : ",
h );
268 seconds =
Int_t(seconds)%3600;
271 if (
m <= 1) out +=
Form(
"%i min",
m );
272 else out +=
Form(
"%i mins",
m );
char * Form(const char *fmt,...)
ostringstream derivative to redirect and format output
Timing information for training and evaluation of MVA methods.
Double_t ElapsedSeconds(void)
computes elapsed tim in seconds
static const Int_t fgNbins
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
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.