Belle II Software  release-08-01-10
DAQPerf.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/dataflow/modules/DAQPerf.h>
10 
11 #include <framework/datastore/StoreArray.h>
12 #include <rawdata/dataobjects/RawCOPPER.h>
13 
14 //#define MAXEVTSIZE 400000000
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 REG_MODULE(DAQPerf)
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
29 {
30  //Set module properties
31  setDescription("Monitor DAQ transfer performance");
32  // setPropertyFlags(c_Input | c_ParallelProcessingCertified);
33 
34  addParam("Cycle", m_ncycle, "Monitor cycle", 10000);
35  addParam("MonitorSize", m_mon, "SW to monitor data flow", false);
36 
37  //Parameter definition
38  B2INFO("Rx: Constructor done.");
39 }
40 
41 
42 DAQPerfModule::~DAQPerfModule()
43 {
44 }
45 
46 void DAQPerfModule::initialize()
47 {
48  m_nevent = 0;
49  m_t0.tv_sec = 0;
50  m_t0.tv_usec = 0;
51  m_totbytes = 0;
52 }
53 
54 
55 void DAQPerfModule::beginRun()
56 {
57 }
58 
59 
60 void DAQPerfModule::event()
61 {
62  if (m_nevent % m_ncycle == 0) {
63  if (m_t0.tv_sec == 0) {
64  gettimeofday(&m_t0, NULL);
65  m_totbytes = 0;
66  } else {
67  timeval t;
68  gettimeofday(&t, NULL);
69  double now = (double)t.tv_sec + (double)t.tv_usec * 0.000001;
70  double t0 = (double)m_t0.tv_sec + (double)m_t0.tv_usec * 0.000001;
71  double elapsed = now - t0;
72  printf("Event = %d : took %5.2f sec for %d evts -> %5.2f kHz",
73  m_nevent, elapsed, m_ncycle, (double)m_ncycle / elapsed / 1000);
74  if (m_mon) {
75  double aveflow = m_totbytes / elapsed / 1000000.0;
76  m_totbytes = 0.0;
77  printf(", %3.2f (MB/s)", aveflow);
78  }
79  printf("\n");
80  gettimeofday(&m_t0, NULL);
81  }
82  }
83  // Calculate data size
84  if (m_mon) {
85  StoreArray<RawCOPPER> rawcprary;
86  double rawsize = 0;
87  for (int i = 0; i < rawcprary.getEntries(); ++i) {
88  rawsize += (double)(rawcprary[i]->TotalBufNwords());
89  }
90  m_totbytes += rawsize * 4;
91  }
92  m_nevent++;
93  return;
94  // return type;
95 }
96 
97 void DAQPerfModule::endRun()
98 {
99  //fill Run data
100 }
101 
102 
103 void DAQPerfModule::terminate()
104 {
105 }
106 
A class definition of an input module for Sequential ROOT I/O.
Definition: DAQPerf.h:24
Base class for Modules.
Definition: Module.h:72
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
#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.