Belle II Software development
PXDUnpackerOldModule.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 <pxd/modules/pxdUnpacking/PXDUnpackerOldModule.h>
10#include <pxd/unpacking/PXDRawDataDefinitions.h>
11#include <pxd/unpacking/PXDRawDataStructs.h>
12#include <pxd/unpacking/PXDMappingLookup.h>
13#include <framework/dataobjects/EventMetaData.h>
14#include <rawdata/dataobjects/RawPXD.h>
15#include <pxd/dataobjects/PXDRawHit.h>
16#include <pxd/dataobjects/PXDRawAdc.h>
17#include <pxd/dataobjects/PXDRawROIs.h>
18#include <vxd/dataobjects/VxdID.h>
19#include <framework/logging/Logger.h>
20
21using namespace std;
22using namespace Belle2;
23using namespace Belle2::PXD;
24using namespace Belle2::PXD::PXDError;
25
26//-----------------------------------------------------------------
27// Register the Module
28//-----------------------------------------------------------------
29REG_MODULE(PXDUnpackerOld);
30
31//-----------------------------------------------------------------
32// Implementation
33//-----------------------------------------------------------------
34
38
40 Module(),
44{
45 //Set module properties
46 setDescription("Unpack Raw PXD Hits from ONSEN data stream");
48
49 addParam("RawPXDsName", m_RawPXDsName, "The name of the StoreArray of RawPXDs to be processed", std::string(""));
50 addParam("PXDRawHitsName", m_PXDRawHitsName, "The name of the StoreArray of generated PXDRawHits", std::string(""));
51 addParam("PXDDAQEvtStatsName", m_PXDDAQEvtStatsName, "The name of the StoreObjPtr of generated PXDDAQEvtStats", std::string(""));
52 addParam("PXDRawAdcsName", m_PXDRawAdcsName, "The name of the StoreArray of generated PXDRawAdcs", std::string(""));
53 addParam("PXDRawROIsName", m_PXDRawROIsName, "The name of the StoreArray of generated PXDRawROIs", std::string(""));
54 addParam("DoNotStore", m_doNotStore, "only unpack and check, but do not store", false);
55// addParam("CriticalErrorMask", m_criticalErrorMask, "Set error mask which stops processing by returning false by task", 0);
56 // m_criticalErrorMask not longer a aparameter
57 // the constructor default to zero anyway
58// addParam("SuppressErrorMask", m_suppressErrorMask, "Set mask for errors msgs which are not printed", getSilenceMask());
59 // m_suppressErrorMask not longer a aparameter
60 m_suppressErrorMask = getSilenceMask();
61 addParam("ForceMapping", m_forceMapping, "Force Mapping even if DHH bit is NOT requesting it", false);
62 addParam("ForceNoMapping", m_forceNoMapping, "Force NO Mapping even if DHH bit is requesting it", false);
63 addParam("CheckPaddingCRC", m_checkPaddingCRC, "Check for susp. padding (debug option, many false positive)", false);
64 addParam("MaxDHPFrameDiff", m_maxDHPFrameDiff, "Maximum DHP Frame Nr Difference w/o reporting error", 2u);
65 addParam("FormatBonnDAQ", m_formatBonnDAQ, "ONSEN or BonnDAQ format", false);
66 addParam("Verbose", m_verbose, "Turn on extra verbosity for log-level debug", false);
67 addParam("ContinueOnError", m_continueOnError, "Continue package depacking on error (for debugging)", false);
68// (
69// /*EPXDErrFlag::c_DHC_END | EPXDErrFlag::c_DHE_START | EPXDErrFlag::c_DATA_OUTSIDE |*/
70// EPXDErrFlag::c_FIX_SIZE | EPXDErrFlag::c_DHE_CRC | EPXDErrFlag::c_DHC_UNKNOWN | /*EPXDErrFlag::c_MERGER_CRC |*/
71// EPXDErrFlag::c_DHP_SIZE | /*EPXDErrFlag::c_DHP_PIX_WO_ROW | EPXDErrFlag::c_DHE_START_END_ID | EPXDErrFlag::c_DHE_START_ID |*/
72// EPXDErrFlag::c_DHE_START_WO_END | EPXDErrFlag::c_DHP_NOT_CONT
73// ));
74
75 // this is not really a parameter, it should be fixed.
76 m_errorSkipPacketMask[c_nrDHE_CRC] = true;
77 m_errorSkipPacketMask[c_nrFIX_SIZE] = true;
78}
79
81{
82 // Required input
83 m_eventMetaData.isRequired();
84 // Optional input
85 m_storeRawPXD.isOptional(m_RawPXDsName);
86
87 //Register output collections
93
94 B2DEBUG(29, "ForceMapping: " << m_forceMapping);
95 B2DEBUG(29, "ForceNoMapping: " << m_forceNoMapping);
96 B2DEBUG(29, "CheckPaddingCRC: " << m_checkPaddingCRC);
97 B2DEBUG(29, "MaxDHPFrameDiff: " << m_maxDHPFrameDiff);
98
100 m_sendrois = 0;
101 m_notaccepted = 0;
103 for (int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) m_errorCounter[i] = 0;
104
105}
106
108{
109 int flag = 0;
110 string errstr = "Statistic ( ;";
111 errstr += to_string(m_unpackedEventsCount) + ";";
112 for (int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) { errstr += to_string(m_errorCounter[i]) + ";"; flag |= m_errorCounter[i];}
113 if (flag != 0) {
114 B2RESULT("PXD Unpacker --> Error Statistics (counted once per event!) in Events: " << m_unpackedEventsCount);
115 B2RESULT(errstr + " )");
116 for (int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
117 if (m_errorCounter[i]) {
118 B2RESULT(getPXDBitErrorName(i) << ": " << m_errorCounter[i]);
119 }
120 }
121 } else {
122 B2RESULT("PXD Unpacker --> No Error found in Events: " << m_unpackedEventsCount);
123 }
124 B2RESULT("Statistic 2: !Accepted: " << m_notaccepted << " SendROIs: " << m_sendrois << " Unfiltered: " << m_sendunfiltered);
125}
126
128{
129 m_storeDAQEvtStats.create();
130
131 m_errorMask = 0;
133
134 m_meta_event_nr = m_eventMetaData->getEvent();// used for error output below
135
136 if (!m_storeRawPXD) {// if no input, nothing to do
137 m_errorMask[c_nrNO_PXD] = true;
138 } else {
139 int nRaws = m_storeRawPXD.getEntries();
140 if (m_verbose) {
141 B2DEBUG(29, "PXD Unpacker --> RawPXD Objects in event: " << LogVar("Objects", nRaws));
142 };
143
144 m_meta_run_nr = m_eventMetaData->getRun();
145 m_meta_subrun_nr = m_eventMetaData->getSubrun();
146 m_meta_experiment = m_eventMetaData->getExperiment();
147 m_meta_time = m_eventMetaData->getTime();
148 m_meta_ticks = (unsigned int)std::round((m_meta_time % 1000000000ull) * 0.127216); // calculate ticks in 127MHz RF clock
149 m_meta_sec = (unsigned int)(m_meta_time / 1000000000ull) & 0x1FFFF;
150
151 int inx = 0; // count index for output objects
152 for (auto& it : m_storeRawPXD) {
153 if (m_verbose) {
154 B2DEBUG(29, "PXD Unpacker --> Unpack Objects: ");
155 };
156 unpack_rawpxd(it, inx++);
157 }
158
159 if (nRaws == 0) m_errorMask[c_nrNO_PXD] = true;
160 }
163
165 {
166 for (unsigned int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
167 if (m_errorMaskEvent[i]) m_errorCounter[i]++;
168 }
169 }
170
171 if ((PXDErrorFlags(m_criticalErrorMask) & m_errorMaskEvent) != PXDErrorFlags(0)) B2ERROR("Error in PXD unpacking" <<
172 LogVar("event nr", m_meta_event_nr));
173 setReturnValue(PXDErrorFlags(0) == (PXDErrorFlags(m_criticalErrorMask) & m_errorMaskEvent));
174}
175
177{
178 int Frames_in_event;
179 int fullsize;
180 int datafullsize;
181
182 m_errorMaskDHE = 0;
183 m_errorMaskDHC = 0;
185 PXDDAQPacketStatus& daqpktstat = m_storeDAQEvtStats->newPacket(inx);
186
187 if (px.size() <= 0 || px.size() > 16 * 1024 * 1024) {
188 if (!(m_suppressErrorMask[c_nrPACKET_SIZE])) {
189 B2WARNING("PXD Unpacker --> invalid packet size" <<
190 LogVar("size [32bit words] $", static_cast < std::ostringstream && >(std::ostringstream() << hex << px.size()).str()));
191 }
192 m_errorMask[c_nrPACKET_SIZE] = true;
193 return;
194 }
195 std::vector<unsigned int> data(px.size());
196 fullsize = px.size() * 4;
197 std::copy_n(px.data(), px.size(), data.begin());
198
199 if (fullsize < 8) {
200 if (!(m_suppressErrorMask[c_nrPACKET_SIZE])) {
201 B2WARNING("Data is to small to hold a valid Header! Will not unpack anything." << LogVar("size [32bit words] $",
202 static_cast < std::ostringstream && >(std::ostringstream() << hex << fullsize).str()));
203 }
204 m_errorMask[c_nrPACKET_SIZE] = true;
205 return;
206 }
207
208 if (data[0] != 0xCAFEBABE && data[0] != 0xBEBAFECA) {
209 if (!(m_suppressErrorMask[c_nrMAGIC])) {
210 B2WARNING("Magic invalid: Will not unpack anything. Header corrupted." <<
211 LogVar("Header Magic $", static_cast < std::ostringstream && >(std::ostringstream() << hex << data[0]).str()));
212 }
213 m_errorMask[c_nrMAGIC] = true;
214 return;
215 }
216
217
218 Frames_in_event = ((ubig32_t*)data.data())[1];
219 if (Frames_in_event < 0 || Frames_in_event > 256) {
220 if (!(m_suppressErrorMask[c_nrFRAME_NR])) {
221 B2WARNING("Number of Frames invalid: Will not unpack anything. Header corrupted!" << LogVar("Frames in event", Frames_in_event));
222 }
223 m_errorMask[c_nrFRAME_NR] = true;
224 return;
225 }
226 if (Frames_in_event < 3) {
227 if (!(m_suppressErrorMask[c_nrNR_FRAMES_TO_SMALL])) {
228 B2WARNING("Number of Frames too small: It cannot contain anything useful." << LogVar("Frames in event", Frames_in_event));
229 }
230 m_errorMask[c_nrNR_FRAMES_TO_SMALL] = true;
231 }
232
234 if (m_verbose) {
235 B2DEBUG(29, "PXD Unpacker --> data[0]: <-- Magic $" << hex << data[0]);
236 B2DEBUG(29, "PXD Unpacker --> data[1]: <-- #Frames $" << hex << data[1]);
237 if (data[1] >= 1 && fullsize < 12) B2DEBUG(29, "PXD Unpacker --> data[2]: <-- Frame 1 len $" << hex << data[2]);
238 if (data[1] >= 2 && fullsize < 16) B2DEBUG(29, "PXD Unpacker --> data[3]: <-- Frame 2 len $" << hex << data[3]);
239 if (data[1] >= 3 && fullsize < 20) B2DEBUG(29, "PXD Unpacker --> data[4]: <-- Frame 3 len $" << hex << data[4]);
240 if (data[1] >= 4 && fullsize < 24) B2DEBUG(29, "PXD Unpacker --> data[5]: <-- Frame 4 len $" << hex << data[5]);
241 };
242
243 unsigned int* tableptr;
244 tableptr = &data[2]; // skip header!!!
245
246 unsigned int* dataptr;
247 dataptr = &tableptr[Frames_in_event];
248 datafullsize = fullsize - 2 * 4 - Frames_in_event * 4; // Size is fullsize minus header minus table
249
250 int ll = 0; // Offset in dataptr in bytes
251 for (int j = 0; j < Frames_in_event; j++) {
252 int lo;
253
254 lo = ((ubig32_t*)tableptr)[j];
255 if (lo <= 0) {
256 if (!(m_suppressErrorMask[c_nrFRAME_SIZE])) {
257 B2WARNING("size of frame invalid");
258 B2DEBUG(29, "size of frame invalid: " << j << "size " << lo << " at byte offset in dataptr " << ll);
259 }
260 m_errorMask[c_nrFRAME_SIZE] = true;
261 return;
262 }
263 if (ll + lo > datafullsize) {
264 if (!(m_suppressErrorMask[c_nrFRAME_SIZE])) {
265 B2WARNING("Frames exceed packet size");
266 B2DEBUG(29, "Frames exceed packet size: " << j << " size " << lo << " at byte offset in dataptr " << ll << " of datafullsize " <<
267 datafullsize << " of fullsize " << fullsize);
268 }
269 m_errorMask[c_nrFRAME_SIZE] = true;
270 return;
271 }
272 if (lo & 0x3) {
273 if (!(m_suppressErrorMask[c_nrFRAME_SIZE])) {
274 B2WARNING("SKIP Frame with Data with not MOD 4 length");
275 B2DEBUG(29, "SKIP Frame with Data with not MOD 4 length " << " ( $" << hex << lo << " ) ");
276 }
277 ll += (lo + 3) & 0xFFFFFFFC;
278 m_errorMask[c_nrFRAME_SIZE] = true;
279 } else {
280 B2DEBUG(29, "unpack DHE(C) frame: " << j << " with size " << lo << " at byte offset in dataptr " << ll);
281 unpack_dhc_frame(ll + (char*)dataptr, lo, j, Frames_in_event, daqpktstat);
282 ll += lo;
283 }
288 m_errorMask = 0;
289
290 if (!m_continueOnError && (m_errorMaskPacket & PXDErrorFlags(m_errorSkipPacketMask)) != PXDErrorFlags(0)) {
291 // skip full package on error, recovery to next DHC/DHE Start might be possible in some cases
292 // But that's to hard to implement
293 // Remark: PXD data for broken events is removed in next PXDPostChecker module, thus skipping the
294 // unpacking is not strictly necessary here.
295 break;
296 }
297 }
299}
300
301void PXDUnpackerOldModule::unpack_dhp_raw(void* data, unsigned int frame_len, unsigned int dhe_ID, unsigned dhe_DHPport,
302 VxdID vxd_id)
303{
304// unsigned int nr_words = frame_len / 2; // frame_len in bytes (excl. CRC)!!!
305 ubig16_t* dhp_pix = (ubig16_t*)data;
306
313
314 // Size: 64*768 + 8 bytes for a full frame readout
315 if (frame_len != 0xC008) {
316 if (!(m_suppressErrorMask[c_nrFIX_SIZE])) B2WARNING("Frame size unsupported for RAW ADC frame! $" <<
317 LogVar("size [bytes] $", static_cast < std::ostringstream && >(std::ostringstream() << hex << frame_len).str())
318 << LogVar("DHE", dhe_ID) << LogVar("DHP", dhe_DHPport));
319 m_errorMask[c_nrFIX_SIZE] = true;
320 return;
321 }
322 unsigned int dhp_header_type = 0;
323// unsigned int dhp_reserved = 0;
324 unsigned int dhp_dhe_id = 0;
325 unsigned int dhp_dhp_id = 0;
326
327 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
328// dhp_reserved = (dhp_pix[2] >> 8) & 0x1F;
329 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
330 dhp_dhp_id = dhp_pix[2] & 0x0003;
331
332 if (dhe_ID != dhp_dhe_id) {
333 if (!(m_suppressErrorMask[c_nrDHE_DHP_DHEID])) {
334 B2WARNING("DHE ID in DHE and DHP header differ");
335 B2DEBUG(29, "DHE ID in DHE and DHP header differ $" << hex << dhe_ID << " != $" << dhp_dhe_id);
336 }
337 m_errorMask[c_nrDHE_DHP_DHEID] = true;
338 }
339 if (dhe_DHPport != dhp_dhp_id) {
340 if (!(m_suppressErrorMask[c_nrDHE_DHP_PORT])) {
341 B2WARNING("DHP ID (Chip/Port) in DHE and DHP header differ");
342 B2DEBUG(29, "DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport << " != $" << dhp_dhp_id);
343 }
344 m_errorMask[c_nrDHE_DHP_PORT] = true;
345 }
346
347 if (dhp_header_type != EDHPFrameHeaderDataType::c_RAW) {
348 if (!(m_suppressErrorMask[c_nrHEADERTYPE_INV])) {
349 B2WARNING("Header type invalid for this kind of DHE frame");
350 B2DEBUG(29, "Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
351 }
352 m_errorMask[c_nrHEADERTYPE_INV] = true;
353 return;
354 }
355
357 B2DEBUG(29, "Raw ADC Data");
358 // size checked already above
359 m_storeRawAdc.appendNew(vxd_id, data, frame_len);
360};
361
362void PXDUnpackerOldModule::unpack_fce([[maybe_unused]] unsigned short* data, [[maybe_unused]] unsigned int length,
363 [[maybe_unused]] VxdID vxd_id)
364{
371
372 B2WARNING("FCE (Cluster) Packet have not yet been tested with real HW clusters. Dont assume that this code is working!");
373 return;
374
375 // implement the unpacking here and not as a separate module ... when it is available in HW
376// ubig16_t* cluster = (ubig16_t*)data;
377// int nr_words; //words in dhp frame
378// unsigned int words_in_cluster = 0; //counts 16bit words in cluster
379// nr_words = length / 2;
380// ubig16_t sor;
381// sor = 0x0000;
382//
383// for (int i = 2 ; i < nr_words ; i++) {
384// if (i != 2) { //skip header
385// if ((((cluster[i] & 0x8000) == 0)
386// && ((cluster[i] & 0x4000) >> 14) == 1)) { //searches for start of row frame with start of cluster flag = 1 => new cluster
387// if (!m_doNotStore) m_storeRawCluster.appendNew(&data[i - words_in_cluster], words_in_cluster, vxd_id);
388// words_in_cluster = 0;
389// }
390// }
391// if ((cluster[i] & 0x8000) == 0) {
392// sor = cluster[i];
393// }
394// words_in_cluster++;
395//
396// if ((cluster[nr_words - 1] & 0xFFFF) == (sor &
397// 0xFFFF)) {//if frame is not 32bit aligned last word will be the last start of row word
398// cluster[nr_words - 1] = 0x0000;//overwrites the last redundant word with zero to make checking easier in PXDHardwareClusterUnpacker
399// }
400//
401// if (i == nr_words - 1) {
402// if (!m_doNotStore) m_storeRawCluster.appendNew(&data[i - words_in_cluster + 1], words_in_cluster, vxd_id);
403// }
404// }
405}
406
407void PXDUnpackerOldModule::dump_dhp(void* data, unsigned int frame_len)
408{
409 // called only for debugging purpose, will never be called in normal running
410 unsigned int w = frame_len / 2;
411 ubig16_t* d = (ubig16_t*)data;
412
413 B2WARNING("HEADER -- $" << hex << d[0] << ",$" << hex << d[1] << ",$" << hex << d[2] << ",$" << hex << d[3] << " -- ");
414
415 auto dhp_header_type = (d[2] & 0xE000) >> 13;
416 auto dhp_reserved = (d[2] & 0x1F00) >> 8;
417 auto dhp_dhe_id = (d[2] & 0x00FC) >> 2;
418 auto dhp_dhp_id = d[2] & 0x0003;
419
420 B2WARNING("DHP type | $" << hex << dhp_header_type << " ( " << dec << dhp_header_type << " ) ");
421 B2WARNING("DHP reserved | $" << hex << dhp_reserved << " ( " << dec << dhp_reserved << " ) ");
422 B2WARNING("DHP DHE ID | $" << hex << dhp_dhe_id << " ( " << dec << dhp_dhe_id << " ) ");
423 B2WARNING("DHP DHP ID | $" << hex << dhp_dhp_id << " ( " << dec << dhp_dhp_id << " ) ");
424 for (unsigned int i = 4; i < w; i++) {
425 B2WARNING("DHP DATA $" << hex << d[i]);
426 }
427 B2WARNING("DHP CRC $" << hex << d[w] << ",$" << hex << d[w + 1]);
428}
429
430void PXDUnpackerOldModule::dump_roi(void* data, unsigned int frame_len)
431{
432 // called only for debugging purpose, will never be called in normal running
433 unsigned int w = frame_len / 4;
434 ubig32_t* d = (ubig32_t*)data;
435
436 B2WARNING("HEADER -- $" << hex << d[0] << ",$" << hex << d[1] << ",$" << hex << d[2] << ",$" << hex << d[3] << " -- Len $" << hex
437 << frame_len);
438
439 for (unsigned int i = 0; i < w; i++) {
440 B2WARNING("ROI DATA $" << hex << d[i]);
441 }
442 B2WARNING("ROI CRC $" << hex << d[w]);
443}
444
445void PXDUnpackerOldModule::unpack_dhp(void* data, unsigned int frame_len, unsigned int dhe_first_readout_frame_id_lo,
446 unsigned int dhe_ID, unsigned dhe_DHPport, unsigned dhe_reformat, VxdID vxd_id,
447 PXDDAQPacketStatus& daqpktstat)
448{
449 unsigned int nr_words = frame_len / 2; // frame_len in bytes (excl. CRC)!!!
450 ubig16_t* dhp_pix = (ubig16_t*)data;
451
452 unsigned int dhp_readout_frame_lo = 0;
453 unsigned int dhp_header_type = 0;
454 unsigned int dhp_reserved = 0;
455 unsigned int dhp_dhe_id = 0;
456 unsigned int dhp_dhp_id = 0;
457
458 // cppcheck-suppress unreadVariable
459 unsigned int dhp_row = 0, dhp_col = 0, dhp_adc = 0, dhp_cm = 0;
460// unsigned int dhp_offset = 0;
461 bool rowflag = false;
462 bool pixelflag = true; // just for first row start
463
464 if (nr_words < 4) {
465 if (!(m_suppressErrorMask[c_nrDHP_SIZE])) B2WARNING("DHP frame size error (too small)" << LogVar("Nr words", nr_words));
466 m_errorMask[c_nrDHP_SIZE] = true;
467 return;
468 }
469
470 B2DEBUG(29, "HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] << " -- ");
471
472 B2DEBUG(29, "DHP Header | $" << hex << dhp_pix[2] << " ( " << dec << dhp_pix[2] << " ) ");
473 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
474 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
475 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
476 dhp_dhp_id = dhp_pix[2] & 0x0003;
477
478 B2DEBUG(29, "DHP type | $" << hex << dhp_header_type << " ( " << dec << dhp_header_type << " ) ");
479 B2DEBUG(29, "DHP reserved | $" << hex << dhp_reserved << " ( " << dec << dhp_reserved << " ) ");
480 B2DEBUG(29, "DHP DHE ID | $" << hex << dhp_dhe_id << " ( " << dec << dhp_dhe_id << " ) ");
481 B2DEBUG(29, "DHP DHP ID | $" << hex << dhp_dhp_id << " ( " << dec << dhp_dhp_id << " ) ");
482
483 if (dhe_ID != dhp_dhe_id) {
484 if (!(m_suppressErrorMask[c_nrDHE_DHP_DHEID])) {
485 B2WARNING("DHE ID in DHE and DHP header differ");
486 B2DEBUG(29, "DHE ID in DHE and DHP header differ $" << hex << dhe_ID << " != $" << dhp_dhe_id);
487 }
488 m_errorMask[c_nrDHE_DHP_DHEID] = true;
489 }
490 if (dhe_DHPport != dhp_dhp_id) {
491 if (!(m_suppressErrorMask[c_nrDHE_DHP_PORT])) {
492 B2WARNING("DHP ID (Chip/Port) in DHE and DHP header differ");
493 B2DEBUG(29, "DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport << " != $" << dhp_dhp_id);
494 }
495 m_errorMask[c_nrDHE_DHP_PORT] = true;
496 }
497
498 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
499 if (!(m_suppressErrorMask[c_nrHEADERTYPE_INV])) {
500 B2WARNING("Header type invalid for this kind of DHE frame");
501 B2DEBUG(29, "Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
502 }
503 m_errorMask[c_nrHEADERTYPE_INV] = true;
504 return;
505 }
506
507// static int offtab[4] = {0, 64, 128, 192};
508// dhp_offset = offtab[dhp_dhp_id];
509
510 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
511 B2DEBUG(29, "DHP Frame Nr | $" << hex << dhp_readout_frame_lo << " ( " << dec << dhp_readout_frame_lo << " ) ");
512
513 /* // TODO removed because data format error is not to be fixed soon
514 if (((dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) & 0x3F) > m_maxDHPFrameDiff) {
515 if (!m_suppressErrorMask[c_nrDHP_DHE_FRAME_DIFFER]) B2WARNING("DHP Frame Nr differ from DHE Frame Nr by >1 DHE " <<
516 dhe_first_readout_frame_id_lo << " != DHP " << (dhp_readout_frame_lo & 0x3F) << " delta " << ((
517 dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) & 0x3F));
518 m_errorMask[c_nrDHP_DHE_FRAME_DIFFER] = true;
519 }
520 */
521 /* // TODO removed because data format error is not to be fixed soon
522 if (m_last_dhp_readout_frame_lo[dhp_dhp_id] != -1) {
523 if (((dhp_readout_frame_lo - m_last_dhp_readout_frame_lo[dhp_dhp_id]) & 0xFFFF) > m_maxDHPFrameDiff) {
524 if(!m_suppressErrorMask&c_DHP_NOT_CONT ) B2WARNING("Two DHP Frames per sensor which frame number differ more than one! " << m_last_dhp_readout_frame_lo[dhp_dhp_id] << ", " <<
525 dhp_readout_frame_lo);
526 m_errorMask[c_nrDHP_NOT_CONT] = true;
527 }
528 }
529 */
530
531 if (daqpktstat.dhc_size() > 0) {
532 if (daqpktstat.dhc_back().dhe_size() > 0) {
533 // only is we have a DHC and DHE object... or back() is undefined
534 // Remark, if we have a broken data (DHE_START/END) structure, we might fill the
535 // previous DHE object ... but then the data is junk anyway
536 daqpktstat.dhc_back().dhe_back().newDHP(dhp_dhp_id, dhp_readout_frame_lo);
537 }
538 }
539
540 /* // TODO removed because the data is not ordered as expected in current firmware
541 for (auto j = 0; j < 4; j++) {
542 if (m_last_dhp_readout_frame_lo[j] != -1) {
543 if (((dhp_readout_frame_lo - m_last_dhp_readout_frame_lo[j]) & 0xFFFF) > m_maxDHPFrameDiff) {
544 if(!m_suppressErrorMask&c_DHP_DHP_FRAME_DIFFER ) B2WARNING("Two DHP Frames (different DHP) per sensor which frame number differ more than one! " << m_last_dhp_readout_frame_lo[j] <<
545 ", " <<
546 dhp_readout_frame_lo);
547 m_errorMask[c_nrDHP_DHP_FRAME_DIFFER] = true;
548 break;// give msg only once
549 }
550 }
551 }
552 */
553 m_last_dhp_readout_frame_lo[dhp_dhp_id] = dhp_readout_frame_lo;
554
555// TODO Please check if this can happen by accident with valid data!
556 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
557 // We see a second "header" with framenr+1 ...
558 if (!(m_suppressErrorMask[c_nrDHP_DBL_HEADER])) {
559 B2WARNING("DHP data: seems to be double header! skipping.");
560 B2DEBUG(29, "DHP data: seems to be double header! skipping." << LogVar("Length",
561 frame_len));
562 }
563 m_errorMask[c_nrDHP_DBL_HEADER] = true;
564 // dump_dhp(data, frame_len); print out guilty dhp packet
565 return;
566 }
567
568 // Start with offset 4, thus skipping header words
569 for (unsigned int i = 4; i < nr_words ; i++) {
570
571 B2DEBUG(29, "-- $" << hex << dhp_pix[i] << " -- " << dec << i);
572 {
573 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
574 rowflag = true;
575 if (!pixelflag) {
576 if (!(m_suppressErrorMask[c_nrDHP_ROW_WO_PIX])) B2WARNING("DHP Unpacking: Row w/o Pix");
577 m_errorMask[c_nrDHP_ROW_WO_PIX] = true;
578 }
579 pixelflag = false;
580 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
581 dhp_cm = dhp_pix[i] & 0x3F;
582 if (dhp_cm == 63) { // fifo overflow
583 B2WARNING("DHP data loss (CM=63) in " << LogVar("DHE", dhe_ID) << LogVar("DHP", dhp_dhp_id));
585 m_errorMask[c_nrDHH_MISC_ERROR] = true;
586 }
587 if (daqpktstat.dhc_size() > 0) {
588 if (daqpktstat.dhc_back().dhe_size() > 0) {
589 PXDDAQDHPComMode cm(dhp_dhp_id, dhp_row, dhp_cm);
590 // only is we have a DHC and DHE object... or back() is undefined
591 // Remark, if we have a broken data (DHE_START/END) structure, we might fill the
592 // previous DHE object ... but then the data is junk anyway
593 daqpktstat.dhc_back().dhe_back().addCM(cm);
594 }
595 }
596 B2DEBUG(29, "SetRow: $" << hex << dhp_row << " CM $" << hex << dhp_cm);
597 } else {
598 if (!rowflag) {
599 if (!(m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING("DHP Unpacking: Pix without Row!!! skip dhp data ");
600 m_errorMask[c_nrDHP_PIX_WO_ROW] = true;
601 // dump_dhp(data, frame_len);// print out faulty dhp frame
602 return;
603 } else {
604 pixelflag = true;
605 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
606 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
607 unsigned int v_cellID, u_cellID;
608 v_cellID = dhp_row;// defaults for no mapping
609 if (dhp_row >= 768) {
610 if (!(m_suppressErrorMask[c_nrROW_OVERFLOW])) B2WARNING("DHP ROW Overflow " << LogVar("Row", dhp_row));
611 m_errorMask[c_nrROW_OVERFLOW] = true;
612 }
613 // we cannot do col overflow check before mapping :-(
614
615 if ((dhe_reformat == 0 && !m_forceNoMapping) || m_forceMapping) {
616 u_cellID = dhp_col;// defaults for no mapping
617 // data has not been pre-processed by DHH, thus we have to do the mapping ourselves
618 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
619 // if IFOB
620 PXDMappingLookup::map_rc_to_uv_IF_OB(v_cellID, u_cellID, dhp_dhp_id, dhe_ID);
621 } else { // else OFIB
622 PXDMappingLookup::map_rc_to_uv_IB_OF(v_cellID, u_cellID, dhp_dhp_id, dhe_ID);
623 }
624 } else {
625 u_cellID = dhp_col + 64 * dhp_dhp_id; // defaults for already mapped
626 }
627 if (u_cellID >= 250) {
628 if (!(m_suppressErrorMask[c_nrCOL_OVERFLOW])) {
629 B2WARNING("DHP COL Overflow (unconnected drain lines)");
630 B2DEBUG(29, "DHP COL Overflow (unconnected drain lines) " << u_cellID << ", reformat " << dhe_reformat << ", dhpcol " << dhp_col <<
631 ", id " << dhp_dhp_id);
632 }
633 m_errorMask[c_nrCOL_OVERFLOW] = true;
634 }
635 dhp_adc = dhp_pix[i] & 0xFF;
636 B2DEBUG(29, "SetPix: Row $" << hex << dhp_row << " Col $" << hex << dhp_col << " ADC $" << hex << dhp_adc
637 << " CM $" << hex << dhp_cm);
638
639 if (dhp_adc == 0) {
640 // if !suppress error flag
641 B2WARNING("DHE Event truncation in DHE " << dhe_ID << " DHP " << dhp_dhp_id);
642 // m_errorMask |= c_DHE_EVENT_TRUNC;
643 daqpktstat.dhc_back().dhe_back().dhp_back().setTruncated();
644 } else {
645 if (!m_doNotStore) m_storeRawHits.appendNew(vxd_id, v_cellID, u_cellID, dhp_adc,
646 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) & 0x3F);
647 }
648 }
649 }
650 }
651 }
652
653 B2DEBUG(29, "(DHE) DHE_ID $" << hex << dhe_ID << " (DHE) DHP ID $" << hex << dhe_DHPport << " (DHP) DHE_ID $" << hex << dhp_dhe_id
654 << " (DHP) DHP ID $" << hex << dhp_dhp_id);
655 /*for (int i = 0; i < raw_nr_words ; i++) {
656 B2DEBUG(29, "RAW | " << hex << p_pix[i]);
657 printf("raw %08X | ", p_pix[i]);
658 B2DEBUG(29, "row " << hex << ((p_pix[i] >> 20) & 0xFFF) << dec << " ( " << ((p_pix[i] >> 20) & 0xFFF) << " ) " << " col " << hex << ((p_pix[i] >> 8) & 0xFFF)
659 << " ( " << dec << ((p_pix[i] >> 8) & 0xFFF) << " ) " << " adc " << hex << (p_pix[i] & 0xFF) << " ( " << (p_pix[i] & 0xFF) << " ) "
660 );
661 }*/
662}
663
664void PXDUnpackerOldModule::unpack_dhc_frame(void* data, const int len, const int Frame_Number, const int Frames_in_event,
665 PXDDAQPacketStatus& daqpktstat)
666{
670 static unsigned int eventNrOfOnsenTrgFrame = 0;
671 static int countedBytesInDHC = 0;
672 static bool cancheck_countedBytesInDHC = false;
673 static int countedBytesInDHE = 0;
674 static bool cancheck_countedBytesInDHE = false;
675 static int countedDHEStartFrames = 0;
676 static int countedDHEEndFrames = 0;
677 static int mask_active_dhe = 0;// DHE mask (5 bit)
678 static int nr_active_dhe =
679 0;// TODO just count the active DHEs. Until now, it is not possible to check for the bit mask. we would need the info on which DHE connects to which DHC at which port from gearbox/geometry?
680 static int mask_active_dhp = 0;// DHP active mask, 4 bit, per current DHE
681 static int found_mask_active_dhp = 0;// mask which DHP send data and check on DHE END frame if it matches
682 static unsigned int dhe_first_readout_frame_id_lo = 0;
683 // cppcheck-suppress variableScope
684 static unsigned int dhe_first_triggergate = 0;
685 static unsigned int currentDHCID = 0xFFFFFFFF;
686 static unsigned int currentDHEID = 0xFFFFFFFF;
687 static unsigned int currentVxdId = 0;
688 static bool isFakedData_event = false;
689 static bool isUnfiltered_event = false;
690
691
692 if (Frame_Number == 0) {
693 // We reset the counters on the first event
694 // we do this before any other check is done
695 eventNrOfOnsenTrgFrame = 0;
696 countedDHEStartFrames = 0;
697 countedDHEEndFrames = 0;
698 countedBytesInDHC = 0;
699 cancheck_countedBytesInDHC = false;
700 countedBytesInDHE = 0;
701 cancheck_countedBytesInDHE = false;
702 currentDHCID = 0xFFFFFFFF;
703 currentDHEID = 0xFFFFFFFF;
704 currentVxdId = 0;
705 isUnfiltered_event = false;
706 isFakedData_event = false;
707 mask_active_dhe = 0;
708 nr_active_dhe = 0;
709 mask_active_dhp = 0;
710 found_mask_active_dhp = 0;
711 }
712
714
715 dhc_frames dhc;
716 dhc.set(data, hw->getFrameType(), len);
717
718 {
719 // if a fixed size frame has a different length, how can we rely on its content???
720 // AND we could by typecasting access memory beyond end of data (but very unlikely)
721 // for that reason this we have to check before any CRC and stop unpacking the frame
722 int s = dhc.getFixedSize();
723 if (len != s && s != 0) {
724 if (!(m_suppressErrorMask[c_nrFIX_SIZE])) {
725 B2WARNING("Fixed frame type size does not match specs" << LogVar("expected length",
726 len) << LogVar("length in data", s));
727 }
728 m_errorMask[c_nrFIX_SIZE] = true;
729 if (!m_continueOnError) return;
730 }
731 }
732
733 // What do we do with wrong checksum frames? As we do not know WHAT is wrong, we have to skip them altogether.
734 // As they might contain HEADER Info, we might better skip the processing of the full package, too.
735 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
736 if (!m_continueOnError && m_errorMask[c_nrDHE_CRC]) {
737 // if CRC is wrong, we cannot rely on the content of the frame, thus skipping is the best option
738 return;
739 }
740
741 unsigned int eventNrOfThisFrame = dhc.getEventNrLo();
742 int frame_type = dhc.getFrameType();
743
744 if (Frame_Number == 0) {
745 if (m_formatBonnDAQ) {
746 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
747 if (!(m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING("This looks not like BonnDAQ format.");
748 m_errorMask[c_nrEVENT_STRUCT] = true;
749// if (!m_continueOnError) return; // requires more testing
750 }
751 } else {
752 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
753 if (!(m_suppressErrorMask[c_nrEVENT_STRUCT]))
754 B2WARNING("This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
755 m_errorMask[c_nrEVENT_STRUCT] = true;
756// if (!m_continueOnError) return; // requires more testing
757 }
758 }
759 }
760
761 if (!m_formatBonnDAQ) {
762 if (Frame_Number == 1) {
763 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
764 isFakedData_event = dhc.data_dhc_start_frame->isFakedData();
765 }
766 }
767
768 // please check if this mask is suitable. At least here we are limited by the 16 bit trigger number in the DHH packet header.
769 // we can use more bits in the DHC and DHE START Frame
770 if ((eventNrOfThisFrame & 0xFFFF) != (m_meta_event_nr & 0xFFFF)) {
771 if (!isFakedData_event) {
772 if (!(m_suppressErrorMask[c_nrMETA_MM])) {
773 B2WARNING("Event Numbers do not match for this frame");
774 B2DEBUG(29, "Event Numbers do not match for this frame" <<
775 LogVar("Event nr in frame $", static_cast < std::ostringstream
776 && >(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
777 LogVar("Event nr in MetaInfo (bits masked) $",
778 static_cast < std::ostringstream && >(std::ostringstream() << hex << m_meta_event_nr).str()));
779 }
780 m_errorMask[c_nrMETA_MM] = true;
781// if (!m_continueOnError) return; // requires more testing
782 }
783 }
784
785 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
786 if (countedDHEStartFrames != countedDHEEndFrames + 1)
787 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
788 if (!(m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING("Data Frame outside a DHE START/END");
789 m_errorMask[c_nrDATA_OUTSIDE] = true;
790// if (!m_continueOnError) return; // requires more testing
791 }
792 }
793 }
794
795 // TODO How do we handle Frames where Error Bit is set in header?
796 // Currently there is no documentation what it actually means... only an error bit is set (below)
797 // the following errors must be "accepted", as all firmware sets it wrong from Ghost frames.
798 if (hw->getErrorFlag()) {
799 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
800 if (!(m_suppressErrorMask[c_nrHEADER_ERR])) B2ERROR("Error Bit set in DHE Header");
801 m_errorMask[c_nrHEADER_ERR] = true;// TODO this should have some effect ... when does it mean something? documentation missing
802 }
803 } else {
804 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
805 m_errorMask[c_nrHEADER_ERR_GHOST] = true;
806 }
807 }
808
809 switch (frame_type) {
810 case EDHCFrameHeaderDataType::c_DHP_RAW: {
811
813 if (currentDHEID != dhc.data_direct_readout_frame_raw->getDHEId()) {
814 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
815 B2WARNING("DHE ID from DHE Start and this frame do not match");
816 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match" <<
817 LogVar("DHEID in this frame $", static_cast < std::ostringstream
818 && >(std::ostringstream() << hex << dhc.data_direct_readout_frame_raw->getDHEId()).str()) <<
819 LogVar("DHEID expected $", static_cast < std::ostringstream && >(std::ostringstream() << hex << currentDHEID).str()));
820 }
821 m_errorMask[c_nrDHE_START_ID] = true;
822 }
823 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
824 found_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
825
826 unpack_dhp_raw(data, len - 4,
829 currentVxdId);
830
831 break;
832 };
833 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
834 // Set the counted size invalid if negative, needs a large negative value because we are adding up to that
835 cancheck_countedBytesInDHC = false;
836 cancheck_countedBytesInDHE = false;
837 [[fallthrough]];
838 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
839
841 if (isUnfiltered_event) {
842 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP) m_errorMask[c_nrSENDALL_TYPE] = true;
843 } else {
844 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD) m_errorMask[c_nrNOTSENDALL_TYPE] = true;
845 }
846
847 //m_errorMask |= dhc.data_direct_readout_frame->check_error();
848
849 if (currentDHEID != dhc.data_direct_readout_frame_raw->getDHEId()) {
850 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
851 B2WARNING("DHE ID from DHE Start and this frame do not match");
852 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match" <<
853 LogVar("DHEID in this frame $", static_cast < std::ostringstream
854 && >(std::ostringstream() << hex << dhc.data_direct_readout_frame_raw->getDHEId()).str()) <<
855 LogVar("DHEID expected $", static_cast < std::ostringstream && >(std::ostringstream() << hex << currentDHEID).str()));
856 }
857 m_errorMask[c_nrDHE_START_ID] = true;
858 }
859 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
860 found_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
861 if (m_checkPaddingCRC) dhc.check_padding(m_errorMask); // isUnfiltered_event
862
863
864 unpack_dhp(data, len - 4,
865 dhe_first_readout_frame_id_lo,
869 currentVxdId, daqpktstat);
870
871 break;
872 };
873 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
874 // Set the counted size invalid if negative, needs a large negative value because we are adding up to that
875 cancheck_countedBytesInDHC = false;
876 cancheck_countedBytesInDHE = false;
877 [[fallthrough]];
878 case EDHCFrameHeaderDataType::c_FCE_RAW: {
879 if (!(m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING("Unexpected Frame Type (Clustering FCE)");
880 m_errorMask[c_nrUNEXPECTED_FRAME_TYPE] = true;
881 if (m_verbose) hw->print();
882 if (isUnfiltered_event) {
883 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
884 // TODO add error message
885 m_errorMask[c_nrSENDALL_TYPE] = true;
886 }
887 } else {
888 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
889 // TODO add error message
890 m_errorMask[c_nrNOTSENDALL_TYPE] = true;
891 }
892 }
893
894 if (currentDHEID != dhc.data_direct_readout_frame_raw->getDHEId()) {
895 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
896 B2WARNING("DHE ID from DHE Start and this frame do not match");
897 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match" <<
898 LogVar("DHEID in this frame $", static_cast < std::ostringstream
899 && >(std::ostringstream() << hex << dhc.data_direct_readout_frame_raw->getDHEId()).str()) <<
900 LogVar("DHEID expected $", static_cast < std::ostringstream && >(std::ostringstream() << hex << currentDHEID).str()));
901 }
902 m_errorMask[c_nrDHE_START_ID] = true;
903 }
904 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
905 found_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
906
907 B2DEBUG(29, "UNPACK FCE FRAME with len $" << hex << len);
908 unpack_fce((unsigned short*) data, len - 4, currentVxdId);
909
910 break;
911 };
912 case EDHCFrameHeaderDataType::c_COMMODE: {
913 // this frame type has up to now not been well defined, we do not expect it until
914 // the firmware supports clustering in hardware
915 if (!(m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING("Unexpected Frame Type (COMMODE)");
916 m_errorMask[c_nrUNEXPECTED_FRAME_TYPE] = true;
917
918 if (m_verbose) hw->print();
919 if (currentDHEID != dhc.data_commode_frame->getDHEId()) {
920 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
921 B2WARNING("DHE ID from DHE Start and this frame do not match");
922 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match" <<
923 LogVar("DHEID in this frame $", static_cast < std::ostringstream
924 && >(std::ostringstream() << hex << dhc.data_commode_frame->getDHEId()).str()) <<
925 LogVar("DHEID expected $", static_cast < std::ostringstream && >(std::ostringstream() << hex << currentDHEID).str()));
926 }
927 m_errorMask[c_nrDHE_START_ID] = true;
928 }
929 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
930 break;
931 };
932 case EDHCFrameHeaderDataType::c_DHC_START: {
933 countedBytesInDHC = 0;
934 cancheck_countedBytesInDHC = true;
935 if (isFakedData_event != dhc.data_dhc_start_frame->isFakedData()) {
936 if (!(m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING("DHC START mixed Fake/no Fake event.");
937 m_errorMask[c_nrFAKE_NO_FAKE_DATA] = true;
938 }
940 if (!(m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING("Faked DHC START Data -> trigger without Data!");
941 m_errorMask[c_nrFAKE_NO_DATA_TRIG] = true;
942 } else {
944 }
945
946// eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
947 currentDHEID = 0xFFFFFFFF;
948 currentVxdId = 0;
949 currentDHCID = dhc.data_dhc_start_frame->get_dhc_id();
950 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
951
952 if (m_formatBonnDAQ) eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
953
954 if (!isFakedData_event) {
958 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_ERS])) {
959 B2WARNING("DHC-Meta Experiment number mismatch");
960 B2DEBUG(29, "DHC-Meta Experiment number mismatch" <<
961 LogVar("DHC exp nr",
963 LogVar("META exp nr", m_meta_experiment));
964 }
965 m_errorMask[c_nrMETA_MM_DHC_ERS] = true;
966 }
968 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_ERS])) {
969 B2WARNING("DHC-Meta Run number mismatch");
970 B2DEBUG(29, "DHC-Meta Run number mismatch" <<
971 LogVar("DHC Run nr",
973 LogVar("META run nr", m_meta_run_nr));
974 }
975 m_errorMask[c_nrMETA_MM_DHC_ERS] = true;
976 }
978 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_ERS])) {
979 B2WARNING("DHC-Meta Sub-Run number mismatch");
980 B2DEBUG(29, "DHC-Meta Sub-Run number mismatch" <<
981 LogVar("DHC subrun nr",
983 LogVar("META subrun nr", m_meta_subrun_nr));
984 }
985 m_errorMask[c_nrMETA_MM_DHC_ERS] = true;
986 }
987 if ((((unsigned int)dhc.data_dhc_start_frame->getEventNrHi() << 16) | dhc.data_dhc_start_frame->getEventNrLo()) !=
988 (m_meta_event_nr & 0xFFFFFFFF)) {
989 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC])) {
990 B2WARNING("DHC-Meta 32 bit event number mismatch");
991 B2DEBUG(29, "DHC-Meta 32 bit event number mismatch" <<
992 LogVar("DHC trigger nr", (((unsigned int) dhc.data_dhc_start_frame->getEventNrHi() << 16) |
994 LogVar("META trigger nr", (unsigned int)(m_meta_event_nr & 0xFFFFFFFF)));
995 }
996 m_errorMask[c_nrMETA_MM_DHC] = true;
997 }
998 uint32_t trig_ticks = (((unsigned int)dhc.data_dhc_start_frame->time_tag_mid & 0x7FFF) << 12) | ((unsigned int)
1000 uint32_t trig_sec = (dhc.data_dhc_start_frame->time_tag_hi * 2) ;
1001 if (dhc.data_dhc_start_frame->time_tag_mid & 0x8000) trig_sec++;
1002
1003 if ((trig_ticks - m_meta_ticks) != 0 || (trig_sec - m_meta_sec) != 0) {
1004 m_errorMask[c_nrMETA_MM_DHC_TT] = true;
1005 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_TT])) {
1006 B2WARNING("DHC-Meta TimeTag mismatch");
1007 B2DEBUG(29, "DHC-Meta TimeTag mismatch" <<
1008 LogVar("Header Time $", static_cast < std::ostringstream && >(std::ostringstream() <<
1009 hex << dhc.data_dhc_start_frame->time_tag_hi << "." <<
1010 dhc.data_dhc_start_frame->time_tag_mid << "." <<
1012 LogVar("Meta Time $", static_cast < std::ostringstream && >(std::ostringstream() << hex << m_meta_time).str()) <<
1013 LogVar("Trigger Type", static_cast < std::ostringstream
1014 && >(std::ostringstream() << hex << (dhc.data_dhc_start_frame->time_tag_lo_and_type & 0xF)).str()) <<
1015 LogVar("Meta seconds: $", static_cast < std::ostringstream && >(std::ostringstream() << hex << m_meta_sec).str()) <<
1016 LogVar("DHC seconds $", static_cast < std::ostringstream && >(std::ostringstream() << hex << trig_sec).str()) <<
1017 LogVar("Seconds difference $", static_cast < std::ostringstream
1018 && >(std::ostringstream() << hex << (trig_sec - m_meta_sec)).str()) <<
1019 LogVar("Meta ticks from 127MHz $", static_cast < std::ostringstream && >(std::ostringstream() << hex << m_meta_ticks).str()) <<
1020 LogVar("DHC ticks from 127MHz $", static_cast < std::ostringstream && >(std::ostringstream() << hex << trig_ticks).str()) <<
1021 LogVar("Tick difference $", static_cast < std::ostringstream
1022 && >(std::ostringstream() << hex << (trig_ticks - m_meta_ticks)).str()));
1023 }
1024 } else {
1025 B2DEBUG(29, "DHC TT: $" << hex << dhc.data_dhc_start_frame->time_tag_hi << "." << dhc.data_dhc_start_frame->time_tag_mid << "." <<
1026 dhc.data_dhc_start_frame->time_tag_lo_and_type << " META " << m_meta_time << " TRG Type " <<
1028 }
1029 }
1030 mask_active_dhe = dhc.data_dhc_start_frame->get_active_dhe_mask();
1031 nr_active_dhe = nr5bits(mask_active_dhe);
1032
1033 m_errorMaskDHC = m_errorMask; // forget about anything before this frame
1034 daqpktstat.newDHC(currentDHCID, m_errorMask);
1037
1038 break;
1039 };
1040 case EDHCFrameHeaderDataType::c_DHE_START: {
1041 countedBytesInDHE = 0;
1042 cancheck_countedBytesInDHE = true;
1048 dhe_first_readout_frame_id_lo = dhc.data_dhe_start_frame->getStartFrameNr();
1049 dhe_first_triggergate = dhc.data_dhe_start_frame->getTriggerGate();
1050 if (currentDHEID != 0xFFFFFFFF && (currentDHEID & 0xFFFF) >= dhc.data_dhe_start_frame->getDHEId()) {
1051 if (!(m_suppressErrorMask[c_nrDHE_WRONG_ID_SEQ])) {
1052 B2WARNING("DHH IDs are not in expected order");
1053 B2DEBUG(29, "DHH IDs are not in expected order" <<
1054 LogVar("Previous ID", (currentDHEID & 0xFFFF)) <<
1055 LogVar("Current ID", dhc.data_dhe_start_frame->getDHEId()));
1056 }
1057 m_errorMask[c_nrDHE_WRONG_ID_SEQ] = true;
1058 }
1059 currentDHEID = dhc.data_dhe_start_frame->getDHEId();
1060 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1061
1062 if (countedDHEStartFrames > countedDHEEndFrames) {
1063 if (!(m_suppressErrorMask[c_nrDHE_START_WO_END])) B2WARNING("DHE_START without DHE_END");
1064 m_errorMask[c_nrDHE_START_WO_END] = true;
1065 }
1066 countedDHEStartFrames++;
1067
1068 found_mask_active_dhp = 0;
1069 mask_active_dhp = dhc.data_dhe_start_frame->getActiveDHPMask();
1070
1071 if ((((unsigned int)dhc.data_dhe_start_frame->getEventNrHi() << 16) | dhc.data_dhe_start_frame->getEventNrLo()) != (unsigned int)(
1072 m_meta_event_nr & 0xFFFFFFFF)) {
1073 if (!(m_suppressErrorMask[c_nrMETA_MM_DHE])) {
1074 B2WARNING("DHE START trigger mismatch in EVT32b/HI WORD");
1075 B2DEBUG(29, "DHE START trigger mismatch in EVT32b/HI WORD" <<
1076 LogVar("DHE Start trigger nr", (dhc.data_dhe_start_frame->getEventNrHi() << 16) | dhc.data_dhe_start_frame->getEventNrLo()) <<
1077 LogVar("Meta trigger nr", (m_meta_event_nr & 0xFFFFFFFF)));
1078 }
1079 m_errorMask[c_nrMETA_MM_DHE] = true;
1080 }
1081// B2WARNING("DHE TT: $" << hex << dhc.data_dhe_start_frame->dhe_time_tag_hi << "." << dhc.data_dhe_start_frame->dhe_time_tag_lo <<
1082// " META " << m_meta_time);
1083
1084 if (currentDHEID == 0) {
1085 if (!(m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING("DHE ID is invalid=0 (not initialized)");
1086 m_errorMask[c_nrDHE_ID_INVALID] = true;
1087 }
1088 // calculate the VXDID for DHE and save them for DHP unpacking
1089 {
1096 unsigned short sensor, ladder, layer;
1097 sensor = (currentDHEID & 0x1) + 1;
1098 ladder = (currentDHEID & 0x1E) >> 1; // no +1
1099 layer = ((currentDHEID & 0x20) >> 5) + 1;
1100 currentVxdId = VxdID(layer, ladder, sensor);
1101 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
1102 if (!(m_suppressErrorMask[c_nrDHE_ID_INVALID])) {
1103 B2WARNING("DHE ID is invalid");
1104 B2DEBUG(29, "DHE ID is invalid" <<
1105 LogVar("DHE ID", currentDHEID) <<
1106 LogVar("Layer", layer) <<
1107 LogVar("Ladder", ladder) <<
1108 LogVar("Sensor", sensor));
1109 }
1110 m_errorMask[c_nrDHE_ID_INVALID] = true;
1111 }
1112 }
1113
1114 m_errorMaskDHE = m_errorMask; // forget about anything before this frame
1115 if (daqpktstat.dhc_size() > 0) {
1116 // if no DHC has been defined yet, do nothing!
1117 daqpktstat.dhc_back().newDHE(currentVxdId, currentDHEID, m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
1118 }
1119 break;
1120 };
1121 case EDHCFrameHeaderDataType::c_GHOST:
1122 if (m_verbose) dhc.data_ghost_frame->print();
1123 if (currentDHEID != dhc.data_ghost_frame->getDHEId()) {
1124 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
1125 B2WARNING("DHE ID from DHE Start and this frame do not match");
1126 B2DEBUG(29, "Start ID $" << hex << currentDHEID << " != $" << dhc.data_ghost_frame->getDHEId());
1127 }
1128 m_errorMask[c_nrDHE_START_ID] = true;
1129 }
1131 found_mask_active_dhp |= 1 << dhc.data_ghost_frame->getDHPPort();
1132
1133 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1134
1135 break;
1136 case EDHCFrameHeaderDataType::c_DHC_END: {
1137 if (dhc.data_dhc_end_frame->isFakedData() != isFakedData_event) {
1138 if (!(m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING("DHC END mixed Fake/no Fake event.");
1139 m_errorMask[c_nrFAKE_NO_FAKE_DATA] = true;
1140 }
1141 if (dhc.data_dhc_end_frame->isFakedData()) {
1142 if (!(m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING("Faked DHC END Data -> trigger without Data!");
1143 m_errorMask[c_nrFAKE_NO_DATA_TRIG] = true;
1144 } else {
1146 }
1147
1148 if (!isFakedData_event) {
1149 if (dhc.data_dhc_end_frame->get_dhc_id() != currentDHCID) {
1150 if (!(m_suppressErrorMask[c_nrDHC_DHCID_START_END_MM])) {
1151 B2WARNING("DHC ID Mismatch between Start and End");
1152 B2DEBUG(29, "DHC ID Mismatch between Start and End $" << std::hex <<
1153 currentDHCID << "!=$" << dhc.data_dhc_end_frame->get_dhc_id());
1154 }
1155 m_errorMask[c_nrDHC_DHCID_START_END_MM] = true;
1156 }
1157 int w;
1158 w = dhc.data_dhc_end_frame->get_words() * 4;
1159 if (cancheck_countedBytesInDHC) {
1160 if (countedBytesInDHC != w) {
1161 if (!(m_suppressErrorMask[c_nrDHC_WIE])) {
1162 B2WARNING("Number of Words in DHC END does not match");
1163 B2DEBUG(29, "Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC << " != DHC END $" << hex << w);
1164 }
1165 m_errorMask[c_nrDHC_WIE] = true;
1166 } else {
1167 if (m_verbose)
1168 B2DEBUG(29, "EVT END: WIE $" << hex << countedBytesInDHC << " == DHC END $" << hex << w);
1169 }
1170 // else ... processed data -> length invalid
1171 }
1172 }
1174 if (dhc.data_dhc_end_frame->getErrorInfo() != 0) {
1175 if (!(m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR("DHC END Error Info set to $" << hex <<
1177 m_errorMask[c_nrDHH_END_ERRORBITS] = true;
1178 }
1179 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1180 m_errorMaskDHC |= m_errorMask; // do latest updates
1181
1182 if (daqpktstat.dhc_size() > 0) {
1183 // only is we have a DHC object... or back() is undefined
1184 // Remark, if we have a broken data (DHC_START/END) structure, we might fill the
1185 // previous DHC object ... but then the data is junk anyway
1186 daqpktstat.dhc_back().setErrorMask(m_errorMaskDHC);
1187 //B2DEBUG(98,"** DHC "<<currentDHCID<<" Raw"<<dhc.data_dhc_end_frame->get_words() * 4 <<" Red"<<countedBytesInDHC);
1188 daqpktstat.dhc_back().setCounters(dhc.data_dhc_end_frame->get_words() * 4, countedBytesInDHC);
1190 }
1191 m_errorMaskDHC = 0;
1192 currentDHEID = 0xFFFFFFFF;
1193 currentDHCID = 0xFFFFFFFF;
1194 currentVxdId = 0;
1195 break;
1196 };
1197 case EDHCFrameHeaderDataType::c_DHE_END: {
1199 if (currentDHEID != dhc.data_dhe_end_frame->getDHEId()) {
1200 if (!(m_suppressErrorMask[c_nrDHE_START_END_ID])) {
1201 B2WARNING("DHE ID from DHE Start and this frame do not match");
1202 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID << " != $" <<
1204 }
1205 m_errorMask[c_nrDHE_START_END_ID] = true;
1206 }
1208 if (dhc.data_dhe_end_frame->getErrorInfo() != 0) {
1209 if (!(m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) {
1210 B2ERROR("DHE END Error Info set to $" << hex <<
1212 }
1213 m_errorMask[c_nrDHH_END_ERRORBITS] = true;
1214 }
1215 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1216 if (found_mask_active_dhp != mask_active_dhp) {
1217 if (!(m_suppressErrorMask[c_nrDHP_ACTIVE])) {
1218 B2WARNING("DHE_END: DHP active mask differs from found data");
1219 B2DEBUG(29, "DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp << " != $" << hex <<
1220 found_mask_active_dhp
1221 << " mask of found dhp/ghost frames");
1222 }
1223 m_errorMask[c_nrDHP_ACTIVE] = true;
1224 }
1225 countedDHEEndFrames++;
1226 if (countedDHEStartFrames < countedDHEEndFrames) {
1227 // the other case is checked in Start
1228 if (!(m_suppressErrorMask[c_nrDHE_END_WO_START])) B2WARNING("DHE_END without DHE_START");
1229 m_errorMask[c_nrDHE_END_WO_START] = true;
1230 }
1231 {
1232 int w;
1233 w = dhc.data_dhe_end_frame->get_words() * 2;
1234 if (cancheck_countedBytesInDHE) {
1235 if (countedBytesInDHE != w) {
1236 if (!(m_suppressErrorMask[c_nrDHE_WIE])) {
1237 B2WARNING("Number of Words in DHE END does not match");
1238 B2DEBUG(29, "Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE << " != DHE END $" << hex << w);
1239 }
1240 m_errorMask[c_nrDHE_WIE] = true;
1241 } else {
1242 if (m_verbose)
1243 B2DEBUG(29, "EVT END: WIE $" << hex << countedBytesInDHE << " == DHE END $" << hex << w);
1244 }
1245 // else ... processed data -> length invalid
1246 }
1247 }
1248 m_errorMaskDHE |= m_errorMask; // do latest updates
1249
1250 if (daqpktstat.dhc_size() > 0) {
1251 if (daqpktstat.dhc_back().dhe_size() > 0) {
1252 // only is we have a DHC and DHE object... or back() is undefined
1253 // Remark, if we have a broken data (DHE_START/END) structure, we might fill the
1254 // previous DHE object ... but then the data is junk anyway
1256 // B2DEBUG(98,"** DHC "<<currentDHEID<<" Raw "<<dhc.data_dhe_end_frame->get_words() * 2 <<" Red"<<countedBytesInDHE);
1257 daqpktstat.dhc_back().dhe_back().setCounters(dhc.data_dhe_end_frame->get_words() * 2, countedBytesInDHE);
1259 }
1260 }
1261 m_errorMaskDHE = 0;
1262 currentDHEID |= 0xFF000000;// differentiate from 0xFFFFFFFFF as initial value
1263 currentVxdId = 0;
1264 break;
1265 };
1266 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
1268 dhc.data_onsen_roi_frame->check_error(m_errorMask, len, m_suppressErrorMask[c_nrROI_PACKET_INV_SIZE]);
1270 len - 4);
1271 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1272 if (!m_doNotStore) {
1273 //dhc.data_onsen_roi_frame->save(m_storeROIs, len, (unsigned int*) data);
1274 // void save(StoreArray<PXDRawROIs>& sa, unsigned int length, unsigned int* data) const
1275 // 4 byte header, ROIS (n*8), 4 byte copy of inner CRC, 4 byte outer CRC
1276 if (len >= dhc.data_onsen_roi_frame->getMinSize()) {
1277 //if ((len - dhc.data_onsen_roi_frame->getMinSize()) % 8 != 0) {
1278 // error checking in check_error() above, this is only for dump-ing
1279 // dump_roi(data, len - 4); // dump ROI payload, minus CRC
1280 //}
1281 unsigned int l;
1282 l = (len - dhc.data_onsen_roi_frame->getMinSize()) / 8;
1283 // Endian swapping is done in Constructor of RawRoi object
1284 m_storeROIs.appendNew(l, &((unsigned int*) data)[1]);
1285 }
1286 }
1287 break;
1288 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
1289 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
1290 if (dhc.data_onsen_trigger_frame->get_trig_nr1() != (unsigned int)(m_meta_event_nr & 0xFFFFFFFF)) {
1291 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_HLT])) {
1292 B2WARNING("Trigger Frame HLT Trigger Nr mismatch");
1293 B2DEBUG(29, "Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
1294 dhc.data_onsen_trigger_frame->get_trig_nr1() << " META " << (m_meta_event_nr & 0xFFFFFFFF));
1295 }
1296 m_errorMask[c_nrMETA_MM_ONS_HLT] = true;
1297 }
1301 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_HLT])) {
1302 B2WARNING("Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
1303 B2DEBUG(29, "Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
1305 " Run HLT $" << dhc.data_onsen_trigger_frame->get_run1() << " META " << m_meta_run_nr <<
1306 " Subrun HLT $" << dhc.data_onsen_trigger_frame->get_subrun1() << " META " << m_meta_subrun_nr);
1307 }
1308 m_errorMask[c_nrMETA_MM_ONS_HLT] = true;
1309 }
1310
1312 if (dhc.data_onsen_trigger_frame->get_trig_nr2() != (unsigned int)(m_meta_event_nr & 0xFFFFFFFF)) {
1313 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_DC])) {
1314 B2WARNING("Trigger Frame DATCON Trigger Nr mismatch");
1315 B2DEBUG(29, "Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
1316 dhc.data_onsen_trigger_frame->get_trig_nr2() << " META " << (m_meta_event_nr & 0xFFFFFFFF));
1317 }
1318 m_errorMask[c_nrMETA_MM_ONS_DC] = true;
1319 }
1323 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_DC])) {
1324 B2WARNING("Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
1325 B2DEBUG(29, "Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
1327 " Run DC $" << dhc.data_onsen_trigger_frame->get_run2() << " META " << m_meta_run_nr <<
1328 " Subrun DC $" << dhc.data_onsen_trigger_frame->get_subrun2() << " META " << m_meta_subrun_nr);
1329 }
1330 m_errorMask[c_nrMETA_MM_ONS_DC] = true;
1331 }
1332 }
1333
1334// B2WARNING("TRG TAG HLT: $" << hex << dhc.data_onsen_trigger_frame->get_trig_tag1() << " DATCON $" << dhc.data_onsen_trigger_frame->get_trig_tag2() << " META " << m_meta_time);
1335
1338 m_suppressErrorMask[c_nrHLTROI_MAGIC],
1339 m_suppressErrorMask[c_nrMERGER_TRIGNR]);
1340 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1341 if (Frame_Number != 0) {
1342 if (!(m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING("ONSEN TRG Frame must be the first one.");
1343 m_errorMask[c_nrEVENT_STRUCT] = true;
1344 }
1345 isUnfiltered_event = dhc.data_onsen_trigger_frame->is_SendUnfiltered();
1346 if (isUnfiltered_event) m_sendunfiltered++;
1349 break;
1350 default:
1351 if (!(m_suppressErrorMask[c_nrDHC_UNKNOWN])) B2WARNING("UNKNOWN DHC frame type");
1352 m_errorMask[c_nrDHC_UNKNOWN] = true;
1353 if (m_verbose) hw->print();
1354 break;
1355 }
1356
1357 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
1358 if (!(m_suppressErrorMask[c_nrFRAME_TNR_MM])) {
1359 B2WARNING("Frame TrigNr != ONSEN Trig Nr");
1360 B2DEBUG(29, "Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame << " != $" << eventNrOfOnsenTrgFrame);
1361 }
1362 m_errorMask[c_nrFRAME_TNR_MM] = true;
1363 }
1364
1365 if (Frame_Number == 0) {
1367 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1368 if (!m_formatBonnDAQ) {
1369 if (!(m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING("First frame is not a ONSEN Trigger frame");
1370 m_errorMask[c_nrONSEN_TRG_FIRST] = true;
1371 }
1372 }
1373 } else { // (Frame_Number != 0 &&
1375 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1376 if (!(m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING("More than one ONSEN Trigger frame");
1377 m_errorMask[c_nrONSEN_TRG_FIRST] = true;
1378 }
1379 }
1380
1381 if (!m_formatBonnDAQ) {
1382 if (Frame_Number == 1) {
1384 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1385 if (!(m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING("Second frame is not a DHC start of subevent frame");
1386 m_errorMask[c_nrDHC_START_SECOND] = true;
1387 }
1388 } else { // (Frame_Number != 0 &&
1390 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1391 if (!(m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING("More than one DHC start of subevent frame");
1392 m_errorMask[c_nrDHC_START_SECOND] = true;
1393 }
1394 }
1395 }
1396
1397 if (Frame_Number == Frames_in_event - 1) {
1399 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
1400 if (!(m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING("Last frame is not a DHC end of subevent frame");
1401 m_errorMask[c_nrDHC_END_MISS] = true;
1402 }
1403
1405 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
1406 if (!(m_suppressErrorMask[c_nrDHE_ACTIVE]) || !(m_suppressErrorMask[c_nrDHE_START_WO_END])
1407 || !(m_suppressErrorMask[c_nrDHE_END_WO_START])) {
1408 B2WARNING("The number of DHE Start/End does not match the number of active DHE in DHC Header!");
1409 B2DEBUG(29, "The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
1410 " Start: " << countedDHEStartFrames << " End: " << countedDHEEndFrames << " Mask: $" << hex << mask_active_dhe << " in Event Nr " <<
1411 eventNrOfThisFrame);
1412 }
1413 if (countedDHEStartFrames == countedDHEEndFrames) m_errorMask[c_nrDHE_ACTIVE] = true;
1414 if (countedDHEStartFrames > countedDHEEndFrames) m_errorMask[c_nrDHE_START_WO_END] = true;
1415 if (countedDHEStartFrames < countedDHEEndFrames) m_errorMask[c_nrDHE_END_WO_START] = true;
1416 }
1417
1418 } else { // (Frame_Number != Frames_in_event - 1 &&
1420 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
1421 if (!(m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING("More than one DHC end of subevent frame");
1422 m_errorMask[c_nrDHC_END_DBL] = true;
1423 }
1424 }
1425
1426 if (!m_formatBonnDAQ) {
1428 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1429 if (!(m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING("Third frame is not a DHE start frame");
1430 m_errorMask[c_nrDHE_START_THIRD] = true;
1431 }
1432 }
1433
1434 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1435 // actually, they should not be within Start and End, but better be sure.
1436 countedBytesInDHC += len;
1437 countedBytesInDHE += len;
1438 }
1439 B2DEBUG(29, "DHC/DHE $" << hex << countedBytesInDHC << ", $" << hex << countedBytesInDHE);
1440}
1441
1443{
1445 const int lut[32] = {
1446 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1447 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5
1448 };
1449 return lut[i & 0x1F];
1450}
1451
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition DataStore.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
Module()
Constructor.
Definition Module.cc:30
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition Module.cc:220
@ 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
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask This should be the OR of error masks of all sub-objects (DHC, DHE)
void setGatedFlag(bool gm)
set gating info from the DHC END
PXDDAQDHEStatus & newDHE(Args &&... params)
Add new DHE information.
void setGatedHER(bool isher)
set HER/LER gating info from the DHC END
PXDDAQDHEStatus & dhe_back()
Returns PXDDAQDHEStatus for last DHE.
void setEndErrorInfo(uint32_t e)
set errorinfo from the DHC END
size_t dhe_size() const
Returns number of DHEs.
void setCounters(uint32_t raw, uint32_t red)
Set Data counters for reduction calculation.
PXDDAQDHPStatus & newDHP(Args &&... params)
New DHP information.
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask.
auto addCM(PXDDAQDHPComMode &daqcm)
Add Common Mode information.
PXDDAQDHPStatus & dhp_back()
Returns PXDDAQDHPStatus for the last DHP.
void setEndErrorInfo(uint32_t e)
set erroinfo from the DHE END
void setCounters(uint32_t raw, uint32_t red)
Set Data counters for reduction calculation.
void setTruncated(void)
set Truncation
The PXD DAQ Packet Status class.
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask This should be the OR of error masks of all sub-objects (DHC, DHE)
size_t dhc_size() const
Returns number of DHCs.
PXDDAQDHCStatus & dhc_back()
Returns PXDDAQDHCStatus for last DHC.
PXDDAQDHCStatus & newDHC(Args &&... params)
Add new DHC information.
static void map_rc_to_uv_IF_OB(unsigned int &row_u, unsigned int &col_v, const unsigned int dhp_id, const unsigned int dhe_ID)
Maps row/col of inner forward (IF) and outer backward (OB) modules of the PXD to U/V cell.
static void map_rc_to_uv_IB_OF(unsigned int &row_u, unsigned int &col_v, const unsigned int dhp_id, const unsigned int dhe_ID)
Maps row/cols of inner backward (IB) and outer forward (OF) modules of the PXD to U/V cell.
PXDUnpackerOldModule()
Constructor defining the parameters.
std::string m_PXDRawHitsName
The name of the StoreArray of PXDRawHits to be generated.
void initialize() override final
Initialize the module.
unsigned long m_meta_experiment
Experiment from MetaInfo.
PXDError::PXDErrorFlags m_errorMaskEvent
Error Mask set per packet / event.
StoreObjPtr< PXDDAQStatus > m_storeDAQEvtStats
Output array for DAQ Status.
bool m_doNotStore
Only unpack, but Do Not Store anything to file.
StoreArray< RawPXD > m_storeRawPXD
Input array for PXD Raw.
bool m_forceNoMapping
Force No Mapping even if DHH bit is requesting it.
std::string m_PXDDAQEvtStatsName
The name of the StoreObjPtr of PXDDAQStatus to be generated.
static void dump_roi(void *data, unsigned int frame_len)
dump to a file, helper function for debugging.
PXDError::PXDErrorFlags m_suppressErrorMask
Mask for suppressing selected error messages.
bool m_formatBonnDAQ
flag ONSEN or BonnDAQ format
unsigned int m_errorCounter[PXDError::ONSEN_MAX_TYPE_ERR]
Error counters.
StoreArray< PXDRawROIs > m_storeROIs
Output array for Raw ROIs.
unsigned int m_sendunfiltered
counter for send unfiltered
PXDError::PXDErrorFlags m_errorMaskDHC
Error Mask set per packet / DHC.
PXDError::PXDErrorFlags m_errorMaskPacket
Error Mask set per packet / packet.
std::string m_RawPXDsName
The name of the StoreArray of processed RawPXDs.
void unpack_dhp(void *data, unsigned int len, unsigned int dhe_first_readout_frame_lo, unsigned int dhe_ID, unsigned dhe_DHPport, unsigned dhe_reformat, VxdID vxd_id, PXDDAQPacketStatus &daqpktstat)
Unpack DHP data within one DHE frame.
void terminate() override final
Terminate the module.
StoreObjPtr< EventMetaData > m_eventMetaData
Input ptr for EventMetaData.
int m_last_dhp_readout_frame_lo[4]
some workaround check for continouous frame ids
unsigned long m_meta_subrun_nr
Subrun Number from MetaInfo.
void event() override final
do the unpacking
StoreArray< PXDRawAdc > m_storeRawAdc
Output array for Raw Adcs.
unsigned long m_meta_event_nr
Event Number from MetaInfo.
PXDError::PXDErrorFlags m_errorSkipPacketMask
Mask for error which stop package unpacking directly.
static int nr5bits(int i)
helper function to "count" nr of set bits within lower 5 bits.
void unpack_fce(unsigned short *data, unsigned int length, VxdID vxd_id)
Unpack DHP/FCE data within one DHE frame Not fully implemented as cluster format not 100% fixed.
std::string m_PXDRawAdcsName
The name of the StoreArray of PXDRawAdcs to be generated.
unsigned long m_meta_run_nr
Run Number from MetaInfo.
bool m_continueOnError
flag continue unpacking of frames even after error (for debugging)
unsigned int m_notaccepted
counter for not accepted events... should not happen TODO discussion ongoing with DAQ group
unsigned int m_meta_sec
Time(Tag) from MetaInfo, seconds (masked to lower bits)
void unpack_dhp_raw(void *data, unsigned int len, unsigned int dhe_ID, unsigned dhe_DHPport, VxdID vxd_id)
Unpack DHP RAW data within one DHE frame (pedestals, etc)
PXDError::PXDErrorFlags m_criticalErrorMask
Critical error mask which defines return value of task.
unsigned int m_sendrois
counter for send debug rois
static void dump_dhp(void *data, unsigned int frame_len)
dump to a file, helper function for debugging.
void unpack_rawpxd(RawPXD &px, int inx)
Unpack one event (several frames) stored in RawPXD object.
unsigned long long int m_meta_time
Time(Tag) from MetaInfo.
unsigned int m_maxDHPFrameDiff
Maximum DHP frame difference until error is reported.
PXDError::PXDErrorFlags m_errorMask
Error Mask set per packet / frame.
unsigned int m_unpackedEventsCount
Event counter.
StoreArray< PXDRawHit > m_storeRawHits
Output array for Raw Hits.
void unpack_dhc_frame(void *data, const int len, const int Frame_Number, const int Frames_in_event, PXDDAQPacketStatus &daqpktstat)
Unpack one frame (within an event).
bool m_forceMapping
Force Mapping even if DHH bit is not requesting it.
unsigned int m_meta_ticks
Time(Tag) from MetaInfo, Ticks of 127MHz.
bool m_verbose
give verbose unpacking information
PXDError::PXDErrorFlags m_errorMaskDHE
Error Mask set per packet / DHE.
std::string m_PXDRawROIsName
The name of the StoreArray of PXDRawROIs to be generated.
DHC frame wrapper class.
const dhc_ghost_frame * data_ghost_frame
data_ghost_frame
unsigned int getEventNrLo(void) const
get event nr lo (from data)
const dhc_end_frame * data_dhc_end_frame
data_dhc_end_frame
unsigned int getFixedSize(void)
get fixed size
int getFrameType(void)
get type of frame
const dhc_dhe_start_frame * data_dhe_start_frame
data_dhe_start_frame
void set(const void *d, unsigned int t)
set data and type (and length to 0)
const dhc_start_frame * data_dhc_start_frame
data_dhc_start_frame
const dhc_direct_readout_frame * data_direct_readout_frame
data_direct_readout_frame
const dhc_dhe_end_frame * data_dhe_end_frame
data_dhe_end_frame
void check_padding(PXDErrorFlags &errormask)
check padding and return it
const dhc_onsen_roi_frame * data_onsen_roi_frame
data_onsen_roi_frame
const dhc_direct_readout_frame_raw * data_direct_readout_frame_raw
data_direct_readout_frame_raw
const dhc_commode_frame * data_commode_frame
data_commode_frame
void check_crc(PXDErrorFlags &errormask, bool ignore_crc_flag=false)
check crc and return it
const dhc_onsen_trigger_frame * data_onsen_trigger_frame
data_onsen_trigger_frame
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
Class to uniquely identify a any structure of the PXD and SVD.
Definition VxdID.h:32
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
std::tuple< uint8_t, uint16_t, uint8_t > PXDDAQDHPComMode
tuple of Chip ID (2 bit), Row (10 bit), Common Mode (6 bit)
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
boost::endian::big_uint16_t ubig16_t
define alias ubig16_t
boost::endian::big_uint32_t ubig32_t
define alias ubig32_t
Abstract base class for different kinds of events.
STL namespace.
unsigned int getDHEId(void) const
get DHE Id (from word0)
unsigned int get_words(void) const
get words
unsigned int getDHEId(void) const
get DHE Id
unsigned int getErrorInfo(void) const
get error info
unsigned int getDHEId(void) const
get DHE Id (from word0)
unsigned short getEventNrLo(void) const
get trigger_nr_lo
unsigned short getTriggerGate(void) const
trigger gate (updated to 8 bit, before 10!)
unsigned short getStartFrameNr(void) const
last DHP frame before trigger
unsigned short getEventNrHi(void) const
get trigger_nr_hi
unsigned int getActiveDHPMask(void) const
get Active DHP Mask (from word0)
bool getDataReformattedFlag(void) const
get DataReformattedFlag (from word0)
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DHP Port (from word0)
void print(void) const
print
unsigned int get_words(void) const
get words
bool isFakedData(void) const
is faked data
unsigned int get_dhc_id(void) const
get dhc id (from word0)
unsigned int getErrorInfo(void) const
get error info
DHC frame header word data struct.
unsigned short getFrameType(void) const
get type of frame
unsigned short getErrorFlag(void) const
get error flag
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DDHP port (from word0)
unsigned int check_inner_crc(PXDErrorFlags &, unsigned int) const
check inner crc (currently not implemented/needed)
void check_error(PXDErrorFlags &errormask, int length, bool ignore_inv_size_flag=false) const
check error and return error mask
int getMinSize(void) const
4 byte header, ROIS (n*8), 4 byte copy of inner CRC, 4 byte outer CRC
unsigned short get_subrun1(void) const
get subrun1 (from trigtag1)
unsigned int get_trig_nr1(void) const
get trignr1
bool is_SendUnfiltered(void) const
is sendUnfiltered
bool is_SendROIs(void) const
is sendROIs
void check_error(PXDErrorFlags &errormask, bool ignore_datcon_flag=false, bool ignore_hltroi_magic_flag=false, bool ignore_merger_mm_flag=false) const
check error and return error mask
unsigned short get_run2(void) const
get run2 (from trigtag2)
bool is_fake_datcon(void) const
is fake datcon
unsigned short get_experiment1(void) const
get experiment1 (from trigtag1)
unsigned int get_trig_nr2(void) const
get trignr2
unsigned short get_experiment2(void) const
get experiment2
unsigned short get_subrun2(void) const
get subrun2 (from trigtag2)
bool is_Accepted(void) const
is accepted
unsigned short get_run1(void) const
get run1 (from trigtag1)
unsigned short get_gated_isher(void) const
get gated_isher (from word0)
unsigned short get_subrun(void) const
get subrun (from run_subrun)
unsigned short get_run(void) const
get run (from run_subrun)
unsigned short get_dhc_id(void) const
get dhc_id (from word0)
const ubig16_t time_tag_hi
time_tag_hi
const ubig16_t time_tag_mid
time_tag_mid
bool isFakedData(void) const
isFakedData
unsigned short getEventNrLo(void) const
get trigger_nr_lo
unsigned short get_experiment(void) const
get experiment (from exp_run)
unsigned short get_gated_flag(void) const
get gated_flag (from word0)
unsigned short get_active_dhe_mask(void) const
get active_dhe_mask (from word0)
const ubig16_t time_tag_lo_and_type
time_tag_lo_and_type
unsigned short getEventNrHi(void) const
get trigger_nr_hi