Fork me on GitHub

source: svn/trunk/Utilities/ExRootAnalysis/src/ExRootProgressBar.cc@ 525

Last change on this file since 525 was 251, checked in by severine ovyn, 16 years ago

add progress bar

File size: 1.9 KB
RevLine 
[3]1
2/** \class ExRootProgressBar
3 *
4 * Class showing progress bar
5 *
[251]6 * $Date: 2009-02-07 15:44:02 $
7 * $Revision: 1.3 $
[3]8 *
9 *
10 * \author P. Demin - UCL, Louvain-la-Neuve
11 *
12 */
13
[220]14#include "ExRootProgressBar.h"
[3]15#include "TSystem.h"
[220]16#include <cstdio>
[251]17#include <iostream>
[3]18
19using namespace std;
20
21ExRootProgressBar::ExRootProgressBar(Long64_t entries, Int_t width) :
22 fEntries(entries), fWidth(width), fTime(0), fHashes(0), fBar(0)
23{
24 fBar = new char[width + 1];
25 memset(fBar, '-', width);
26 fBar[width] = 0;
27
28}
29
30//------------------------------------------------------------------------------
31
32ExRootProgressBar::~ExRootProgressBar()
33{
[251]34 if(fBar) delete[] fBar;
[3]35}
36
37//------------------------------------------------------------------------------
38
39void ExRootProgressBar::Update(Long64_t entry)
40{
41 ULong_t time = gSystem->Now();
42
[251]43 if(time < fTime + 500 && entry < fEntries - 1) return;
[3]44
45 fTime = time;
46
47 Int_t hashes = Int_t((entry + 1.0)/fEntries*fWidth);
48
49 if(hashes > fHashes)
50 {
[251]51 memset(fBar + fHashes, '$', hashes - fHashes);
[3]52 fHashes = hashes;
53 }
[251]54 float frac=(entry + 1.0)/fEntries*100.0;
55 if(frac<10) fprintf(stdout, "** [%s] %.2f%% processed **\r", fBar,(entry + 1.0)/fEntries*100.0);
56 if(frac==100) fprintf(stdout, "** [%s] %.2f%% processed **\r", fBar,(entry + 1.0)/fEntries*100.0);
57 else fprintf(stdout, "** [%s] %.2f%% processed **\r", fBar,(entry + 1.0)/fEntries*100.0);
58 fflush(stdout);
[3]59
[251]60 if(entry+1==fEntries)
61 {
62 char temp[500];
63 sprintf(temp, "** [%s] %.2f%% processed ", fBar,(entry + 1.0)/fEntries*100.0);
64 string mystringName(temp);
65 cout << mystringName <<endl;
66 }
[3]67}
68
69//------------------------------------------------------------------------------
70
71void ExRootProgressBar::Finish()
72{
73 fprintf(stderr, "\n");
74 fflush(stderr);
75}
76
77//------------------------------------------------------------------------------
78
Note: See TracBrowser for help on using the repository browser.