Fork me on GitHub

source: git/external/ExRootAnalysis/ExRootProgressBar.cc@ ce4feac

ImprovedOutputFile Timing dual_readout llp
Last change on this file since ce4feac was cab38f6, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

remove svn tags and fix formatting

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