Belle II Software development
PrintData.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/PrintData.h>
10#include <rawdata/dataobjects/RawPXD.h>
11#include <framework/core/InputController.h>
12
13#include <iostream>
14#include <fstream>
15#include <time.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <vector>
19
20
21using namespace std;
22using namespace Belle2;
23
24//#define DEBUG
25
26//-----------------------------------------------------------------
27// Register the Module
28//-----------------------------------------------------------------
29REG_MODULE(PrintData);
30
31//-----------------------------------------------------------------
32// Implementation
33//-----------------------------------------------------------------
34
36{
37 //Set module properties
38 setDescription("Encode DataStore into RingBuffer");
39 n_basf2evt = -1;
41 B2INFO("PrintData: Constructor done.");
42 m_ncpr = 0;
43 m_nftsw = 0;
44 m_print_cnt = 0;
45 m_start_utime = 0;
46 for (int i = 0; i < 10; i++) hist[ i ] = NULL;
47 for (int i = 0; i < 1000; i++) prev_tv_eve[ i ] = 0;
48 prev_tv_pos = 0;
49 for (int i = 0; i < 1000; i++) tv_flag[ i ] = 0;
50
51}
52
53
54
55PrintDataModule::~PrintDataModule()
56{
57}
58
60{
61
62 B2INFO("PrintData: initialize() started.");
63 prev_tv_pos = 0;
64
65 // StoreArray<RawCOPPER>::registerTransient(s_auxMCParticlesName.c_str());
66 // StoreObjPtr<RawCOPPER>::registerTransient();
67 // Initialize EvtMetaData
68 // m_eventMetaDataPtr.registerAsPersistent();
69 // Create Message Handler
70 B2INFO("PrintData: initialize() done.");
71
72
73 char hname[100];
74
75
76 char title[100];
77 int size = 0;
78 double min = 0.;
79 double max = 100.;
80
81
82 sprintf(title, "Event Number");
83 sprintf(hname, "h_00");
84 size = 1000;
85 min = 0.;
86 max = 1.e5;
87 hist[ 0 ] = new TH1F(hname, title, size, min, max);
88 sprintf(title, "Size per COPPER");
89 sprintf(hname, "h_01");
90 size = 1000;
91 min = 0.;
92 max = 1000.;
93 hist[ 1 ] = new TH1F(hname, title, size, min, max);
94 sprintf(title, "nodeid");
95 sprintf(hname, "h_02");
96 size = 50;
97 min = 0.;
98 max = 50.;
99 hist[ 2 ] = new TH1F(hname, title, size, min, max);
100 sprintf(hname, "h_03");
101 sprintf(title, "event rate");
102 size = 5000;
103 min = 0.;
104 max = 5000.;
105 hist[ 3 ] = new TH1F(hname, title, size, min, max);
106 sprintf(hname, "h_04");
107 sprintf(title, "time difference");
108 size = 300;
109 min = 0.;
110 max = 3.;
111 hist[ 4 ] = new TH1F(hname, title, size, min, max);
112 sprintf(title, "time difference");
113 size = 2000;
114 min = -0.01;
115 max = 0.01;
116 sprintf(hname, "h_05");
117 hist[ 5 ] = new TH1F(hname, title, size, min, max);
118 sprintf(hname, "h_06");
119 hist[ 6 ] = new TH1F(hname, title, size, min, max);
120 sprintf(hname, "h_07");
121 hist[ 7 ] = new TH1F(hname, title, size, min, max);
122 sprintf(hname, "h_08");
123 hist[ 8 ] = new TH1F(hname, title, size, min, max);
124 sprintf(hname, "h_09");
125 hist[ 9 ] = new TH1F(hname, title, size, min, max);
126
127}
128
130{
131
132 TFile f("temp.root", "RECREATE");
133 // TFile f(argv[1], "RECREATE");
134 // tree.Write();
135 for (int i = 0; i < 10 ; i++) {
136 hist[ i ]->Write();
137 delete hist[ i ];
138 }
139 f.Close();
140
141}
142
143
144
145
146//
147// User defined functions
148//
149
150
151void PrintDataModule::printBuffer(int* buf, int nwords)
152{
153 // printf("%.8x :", 0);
154 for (int j = 0; j < nwords; j++) {
155 printf(" %.8x", buf[ j ]);
156 if ((j + 1) % 10 == 0) {
157 // printf("\n%.8x :", j + 1);
158 printf("\n");
159 }
160 m_print_cnt++;
161 }
162 printf("\n");
163
164 return;
165}
166
167
169{
170 int* buf = raw_datablock->GetBuffer(i);
171 int nwords = raw_datablock->GetBlockNwords(i);
172 printf("*******FTSW data**********: nwords %d\n", nwords);
173 printBuffer(buf, nwords);
174
175
176 RawFTSW rawftsw;
177 int delete_flag = 0; // No need to free the buffer
178 int num_event = 1;
179 int num_nodes = 1;
180 rawftsw.SetBuffer(buf, nwords, delete_flag, num_event, num_nodes);
181
182
183 timeval tv;
184 int n = 0;
185 rawftsw.GetTTTimeVal(n, &tv);
186 printf("eve %u TLU %d: %d %d %.8x: tv %d %d\n",
187 rawftsw.GetEveNo(n),
188 rawftsw.Get15bitTLUTag(n),
189 rawftsw.GetBlockNwords(n),
190 rawftsw.GetNwordsHeader(n),
191 rawftsw.GetFTSWNodeID(n),
192 (int)(tv.tv_sec), (int)(tv.tv_usec)
193 );
194
195
196 m_nftsw++;
197 return;
198}
199
200
201void PrintDataModule::printCOPPEREvent(RawCOPPER* raw_copper, int n, int array_index)
202{
203
204// printf("%%%%%%%%%%%%%%%%%%%%%%%%%\n");
205// printBuffer(raw_copper->GetWholeBuffer(),raw_copper->TotalBufNwords());
206
207 unsigned int eve = raw_copper->GetEveNo(n);
208
209 if (array_index == 0 && n == 0) {
210 timeval tv;
211 raw_copper->GetTTTimeVal(n, &tv);
212 // printf("%.8x %.8x %x\n", raw_copper->GetTTUtime(n), raw_copper->GetTTCtimeTRGType(n), raw_copper->GetTTCtime(n));
213 if (hist[3]->GetEntries() == 0) {
214 m_start_utime = raw_copper->GetTTUtime(n);
215 }
216
217
218 prev_tv[ prev_tv_pos ] = tv;
219 prev_tv_eve[ prev_tv_pos ] = eve;
220 tv_flag[ prev_tv_pos ] = 0;
221 prev_tv_pos++;
222
223 // 1
224 for (int i = 0; i < prev_tv_pos ; i++) {
225 if ((int)(eve - prev_tv_eve[ i ]) == 1) {
226 float diff = (float)(tv.tv_sec - prev_tv[ i ].tv_sec) + (float)(tv.tv_usec - prev_tv[ i ].tv_usec) * 1.e-6 ;
227 hist[ 4 ]->Fill(diff);
228 hist[ 5 ]->Fill(diff);
229 tv_flag[ i ] |= 0x2;
230 tv_flag[ prev_tv_pos - 1 ] |= 0x1;
231 }
232 if ((int)(eve - prev_tv_eve[ i ]) == -1) {
233 float diff = (float)(tv.tv_sec - prev_tv[ i ].tv_sec) + (float)(tv.tv_usec - prev_tv[ i ].tv_usec) * 1.e-6 ;
234 hist[ 4 ]->Fill(-diff);
235 hist[ 5 ]->Fill(-diff);
236 tv_flag[ i ] |= 0x1;
237 tv_flag[ prev_tv_pos - 1 ] |= 0x2;
238 }
239 }
240
241 for (int i = 0; i < prev_tv_pos ; i++) {
242 if (tv_flag[ i ] == 3) {
243 for (int j = i; j < prev_tv_pos - 1 ; j++) {
244 prev_tv[ j ] = prev_tv[ j + 1 ];
245 prev_tv_eve[ j ] = prev_tv_eve[ j + 1 ];
246 tv_flag[ j ] = tv_flag[ j + 1 ];
247 }
248 prev_tv_pos--;
249 }
250 }
251
252 if (eve % 10000 == 0) printf("1 %d %d\n", (int)(tv.tv_sec) - 1422134556, (int)eve);
253 if (prev_tv_pos > 100) {
254 for (int i = 0; i < prev_tv_pos ; i++) {
255 printf(" a %d %u %d\n", i, prev_tv_eve[i ], tv_flag[ i ]);
256 }
257 exit(1);
258 }
259
260
261
262
263 hist[ 3 ]->Fill((float)(raw_copper->GetTTUtime(n) - m_start_utime));
264 }
265
266 hist[ 0 ]->Fill((float)(eve));
267 hist[ 1 ]->Fill((float)(raw_copper->GetBlockNwords(n)));
268 hist[ 2 ]->Fill((float)(raw_copper->GetNodeID(n) & 0xFFF));
269
270
271 for (int i = 0; i < 4; i++) {
272 if (raw_copper->Get1stFINESSENwords(n) > 0) {
273
274 }
275 }
276
277 return;
278
279 /* The following code is commented out since it's placed after a return
280 * and it causes a cppcheck warning unreachableCode */
281
282 /*
283 printf(": Event # %u : node ID 0x%.8x : block size %d bytes\n",
284 raw_copper->GetEveNo(n), raw_copper->GetNodeID(n),
285 (int)(raw_copper->GetBlockNwords(n) * sizeof(int)));
286
287
288 //#ifdef DEBUG
289 printf("===== Raw COPPER data block(including 4 FINESSE buffers )\n");
290 printBuffer(raw_copper->GetBuffer(n), raw_copper->GetBlockNwords(n));
291
292 // if (!(raw_copper->CheckCOPPERMagic( i ))) {
293 // ErrorMessage print_err;
294 // char err_buf[500];
295 // sprintf(err_buf, "Invalid Magic word 0x7FFFF0008=%x 0xFFFFFAFA=%x 0xFFFFF5F5=%x 0x7FFF0009=%x\n",
296 // raw_copper->GetMagicDriverHeader( i ),
297 // raw_copper->GetMagicFPGAHeader( i ),
298 // raw_copper->GetMagicFPGATrailer( i ),
299 // raw_copper->GetMagicDriverTrailer( i ));
300 // print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
301 // sleep(12345678);
302 // exit(-1);
303 // }
304 //#endif
305
306 //
307 // Print data from each FINESSE
308 //
309
310 m_ncpr++;
311 */
312}
313
315{
316 printf(": block size %d bytes : bebafeca = %04x :\n",
317 (int)raw_pxd->size(), raw_pxd->data()[0]);
318 printf("******* Raw PXD data block (including Detector Buffer) **********\n");
319 printBuffer(raw_pxd->data(), raw_pxd->size());
320}
321
323{
324
325 B2INFO("aPrintData: event() started.");
326
327 StoreArray<RawECL> raw_eclarray;
328 for (int i = 0; i < raw_eclarray.getEntries(); i++) {
329 for (int j = 0; j < raw_eclarray[ i ]->GetNumEntries(); j++) {
330 // printf("\n===== DataBlock(RawECL) : Block # %d ", i);
331 printCOPPEREvent(raw_eclarray[ i ], j, i);
332 }
333 }
334
335
336
337 // printf("loop %d\n", n_basf2evt);
338 n_basf2evt++;
339
340}
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
unsigned int m_start_utime
Unix time of the run start.
Definition: PrintData.h:93
int tv_flag[1000]
flag of timevalue
Definition: PrintData.h:105
virtual void initialize() override
initialization
Definition: PrintData.cc:59
virtual void printFTSWEvent(RawDataBlock *raw_array, int i)
print the contents of a RawFTSW event
Definition: PrintData.cc:168
virtual void printBuffer(int *buf, int nwords)
print the hex dump of an input
Definition: PrintData.cc:151
virtual void event() override
Module functions to be called from event process.
Definition: PrintData.cc:322
virtual void endRun() override
Called if the current run ends.
Definition: PrintData.cc:129
PrintDataModule()
Constructor / Destructor.
Definition: PrintData.cc:35
int n_basf2evt
No. of sent events.
Definition: PrintData.h:78
unsigned int prev_tv_eve[1000]
Integer time of the previous event.
Definition: PrintData.h:99
timeval prev_tv[1000]
Time of the previous event.
Definition: PrintData.h:96
int m_compressionLevel
Compression parameter.
Definition: PrintData.h:75
int prev_tv_pos
previous timevalue
Definition: PrintData.h:102
int m_print_cnt
counter
Definition: PrintData.h:87
virtual void printPXDEvent(RawPXD *raw_pxd)
print a PXD event
Definition: PrintData.cc:314
TH1F * hist[10]
histogram array
Definition: PrintData.h:90
virtual void printCOPPEREvent(RawCOPPER *raw_array, int i, int array_index)
print the contents of a RawCOPPER event
Definition: PrintData.cc:201
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition: RawCOPPER.h:52
The RawDataBlock class Base class for rawdata handling.
Definition: RawDataBlock.h:27
virtual int * GetBuffer(int n)
get nth buffer pointer
Definition: RawDataBlock.h:53
virtual int GetBlockNwords(int n)
get size of a data block
Definition: RawDataBlock.h:94
The Raw FTSW class.
Definition: RawFTSW.h:30
unsigned int GetFTSWNodeID(int n)
Get Node # ( should be "TTD " )
Definition: RawFTSW.h:58
unsigned int GetEveNo(int n)
Get event #.
Definition: RawFTSW.h:65
int Get15bitTLUTag(int n)
DESY test only.
Definition: RawFTSW.h:166
int GetNwordsHeader(int n)
Get # of words of header.
Definition: RawFTSW.h:51
void GetTTTimeVal(int n, struct timeval *tv)
Get timeval from ctime and utime.
Definition: RawFTSW.h:100
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: RawFTSW.cc:107
The Raw PXD class.
Definition: RawPXD.h:27
virtual int * data(void)
get pointer to data
Definition: RawPXD.cc:81
virtual int size() const
get size of buffer in 32 Bit words
Definition: RawPXD.cc:76
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
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 Get1stFINESSENwords(int n)
get data size of FINESSE slot A buffer
Definition: RawCOPPER.h:476
void GetTTTimeVal(int n, struct timeval *tv)
Get timeval.
Definition: RawCOPPER.h:632
unsigned int GetNodeID(int n)
get node-ID from data
Definition: RawCOPPER.h:397
Abstract base class for different kinds of events.
STL namespace.