Loading [MathJax]/extensions/tex2jax.js
hej is hosted by Hepforge, IPPP Durham
HEJ  2.3.0
High energy resummation for hadron colliders
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 
15 namespace HEJ {
16 
18  template<typename T>
19  class ProgressBar {
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  if (max != 0) {
37  print_bar();
38  }
39  }
40 
42 
49  ProgressBar & increment(T count) {
50  counter_ += count;
51  update_progress();
52  return *this;
53  }
54 
56 
62  ++counter_;
63  update_progress();
64  return *this;
65  }
66 
67  private:
68  void update_progress() {
69  counter_ = std::min(counter_, max_);
70  const int ndots = (100*counter_)/max_;
71  const int new_dots = ndots - ndots_;
72  if(new_dots > 0) {
73  for(int dot = 0; dot < new_dots; ++dot) out_.get() << '.';
74  out_.get().flush();
75  ndots_ = ndots;
76  }
77  }
78 
79  void print_bar() const {
80  out_.get() << "0% ";
81  for(int i = 10; i <= 100; i+= 10){
82  out_.get() << " " + std::to_string(i) + "%";
83  }
84  out_.get() << "\n|";
85  for(int i = 10; i <= 100; i+= 10){
86  out_.get() << "---------|";
87  }
88  out_.get() << '\n';
89  }
90 
91  std::reference_wrapper<std::ostream> out_;
92  T counter_ = 0;
93  T ndots_ = 0;
94  T max_;
95  };
96 } // namespace HEJ
Class representing (and printing) a progress bar.
Definition: ProgressBar.hh:19
ProgressBar & operator++()
Increase progress by one unit.
Definition: ProgressBar.hh:61
ProgressBar & increment(T count)
Increment progress.
Definition: ProgressBar.hh:49
ProgressBar(std::ostream &out, T max)
Constructor.
Definition: ProgressBar.hh:28
@ out
Final outgoing.
Definition: HepMCInterface_common.hh:24
Main HEJ 2 Namespace.
Definition: mainpage.dox:1
std::string to_string(Event const &ev)
auto dot(CLHEP::HepLorentzVector const &pi, CLHEP::HepLorentzVector const &pj)
"dot" product
Definition: LorentzVector.hh:20