Belle II Software  release-08-01-10
PrintEventRate.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 <rawdata/modules/PrintEventRate.h>
10 #include <time.h>
11 
12 using namespace std;
13 using namespace Belle2;
14 
15 #define EVENT_UNIT 75000
16 #define BYTES_PER_WORD 4
17 
18 //-----------------------------------------------------------------
19 // Register the Module
20 //-----------------------------------------------------------------
21 REG_MODULE(PrintEventRate);
22 
23 //-----------------------------------------------------------------
24 // Implementation
25 //-----------------------------------------------------------------
26 
27 PrintEventRateModule::PrintEventRateModule() :
28  m_subrun(0),
29  m_size(0),
30  m_cpr(0),
31  m_cpr_svd(0),
32  m_cpr_cdc(0),
33  m_cpr_top(0),
34  m_cpr_arich(0),
35  m_cpr_ecl(0),
36  m_cpr_klm(0),
37  m_cpr_trg(0),
38  m_cpr_others(0),
39  m_evecnt(0)
40 {
41  addParam("PrintInterval", m_print_interval, "Print Interval", 60);
42 
43  m_prev_utime = 0;
44  m_prev_event = 0;
45  m_start_event = 0;
46  m_start_utime = 0;
47  m_run = 0;
48  m_cur_utime = 0;
49  m_cur_event = 0;
50  m_tot_bytes = 0;
51  m_prev_tot_bytes = 0;
52  m_n_basf2evt = 0;
53  m_first_evt = 0;
54 
55  m_erreve = 0;
56  m_errcpr = 0;
57 
58 }
59 
60 
61 
63 {
64 
65 }
66 
67 
69 {
70  B2INFO("PrintDataTemplate: initialize() started.");
71 
72  // StoreArray<RawCOPPER>::registerTransient(s_auxMCParticlesName.c_str());
73  // StoreObjPtr<RawCOPPER>::registerTransient();
74  // Initialize EvtMetaData
75  // m_eventMetaDataPtr.registerPersistent();
76  // Create Message Handler
77  B2INFO("PrintDataTemplate: initialize() done.");
78 
79 }
80 
81 
82 
84 {
85  m_cur_utime = raw_copper->GetTTUtime(i);
86  m_cur_event = raw_copper->GetEveNo(i);
87  m_run = raw_copper->GetRunNo(i);
88  m_subrun = raw_copper->GetSubRunNo(i);
89 
90  unsigned int error_flag = 0;
91  error_flag = (unsigned int)(raw_copper->GetDataType(i));
92  if (error_flag) {
93  printf("!!!!!!!!! ERROR (RawCOPPER hdr) !!!!!!!!!! : run %d sub %d event %u errflag %.8x nodeID %.8x\n",
94  m_run, m_subrun, m_cur_event, error_flag, raw_copper->GetNodeID(i));
95  m_errcpr++;
96  }
97 
98  // printf("eve %d\n", m_cur_event );
99  m_tot_bytes += (double)(BYTES_PER_WORD * raw_copper->GetBlockNwords(i));
100 
101  // printf("TIME %u start %u eve %d\n", m_cur_utime, m_start_utime, m_n_basf2evt );
102 
103  // fflush(stdout);
104  if (m_first_evt == 0) {
105  m_first_evt = 1;
110  m_prev_tot_bytes = 0;
111  }
112 
113 
114 }
115 
117 {
118  int interval = m_cur_utime - m_prev_utime;
119  int total_time = m_cur_utime - m_start_utime;
120  time_t timer = (time_t)m_cur_utime;
121  struct tm t_st;
122  // time(&timer);
123  localtime_r(&timer, &t_st);
124 
125  if (interval != 0) {
126  printf("END %d/%d/%d/%d:%d:%d run %d sub %d Event %u Rate %lf [kHz] %lf [MB/s] RunTime %d [s] interval %d [s] total %lf [bytes] cpr %d s %d c %d to %d a %d e %d k %d tr %d other %d erreve %d errcpr %d\n",
127  t_st.tm_year + 1900, t_st.tm_mon + 1, t_st.tm_mday, t_st.tm_hour, t_st.tm_min, t_st.tm_sec,
128  m_run, m_subrun, m_n_basf2evt, (double)(m_n_basf2evt - m_prev_event) / interval / 1.e3,
129  (double)(m_tot_bytes - m_prev_tot_bytes) / interval / 1.e6,
130  total_time, interval, m_tot_bytes / 1.e6,
132 
133  } else {
134  printf("END %d/%d/%d/%d:%d:%d run %d sub %d Event %u Rate %lf [kHz] %lf [MB/s] RunTime %d [s] interval %d [s] total %lf [bytes] cpr %d s %d c %d to %d a %d e %d k %d tr %d other %d erreve %d errcpr %d\n",
135  t_st.tm_year + 1900, t_st.tm_mon + 1, t_st.tm_mday, t_st.tm_hour, t_st.tm_min, t_st.tm_sec,
136  m_run, m_subrun, m_n_basf2evt, 0., 0.,
137  total_time, interval, m_tot_bytes / 1.e6,
139  }
140  fflush(stdout);
141 }
142 
144 {
145  StoreArray<RawCOPPER> raw_cprarray;
146  StoreArray<RawFTSW> raw_ftswarray;
147  StoreArray<RawDataBlock> raw_datablkarray;
148  StoreArray<RawTLU> raw_tluarray;
149  StoreArray<RawPXD> raw_pxdarray;
150  StoreArray<RawSVD> raw_svdarray;
151  StoreArray<RawCDC> raw_cdcarray;
152  StoreArray<RawTOP> raw_toparray;
153  StoreArray<RawARICH> raw_aricharray;
154  StoreArray<RawECL> raw_eclarray;
155  StoreArray<RawKLM> raw_klmarray;
156  StoreArray<RawTRG> raw_trgarray;
157 
158 
159  int datablk_blknum = raw_datablkarray.getEntries();
160  int cpr_blknum = raw_cprarray.getEntries();
161  int tlu_blknum = raw_tluarray.getEntries();
162  int ftsw_blknum = raw_ftswarray.getEntries();
163  int pxd_blknum = raw_pxdarray.getEntries();
164  int svd_blknum = raw_svdarray.getEntries();
165  int cdc_blknum = raw_cdcarray.getEntries();
166  int top_blknum = raw_toparray.getEntries();
167  int arich_blknum = raw_aricharray.getEntries();
168  int ecl_blknum = raw_eclarray.getEntries();
169  int klm_blknum = raw_klmarray.getEntries();
170  int trg_blknum = raw_trgarray.getEntries();
171 
172 
173 
174  if (m_n_basf2evt == 0) {
175  m_cpr =
176  datablk_blknum +
177  cpr_blknum +
178  tlu_blknum +
179  ftsw_blknum +
180  pxd_blknum +
181  svd_blknum +
182  cdc_blknum +
183  top_blknum +
184  arich_blknum +
185  ecl_blknum +
186  klm_blknum +
187  trg_blknum;
188 
189  m_cpr_svd = svd_blknum;
190  m_cpr_cdc = cdc_blknum;
191  m_cpr_top = top_blknum;
192  m_cpr_arich = arich_blknum;
193  m_cpr_ecl = ecl_blknum;
194  m_cpr_klm = klm_blknum;
195  m_cpr_trg = trg_blknum;
197  - (m_cpr_svd
198  + m_cpr_cdc
199  + m_cpr_top
200  + m_cpr_arich
201  + m_cpr_ecl
202  + m_cpr_klm
203  + m_cpr_trg);
204  }
205 
206 
207  //
208  // FTSW + COPPER can be combined in the array
209  //
210  for (int i = 0; i < datablk_blknum; i++) {
211  for (int j = 0; j < raw_datablkarray[ i ]->GetNumEntries(); j++) {
212  int* temp_buf = raw_datablkarray[ i ]->GetBuffer(j);
213  int nwords = raw_datablkarray[ i ]->GetBlockNwords(j);
214  int delete_flag = 0;
215  int num_nodes = 1;
216  int num_events = 1;
217  if (raw_datablkarray[ i ]->CheckFTSWID(j)) {
218  // No operation
219  } else if (raw_datablkarray[ i ]->CheckTLUID(j)) {
220  // No operation
221  } else {
222  // COPPER data block
223  // printf("\n===== DataBlock( RawDataBlock(COPPER) ) : Block # %d ", i);
224  RawCOPPER temp_raw_copper;
225  temp_raw_copper.SetBuffer(temp_buf, nwords, delete_flag, num_nodes, num_events);
226  printCOPPEREvent(&temp_raw_copper, 0);
227 
228  }
229  }
230  }
231 
232  for (int i = 0; i < cpr_blknum; i++) {
233  for (int j = 0; j < raw_cprarray[ i ]->GetNumEntries(); j++) {
234  printCOPPEREvent(raw_cprarray[ i ], j);
235  }
236  }
237 
238  for (int i = 0; i < svd_blknum; i++) {
239  for (int j = 0; j < raw_svdarray[ i ]->GetNumEntries(); j++) {
240  printCOPPEREvent(raw_svdarray[ i ], j);
241  }
242  }
243 
244  for (int i = 0; i < cdc_blknum; i++) {
245  for (int j = 0; j < raw_cdcarray[ i ]->GetNumEntries(); j++) {
246  printCOPPEREvent(raw_cdcarray[ i ], j);
247  }
248  }
249 
250  for (int i = 0; i < top_blknum; i++) {
251  for (int j = 0; j < raw_toparray[ i ]->GetNumEntries(); j++) {
252  printCOPPEREvent(raw_toparray[ i ], j);
253  }
254  }
255 
256  for (int i = 0; i < arich_blknum; i++) {
257  for (int j = 0; j < raw_aricharray[ i ]->GetNumEntries(); j++) {
258  printCOPPEREvent(raw_aricharray[ i ], j);
259  }
260  }
261 
262  for (int i = 0; i < ecl_blknum; i++) {
263  for (int j = 0; j < raw_eclarray[ i ]->GetNumEntries(); j++) {
264  printCOPPEREvent(raw_eclarray[ i ], j);
265  }
266  }
267 
268  for (int i = 0; i < klm_blknum; i++) {
269  for (int j = 0; j < raw_klmarray[ i ]->GetNumEntries(); j++) {
270  printCOPPEREvent(raw_klmarray[ i ], j);
271  }
272  }
273 
274  for (int i = 0; i < trg_blknum; i++) {
275  for (int j = 0; j < raw_trgarray[ i ]->GetNumEntries(); j++) {
276  printCOPPEREvent(raw_trgarray[ i ], j);
277  }
278  }
279 
280  if (m_eventMetaDataPtr->getErrorFlag()) {
281  printf("!!!!!!!!! ERROR (EventMetaData) !!!!!!!!!! : run %d sub %d event %d errflag %.8x\n",
282  m_eventMetaDataPtr->getRun(), m_eventMetaDataPtr->getSubrun(),
283  m_eventMetaDataPtr->getEvent(), m_eventMetaDataPtr->getErrorFlag());
284  m_erreve++;
285  }
286 
287  int interval = (m_cur_utime - m_prev_utime);
288  if (interval >= m_print_interval) {
289  int total_time = m_cur_utime - m_start_utime;
290 
291  time_t timer = (time_t)m_cur_utime;
292  struct tm t_st;
293  // time(&timer);
294  localtime_r(&timer, &t_st);
295 
296  printf("MID %d/%d/%d/%d:%d:%d run %d sub %d Event %u Rate %lf [kHz] %lf [MB/s] RunTime %d [s] interval %d [s] total %lf [bytes]\n",
297  t_st.tm_year + 1900, t_st.tm_mon + 1, t_st.tm_mday, t_st.tm_hour, t_st.tm_min, t_st.tm_sec,
298  m_run, m_subrun, m_n_basf2evt, (double)(m_n_basf2evt - m_prev_event) / interval / 1.e3,
299  (double)(m_tot_bytes - m_prev_tot_bytes) / interval / 1.e6,
300  total_time, interval, m_tot_bytes / 1.e6);
301 
302  fflush(stdout);
306 
310  }
311 
312  // printf("loop %d\n", n_basf2evt);
313  m_n_basf2evt++;
314 
315 }
virtual ~PrintEventRateModule()
Destructor.
unsigned int m_start_utime
unixtime at the beginning
unsigned int m_prev_event
previous event number
virtual void initialize() override
Module function to be called from main process.
unsigned int m_cur_utime
current unixtime
virtual void event() override
Module function to be called from event process.
double m_prev_tot_bytes
previous value of processed data size
virtual void endRun() override
Module function to be called after main process.
unsigned int m_start_event
the first event number
int m_first_evt
first event number
double m_tot_bytes
total processed data size
virtual void printCOPPEREvent(RawCOPPER *raw_array, int i)
print an event
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
Event Meta Data.
unsigned int m_cur_event
current event number
unsigned int m_prev_utime
previous unixtime
int m_print_interval
output interval
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
virtual int GetBlockNwords(int n)
get size of a data block
Definition: RawDataBlock.h:94
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
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
unsigned int GetEveNo(int n)
get subrun #(8bit)
Definition: RawCOPPER.h:390
unsigned int GetTTUtime(int n)
Check if COPPER Magic words are correct.
Definition: RawCOPPER.h:614
int GetSubRunNo(int n)
get run # (14bit)
Definition: RawCOPPER.h:384
int GetDataType(int n)
get contents of header
Definition: RawCOPPER.h:404
unsigned int GetNodeID(int n)
get node-ID from data
Definition: RawCOPPER.h:397
int GetRunNo(int n)
Exp# (10bit) run# (14bit) restart # (8bit)
Definition: RawCOPPER.h:377
Abstract base class for different kinds of events.