9#include <framework/modules/core/ProgressBarModule.h>
11#include <framework/core/Environment.h>
12#include <framework/utilities/Utils.h>
27 Display a progress bar and an estimate of remaining time when number of
28 events is known (e.g. reading from file, or -n switch used).
30 The progress bar uses stderr for its output, so it works best when stdout
31 is piped to a file. However it should also work when printing direct to a
34 .. versionchanged:: release-03-00-00
35 the module now detects if it outputs to a terminal or into a file and
36 will only update the bar if it has changed and not use any control
37 characters to make log files much more readable than before.
50 m_isTTY = isatty(STDERR_FILENO);
72 double time_per_event = elapsedSec /
m_evtNr;
73 auto remainingSeconds = (int)std::round((
m_nTotal -
m_evtNr) * time_per_event);
75 if (remainingSeconds >= 0) {
76 const int bar_length = 50;
84 for (
int i = 0; i <
m_progress; ++i) cerr <<
'=';
86 for (
int i =
m_progress + 1; i < bar_length; ++i) cerr <<
' ';
87 cerr <<
"] " << setw(3) << int(ratio * 100) <<
"% ";
88 if (remainingSeconds > 3600) {
89 int hours = remainingSeconds / 3600;
90 remainingSeconds %= 3600;
93 if (remainingSeconds > 60) {
94 int minutes = remainingSeconds / 60;
95 remainingSeconds %= 60;
96 cerr << minutes <<
"m";
98 cerr << remainingSeconds <<
"s remaining";
unsigned int getNumberOfEvents() const
Return the number of events, from either input or EventInfoSetter, or -n command line override (if le...
static Environment & Instance()
Static method to get a reference to the Environment instance.
void setDescription(const std::string &description)
Sets the description of the module.
long m_nTotal
Total number of events.
virtual void initialize() override
Init the module.
virtual void event() override
Show progress.
virtual void terminate() override
Don't break the terminal.
int m_progress
progress in percent since we last printed
double m_lastPrint
Timestamp when we last printed something (ns).
double m_startTime
Start time (ns).
long m_evtNr
Number of processed events.
bool m_isTTY
If true we don't show the interactive progress bar but just print a new one every time the progress a...
ProgressBarModule()
Constructor.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
double getClock()
Return current value of the real-time clock.
Abstract base class for different kinds of events.