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