Fork me on GitHub

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

Last change on this file since 606 was 590, checked in by Pavel Demin, 12 years ago

adapt to the new TTime interface

File size: 1.9 KB
Line 
1
2/** \class ExRootProgressBar
3 *
4 * Class showing progress bar
5 *
6 * $Date: 2009-02-07 15:44:02 $
7 * $Revision: 1.3 $
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#include <iostream>
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{
34 if(fBar) delete[] fBar;
35}
36
37//------------------------------------------------------------------------------
38
39void ExRootProgressBar::Update(Long64_t entry)
40{
41 ULong64_t time = gSystem->Now();
42
43 if(time < fTime + 500 && entry < fEntries - 1) return;
44
45 fTime = time;
46
47 Int_t hashes = Int_t((entry + 1.0)/fEntries*fWidth);
48
49 if(hashes > fHashes)
50 {
51 memset(fBar + fHashes, '$', hashes - fHashes);
52 fHashes = hashes;
53 }
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);
59
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 }
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.