Belle II Software development
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
11using namespace std;
12using namespace Belle2;
13
14//-----------------------------------------------------------------
15// Register the Module
16//-----------------------------------------------------------------
17REG_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
36ElapsedTimeModule::~ElapsedTimeModule()
37{
38}
39
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
51{
52 B2INFO("ElapsedTime: started to measure elapsed time.");
53}
54
55
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
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
92{
93 B2INFO("ElapsedTime: terminate called");
94}
95
void initialize() override
Module functions to be called from main process.
void event() override
This method is the core of the module.
ElapsedTimeModule()
Constructor / Destructor.
void endRun() override
This method is called if the current run ends.
void terminate() override
This method is called at the end of the event processing.
void beginRun() override
Module functions to be called from event process.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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
#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.
STL namespace.