Belle II Software development
MonitorDataCOPPER.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/rawdata/modules/MonitorDataCOPPER.h>
9#include <framework/datastore/StoreArray.h>
10#include <rawdata/dataobjects/RawECL.h>
11
12#include <TDirectory.h>
13
14using namespace std;
15using namespace Belle2;
16
17
18//#define DEBUG
19
20//-----------------------------------------------------------------
21// Register the Module
22//-----------------------------------------------------------------
23REG_MODULE(MonitorDataCOPPER);
24
25//-----------------------------------------------------------------
26// Implementation
27//-----------------------------------------------------------------
28
30{
31 //Set module properties
32
33 setDescription("Monitor Raw Data");
35 m_loop = -1;
36
37}
38
39
40
41MonitorDataCOPPERModule::~MonitorDataCOPPERModule()
42{
43}
44
46{
47
48// double t_min = 0.;
49// double t_max = 600.;
50// int t_nbin = 600;
51 TDirectory* oldDir = gDirectory;
52
53 TDirectory* dirDAQ = NULL;
54 dirDAQ = oldDir->mkdir("DAQExample");
55 dirDAQ->cd();
56 h_nevt = new TH1F("h_nevt", "Number of Events / COPPER; COPPER ID; # of Events", 20, 0, 20);
57
58 h_size = new TH1F("h_size", "Data size / COPPER; Data size [Byte]; entries", 50, 0, 10000);
59
60 h_rate = new TH1F("h_rate", "Event rate; Time [s]; Event Rate [Hz]", 1000, 0, 100000);
61 h_diff = new TH1F("h_diff", "Event inetrval; Event interval[s]; # of Events", 2000, 0, 0.2);
62 oldDir->cd();
63
64}
65
66
68{
69 REG_HISTOGRAM
70}
71
72
73double MonitorDataCOPPERModule::getTimeSec()
74{
75 struct timeval t;
76 gettimeofday(&t, NULL);
77 return (t.tv_sec + t.tv_usec * 1.e-6);
78}
79
80
81
82//
83// User defined functions
84//
85
86
88{
89 if (m_loop <= 0) {
90
91 m_loop = 0;
92 m_nevt = 0;
93 }
94
95
96 //StoreArray<RawCOPPER> rawcprarray;
97 //StoreArray<RawCDC> raw_dblkarray;
98 //StoreArray<RawDataBlock> raw_dblkarray;
99 StoreArray<RawECL> raw_dblkarray;
100
101 int ncpr = raw_dblkarray.getEntries();
102 timeval prev_tv;
103 prev_tv = m_tv;
104 for (int j = 0; j < ncpr; j++) {
105 m_nevt++;
106 for (int i = 0; i < raw_dblkarray[j]->GetNumEntries(); i++) {
107 RawCOPPER temp_rawcopper;
108 temp_rawcopper.SetBuffer(raw_dblkarray[j]->GetBuffer(i),
109 raw_dblkarray[j]->GetBlockNwords(i), 0, 1, 1);
110
111 if (j == 0 && i == 0) {
112 temp_rawcopper.GetTTTimeVal(i, &m_tv);
113 //int utime = temp_rawcopper.GetTTUtime(i);
114 if (m_loop == 0) {
115 m_start_time = (double)m_tv.tv_sec;
116 }
117 }
118 int size_byte = raw_dblkarray[j]->GetBlockNwords(i) * sizeof(int);
119 h_nevt->SetBinContent(j + 1, m_nevt);
120 h_size->SetBinContent(j + 1, h_size->GetBinContent(i + 1) + size_byte);
121
122 }
123 }
124
125 h_diff->Fill(m_tv.tv_sec - prev_tv.tv_sec + (m_tv.tv_usec - prev_tv.tv_usec) * 1.e-6);
126
127
128
129 int tdiff_cur = m_tv.tv_sec - (int)m_start_time;
130
131 if (m_loop % 1000 == 99) {
132 // printf("utime %d timeval %d %lf time %d\n", utime, m_tv.tv_sec, m_start_time,tdiff_cur );
133 }
134 if (tdiff_cur < 100000 && tdiff_cur > 0) {
135 h_rate->SetBinContent(tdiff_cur / 100, h_rate->GetBinContent(tdiff_cur / 100) + 0.01);
136 }
137
138
139 m_loop++;
140
141
142
143}
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
void initialize() override
Module functions to be called from main process.
void event() override
Module functions to be called from event process.
int m_loop
No. of sent events.
MonitorDataCOPPERModule()
Constructor / Destructor.
void defineHisto() override
Histogram definition.
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition: RawCOPPER.h:52
void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
Definition: RawCOPPER.cc:141
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
void GetTTTimeVal(int n, struct timeval *tv)
Get timeval.
Definition: RawCOPPER.h:632
Abstract base class for different kinds of events.
STL namespace.