Belle II Software  release-08-01-10
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 
14 using namespace std;
15 using namespace Belle2;
16 
17 
18 //#define DEBUG
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 REG_MODULE(MonitorDataCOPPER)
24 
25 //-----------------------------------------------------------------
26 // Implementation
27 //-----------------------------------------------------------------
28 
30 {
31  //Set module properties
32 
33  setDescription("Monitor Raw Data");
34  setPropertyFlags(c_ParallelProcessingCertified);
35  m_loop = -1;
36 
37 }
38 
39 
40 
41 MonitorDataCOPPERModule::~MonitorDataCOPPERModule()
42 {
43 }
44 
45 void MonitorDataCOPPERModule::defineHisto()
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  h_hslb_size[0] = new TH1F("h_hslb_size_0", "Data size / HSLB; Data size [Byte]; entries", 50, 0, 10000);
66  h_hslb_size[1] = new TH1F("h_hslb_size_1", "Data size / HSLB; Data size [Byte]; entries", 50, 0, 10000);
67  h_hslb_size[2] = new TH1F("h_hslb_size_2", "Data size / HSLB; Data size [Byte]; entries", 50, 0, 10000);
68  h_hslb_size[3] = new TH1F("h_hslb_size_3", "Data size / HSLB; Data size [Byte]; entries", 50, 0, 10000);
69  h_hslb_nevt = new TH1F("h_hslb_nevt", "Number of Events / HSLB; HSLB slot; # of Events", 4, 0, 4);
70  h_hslb_rate = new TH1F("h_hslb_rate", "Data rate / HSLB; HSLB slot; Data rate [Bytes/s]", 4, 0, 4);
71  */
72 }
73 
74 
75 void MonitorDataCOPPERModule::initialize()
76 {
77  REG_HISTOGRAM
78 }
79 
80 
81 void MonitorDataCOPPERModule::beginRun()
82 {
83 
84 }
85 
86 
87 
88 
89 void MonitorDataCOPPERModule::endRun()
90 {
91  //fill Run data
92 
93 
94 }
95 
96 
97 void MonitorDataCOPPERModule::terminate()
98 {
99 
100 }
101 
102 double MonitorDataCOPPERModule::getTimeSec()
103 {
104  struct timeval t;
105  gettimeofday(&t, NULL);
106  return (t.tv_sec + t.tv_usec * 1.e-6);
107 }
108 
109 
110 
111 //
112 // User defined functions
113 //
114 
115 
116 void MonitorDataCOPPERModule::event()
117 {
118  if (m_loop <= 0) {
119 
120  m_loop = 0;
121  m_nevt = 0;
122  }
123 
124 
125  //StoreArray<RawCOPPER> rawcprarray;
126  //StoreArray<RawCDC> raw_dblkarray;
127  //StoreArray<RawDataBlock> raw_dblkarray;
128  StoreArray<RawECL> raw_dblkarray;
129 
130  int ncpr = raw_dblkarray.getEntries();
131  timeval prev_tv;
132  prev_tv = m_tv;
133  for (int j = 0; j < ncpr; j++) {
134  m_nevt++;
135  for (int i = 0; i < raw_dblkarray[j]->GetNumEntries(); i++) {
136  RawCOPPER temp_rawcopper;
137  temp_rawcopper.SetBuffer(raw_dblkarray[j]->GetBuffer(i),
138  raw_dblkarray[j]->GetBlockNwords(i), 0, 1, 1);
139 
140  if (j == 0 && i == 0) {
141  temp_rawcopper.GetTTTimeVal(i, &m_tv);
142  //int utime = temp_rawcopper.GetTTUtime(i);
143  if (m_loop == 0) {
144  m_start_time = (double)m_tv.tv_sec;
145  }
146  }
147  int size_byte = raw_dblkarray[j]->GetBlockNwords(i) * sizeof(int);
148  h_nevt->SetBinContent(j + 1, m_nevt);
149  h_size->SetBinContent(j + 1, h_size->GetBinContent(i + 1) + size_byte);
150 
151  }
152  }
153 
154  h_diff->Fill(m_tv.tv_sec - prev_tv.tv_sec + (m_tv.tv_usec - prev_tv.tv_usec) * 1.e-6);
155 
156 
157 
158  int tdiff_cur = m_tv.tv_sec - (int)m_start_time;
159 
160  if (m_loop % 1000 == 99) {
161  // printf("utime %d timeval %d %lf time %d\n", utime, m_tv.tv_sec, m_start_time,tdiff_cur );
162  }
163  if (tdiff_cur < 100000 && tdiff_cur > 0) {
164  h_rate->SetBinContent(tdiff_cur / 100, h_rate->GetBinContent(tdiff_cur / 100) + 0.01);
165  }
166 
167 
168  m_loop++;
169 
170 
171 
172 }
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
A class definition of an input module for Sequential ROOT I/O.
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.