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