hej is hosted by Hepforge, IPPP Durham
HEJ 2.1.4
High energy resummation for hadron colliders
Loading...
Searching...
No Matches
ProgressBar.hh
Go to the documentation of this file.
1
8#pragma once
9
10#include <algorithm>
11#include <functional>
12#include <ostream>
13#include <stdexcept>
14
15namespace HEJ {
16
18 template<typename T>
20 public:
22
28 ProgressBar(std::ostream & out, T max) :
29 out_{out}, max_{max}
30 {
31 if(max <= 0) {
32 throw std::invalid_argument{
33 "Maximum in progress bar has to be positive"
34 };
35 }
36 print_bar();
37 }
38
40
48 counter_ += count;
49 update_progress();
50 return *this;
51 }
52
54
60 ++counter_;
61 update_progress();
62 return *this;
63 }
64
65 private:
66 void update_progress() {
67 counter_ = std::min(counter_, max_);
68 const int ndots = (100*counter_)/max_;
69 const int new_dots = ndots - ndots_;
70 if(new_dots > 0) {
71 for(int dot = 0; dot < new_dots; ++dot) out_.get() << '.';
72 out_.get().flush();
73 ndots_ = ndots;
74 }
75 }
76
77 void print_bar() const {
78 out_.get() << "0% ";
79 for(int i = 10; i <= 100; i+= 10){
80 out_.get() << " " + std::to_string(i) + "%";
81 }
82 out_.get() << "\n|";
83 for(int i = 10; i <= 100; i+= 10){
84 out_.get() << "---------|";
85 }
86 out_.get() << '\n';
87 }
88
89 std::reference_wrapper<std::ostream> out_;
90 T counter_ = 0;
91 T ndots_ = 0;
92 T max_;
93 };
94} // namespace HEJ
Class representing (and printing) a progress bar.
Definition: ProgressBar.hh:19
ProgressBar & increment(T count)
Increment progress.
Definition: ProgressBar.hh:47
ProgressBar(std::ostream &out, T max)
Constructor.
Definition: ProgressBar.hh:28
ProgressBar & operator++()
Increase progress by one unit.
Definition: ProgressBar.hh:59
Main HEJ 2 Namespace.
Definition: mainpage.dox:1
auto dot(CLHEP::HepLorentzVector const &pi, CLHEP::HepLorentzVector const &pj)
"dot" product
Definition: LorentzVector.hh:20