1 #include "ProgressBar.h" 3 #define ANSI_COLOR_RED "\x1b[31m" 4 #define ANSI_COLOR_GREEN "\x1b[32m" 5 #define ANSI_COLOR_YELLOW "\x1b[33m" 6 #define ANSI_COLOR_BLUE "\x1b[34m" 7 #define ANSI_COLOR_MAGENTA "\x1b[35m" 8 #define ANSI_COLOR_CYAN "\x1b[36m" 9 #define ANSI_COLOR_RESET "\x1b[0m" 13 Int_t Acclaim::ProgressBar::progState = 0;
20 std::cerr <<
"Assuming 100 events in ProgressBar" << std::endl;
41 fMaxEntry = maxEntryInit > 1 ? maxEntryInit - 1 : 1;
61 if(fPercentage>=100)
return;
64 Int_t seconds = Int_t(fWatch.RealTime());
65 Int_t hours = seconds / 3600;
66 hours = hours < 0 ? 0 : hours;
67 seconds = seconds - hours * 3600;
68 Int_t mins = seconds / 60;
69 mins = mins < 0 ? 0 : mins;
71 seconds = seconds - mins * 60;
74 double ratio = double(fCounter)/fMaxEntry;
77 if(ratio*100 > fPercentage){
79 while(ratio*100 > fPercentage){
86 fprintf(stderr,
"\r");
89 fprintf(stderr, ANSI_COLOR_RED);
90 fprintf(stderr,
"%3u%%", (UInt_t)(fPercentage) );
91 fprintf(stderr, ANSI_COLOR_RESET);
92 fprintf(stderr,
" [");
95 fprintf(stderr, ANSI_COLOR_BLUE);
96 fprintf(stderr,
"%02d:%02d:%02d", hours, mins, seconds);
97 for (UInt_t i=8; i<fPercentage; i++){
100 fprintf(stderr, ANSI_COLOR_RESET);
102 Int_t startSpace = fPercentage > 8 ? fPercentage : 8;
103 for (Int_t i=startSpace; i<100; i++){
104 fprintf(stderr,
" ");
107 fprintf(stderr,
"]");
110 if(fPercentage>=100) fprintf(stderr,
"\n");
111 fWatch.Start(kFALSE);
128 Long64_t entryL64 = entry;
129 inc(entryL64, numEntries);
144 Long64_t entryL64 = entry;
145 inc(entryL64, numEntries);
161 numEntries = numEntries < 0 ? fMaxEntry : numEntries;
168 if(fSetHandler==1 && fLastProgState!=0){
169 if(fNumBreakTries==0)
171 std::cerr <<
"Program with ProgressBar received SIGINT, will try and exit main loop gracefully. " << std::endl;
176 std::cerr <<
"Unable to exit main loop gracefully, raising SIGINT properly." << std::endl;
177 signal(SIGINT, SIG_DFL);
183 int diff = entry - fCounter;
184 for(
int i=0; i < diff; i++){
188 fLastProgState = progState;
200 std::cout << fPercentage <<
"\t" << fCounter <<
"\t" << fMaxEntry << std::endl;
ProgressBar()
Default constructor - don't use this.
void status()
For debugging, prints state of internal variables.
static void mainLoopSigintHandle(int param)
Custom handler, sets variable when signal is received.
void inc(Long64_t &entry, Long64_t numEntries=-1)
New primary function to move through main for loop in analysis program.
void operator++(int)
Increment operator, use when you have completed one iteration of the main loop.