Fork me on GitHub

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

Last change on this file since 192 was 3, checked in by Xavier Rouby, 16 years ago

first commit

File size: 1.7 KB
Line 
1
2/** \class ExRootProgressBar
3 *
4 * Class showing progress bar
5 *
6 * $Date: 2008-11-04 10:32:27 $
7 * $Revision: 1.1 $
8 *
9 *
10 * \author P. Demin - UCL, Louvain-la-Neuve
11 *
12 */
13
14#include "Utilities/ExRootAnalysis/interface/ExRootProgressBar.h"
15
16#include "TSystem.h"
17
18#include <iostream>
19
20#include <string.h>
21#include <stdio.h>
22
23using namespace std;
24
25ExRootProgressBar::ExRootProgressBar(Long64_t entries, Int_t width) :
26 fEntries(entries), 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
36ExRootProgressBar::~ExRootProgressBar()
37{
38 if(fBar) delete[] fBar;
39}
40
41//------------------------------------------------------------------------------
42
43void ExRootProgressBar::Update(Long64_t entry)
44{
45 ULong_t time = gSystem->Now();
46
47 if(time < fTime + 1000 && entry < fEntries - 1) return;
48
49 fTime = time;
50
51 Int_t hashes = Int_t((entry + 1.0)/fEntries*fWidth);
52
53 if(hashes > fHashes)
54 {
55 memset(fBar + fHashes, '#', hashes - fHashes);
56 fHashes = hashes;
57 }
58
59/*
60 cerr << "[" << fBar << "] (";
61 cerr.setf(ios::fixed);
62 cerr.precision(2);
63 cerr << (entry + 1.0)/fEntries*100.0 << "%) : ";
64 cerr << entry + 1 << "/" << fEntries;
65 cerr << " events processed\r" << flush;
66*/
67
68 fprintf(stderr, "[%s] (%.2f%%) : %lli/%lli entries processed\r", fBar,
69 (entry + 1.0)/fEntries*100.0, entry + 1, fEntries);
70 fflush(stderr);
71}
72
73//------------------------------------------------------------------------------
74
75void ExRootProgressBar::Finish()
76{
77 fprintf(stderr, "\n");
78 fflush(stderr);
79}
80
81//------------------------------------------------------------------------------
82
Note: See TracBrowser for help on using the repository browser.