Belle II Software  release-08-01-10
ProgressModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 /* Own header. */
10 #include <framework/modules/core/ProgressModule.h>
11 
12 /* Framework headers. */
13 #include <framework/core/Environment.h>
14 #include <framework/logging/Logger.h>
15 
16 /* C++ headers. */
17 #include <cmath>
18 
19 using namespace Belle2;
20 
21 REG_MODULE(Progress);
22 
24 {
25  setDescription("Periodically writes the number of processed events/runs to the"
26  " logging system to give a progress indication.\n"
27  "The output is logarithmic, meaning it will output the first 10 events, "
28  "then every tenth event up to 100, then every hundreth event up to 1000, etc. "
29  "Output cannot be suppressed using set_log_level. "
30  "If you don't want messages, you don't want this module");
31  addParam("maxN", m_maxOrder,
32  "At most, 10^N events will lie between outputs", m_maxOrder);
33 }
34 
36 {
37  // Force module logging level to be c_Info
40 }
41 
43 {
44  ++m_runNr;
45  B2INFO("Begin of new run.");
46 }
47 
49 {
50  ++m_evtNr;
51  // Calculate the order of magnitude
52  uint32_t order = (m_evtNr == 0) ? 1 : (uint32_t)(std::min(std::log10(m_evtNr), (double)m_maxOrder));
53  uint32_t interval = (uint32_t)std::pow(10., order);
54  if (m_evtNr % interval == 0)
55  B2INFO(m_output % m_runNr % m_evtNr % m_totalEvtNr);
56 }
unsigned int getNumberOfEvents() const
Return the number of events, from either input or EventInfoSetter, or -n command line override (if le...
Definition: Environment.cc:39
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
@ c_Info
Info: for informational messages, e.g.
Definition: LogConfig.h:27
Base class for Modules.
Definition: Module.h:72
void setLogLevel(int logLevel)
Configure the log level.
Definition: Module.cc:55
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
uint32_t m_totalEvtNr
Total number of events in the current process.
void initialize() override
Init the module.
void event() override
Show progress.
uint32_t m_evtNr
Number of processed events.
uint32_t m_maxOrder
Maximum order of magnitude for interval between showing progress.
boost::format m_output
Compiled output format.
void beginRun() override
Show beginRun message.
ProgressModule()
Constructor.
uint32_t m_runNr
Number of processed runs.
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
Abstract base class for different kinds of events.