[d7d2da3] | 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 <stdio.h>
|
---|
[341014c] | 17 | #include <string.h>
|
---|
[d7d2da3] | 18 |
|
---|
| 19 | using namespace std;
|
---|
| 20 |
|
---|
| 21 | ExRootProgressBar::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 |
|
---|
| 31 | ExRootProgressBar::~ExRootProgressBar()
|
---|
| 32 | {
|
---|
| 33 | if(fBar) delete[] fBar;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | //------------------------------------------------------------------------------
|
---|
| 37 |
|
---|
| 38 | void 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 | {
|
---|
[341014c] | 48 | Int_t hashes = Int_t(Double_t(entry) / fEntries * fWidth);
|
---|
[d7d2da3] | 49 | if(hashes > fWidth) hashes = fWidth;
|
---|
| 50 | if(hashes != fHashes)
|
---|
| 51 | {
|
---|
| 52 | memset(fBar, '#', hashes);
|
---|
| 53 | memset(fBar + hashes, '-', fWidth - hashes);
|
---|
| 54 | fHashes = hashes;
|
---|
[341014c] | 55 | fprintf(stderr, "** [%s] (%.2f%%)\r", fBar, Float_t(entry) / fEntries * 100.0);
|
---|
[d7d2da3] | 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 |
|
---|
| 72 | void ExRootProgressBar::Finish()
|
---|
| 73 | {
|
---|
| 74 | fprintf(stderr, "\n");
|
---|
| 75 | fflush(stderr);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | //------------------------------------------------------------------------------
|
---|