Belle II Software  release-08-01-10
ElapsedTimeModule.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 #include <daq/modules/ElapsedTime/ElapsedTimeModule.h>
10 
11 using namespace std;
12 using namespace Belle2;
13 
14 //-----------------------------------------------------------------
15 // Register the Module
16 //-----------------------------------------------------------------
17 REG_MODULE(ElapsedTime)
18 
19 //-----------------------------------------------------------------
20 // Implementation
21 //-----------------------------------------------------------------
22 
24 {
25  //Set module properties
26  setDescription("Encode DataStore into RingBuffer");
27 
28  addParam("EventInterval", m_interval, "Event interval to measure time",
29  100);
30 
31  //Parameter definition
32  B2INFO("ElapsedTime: Constructor done.");
33 }
34 
35 
36 ElapsedTimeModule::~ElapsedTimeModule()
37 {
38 }
39 
40 void ElapsedTimeModule::initialize()
41 {
42  gettimeofday(&m_t0, 0); \
43  m_tnow = m_t0;
44  m_tprev = m_tnow;
45  m_nevent = 0;
46  m_nevprev = 0;
47 }
48 
49 
50 void ElapsedTimeModule::beginRun()
51 {
52  B2INFO("ElapsedTime: started to measure elapsed time.");
53 }
54 
55 
56 void ElapsedTimeModule::event()
57 {
58  if (m_nevent % m_interval == 0) {
59  gettimeofday(&m_tnow, 0);
60  double etime = (double)((m_tnow.tv_sec - m_t0.tv_sec) * 1000000 +
61  (m_tnow.tv_usec - m_t0.tv_usec));
62  double delta = (double)((m_tnow.tv_sec - m_tprev.tv_sec) * 1000000 +
63  (m_tnow.tv_usec - m_tprev.tv_usec));
64  double evtime = etime / ((double)m_nevent);
65  // double devtime = delta/(double)(m_nevent-m_nevprev);
66  double devtime = delta / (double)m_interval;
67  double erate = (double)m_nevent / etime * 1000.0;
68  double derate = (double)m_interval / delta * 1000.0;
69  printf("Elapsed( %d ) : time = %7.2f (msec), time/evt = %5.2f [ %5.3f ](msec) (%f[%f]kHz)\n",
70  m_nevent, etime / 1000.0, evtime / 1000.0, devtime / 1000.0,
71  erate, derate);
72  m_nevprev = m_nevent;
73  m_tprev = m_tnow;
74  }
75  m_nevent++;
76 
77 }
78 
79 void ElapsedTimeModule::endRun()
80 {
81  //fill Run data
82  gettimeofday(&m_tend, 0);
83  double etime = (double)((m_tnow.tv_sec - m_t0.tv_sec) * 1000000 +
84  (m_tnow.tv_usec - m_t0.tv_usec));
85  double evtime = etime / ((double)m_nevent);
86  printf("Total Elapsed : time = %f (msec), time/evt = %f (msec)\n",
87  etime / 1000.0, evtime / 1000.0);
88 }
89 
90 
91 void ElapsedTimeModule::terminate()
92 {
93  B2INFO("ElapsedTime: terminate called");
94 }
95 
A class definition of an input module for Sequential ROOT I/O.
Base class for Modules.
Definition: Module.h:72
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.