Belle II Software  release-06-01-15
trgtopUnpackerModule.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 <trg/top/modules/trgtopUnpacker/trgtopUnpackerModule.h>
10 
11 #include <iostream>
12 
13 /* --------------- WARNING ---------------------------------------------- *
14 If you have more complex parameter types in your class then simple int,
15 double or std::vector of those you might need to uncomment the following
16 include directive to avoid an undefined reference on compilation.
17 * ---------------------------------------------------------------------- */
18 // #include <framework/core/ModuleParam.templateDetails.h>
19 
20 //using namespace std;
21 using namespace Belle2;
22 
23 //-----------------------------------------------------------------
24 // Register the Module
25 //-----------------------------------------------------------------
26 REG_MODULE(TRGTOPUnpacker);
27 
28 std::string TRGTOPUnpackerModule::version() const
29 {
30  return std::string("1.00");
31 }
32 
33 //-----------------------------------------------------------------
34 // Implementation
35 //-----------------------------------------------------------------
36 
38  : Module::Module(), m_eventNumber(0), m_trigType(0), m_nodeId(0), m_nWords(0), m_reportedAlreadyRun_1(false),
39  m_reportedAlreadyRun_2(false)
40 {
41  // Set module properties
42 
43 
44  std::string desc = "TRGTOPUnpackerModule(" + version() + ")";
45  setDescription(desc);
47 
48  B2DEBUG(20, "TRGTOPUnpacker: Constructor done.");
49 
50 
51  // Parameter definitions
52  addParam("overrideControlBits", m_overrideControlBits,
53  "Override control bits in data",
54  true);
55  // false);
56 
57 }
58 
59 TRGTOPUnpackerModule::~TRGTOPUnpackerModule()
60 {
61 }
62 
64 {
65 
66  m_TRGTOPCombinedT0DecisionArray.registerInDataStore();
67  // m_TRGTOPCombinedTimingArray.registerInDataStore();
68  m_TRGTOPSlotTimingArray.registerInDataStore();
69 
70  // m_TRGTOPCombinedTimingArray.registerRelationTo(m_TRGTOPSlotTimingArray);
71  // m_TRGTOPSlotTimingArray.registerRelationTo(m_TRGTOPCombinedTimingArray);
72 
73 }
74 
75 
77 {
78  m_reportedAlreadyRun_1 = false;
79  m_reportedAlreadyRun_2 = false;
80 }
81 
83 {
84 
85  StoreArray<RawTRG> raw_trgarray;
86 
87  for (int i = 0; i < raw_trgarray.getEntries(); i++) {
88 
89  // Check PCIe40 data or Copper data
90  if (raw_trgarray[i]->GetMaxNumOfCh(0) == 48) { m_pciedata = true; }
91  else if (raw_trgarray[i]->GetMaxNumOfCh(0) == 4) { m_pciedata = false; }
92  else { B2FATAL("TRGTOPUnpackerModule: Invalid value of GetMaxNumOfCh from raw data: " << LogVar("Number of ch: ", raw_trgarray[i]->GetMaxNumOfCh(0))); }
93 
94  int node_id = 0;
95  int ch_id_1 = 0;
96  int ch_id_2 = 1;
97  if (m_pciedata) {
98  node_id = 0x10000001;
99  ch_id_1 = 23;
100  ch_id_2 = 24;
101  } else {
102  node_id = 0x12000001;
103  ch_id_1 = 0;
104  ch_id_2 = 1;
105  }
106 
107  for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
108 
109  m_nodeId = raw_trgarray[i]->GetNodeID(j);
110 
111  if (m_nodeId == node_id) {
112 
113  int numberOfChannels = raw_trgarray[i]->GetMaxNumOfCh(i);
114 
115  // B2INFO("raw_trgarray.GetMaxNumOfCh() = " << numberOfChannels);
116 
117  for (int channel = 0; channel < numberOfChannels; channel++) {
118 
119  if (channel != ch_id_1 && channel != ch_id_2) continue;
120 
121  m_nWords = raw_trgarray[i]->GetDetectorNwords(j, channel);
122 
123  // B2INFO("raw_trgarray[" << i << "]->GetDetectorNwords(" << j << ", " << channel << ") = " << m_nWords);
124 
125  // if ( m_nWords > 3 ) { ////general header is 3 words long
126  if (m_nWords > 0) {
127 
128  m_eventNumber = raw_trgarray[i]->GetEveNo(j);
129  m_trigType = raw_trgarray[i]->GetTRGType(j);
130 
131  // B2INFO("raw_trgarray.getEntries() = " << raw_trgarray.getEntries());
132  // B2INFO("raw_trgarray[i]->GetNumEntries() = " << raw_trgarray[i]->GetNumEntries());
133  // B2INFO("raw_trgarray[]->GetEveNo(j) = " << raw_trgarray[i]->GetEveNo(j));
134  // B2INFO("raw_trgarray[]->GetNodeID(j) = " << std::hex << raw_trgarray[i]->GetNodeID(j) << std::dec);
135  // B2INFO("raw_trgarray[]->GetDetectorNwords(j,0) = " << m_nWords);
136 
137  readDAQEvent(raw_trgarray[i], j, channel);
138 
139  }
140  }
141  }
142  }
143  }
144 }
145 
146 void TRGTOPUnpackerModule::readDAQEvent(RawTRG* raw_daq, int j, int channel)
147 {
148  // if (raw_daq->GetDetectorNwords(j, channel) > 3) { ///general header is 3 words long
149  if (raw_daq->GetDetectorNwords(j, channel) > 0) {
150  unpackT0Decisions(raw_daq->GetDetectorBuffer(j, channel), channel);
151  }
152 }
153 
154 void TRGTOPUnpackerModule::unpackT0Decisions(int* rdat, int channel)
155 {
156 
157  // B2INFO("channel, data size (32bit words) = " << channel << ", " << m_nWords);
158 
159  // Information for each data window
160 
161  // rvc from the header of the buffer
162  int rvcL1 = rdat[2] & 0x7ff;
163 
164  // L1 event number
165  int eventNumberL1 = (rdat[2] >> 12) & 0xfffff;
166 
167  // B2INFO("l1_rvc from header = " << rvcL1);
168  // B2INFO("eventNumberL1 (evt) from buffer header = " << eventNumberL1);
169 
170  bool dataFormatKnown = false;
171 
172  int windowSize = -1;
173  int numberOfWindows = -1;
174 
175  int dataFormatVersionExpected = -1;
176  int revoClockDeltaExpected = 4;
177  int cntr127DeltaExpected = 4;
178 
179  // 3 = 3: header only
180  // 1875 = 3 + 48*39: format used starting ~June 30 2019 and until Oct. 1, 2019 (until Receive FW version 0x02067301)
181  // 771 = 3 + 24*32: format used starting ~Oct. 1, 2019 (Receive FW version 0x02067301 and newer)
182  // 1539 = 3 + 48*32: format used starting ~Mar. 25, 2021 (Receive FW version 0x03020003 and newer)
183  // 3075 = 3 + 96*32: format used starting ~Mar. 25, 2021 (Receive FW version 0x03020003 and newer)
184 
185  // m_nWords==3 means only a header
186  if (m_nWords == 3) {
187  windowSize = 0;
188  numberOfWindows = 0;
189  dataFormatKnown = true;
190  dataFormatVersionExpected = 0;
191  } else if (m_nWords == 771) {
192  windowSize = 32;
193  numberOfWindows = 24;
194  dataFormatKnown = true;
195  dataFormatVersionExpected = 2;
196  } else if (m_nWords == 1875) {
197  windowSize = 39;
198  numberOfWindows = 48;
199  dataFormatKnown = true;
200  dataFormatVersionExpected = 1;
201  } else if (m_nWords == 1539) {
202  windowSize = 32;
203  numberOfWindows = 48;
204  dataFormatKnown = true;
205  dataFormatVersionExpected = 4;
206  } else if (m_nWords == 3075) {
207  windowSize = 32;
208  numberOfWindows = 96;
209  dataFormatKnown = true;
210  dataFormatVersionExpected = 5;
211  }
212 
213  if (!dataFormatKnown) {
214  if (!m_reportedAlreadyRun_1) {
215  B2INFO("Unknown data format / error / exiting. This condition is reported only once per run.");
216  m_reportedAlreadyRun_1 = true;
217  }
218  return;
219  }
220 
221  // FTSW / rvc / the difference is 1280 (expected)
222  // int revoClockDeltaJump1 = -92;
223  // int revoClockDeltaJump2 = 1188;
224 
225  // VME / 16bit counter
226  // int cntr127DeltaJump1 = -92;
227  // int cntr127DeltaJump2 = -65532;
228 
229  // if ( dataFormatVersionExpected > 0 ) B2INFO("---------------------------------------------------------------------------------------------------------------");
230 
231  // B2INFO("Data format version (as expected according to data size) = " << dataFormatVersionExpected);
232 
233  // if ( numberOfWindows != 0 ) {
234  // B2INFO("Number of 32bit words in TOP L1 data buffer = " << m_nWords);
235  // B2INFO("Number of windows = " << numberOfWindows);
236  // B2INFO("Window size in 32bit words = " << windowSize);
237  // }
238 
239  // various test patterns will be used to check the data
240  unsigned int testPattern;
241 
242  int revoClockLast = -1;
243  int cntr127Last = -1;
244 
245  // error counter for possible data corruption
246  unsigned int errorCountEvent = 0;
247 
248  bool performBufferAnalysis = true;
249  bool reportAllErrors = true;
250  bool reportSummaryErrors = true;
251 
252  // check if this event's buffer is a dummy buffer
253  int counterDummyWindows = 0;
254  unsigned int testPatternDummyEvent = 0xbbbb;
255  for (int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
256  int index = iWindow * windowSize + 3;
257  testPattern = (rdat[index] >> 16) & 0xffff;
258  if (testPattern == testPatternDummyEvent) {
259  counterDummyWindows++;
260  }
261  // March 30, 2022: need to be able to override the settings in data
262  if (!m_overrideControlBits) {
263  // Oct. 31, 2020: three most significant bits are now used to control unpacker from FW
264  // Note that setting either flag for any of the windows changes it for all windows here
265  testPattern = (rdat[index + 2] >> 29) & 0x7;
266  if (testPattern & 0x1) performBufferAnalysis = false;
267  if (testPattern & 0x2) reportAllErrors = false;
268  if (testPattern & 0x4) reportSummaryErrors = false;
269  }
270  }
271 
272  // note that events with empty buffer have numberOfWindows=0
273  if (counterDummyWindows == numberOfWindows) {
274  performBufferAnalysis = false;
275  } else {
276  if (counterDummyWindows != 0) {
277  if (reportAllErrors) B2ERROR("Corrupted data? numberOfWindows = " << numberOfWindows << ", counterDummyWindows = " <<
278  counterDummyWindows);
279  performBufferAnalysis = false;
280  }
281  }
282 
283  /*
284  int numberRvcJumps = 0;
285  int numberCntr127Jumps = 0;
286  int windowRvcJumpFirst = -1;
287  int windowCntr127JumpFirst = -1;
288  int clocksRvcJumpFirst = -1;
289  int clocksCntr127JumpFirst = -1;
290 
291  if (performBufferAnalysis) {
292  for (int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
293  int index = iWindow * windowSize + 3;
294 
295  // revoclk (comes from b2tt) has the range between 0 and 1279 @127MHz => 1279*7.8ns ~10us = 1 revolution (11bits are used)
296  int revoClockNow = rdat[index] & 0x7ff;
297  // B2INFO("rvc now = " << revoClockNow);
298  // first need to know max revoClock (1279)
299  if (revoClockLast != -1) {
300  // if (revoClockLast != -1 && revoClockNow > revoClockLast) {
301  int revoClockDeltaNow = revoClockNow - revoClockLast;
302  if (revoClockDeltaNow != revoClockDeltaExpected) {
303  // -1276 is simply going to the next cycle of rvc counting, but 1188 or -92 means that there was one frame missing in data / corrupted data
304  if (revoClockDeltaNow != -1276) {
305  if (reportAllErrors) B2INFO("rvc changed by an unexpected number of units (1): " << revoClockDeltaNow << ", last rvc = " <<
306  revoClockLast <<
307  ", current rvc = " << revoClockNow << ", window " << iWindow << ", index = " << index);
308  numberRvcJumps++;
309  if (windowRvcJumpFirst < 0) {
310  windowRvcJumpFirst = iWindow;
311  clocksRvcJumpFirst = revoClockDeltaNow;
312  }
313  }
314  }
315  }
316  revoClockLast = revoClockNow;
317 
318  int cntr127Now = (rdat[index + 1] >> 16) & 0xffff;
319  // B2INFO("cntr127 now = " << cntr127Now);
320  // first need to know max cntr127
321  if (cntr127Last != -1) {
322  // if (cntr127Last != -1 && cntr127Now > cntr127Last) {
323  int cntr127DeltaNow = cntr127Now - cntr127Last;
324  if (cntr127DeltaNow != cntr127DeltaExpected) {
325  // 65444 is the value of the difference in cntr127 (VME counter) because we use 16 bits of 64 bit-long counter
326  if (cntr127DeltaNow != 65444) {
327  if (reportAllErrors) B2INFO("cntr127 changed by an unexpected number of units (1): " << cntr127DeltaNow << ", cntr127 last = " <<
328  cntr127Last <<
329  ", cntr127 now = " << cntr127Now << ", window " << iWindow << ", index = " << index + 1);
330  numberCntr127Jumps++;
331  if (windowCntr127JumpFirst < 0) {
332  windowCntr127JumpFirst = iWindow;
333  clocksCntr127JumpFirst = cntr127DeltaNow;
334  }
335  }
336  }
337  }
338  cntr127Last = cntr127Now;
339  }
340  }
341  */
342 
343  /*
344  if (numberRvcJumps > 0) {
345  B2INFO("The number of rvc jumps = " << numberRvcJumps);
346  B2INFO("The window of the first rvc jump = " << windowRvcJumpFirst);
347  B2INFO("The number of clock cycles associated with the first rvc jump = " << clocksRvcJumpFirst);
348  }
349 
350  if (numberCntr127Jumps > 0) {
351  B2INFO("The number of cntr127 jumps = " << numberCntr127Jumps);
352  B2INFO("The window of the first cntr127 jump = " << windowCntr127JumpFirst);
353  B2INFO("The number of clock cycles associated with the first cntr127 jump = " << clocksCntr127JumpFirst);
354  }
355  */
356 
357  // debugging: report everything from every single window when we are seeing unexpected jumps in either of the two counters
358  /*
359  if (numberRvcJumps > 0 || numberCntr127Jumps > 0) {
360  B2INFO("===========================================================================================================");
361  B2INFO("l1_rvc from header = " << rvcL1);
362  B2INFO("eventNumberL1 (evt) from buffer header = " << eventNumberL1);
363  B2INFO("Reporting the entire data buffer");
364  B2INFO("Header 0 = : " << std::hex << rdat[0] << std::dec);
365  B2INFO("Header 1 = : " << std::hex << rdat[1] << std::dec);
366  B2INFO("Header 2 = : " << std::hex << rdat[2] << std::dec);
367  for (int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
368  int index = iWindow * windowSize + 3;
369 
370  B2INFO("---------------------------------------------------------------------------------");
371  int revoClockNow = rdat[index] & 0x7ff;
372  B2INFO("w rvc ---------------------------- = " << iWindow << " " << revoClockNow);
373 
374  int cntr127Now = (rdat[index + 1] >> 16) & 0xffff;
375  B2INFO("w cntr127 ---------------------------- = " << iWindow << " " << cntr127Now);
376 
377  for (int i = 0; i < 24; i++) {
378  B2INFO("w i = : " << iWindow << " " << i << " " << std::hex << rdat[index+i] << std::dec);
379  }
380  }
381  }
382  */
383 
384  // reset "most recent" rvc and cntr127
385  revoClockLast = -1;
386  cntr127Last = -1;
387 
388  // events with no buffer (i.e. no payload), empty (i.e. dummy) windows and presumably corrupted events are NOT analyzed
389  if (performBufferAnalysis) {
390 
391  int slotT0Last[8];
392  int slotNHitLast[8];
393  int slotSegmentLast[8];
394 
395  int otherInformationLast[8];
396 
397  int combinedT0Last;
398  int combinedT0RVC2GDLLast;
399 
400  // Loop over windows in B2L buffer and locate all unique slot-level TOP L1 decisions
401  for (int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
402 
403  // B2INFO("REAL DEBUG: window number = " << iWindow);
404 
405  int clockCycle = iWindow * 4;
406 
407  // error counters for possible data corruption in the current window
408  unsigned int errorCountWindow = 0;
409 
410  // a pointer-like variable for accessing the data in the buffer sequentially
411  int index = iWindow * windowSize + 3;
412 
413  unsigned int testPatternExpected = 0;
414  if (dataFormatVersionExpected == 1) testPatternExpected = 0xbbba;
415  else if (dataFormatVersionExpected >= 2) testPatternExpected = 0xdddd;
416 
417  testPattern = (rdat[index] >> 16) & 0xffff;
418  // B2INFO("testPattern = " << std::hex << testPattern << std::dec);
419  if (testPattern != testPatternExpected) {
420  if (reportAllErrors) B2ERROR("An unexpected test pattern: " << std::hex << testPattern << std::dec << ", window " << iWindow <<
421  ", index = " << index);
422  errorCountWindow++;
423  }
424 
425  int dataFormatVersionNow = (rdat[index] >> 11) & 0x1f;
426  // B2INFO("dataFormatVersionNow = " << dataFormatVersionNow);
427  if (dataFormatVersionNow == 3 && dataFormatVersionExpected == 2) {
428  dataFormatVersionExpected = 3;
429  }
430  if (dataFormatVersionNow == 4 && dataFormatVersionExpected == 2) {
431  dataFormatVersionExpected = 4;
432  }
433  if (dataFormatVersionNow == 5) {
434  dataFormatVersionExpected = 5;
435  }
436 
437  if (dataFormatVersionNow != dataFormatVersionExpected) {
438  if (reportAllErrors) {
439  if (!m_reportedAlreadyRun_2) {
440  B2ERROR("An unexpected data format version: " << dataFormatVersionNow << ", window " << iWindow << ", index = " <<
441  index);
442  m_reportedAlreadyRun_2 = true;
443  }
444  }
445  errorCountWindow++;
446  }
447 
448  // revoclk (comes from b2tt) has the range between 0 and 1279 @127MHz => 1279*7.8ns ~10us = 1 revolution (11bits are used)
449  int revoClockNow = rdat[index] & 0x7ff;
450  // B2INFO("window = " << iWindow << ", rvc now = " << revoClockNow);
451  // first need to know max revoClock (1279)
452  if (revoClockLast != -1) {
453  // if (revoClockLast != -1 && revoClockNow > revoClockLast) {
454  int revoClockDeltaNow = revoClockNow - revoClockLast;
455  if (revoClockDeltaNow != revoClockDeltaExpected) {
456  if (revoClockDeltaNow != -1276) {
457  if (reportAllErrors) B2INFO("rvc changed by an unexpected number of units (2): " << revoClockDeltaNow << ", last rvc = " <<
458  revoClockLast <<
459  ", current rvc = " << revoClockNow << ", window " << iWindow << ", index = " << index);
460  // errorCountWindow++;
461  }
462  }
463  }
464  if (revoClockNow > 1279) {
465  if (reportAllErrors) B2ERROR("An unexpected rvc value = " << revoClockNow << ", window " << iWindow << ", index = " << index);
466  errorCountWindow++;
467  }
468  revoClockLast = revoClockNow;
469 
470  int cntr127Now = (rdat[index + 1] >> 16) & 0xffff;
471  // B2INFO("cntr127 now = " << cntr127Now);
472  // first need to know max cntr127
473  if (cntr127Last != -1) {
474  // if (cntr127Last != -1 && cntr127Now > cntr127Last) {
475  int cntr127DeltaNow = cntr127Now - cntr127Last;
476  if (cntr127DeltaNow != cntr127DeltaExpected) {
477  // 65444 is the value of the difference in cntr127 (VME counter) because we use 16 bits of 64 bit-long counter
478  if (cntr127DeltaNow != 65444 && cntr127DeltaNow != -65532) {
479  if (reportAllErrors) B2INFO("cntr127 changed by an unexpected number of units (2): " << cntr127DeltaNow << ", cntr127 last = " <<
480  cntr127Last <<
481  ", cntr127 now = " << cntr127Now << ", window " << iWindow << ", index = " << index + 1);
482  errorCountWindow++;
483  }
484  }
485  }
486  cntr127Last = cntr127Now;
487 
488  //
489 
490  int slotT0[8];
491  int slotNHit[8];
492  int slotSegment[8];
493 
494  int otherInformation[8];
495 
496  // int versionFW = rdat[index + 3];
497 
498  int combinedT0 = rdat[index + 2] & 0x3ffff;
499  int combinedT0RVC2GDL = (rdat[index + 2] >> 18) & 0x7ff;
500  int combinedT0ClockCycle = clockCycle;
501 
502  slotT0[0] = (rdat[index + 4] >> 16) & 0xffff;
503  slotT0[1] = (rdat[index + 4]) & 0xffff;
504  slotT0[2] = (rdat[index + 5] >> 16) & 0xffff;
505  slotT0[3] = (rdat[index + 5]) & 0xffff;
506  slotT0[4] = (rdat[index + 6] >> 16) & 0xffff;
507  slotT0[5] = (rdat[index + 6]) & 0xffff;
508  slotT0[6] = (rdat[index + 7] >> 16) & 0xffff;
509  slotT0[7] = (rdat[index + 7]) & 0xffff;
510 
511  slotNHit[0] = (rdat[index + 8] >> 20) & 0x3ff;
512  slotNHit[1] = (rdat[index + 8] >> 10) & 0x3ff;
513  slotNHit[2] = (rdat[index + 8]) & 0x3ff;
514 
515  slotNHit[3] = (rdat[index + 9] >> 20) & 0x3ff;
516  slotNHit[4] = (rdat[index + 9] >> 10) & 0x3ff;
517  slotNHit[5] = (rdat[index + 9]) & 0x3ff;
518 
519  slotNHit[6] = (rdat[index + 10] >> 10) & 0x3ff;
520  slotNHit[7] = (rdat[index + 10]) & 0x3ff;
521 
522  slotSegment[0] = (rdat[index + 11] >> 28) & 0xf;
523  slotSegment[1] = (rdat[index + 11] >> 24) & 0xf;
524  slotSegment[2] = (rdat[index + 11] >> 20) & 0xf;
525  slotSegment[3] = (rdat[index + 11] >> 16) & 0xf;
526  slotSegment[4] = (rdat[index + 11] >> 12) & 0xf;
527  slotSegment[5] = (rdat[index + 11] >> 8) & 0xf;
528  slotSegment[6] = (rdat[index + 11] >> 4) & 0xf;
529  slotSegment[7] = (rdat[index + 11] >> 0) & 0xf;
530 
531  // the following information is board-dependent
532  otherInformation[0] = (rdat[index + 12] >> 16) & 0xffff;
533  otherInformation[1] = (rdat[index + 12]) & 0xffff;
534  otherInformation[2] = (rdat[index + 13] >> 16) & 0xffff;
535  otherInformation[3] = (rdat[index + 13]) & 0xffff;
536  otherInformation[4] = (rdat[index + 14] >> 16) & 0xffff;
537  otherInformation[5] = (rdat[index + 14]) & 0xffff;
538  otherInformation[6] = (rdat[index + 15] >> 16) & 0xffff;
539  otherInformation[7] = (rdat[index + 15]) & 0xffff;
540 
541  if (iWindow != 0) {
542 
543  // try to retrieve combined t0 decisions (limited info)
544  if (channel == 0) {
545  if (combinedT0 != combinedT0Last ||
546  combinedT0RVC2GDL != combinedT0RVC2GDLLast
547  ) {
548 
549  // int toptrgT0_revoToNS = combinedT0%revoToNS;
550  // int rvcL1_NS = rvcL1 * 8;
551  // int deltaT0 = rvcL1_NS >= toptrgT0_revoToNS ? rvcL1_NS - toptrgT0_revoToNS : rvcL1_NS - toptrgT0_revoToNS + revoToNS;
552  // int latencyL12TOPTRG = revoClockNow >= rvcL1 ? revoClockNow - rvcL1 : revoClockNow - rvcL1 + 1280;
553 
554  TRGTOPCombinedT0Decision combinedT0Decision(combinedT0,
555  revoClockNow,
556  combinedT0ClockCycle,
557  combinedT0RVC2GDL,
558  eventNumberL1,
559  rvcL1
560  );
561 
562  m_TRGTOPCombinedT0DecisionArray.appendNew(combinedT0Decision);
563 
564  /*
565  cout << "-DEBUG- new combined decision: t0 (2ns), eventNumberL1, rvc2GDL, clock cycle, rvcNOW, rvcL1, latency, deltaT0 (ns) = "
566  << combinedT0/2 << ", "
567  << eventNumberL1 << ", "
568  << combinedT0RVC2GDL << ", "
569  << combinedT0ClockCycle << ", "
570  << revoClockNow << ", "
571  << rvcL1 << ", "
572  << latencyL12TOPTRG << ", "
573  << deltaT0
574  << endl;
575  */
576 
577  combinedT0Last = combinedT0;
578  combinedT0RVC2GDLLast = combinedT0RVC2GDL;
579  }
580  }
581 
582  // retrieve slot-level decisions (limited info) for slots 1 through 8 as observed on the board used for slots 9 through 16
583  if (channel == 0) {
584  for (int i = 0; i < 8; i++) {
585 
586  if (otherInformation[i] != otherInformationLast[i]) {
587 
588  int slotOther = i + 1;
589 
590  TRGTOPSlotTiming slotTiming(slotOther,
591  2 * otherInformation[i],
592  0,
593  0,
594  0,
595  clockCycle,
596  errorCountWindow,
597  0,
598  -1
599  );
600 
601  // auto* thisSlotTiming = m_TRGTOPSlotTimingArray.appendNew(slotTiming);
602  m_TRGTOPSlotTimingArray.appendNew(slotTiming);
603 
604  otherInformationLast[i] = otherInformation[i];
605 
606  }
607  }
608  }
609 
610  // retrieve slot-level decisions (complete info) for the currently-processed readout board
611 
612  int slotNow = 1;
613  if (channel == 0) slotNow = 9;
614 
615  for (int i = 0; i < 8; i++) {
616 
617  if (slotT0[i] != slotT0Last[i] ||
618  slotNHit[i] != slotNHitLast[i] ||
619  slotSegment[i] != slotSegmentLast[i]) {
620 
621  /*
622  cout << "-DEBUG- slot, index, clockCycle = " << slotNow << ", " << index << ", " << clockCycle
623  << ", combT0 = " << combT0
624  <<", rvcL1 from header = " << rvcL1
625  << ", eventNumberL1 (evt) = " << eventNumberL1
626  << ", FW version = " << std::hex << versionFW << std::dec
627  << ", slot T0 = " << slotT0[i]
628  << ", NHit = " << slotNHit[i]
629  << ", Segment = " << slotSegment[i]
630  << ", other information = " << otherInformation[i]
631  << endl;
632  */
633 
634  // TRGTOPSlotTiming* thisSlotTiming(NULL);
635 
636  // logL is currently not available (use nHit in lieu of that), so set to 0
637  // firstTS info is only available for slots 1 through 8 (channel == 1)
638  // -1 for firstTS means no info
639  // 1 as the next to the last parameter means "information from the board being read-out"
640 
641  if (channel == 1) {
642 
643  TRGTOPSlotTiming slotTiming(slotNow,
644  2 * slotT0[i],
645  slotSegment[i],
646  slotNHit[i],
647  0,
648  clockCycle,
649  errorCountWindow,
650  1,
651  otherInformation[i]
652  );
653  // thisSlotTiming = m_TRGTOPSlotTimingArray.appendNew(slotTiming);
654  m_TRGTOPSlotTimingArray.appendNew(slotTiming);
655  } else {
656 
657  TRGTOPSlotTiming slotTiming(slotNow,
658  2 * slotT0[i],
659  slotSegment[i],
660  slotNHit[i],
661  0,
662  clockCycle,
663  errorCountWindow,
664  1,
665  -1
666  );
667  // thisSlotTiming = m_TRGTOPSlotTimingArray.appendNew(slotTiming);
668  m_TRGTOPSlotTimingArray.appendNew(slotTiming);
669  }
670 
671  // slot-level decisions are not currently related to combined decisions
672  // thisSlotTiming->addRelationTo(thisCombinedTiming);
673  // thisCombinedTiming->addRelationTo(thisSlotTiming);
674 
675  slotT0Last[i] = slotT0[i];
676  slotNHitLast[i] = slotNHit[i];
677  slotSegmentLast[i] = slotSegment[i];
678 
679  }
680 
681  slotNow++;
682 
683  }
684  } else {
685 
686  combinedT0Last = combinedT0;
687  for (int i = 0; i < 8; i++) {
688  slotT0Last[i] = slotT0[i];
689  slotNHitLast[i] = slotNHit[i];
690  slotSegmentLast[i] = slotSegment[i];
691  otherInformationLast[i] = otherInformation[i];
692 
693  combinedT0Last = combinedT0;
694  combinedT0RVC2GDLLast = combinedT0RVC2GDL;
695  }
696  }
697  }
698  }
699 
700  // at this time any unexpected features in the data are lumped together
701  // this includes possibly corrupted data (checksum would be a better solution to diagnose such problem)
702  // AND incorrectly prepared (but not corrupted) data
703  if (reportSummaryErrors) {
704  if (errorCountEvent != 0) {
705  B2INFO("Number of instances of unexpected data diagnozed during unpacking = " << errorCountEvent);
706  }
707 
708  /*
709  if (numberRvcJumps > 0) {
710  B2INFO("The number of rvc jumps = " << numberRvcJumps);
711  B2INFO("The window of the first rvc jump = " << windowRvcJumpFirst);
712  B2INFO("The number of clock cycles associated with the first rvc jump = " << clocksRvcJumpFirst);
713  B2INFO("The number of combined decisions = " << m_TRGTOPCombinedTimingArray.getEntries());
714  }
715 
716  if (numberCntr127Jumps > 0) {
717  B2INFO("The number of cntr127 jumps = " << numberCntr127Jumps);
718  B2INFO("The window of the first cntr127 jump = " << windowCntr127JumpFirst);
719  B2INFO("The number of clock cycles associated with the first cntr127 jump = " << clocksCntr127JumpFirst);
720  B2INFO("The number of combined decisions = " << m_TRGTOPCombinedTimingArray.getEntries());
721  }
722  */
723 
724  }
725 
726 }
727 
728 
730 {
731 }
732 
734 {
735 }
736 
737 
738 
Base class for Modules.
Definition: Module.h:72
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
The Raw TOP class Class for RawCOPPER class data taken by TOP Currently, this class is almost same as...
Definition: RawTRG.h:27
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
virtual void readDAQEvent(RawTRG *, int, int)
Read data from TRG DAQ.
bool m_reportedAlreadyRun_1
PCIe40 data or copper data.
bool m_pciedata
N words in raw data.
virtual void initialize() override
Initialize the Module.
virtual void event() override
This method is the core of the module.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
virtual void beginRun() override
Called when entering a new run.
virtual void unpackT0Decisions(int *, int)
Unpacker main function.
TRGTOPUnpackerModule()
Constructor: Sets the description, the properties and the parameters of the module.
int m_trigType
Event number (according to L1/global)
std::string version() const
returns version of TRGGDLUnpackerModule.
Class to store variables with their name which were sent to the logging service.
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
int GetDetectorNwords(int n, int finesse_num)
get Detector buffer length
Definition: RawCOPPER.h:654
int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
Definition: RawCOPPER.h:678
Abstract base class for different kinds of events.