1 |
|
---|
2 | /** \class ExRootProgressBar
|
---|
3 | *
|
---|
4 | * Class showing progress bar
|
---|
5 | *
|
---|
6 | * $Date: 2009-02-02 11:32:01 $
|
---|
7 | * $Revision: 1.2 $
|
---|
8 | *
|
---|
9 | *
|
---|
10 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
11 | *
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "ExRootProgressBar.h"
|
---|
15 | #include "TSystem.h"
|
---|
16 | #include <cstdio>
|
---|
17 |
|
---|
18 | using namespace std;
|
---|
19 |
|
---|
20 | ExRootProgressBar::ExRootProgressBar(Long64_t entries, Int_t width) :
|
---|
21 | fEntries(entries), fWidth(width), fTime(0), fHashes(0), fBar(0)
|
---|
22 | {
|
---|
23 | fBar = new char[width + 1];
|
---|
24 | memset(fBar, '-', width);
|
---|
25 | fBar[width] = 0;
|
---|
26 |
|
---|
27 | }
|
---|
28 |
|
---|
29 | //------------------------------------------------------------------------------
|
---|
30 |
|
---|
31 | ExRootProgressBar::~ExRootProgressBar()
|
---|
32 | {
|
---|
33 | if(fBar) delete[] fBar;
|
---|
34 | }
|
---|
35 |
|
---|
36 | //------------------------------------------------------------------------------
|
---|
37 |
|
---|
38 | void ExRootProgressBar::Update(Long64_t entry)
|
---|
39 | {
|
---|
40 | ULong_t time = gSystem->Now();
|
---|
41 |
|
---|
42 | if(time < fTime + 1000 && entry < fEntries - 1) return;
|
---|
43 |
|
---|
44 | fTime = time;
|
---|
45 |
|
---|
46 | Int_t hashes = Int_t((entry + 1.0)/fEntries*fWidth);
|
---|
47 |
|
---|
48 | if(hashes > fHashes)
|
---|
49 | {
|
---|
50 | memset(fBar + fHashes, '#', hashes - fHashes);
|
---|
51 | fHashes = hashes;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /*
|
---|
55 | cerr << "[" << fBar << "] (";
|
---|
56 | cerr.setf(ios::fixed);
|
---|
57 | cerr.precision(2);
|
---|
58 | cerr << (entry + 1.0)/fEntries*100.0 << "%) : ";
|
---|
59 | cerr << entry + 1 << "/" << fEntries;
|
---|
60 | cerr << " events processed\r" << flush;
|
---|
61 | */
|
---|
62 |
|
---|
63 | fprintf(stderr, "[%s] (%.2f%%) : %lli/%lli entries processed\r", fBar,
|
---|
64 | (entry + 1.0)/fEntries*100.0, entry + 1, fEntries);
|
---|
65 | fflush(stderr);
|
---|
66 | }
|
---|
67 |
|
---|
68 | //------------------------------------------------------------------------------
|
---|
69 |
|
---|
70 | void ExRootProgressBar::Finish()
|
---|
71 | {
|
---|
72 | fprintf(stderr, "\n");
|
---|
73 | fflush(stderr);
|
---|
74 | }
|
---|
75 |
|
---|
76 | //------------------------------------------------------------------------------
|
---|
77 |
|
---|