72#define STDERR_FILENO 2
86 :
Timer(0, prefix, colourfulOutput)
97 : fNcounts ( ncounts ),
98 fPrefix ( strcmp(prefix,
"")==0?
Timer::fgClassName:
TString(prefix) ),
99 fColourfulOutput( colourfulOutput ),
100 fPreviousProgress(-1),
101 fOutputToFile(!isatty(STDERR_FILENO)),
102 fProgressBarStringLength (0),
103 fLogger ( new
MsgLogger( fPrefix.Data() ) )
130 fPreviousProgress = -1;
131 fPreviousTimeEstimate.Clear();
148 return SecToText( ElapsedSeconds(), Scientific );
156 Double_t leftTime = ( icounts <= 0 ? -1 :
157 icounts > fNcounts ? -1 :
160 return SecToText( leftTime,
kFALSE );
168 fProgressBarStringLength = 0;
171 std::clog << fLogger->GetPrintedSource();
172 std::clog <<
"Please wait ";
175 std::clog <<
"." << std::flush;
184 std::clog << fLogger->GetPrintedSource();
192 for (
int i = fProgressBarStringLength; i < theString.
Length (); ++i)
194 std::clog <<
"\r" << std::flush;
195 fProgressBarStringLength = theString.
Length ();
204 if (!
gConfig().DrawProgressBar())
return;
207 if (icounts > fNcounts-1) icounts = fNcounts-1;
208 if (icounts < 0 ) icounts = 0;
211 auto timeLeft = this->GetLeftTime( icounts );
214 if (ic == fPreviousProgress && timeLeft == fPreviousTimeEstimate && icounts != fNcounts-1)
return;
217 if (ic != fPreviousProgress) {
218 std::clog <<
Int_t((100*(icounts+1))/
Float_t(fNcounts)) <<
"%, time left: " << timeLeft << std::endl;
219 fPreviousProgress = ic;
223 fPreviousProgress = ic;
224 fPreviousTimeEstimate = timeLeft;
226 std::clog << fLogger->GetPrintedSource();
228 else std::clog <<
"[";
229 for (
Int_t i=0; i<ic; i++) {
231 else std::clog <<
">";
233 for (
Int_t i=ic+1; i<fgNbins; i++) {
235 else std::clog <<
".";
238 else std::clog <<
"]" ;
241 if (fColourfulOutput) {
250 std::clog <<
"(" <<
Int_t((100*(icounts+1))/
Float_t(fNcounts)) <<
"%"
251 <<
", " <<
"time left: " << timeLeft <<
") ";
254 std::clog <<
"[" << comment <<
"] ";
256 std::clog <<
"\r" << std::flush;
265 if (Scientific ) out =
Form(
"%.3g sec", seconds );
266 else if (seconds < 0 ) out =
"unknown";
267 else if (seconds <= 300) out =
Form(
"%i sec",
Int_t(seconds) );
269 if (seconds > 3600) {
271 if (
h <= 1) out =
Form(
"%i hr : ",
h );
272 else out =
Form(
"%i hrs : ",
h );
274 seconds =
Int_t(seconds)%3600;
277 if (
m <= 1) out +=
Form(
"%i min",
m );
278 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.