73#define STDERR_FILENO 2
87 :
Timer(0, prefix, colourfulOutput)
98 : fNcounts ( ncounts ),
99 fPrefix ( strcmp(prefix,
"")==0?
Timer::fgClassName:
TString(prefix) ),
100 fColourfulOutput( colourfulOutput ),
101 fPreviousProgress(-1),
102 fOutputToFile(!isatty(STDERR_FILENO)),
103 fProgressBarStringLength (0),
104 fLogger ( new
MsgLogger( fPrefix.Data() ) )
131 fPreviousProgress = -1;
132 fPreviousTimeEstimate.Clear();
149 return SecToText( ElapsedSeconds(), Scientific );
157 Double_t leftTime = ( icounts <= 0 ? -1 :
158 icounts > fNcounts ? -1 :
161 return SecToText( leftTime,
kFALSE );
169 fProgressBarStringLength = 0;
172 std::clog << fLogger->GetPrintedSource();
173 std::clog <<
"Please wait ";
176 std::clog <<
"." << std::flush;
185 std::clog << fLogger->GetPrintedSource();
193 for (
int i = fProgressBarStringLength; i < theString.
Length (); ++i)
195 std::clog <<
"\r" << std::flush;
196 fProgressBarStringLength = theString.
Length ();
205 if (!
gConfig().DrawProgressBar())
return;
208 if (icounts > fNcounts-1) icounts = fNcounts-1;
209 if (icounts < 0 ) icounts = 0;
212 auto timeLeft = this->GetLeftTime( icounts );
215 if (ic == fPreviousProgress && timeLeft == fPreviousTimeEstimate && icounts != fNcounts-1)
return;
218 if (ic != fPreviousProgress) {
219 std::clog <<
Int_t((100*(icounts+1))/
Float_t(fNcounts)) <<
"%, time left: " << timeLeft << std::endl;
220 fPreviousProgress = ic;
224 fPreviousProgress = ic;
225 fPreviousTimeEstimate = timeLeft;
227 std::clog << fLogger->GetPrintedSource();
229 else std::clog <<
"[";
230 for (
Int_t i=0; i<ic; i++) {
232 else std::clog <<
">";
234 for (
Int_t i=ic+1; i<fgNbins; i++) {
236 else std::clog <<
".";
239 else std::clog <<
"]" ;
242 if (fColourfulOutput) {
251 std::clog <<
"(" <<
Int_t((100*(icounts+1))/
Float_t(fNcounts)) <<
"%"
252 <<
", " <<
"time left: " << timeLeft <<
") ";
255 std::clog <<
"[" <<
comment <<
"] ";
257 std::clog <<
"\r" << std::flush;
266 if (Scientific ) out =
Form(
"%.3g sec", seconds );
267 else if (seconds < 0 ) out =
"unknown";
268 else if (seconds <= 300) out =
Form(
"%i sec",
Int_t(seconds) );
270 if (seconds > 3600) {
272 if (
h <= 1) out =
Form(
"%i hr : ",
h );
273 else out =
Form(
"%i hrs : ",
h );
275 seconds =
Int_t(seconds)%3600;
278 if (
m <= 1) out +=
Form(
"%i min",
m );
279 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.