Belle II Software  release-05-02-19
ProgressModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Susanne Koblitz *
7  * *
8  **************************************************************************/
9 
10 #include <framework/modules/core/ProgressModule.h>
11 #include <framework/logging/Logger.h>
12 #include <cmath>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 REG_MODULE(Progress)
18 
19 ProgressModule::ProgressModule() : Module(), m_maxOrder(3), m_evtNr(0), m_runNr(0),
20  m_output("Processed: %3d runs, %6d events")
21 {
22  setDescription("Periodically writes the number of processed events/runs to the"
23  " logging system to give a progress indication.\n"
24  "The output is logarithmic, meaning it will output the first 10 events, "
25  "then every tenth event up to 100, then every hundreth event up to 1000, etc. "
26  "Output cannot be suppressed using set_log_level. "
27  "If you don't want messages, you don't want this module");
28  addParam("maxN", m_maxOrder,
29  "At most, 10^N events will lie between outputs", m_maxOrder);
30 }
31 
32 void ProgressModule::initialize()
33 {
34  //Force module logging level to be info
35  setLogLevel(LogConfig::c_Info);
36  m_runNr = m_evtNr = 0;
37 }
38 
39 void ProgressModule::beginRun()
40 {
41  ++m_runNr;
42  B2INFO("Begin of new run");
43 }
44 
45 void ProgressModule::event()
46 {
47  ++m_evtNr;
48  //Calculate the order of magnitude
49  int order = (m_evtNr == 0) ? 1 : (int)(min(log10(m_evtNr), (double)m_maxOrder));
50  auto interval = (int)pow(10., order);
51  if (m_evtNr % interval == 0) B2INFO(m_output % m_runNr % m_evtNr);
52 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ProgressModule
Periodically writes the number of processed events/runs to the logging system to give a progress indi...
Definition: ProgressModule.h:39