Belle II Software  release-08-01-10
FlowMonitor.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 #include "daq/slc/readout/FlowMonitor.h"
9 
10 #include <daq/slc/system/Time.h>
11 
12 #include <cstring>
13 
14 using namespace Belle2;
15 
16 bool FlowMonitor::open(RunInfoBuffer* info)
17 {
18  m_info = info;
19  if (m_info->isAvailable()) {
20  m_status.nodeid = m_info->getNodeId();
21  m_nbyte[0] = m_nbyte[1] = 0;
22  m_ioinfo[0].setLocalPort(m_info->getInputPort());
23  m_ioinfo[0].setLocalAddress(m_info->getInputAddress());
24  m_ip[0] = m_ioinfo[0].getLocalIP();
25  m_ioinfo[1].setLocalPort(m_info->getOutputPort());
26  m_ioinfo[1].setLocalAddress(m_info->getOutputAddress());
27  m_ip[1] = m_ioinfo[1].getLocalIP();
28  }
29  return true;
30 }
31 
32 bool FlowMonitor::close()
33 {
34  return true;
35 }
36 
37 ronode_status& FlowMonitor::monitor()
38 {
39  if (m_info->isAvailable()) {
40  m_ioinfo[0].setLocalAddress(m_info->getInputAddress());
41  m_ioinfo[0].setLocalPort(m_info->getInputPort());
42  m_ioinfo[1].setLocalAddress(m_info->getOutputAddress());
43  m_ioinfo[1].setLocalPort(m_info->getOutputPort());
44  IOInfo::checkTCP(m_ioinfo);
45  unsigned int ctime = Time().getSecond();
46  ronode_info info;
47  memcpy(&info, m_info->get(), sizeof(ronode_info));
48  memcpy(&(m_status.header), &(info.header), sizeof(event_header));
49  double length = ctime - m_status.ctime;
50  m_status.eflag = info.eflag;
51  m_status.state = info.state;
52  m_status.expno = info.expno;
53  m_status.runno = info.runno;
54  m_status.subno = info.subno;
55  m_status.reserved_i[0] = info.reserved[0];
56  m_status.reserved_i[1] = info.reserved[1];
57  m_status.reserved_f[0] = info.reserved_f[0];
58  m_status.reserved_f[1] = info.reserved_f[1];
59  m_status.reserved_f[2] = info.reserved_f[2];
60  m_status.reserved_f[3] = info.reserved_f[3];
61  m_status.ctime = ctime;
62 
63  double dcount;
64  double dnbyte;
65  m_status.evtrate_in = 0;
66  m_status.evtsize_in = 0;
67  m_status.flowrate_in = 0;
68  m_status.evtrate_out = 0;
69  m_status.evtsize_out = 0;
70  m_status.flowrate_out = 0;
71  if (m_ioinfo[0].getLocalPort() > 0) {
72  m_status.connection_in = m_ioinfo[0].getState() == 1;
73  m_status.nqueue_in = m_ioinfo[0].getRXQueue();
74  }
75  if (m_ioinfo[1].getLocalPort() > 0) {
76  m_status.connection_out = m_ioinfo[1].getState() == 1;
77  m_status.nqueue_out = m_ioinfo[1].getRXQueue();
78  }
79  if ((dcount = info.io[0].count - m_status.nevent_in) > 0) {
80  dnbyte = info.io[0].nbyte - m_nbyte[0];
81  m_status.evtrate_in = dcount / length / 1000.;
82  m_status.evtsize_in = dnbyte / dcount / 1000.;
83  m_status.flowrate_in = dnbyte / length / 1000000.;
84  m_status.nevent_in = info.io[0].count;
85  m_nbyte[0] = info.io[0].nbyte;
86  } else {
87  m_status.evtrate_in = 0;
88  m_status.evtsize_in = 0;
89  m_status.flowrate_in = 0;
90  }
91  if ((dcount = info.io[1].count - m_status.nevent_out) > 0) {
92  dnbyte = info.io[1].nbyte - m_nbyte[1];
93  m_status.evtrate_out = dcount / length / 1000.;
94  m_status.evtsize_out = dnbyte / dcount / 1000.;
95  m_status.flowrate_out = dnbyte / length / 1000000.;
96  m_status.nevent_out = info.io[1].count;
97  m_nbyte[1] = info.io[1].nbyte;
98  } else {
99  m_status.evtrate_out = 0;
100  m_status.evtsize_out = 0;
101  m_status.flowrate_out = 0;
102  }
103  }
104  return m_status;
105 }
Abstract base class for different kinds of events.