9 #include <pxd/unpacking/PXDRawDataDefinitions.h>
10 #include <pxd/unpacking/PXDRawDataStructs.h>
11 #include <pxd/unpacking/PXDMappingLookup.h>
12 #include <pxd/modules/pxdUnpacking/PXDUnpackerModule.h>
13 #include <framework/datastore/DataStore.h>
14 #include <framework/logging/Logger.h>
15 #include <framework/datastore/StoreObjPtr.h>
17 #include <boost/endian/arithmetic.hpp>
22 using namespace Belle2::PXD::PXDError;
44 setDescription(
"Unpack Raw PXD Hits from ONSEN data stream");
45 setPropertyFlags(c_ParallelProcessingCertified);
47 addParam(
"RawPXDsName", m_RawPXDsName,
"The name of the StoreArray of RawPXDs to be processed", std::string(
""));
48 addParam(
"PXDRawHitsName", m_PXDRawHitsName,
"The name of the StoreArray of generated PXDRawHits", std::string(
""));
49 addParam(
"PXDDAQEvtStatsName", m_PXDDAQEvtStatsName,
"The name of the StoreObjPtr of generated PXDDAQEvtStats", std::string(
""));
50 addParam(
"PXDRawAdcsName", m_PXDRawAdcsName,
"The name of the StoreArray of generated PXDRawAdcs", std::string(
""));
51 addParam(
"PXDRawROIsName", m_PXDRawROIsName,
"The name of the StoreArray of generated PXDRawROIs", std::string(
""));
52 addParam(
"DoNotStore", m_doNotStore,
"only unpack and check, but do not store",
false);
58 m_suppressErrorMask = getSilenceMask();
59 addParam(
"ForceMapping", m_forceMapping,
"Force Mapping even if DHH bit is NOT requesting it",
false);
60 addParam(
"ForceNoMapping", m_forceNoMapping,
"Force NO Mapping even if DHH bit is requesting it",
false);
61 addParam(
"CheckPaddingCRC", m_checkPaddingCRC,
"Check for susp. padding (debug option, many false positive)",
false);
62 addParam(
"MaxDHPFrameDiff", m_maxDHPFrameDiff,
"Maximum DHP Frame Nr Difference w/o reporting error", 2u);
63 addParam(
"FormatBonnDAQ", m_formatBonnDAQ,
"ONSEN or BonnDAQ format",
false);
64 addParam(
"Verbose", m_verbose,
"Turn on extra verbosity for log-level debug",
false);
65 addParam(
"ContinueOnError", m_continueOnError,
"Continue package depacking on error (for debugging)",
false);
74 m_errorSkipPacketMask[c_nrDHE_CRC] =
true;
75 m_errorSkipPacketMask[c_nrFIX_SIZE] =
true;
78 void PXDUnpackerModule::initialize()
81 m_eventMetaData.isRequired();
83 m_storeRawPXD.isOptional(m_RawPXDsName);
86 m_storeRawHits.registerInDataStore(m_PXDRawHitsName, DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered);
87 m_storeRawAdc.registerInDataStore(m_PXDRawAdcsName, DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered);
88 m_storeROIs.registerInDataStore(m_PXDRawROIsName, DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered);
89 m_storeDAQEvtStats.registerInDataStore(m_PXDDAQEvtStatsName, DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered);
92 B2DEBUG(29,
"ForceMapping: " << m_forceMapping);
93 B2DEBUG(29,
"ForceNoMapping: " << m_forceNoMapping);
94 B2DEBUG(29,
"CheckPaddingCRC: " << m_checkPaddingCRC);
95 B2DEBUG(29,
"MaxDHPFrameDiff: " << m_maxDHPFrameDiff);
100 m_unpackedEventsCount = 0;
101 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) m_errorCounter[i] = 0;
105 void PXDUnpackerModule::terminate()
108 string errstr =
"Statistic ( ;";
109 errstr += to_string(m_unpackedEventsCount) +
";";
110 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) { errstr += to_string(m_errorCounter[i]) +
";"; flag |= m_errorCounter[i];}
112 B2RESULT(
"PXD Unpacker --> Error Statistics (counted once per event!) in Events: " << m_unpackedEventsCount);
113 B2RESULT(errstr +
" )");
114 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
115 if (m_errorCounter[i]) {
116 B2RESULT(getPXDBitErrorName(i) <<
": " << m_errorCounter[i]);
120 B2RESULT(
"PXD Unpacker --> No Error found in Events: " << m_unpackedEventsCount);
122 B2RESULT(
"Statistic 2: !Accepted: " << m_notaccepted <<
" SendROIs: " << m_sendrois <<
" Unfiltered: " << m_sendunfiltered);
125 void PXDUnpackerModule::event()
127 m_storeDAQEvtStats.create();
130 m_errorMaskEvent = 0;
132 m_meta_event_nr = m_eventMetaData->getEvent();
134 if (!m_storeRawPXD) {
135 m_errorMask[c_nrNO_PXD] =
true;
137 int nRaws = m_storeRawPXD.getEntries();
139 B2DEBUG(29,
"PXD Unpacker --> RawPXD Objects in event: " <<
LogVar(
"Objects", nRaws));
142 m_meta_run_nr = m_eventMetaData->getRun();
143 m_meta_subrun_nr = m_eventMetaData->getSubrun();
144 m_meta_experiment = m_eventMetaData->getExperiment();
145 m_meta_time = m_eventMetaData->getTime();
146 m_meta_ticks = (
unsigned int)std::round((m_meta_time % 1000000000ull) * 0.127216);
147 m_meta_sec = (
unsigned int)(m_meta_time / 1000000000ull) & 0x1FFFF;
150 for (
auto& it : m_storeRawPXD) {
152 B2DEBUG(29,
"PXD Unpacker --> Unpack Objects: ");
154 unpack_rawpxd(it, inx++);
157 if (nRaws == 0) m_errorMask[c_nrNO_PXD] =
true;
159 m_errorMaskEvent |= m_errorMask;
160 m_storeDAQEvtStats->setErrorMask(m_errorMaskEvent);
162 m_unpackedEventsCount++;
164 for (
unsigned int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
165 if (m_errorMaskEvent[i]) m_errorCounter[i]++;
169 if ((PXDErrorFlags(m_criticalErrorMask) & m_errorMaskEvent) != PXDErrorFlags(0)) B2ERROR(
"Error in PXD unpacking" <<
170 LogVar(
"event nr", m_meta_event_nr));
171 setReturnValue(PXDErrorFlags(0) == (PXDErrorFlags(m_criticalErrorMask) & m_errorMaskEvent));
174 void PXDUnpackerModule::unpack_rawpxd(
RawPXD& px,
int inx)
182 m_errorMaskPacket = 0;
185 if (px.
size() <= 0 || px.
size() > 16 * 1024 * 1024) {
186 if (!(m_suppressErrorMask[c_nrPACKET_SIZE])) {
187 B2WARNING(
"PXD Unpacker --> invalid packet size" <<
188 LogVar(
"size [32bit words] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << px.
size()).str()));
190 m_errorMask[c_nrPACKET_SIZE] =
true;
193 std::vector<unsigned int> data(px.
size());
194 fullsize = px.
size() * 4;
195 std::copy_n(px.
data(), px.
size(), data.begin());
198 if (!(m_suppressErrorMask[c_nrPACKET_SIZE])) {
199 B2WARNING(
"Data is to small to hold a valid Header! Will not unpack anything." <<
LogVar(
"size [32bit words] $",
200 static_cast < std::ostringstream &&
>(std::ostringstream() << hex << fullsize).str()));
202 m_errorMask[c_nrPACKET_SIZE] =
true;
206 if (data[0] != 0xCAFEBABE && data[0] != 0xBEBAFECA) {
207 if (!(m_suppressErrorMask[c_nrMAGIC])) {
208 B2WARNING(
"Magic invalid: Will not unpack anything. Header corrupted." <<
209 LogVar(
"Header Magic $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << data[0]).str()));
211 m_errorMask[c_nrMAGIC] =
true;
216 Frames_in_event = ((
ubig32_t*)data.data())[1];
217 if (Frames_in_event < 0 || Frames_in_event > 256) {
218 if (!(m_suppressErrorMask[c_nrFRAME_NR])) {
219 B2WARNING(
"Number of Frames invalid: Will not unpack anything. Header corrupted!" <<
LogVar(
"Frames in event", Frames_in_event));
221 m_errorMask[c_nrFRAME_NR] =
true;
224 if (Frames_in_event < 3) {
225 if (!(m_suppressErrorMask[c_nrNR_FRAMES_TO_SMALL])) {
226 B2WARNING(
"Number of Frames too small: It cannot contain anything useful." <<
LogVar(
"Frames in event", Frames_in_event));
228 m_errorMask[c_nrNR_FRAMES_TO_SMALL] =
true;
233 B2DEBUG(29,
"PXD Unpacker --> data[0]: <-- Magic $" << hex << data[0]);
234 B2DEBUG(29,
"PXD Unpacker --> data[1]: <-- #Frames $" << hex << data[1]);
235 if (data[1] >= 1 && fullsize < 12) B2DEBUG(29,
"PXD Unpacker --> data[2]: <-- Frame 1 len $" << hex << data[2]);
236 if (data[1] >= 2 && fullsize < 16) B2DEBUG(29,
"PXD Unpacker --> data[3]: <-- Frame 2 len $" << hex << data[3]);
237 if (data[1] >= 3 && fullsize < 20) B2DEBUG(29,
"PXD Unpacker --> data[4]: <-- Frame 3 len $" << hex << data[4]);
238 if (data[1] >= 4 && fullsize < 24) B2DEBUG(29,
"PXD Unpacker --> data[5]: <-- Frame 4 len $" << hex << data[5]);
241 unsigned int* tableptr;
244 unsigned int* dataptr;
245 dataptr = &tableptr[Frames_in_event];
246 datafullsize = fullsize - 2 * 4 - Frames_in_event * 4;
249 for (
int j = 0; j < Frames_in_event; j++) {
254 if (!(m_suppressErrorMask[c_nrFRAME_SIZE])) {
255 B2WARNING(
"size of frame invalid");
256 B2DEBUG(29,
"size of frame invalid: " << j <<
"size " << lo <<
" at byte offset in dataptr " << ll);
258 m_errorMask[c_nrFRAME_SIZE] =
true;
261 if (ll + lo > datafullsize) {
262 if (!(m_suppressErrorMask[c_nrFRAME_SIZE])) {
263 B2WARNING(
"Frames exceed packet size");
264 B2DEBUG(29,
"Frames exceed packet size: " << j <<
" size " << lo <<
" at byte offset in dataptr " << ll <<
" of datafullsize " <<
265 datafullsize <<
" of fullsize " << fullsize);
267 m_errorMask[c_nrFRAME_SIZE] =
true;
271 if (!(m_suppressErrorMask[c_nrFRAME_SIZE])) {
272 B2WARNING(
"SKIP Frame with Data with not MOD 4 length");
273 B2DEBUG(29,
"SKIP Frame with Data with not MOD 4 length " <<
" ( $" << hex << lo <<
" ) ");
275 ll += (lo + 3) & 0xFFFFFFFC;
276 m_errorMask[c_nrFRAME_SIZE] =
true;
278 B2DEBUG(29,
"unpack DHE(C) frame: " << j <<
" with size " << lo <<
" at byte offset in dataptr " << ll);
279 unpack_dhc_frame(ll + (
char*)dataptr, lo, j, Frames_in_event, daqpktstat);
282 m_errorMaskDHE |= m_errorMask;
283 m_errorMaskDHC |= m_errorMask;
284 m_errorMaskPacket |= m_errorMask;
285 m_errorMaskEvent |= m_errorMask;
288 if (!m_continueOnError && (m_errorMaskPacket & PXDErrorFlags(m_errorSkipPacketMask)) != PXDErrorFlags(0)) {
299 void PXDUnpackerModule::unpack_dhp_raw(
void* data,
unsigned int frame_len,
unsigned int dhe_ID,
unsigned dhe_DHPport,
313 if (frame_len != 0xC008) {
314 if (!(m_suppressErrorMask[c_nrFIX_SIZE])) B2WARNING(
"Frame size unsupported for RAW ADC frame! $" <<
315 LogVar(
"size [bytes] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << frame_len).str())
316 <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhe_DHPport));
317 m_errorMask[c_nrFIX_SIZE] =
true;
320 unsigned int dhp_header_type = 0;
322 unsigned int dhp_dhe_id = 0;
323 unsigned int dhp_dhp_id = 0;
325 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
327 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
328 dhp_dhp_id = dhp_pix[2] & 0x0003;
330 if (dhe_ID != dhp_dhe_id) {
331 if (!(m_suppressErrorMask[c_nrDHE_DHP_DHEID])) {
332 B2WARNING(
"DHE ID in DHE and DHP header differ");
333 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
335 m_errorMask[c_nrDHE_DHP_DHEID] =
true;
337 if (dhe_DHPport != dhp_dhp_id) {
338 if (!(m_suppressErrorMask[c_nrDHE_DHP_PORT])) {
339 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
340 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
342 m_errorMask[c_nrDHE_DHP_PORT] =
true;
345 if (dhp_header_type != EDHPFrameHeaderDataType::c_RAW) {
346 if (!(m_suppressErrorMask[c_nrHEADERTYPE_INV])) {
347 B2WARNING(
"Header type invalid for this kind of DHE frame");
348 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
350 m_errorMask[c_nrHEADERTYPE_INV] =
true;
355 B2DEBUG(29,
"Raw ADC Data");
357 m_storeRawAdc.appendNew(vxd_id, data, frame_len);
360 void PXDUnpackerModule::unpack_fce([[maybe_unused]]
unsigned short* data, [[maybe_unused]]
unsigned int length,
361 [[maybe_unused]]
VxdID vxd_id)
370 B2WARNING(
"FCE (Cluster) Packet have not yet been tested with real HW clusters. Dont assume that this code is working!");
405 void PXDUnpackerModule::dump_dhp(
void* data,
unsigned int frame_len)
408 unsigned int w = frame_len / 2;
411 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- ");
413 auto dhp_header_type = (d[2] & 0xE000) >> 13;
414 auto dhp_reserved = (d[2] & 0x1F00) >> 8;
415 auto dhp_dhe_id = (d[2] & 0x00FC) >> 2;
416 auto dhp_dhp_id = d[2] & 0x0003;
418 B2WARNING(
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
419 B2WARNING(
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
420 B2WARNING(
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
421 B2WARNING(
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
422 for (
unsigned int i = 4; i < w; i++) {
423 B2WARNING(
"DHP DATA $" << hex << d[i]);
425 B2WARNING(
"DHP CRC $" << hex << d[w] <<
",$" << hex << d[w + 1]);
428 void PXDUnpackerModule::dump_roi(
void* data,
unsigned int frame_len)
431 unsigned int w = frame_len / 4;
434 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- Len $" << hex
437 for (
unsigned int i = 0; i < w; i++) {
438 B2WARNING(
"ROI DATA $" << hex << d[i]);
440 B2WARNING(
"ROI CRC $" << hex << d[w]);
443 void PXDUnpackerModule::unpack_dhp(
void* data,
unsigned int frame_len,
unsigned int dhe_first_readout_frame_id_lo,
444 unsigned int dhe_ID,
unsigned dhe_DHPport,
unsigned dhe_reformat,
VxdID vxd_id,
447 unsigned int nr_words = frame_len / 2;
450 unsigned int dhp_readout_frame_lo = 0;
451 unsigned int dhp_header_type = 0;
452 unsigned int dhp_reserved = 0;
453 unsigned int dhp_dhe_id = 0;
454 unsigned int dhp_dhp_id = 0;
457 unsigned int dhp_row = 0, dhp_col = 0, dhp_adc = 0, dhp_cm = 0;
459 bool rowflag =
false;
460 bool pixelflag =
true;
463 if (!(m_suppressErrorMask[c_nrDHP_SIZE])) B2WARNING(
"DHP frame size error (too small)" <<
LogVar(
"Nr words", nr_words));
464 m_errorMask[c_nrDHP_SIZE] =
true;
468 B2DEBUG(29,
"HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] <<
" -- ");
470 B2DEBUG(29,
"DHP Header | $" << hex << dhp_pix[2] <<
" ( " << dec << dhp_pix[2] <<
" ) ");
471 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
472 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
473 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
474 dhp_dhp_id = dhp_pix[2] & 0x0003;
476 B2DEBUG(29,
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
477 B2DEBUG(29,
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
478 B2DEBUG(29,
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
479 B2DEBUG(29,
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
481 if (dhe_ID != dhp_dhe_id) {
482 if (!(m_suppressErrorMask[c_nrDHE_DHP_DHEID])) {
483 B2WARNING(
"DHE ID in DHE and DHP header differ");
484 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
486 m_errorMask[c_nrDHE_DHP_DHEID] =
true;
488 if (dhe_DHPport != dhp_dhp_id) {
489 if (!(m_suppressErrorMask[c_nrDHE_DHP_PORT])) {
490 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
491 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
493 m_errorMask[c_nrDHE_DHP_PORT] =
true;
496 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
497 if (!(m_suppressErrorMask[c_nrHEADERTYPE_INV])) {
498 B2WARNING(
"Header type invalid for this kind of DHE frame");
499 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
501 m_errorMask[c_nrHEADERTYPE_INV] =
true;
508 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
509 B2DEBUG(29,
"DHP Frame Nr | $" << hex << dhp_readout_frame_lo <<
" ( " << dec << dhp_readout_frame_lo <<
" ) ");
551 m_last_dhp_readout_frame_lo[dhp_dhp_id] = dhp_readout_frame_lo;
554 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
556 if (!(m_suppressErrorMask[c_nrDHP_DBL_HEADER])) {
557 B2WARNING(
"DHP data: seems to be double header! skipping.");
558 B2DEBUG(29,
"DHP data: seems to be double header! skipping." <<
LogVar(
"Length",
561 m_errorMask[c_nrDHP_DBL_HEADER] =
true;
567 for (
unsigned int i = 4; i < nr_words ; i++) {
569 B2DEBUG(29,
"-- $" << hex << dhp_pix[i] <<
" -- " << dec << i);
571 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
574 if (!(m_suppressErrorMask[c_nrDHP_ROW_WO_PIX])) B2WARNING(
"DHP Unpacking: Row w/o Pix");
575 m_errorMask[c_nrDHP_ROW_WO_PIX] =
true;
578 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
579 dhp_cm = dhp_pix[i] & 0x3F;
581 B2WARNING(
"DHP data loss (CM=63) in " <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhp_dhp_id));
583 m_errorMask[c_nrDHH_MISC_ERROR] =
true;
594 B2DEBUG(29,
"SetRow: $" << hex << dhp_row <<
" CM $" << hex << dhp_cm);
597 if (!(m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING(
"DHP Unpacking: Pix without Row!!! skip dhp data ");
598 m_errorMask[c_nrDHP_PIX_WO_ROW] =
true;
603 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
604 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
605 unsigned int v_cellID, u_cellID;
607 if (dhp_row >= 768) {
608 if (!(m_suppressErrorMask[c_nrROW_OVERFLOW])) B2WARNING(
"DHP ROW Overflow " <<
LogVar(
"Row", dhp_row));
609 m_errorMask[c_nrROW_OVERFLOW] =
true;
613 if ((dhe_reformat == 0 && !m_forceNoMapping) || m_forceMapping) {
616 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
618 PXDMappingLookup::map_rc_to_uv_IF_OB(v_cellID, u_cellID, dhp_dhp_id, dhe_ID);
620 PXDMappingLookup::map_rc_to_uv_IB_OF(v_cellID, u_cellID, dhp_dhp_id, dhe_ID);
623 u_cellID = dhp_col + 64 * dhp_dhp_id;
625 if (u_cellID >= 250) {
626 if (!(m_suppressErrorMask[c_nrCOL_OVERFLOW])) {
627 B2WARNING(
"DHP COL Overflow (unconnected drain lines)");
628 B2DEBUG(29,
"DHP COL Overflow (unconnected drain lines) " << u_cellID <<
", reformat " << dhe_reformat <<
", dhpcol " << dhp_col <<
629 ", id " << dhp_dhp_id);
631 m_errorMask[c_nrCOL_OVERFLOW] =
true;
633 dhp_adc = dhp_pix[i] & 0xFF;
634 B2DEBUG(29,
"SetPix: Row $" << hex << dhp_row <<
" Col $" << hex << dhp_col <<
" ADC $" << hex << dhp_adc
635 <<
" CM $" << hex << dhp_cm);
639 B2WARNING(
"DHE Event truncation in DHE " << dhe_ID <<
" DHP " << dhp_dhp_id);
643 if (!m_doNotStore) m_storeRawHits.appendNew(vxd_id, v_cellID, u_cellID, dhp_adc,
644 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) & 0x3F);
651 B2DEBUG(29,
"(DHE) DHE_ID $" << hex << dhe_ID <<
" (DHE) DHP ID $" << hex << dhe_DHPport <<
" (DHP) DHE_ID $" << hex << dhp_dhe_id
652 <<
" (DHP) DHP ID $" << hex << dhp_dhp_id);
662 void PXDUnpackerModule::unpack_dhc_frame(
void* data,
const int len,
const int Frame_Number,
const int Frames_in_event,
668 static unsigned int eventNrOfOnsenTrgFrame = 0;
669 static int countedBytesInDHC = 0;
670 static bool cancheck_countedBytesInDHC =
false;
671 static int countedBytesInDHE = 0;
672 static bool cancheck_countedBytesInDHE =
false;
673 static int countedDHEStartFrames = 0;
674 static int countedDHEEndFrames = 0;
675 static int mask_active_dhe = 0;
676 static int nr_active_dhe =
678 static int mask_active_dhp = 0;
679 static int found_mask_active_dhp = 0;
680 static unsigned int dhe_first_readout_frame_id_lo = 0;
682 static unsigned int dhe_first_triggergate = 0;
683 static unsigned int currentDHCID = 0xFFFFFFFF;
684 static unsigned int currentDHEID = 0xFFFFFFFF;
685 static unsigned int currentVxdId = 0;
686 static bool isFakedData_event =
false;
687 static bool isUnfiltered_event =
false;
690 if (Frame_Number == 0) {
693 eventNrOfOnsenTrgFrame = 0;
694 countedDHEStartFrames = 0;
695 countedDHEEndFrames = 0;
696 countedBytesInDHC = 0;
697 cancheck_countedBytesInDHC =
false;
698 countedBytesInDHE = 0;
699 cancheck_countedBytesInDHE =
false;
700 currentDHCID = 0xFFFFFFFF;
701 currentDHEID = 0xFFFFFFFF;
703 isUnfiltered_event =
false;
704 isFakedData_event =
false;
708 found_mask_active_dhp = 0;
721 if (len != s && s != 0) {
722 if (!(m_suppressErrorMask[c_nrFIX_SIZE])) {
723 B2WARNING(
"Fixed frame type size does not match specs" <<
LogVar(
"expected length",
724 len) <<
LogVar(
"length in data", s));
726 m_errorMask[c_nrFIX_SIZE] =
true;
727 if (!m_continueOnError)
return;
733 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
734 if (!m_continueOnError && m_errorMask[c_nrDHE_CRC]) {
742 if (Frame_Number == 0) {
743 if (m_formatBonnDAQ) {
744 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
745 if (!(m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"This looks not like BonnDAQ format.");
746 m_errorMask[c_nrEVENT_STRUCT] =
true;
750 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
751 if (!(m_suppressErrorMask[c_nrEVENT_STRUCT]))
752 B2WARNING(
"This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
753 m_errorMask[c_nrEVENT_STRUCT] =
true;
759 if (!m_formatBonnDAQ) {
760 if (Frame_Number == 1) {
761 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
768 if ((eventNrOfThisFrame & 0xFFFF) != (m_meta_event_nr & 0xFFFF)) {
769 if (!isFakedData_event) {
770 if (!(m_suppressErrorMask[c_nrMETA_MM])) {
771 B2WARNING(
"Event Numbers do not match for this frame");
772 B2DEBUG(29,
"Event Numbers do not match for this frame" <<
773 LogVar(
"Event nr in frame $",
static_cast < std::ostringstream
774 &&
>(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
775 LogVar(
"Event nr in MetaInfo (bits masked) $",
776 static_cast < std::ostringstream &&
>(std::ostringstream() << hex << m_meta_event_nr).str()));
778 m_errorMask[c_nrMETA_MM] =
true;
783 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
784 if (countedDHEStartFrames != countedDHEEndFrames + 1)
785 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
786 if (!(m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING(
"Data Frame outside a DHE START/END");
787 m_errorMask[c_nrDATA_OUTSIDE] =
true;
797 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
798 if (!(m_suppressErrorMask[c_nrHEADER_ERR])) B2ERROR(
"Error Bit set in DHE Header");
799 m_errorMask[c_nrHEADER_ERR] =
true;
802 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
803 m_errorMask[c_nrHEADER_ERR_GHOST] =
true;
807 switch (frame_type) {
808 case EDHCFrameHeaderDataType::c_DHP_RAW: {
812 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
813 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
814 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
815 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
817 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
819 m_errorMask[c_nrDHE_START_ID] =
true;
821 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
824 unpack_dhp_raw(data, len - 4,
831 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
833 cancheck_countedBytesInDHC =
false;
834 cancheck_countedBytesInDHE =
false;
836 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
839 if (isUnfiltered_event) {
840 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP) m_errorMask[c_nrSENDALL_TYPE] =
true;
842 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD) m_errorMask[c_nrNOTSENDALL_TYPE] =
true;
848 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
849 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
850 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
851 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
853 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
855 m_errorMask[c_nrDHE_START_ID] =
true;
857 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
862 unpack_dhp(data, len - 4,
863 dhe_first_readout_frame_id_lo,
867 currentVxdId, daqpktstat);
871 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
873 cancheck_countedBytesInDHC =
false;
874 cancheck_countedBytesInDHE =
false;
876 case EDHCFrameHeaderDataType::c_FCE_RAW: {
877 if (!(m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (Clustering FCE)");
878 m_errorMask[c_nrUNEXPECTED_FRAME_TYPE] =
true;
879 if (m_verbose) hw->
print();
880 if (isUnfiltered_event) {
881 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
883 m_errorMask[c_nrSENDALL_TYPE] =
true;
886 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
888 m_errorMask[c_nrNOTSENDALL_TYPE] =
true;
893 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
894 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
895 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
896 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
898 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
900 m_errorMask[c_nrDHE_START_ID] =
true;
902 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
905 B2DEBUG(29,
"UNPACK FCE FRAME with len $" << hex << len);
906 unpack_fce((
unsigned short*) data, len - 4, currentVxdId);
910 case EDHCFrameHeaderDataType::c_COMMODE: {
913 if (!(m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (COMMODE)");
914 m_errorMask[c_nrUNEXPECTED_FRAME_TYPE] =
true;
916 if (m_verbose) hw->
print();
918 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
919 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
920 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
921 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
923 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
925 m_errorMask[c_nrDHE_START_ID] =
true;
927 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
930 case EDHCFrameHeaderDataType::c_DHC_START: {
931 countedBytesInDHC = 0;
932 cancheck_countedBytesInDHC =
true;
934 if (!(m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC START mixed Fake/no Fake event.");
935 m_errorMask[c_nrFAKE_NO_FAKE_DATA] =
true;
938 if (!(m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC START Data -> trigger without Data!");
939 m_errorMask[c_nrFAKE_NO_DATA_TRIG] =
true;
945 currentDHEID = 0xFFFFFFFF;
948 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
950 if (m_formatBonnDAQ) eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
952 if (!isFakedData_event) {
956 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_ERS])) {
957 B2WARNING(
"DHC-Meta Experiment number mismatch");
958 B2DEBUG(29,
"DHC-Meta Experiment number mismatch" <<
961 LogVar(
"META exp nr" , m_meta_experiment));
963 m_errorMask[c_nrMETA_MM_DHC_ERS] =
true;
966 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_ERS])) {
967 B2WARNING(
"DHC-Meta Run number mismatch");
968 B2DEBUG(29,
"DHC-Meta Run number mismatch" <<
971 LogVar(
"META run nr", m_meta_run_nr));
973 m_errorMask[c_nrMETA_MM_DHC_ERS] =
true;
976 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_ERS])) {
977 B2WARNING(
"DHC-Meta Sub-Run number mismatch");
978 B2DEBUG(29,
"DHC-Meta Sub-Run number mismatch" <<
981 LogVar(
"META subrun nr", m_meta_subrun_nr));
983 m_errorMask[c_nrMETA_MM_DHC_ERS] =
true;
986 (m_meta_event_nr & 0xFFFFFFFF)) {
987 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC])) {
988 B2WARNING(
"DHC-Meta 32 bit event number mismatch");
989 B2DEBUG(29,
"DHC-Meta 32 bit event number mismatch" <<
992 LogVar(
"META trigger nr" , (
unsigned int)(m_meta_event_nr & 0xFFFFFFFF)));
994 m_errorMask[c_nrMETA_MM_DHC] =
true;
1001 if ((trig_ticks - m_meta_ticks) != 0 || (trig_sec - m_meta_sec) != 0) {
1002 m_errorMask[c_nrMETA_MM_DHC_TT] =
true;
1003 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_TT])) {
1004 B2WARNING(
"DHC-Meta TimeTag mismatch");
1005 B2DEBUG(29,
"DHC-Meta TimeTag mismatch" <<
1006 LogVar(
"Header Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() <<
1010 LogVar(
"Meta Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << m_meta_time).str()) <<
1011 LogVar(
"Trigger Type",
static_cast < std::ostringstream
1013 LogVar(
"Meta seconds: $" ,
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << m_meta_sec).str()) <<
1014 LogVar(
"DHC seconds $" ,
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_sec).str()) <<
1015 LogVar(
"Seconds difference $" ,
static_cast < std::ostringstream
1016 &&
>(std::ostringstream() << hex << (trig_sec - m_meta_sec)).str()) <<
1017 LogVar(
"Meta ticks from 127MHz $" ,
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << m_meta_ticks).str()) <<
1018 LogVar(
"DHC ticks from 127MHz $" ,
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_ticks).str()) <<
1019 LogVar(
"Tick difference $" ,
static_cast < std::ostringstream
1020 &&
>(std::ostringstream() << hex << (trig_ticks - m_meta_ticks)).str()));
1029 nr_active_dhe = nr5bits(mask_active_dhe);
1031 m_errorMaskDHC = m_errorMask;
1032 daqpktstat.
newDHC(currentDHCID, m_errorMask);
1038 case EDHCFrameHeaderDataType::c_DHE_START: {
1039 countedBytesInDHE = 0;
1040 cancheck_countedBytesInDHE =
true;
1041 m_last_dhp_readout_frame_lo[0] = -1;
1042 m_last_dhp_readout_frame_lo[1] = -1;
1043 m_last_dhp_readout_frame_lo[2] = -1;
1044 m_last_dhp_readout_frame_lo[3] = -1;
1049 if (!(m_suppressErrorMask[c_nrDHE_WRONG_ID_SEQ])) {
1050 B2WARNING(
"DHH IDs are not in expected order");
1051 B2DEBUG(29,
"DHH IDs are not in expected order" <<
1052 LogVar(
"Previous ID", (currentDHEID & 0xFFFF)) <<
1055 m_errorMask[c_nrDHE_WRONG_ID_SEQ] =
true;
1058 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1060 if (countedDHEStartFrames > countedDHEEndFrames) {
1061 if (!(m_suppressErrorMask[c_nrDHE_START_WO_END])) B2WARNING(
"DHE_START without DHE_END");
1062 m_errorMask[c_nrDHE_START_WO_END] =
true;
1064 countedDHEStartFrames++;
1066 found_mask_active_dhp = 0;
1070 m_meta_event_nr & 0xFFFFFFFF)) {
1071 if (!(m_suppressErrorMask[c_nrMETA_MM_DHE])) {
1072 B2WARNING(
"DHE START trigger mismatch in EVT32b/HI WORD");
1073 B2DEBUG(29,
"DHE START trigger mismatch in EVT32b/HI WORD" <<
1075 LogVar(
"Meta trigger nr", (m_meta_event_nr & 0xFFFFFFFF)));
1077 m_errorMask[c_nrMETA_MM_DHE] =
true;
1082 if (currentDHEID == 0) {
1083 if (!(m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING(
"DHE ID is invalid=0 (not initialized)");
1084 m_errorMask[c_nrDHE_ID_INVALID] =
true;
1094 unsigned short sensor, ladder, layer;
1095 sensor = (currentDHEID & 0x1) + 1;
1096 ladder = (currentDHEID & 0x1E) >> 1;
1097 layer = ((currentDHEID & 0x20) >> 5) + 1;
1098 currentVxdId =
VxdID(layer, ladder, sensor);
1099 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
1100 if (!(m_suppressErrorMask[c_nrDHE_ID_INVALID])) {
1101 B2WARNING(
"DHE ID is invalid");
1102 B2DEBUG(29,
"DHE ID is invalid" <<
1103 LogVar(
"DHE ID", currentDHEID) <<
1104 LogVar(
"Layer", layer) <<
1105 LogVar(
"Ladder", ladder) <<
1106 LogVar(
"Sensor", sensor));
1108 m_errorMask[c_nrDHE_ID_INVALID] =
true;
1112 m_errorMaskDHE = m_errorMask;
1115 daqpktstat.
dhc_back().
newDHE(currentVxdId, currentDHEID, m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
1119 case EDHCFrameHeaderDataType::c_GHOST:
1122 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
1123 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1126 m_errorMask[c_nrDHE_START_ID] =
true;
1131 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1134 case EDHCFrameHeaderDataType::c_DHC_END: {
1136 if (!(m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC END mixed Fake/no Fake event.");
1137 m_errorMask[c_nrFAKE_NO_FAKE_DATA] =
true;
1140 if (!(m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC END Data -> trigger without Data!");
1141 m_errorMask[c_nrFAKE_NO_DATA_TRIG] =
true;
1146 if (!isFakedData_event) {
1148 if (!(m_suppressErrorMask[c_nrDHC_DHCID_START_END_MM])) {
1149 B2WARNING(
"DHC ID Mismatch between Start and End");
1150 B2DEBUG(29,
"DHC ID Mismatch between Start and End $" << std::hex <<
1153 m_errorMask[c_nrDHC_DHCID_START_END_MM] =
true;
1157 if (cancheck_countedBytesInDHC) {
1158 if (countedBytesInDHC != w) {
1159 if (!(m_suppressErrorMask[c_nrDHC_WIE])) {
1160 B2WARNING(
"Number of Words in DHC END does not match");
1161 B2DEBUG(29,
"Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC <<
" != DHC END $" << hex << w);
1163 m_errorMask[c_nrDHC_WIE] =
true;
1166 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHC <<
" == DHC END $" << hex << w);
1173 if (!(m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHC END Error Info set to $" << hex <<
1175 m_errorMask[c_nrDHH_END_ERRORBITS] =
true;
1177 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1178 m_errorMaskDHC |= m_errorMask;
1190 currentDHEID = 0xFFFFFFFF;
1191 currentDHCID = 0xFFFFFFFF;
1195 case EDHCFrameHeaderDataType::c_DHE_END: {
1198 if (!(m_suppressErrorMask[c_nrDHE_START_END_ID])) {
1199 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1200 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID <<
" != $" <<
1203 m_errorMask[c_nrDHE_START_END_ID] =
true;
1207 if (!(m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) {
1208 B2ERROR(
"DHE END Error Info set to $" << hex <<
1211 m_errorMask[c_nrDHH_END_ERRORBITS] =
true;
1213 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1214 if (found_mask_active_dhp != mask_active_dhp) {
1215 if (!(m_suppressErrorMask[c_nrDHP_ACTIVE])) {
1216 B2WARNING(
"DHE_END: DHP active mask differs from found data");
1217 B2DEBUG(29,
"DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp <<
" != $" << hex <<
1218 found_mask_active_dhp
1219 <<
" mask of found dhp/ghost frames");
1221 m_errorMask[c_nrDHP_ACTIVE] =
true;
1223 countedDHEEndFrames++;
1224 if (countedDHEStartFrames < countedDHEEndFrames) {
1226 if (!(m_suppressErrorMask[c_nrDHE_END_WO_START])) B2WARNING(
"DHE_END without DHE_START");
1227 m_errorMask[c_nrDHE_END_WO_START] =
true;
1232 if (cancheck_countedBytesInDHE) {
1233 if (countedBytesInDHE != w) {
1234 if (!(m_suppressErrorMask[c_nrDHE_WIE])) {
1235 B2WARNING(
"Number of Words in DHE END does not match");
1236 B2DEBUG(29,
"Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE <<
" != DHE END $" << hex << w);
1238 m_errorMask[c_nrDHE_WIE] =
true;
1241 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHE <<
" == DHE END $" << hex << w);
1246 m_errorMaskDHE |= m_errorMask;
1260 currentDHEID |= 0xFF000000;
1264 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
1269 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1270 if (!m_doNotStore) {
1282 m_storeROIs.appendNew(l, &((
unsigned int*) data)[1]);
1286 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
1287 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
1289 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_HLT])) {
1290 B2WARNING(
"Trigger Frame HLT Trigger Nr mismatch");
1291 B2DEBUG(29,
"Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
1294 m_errorMask[c_nrMETA_MM_ONS_HLT] =
true;
1299 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_HLT])) {
1300 B2WARNING(
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
1301 B2DEBUG(29,
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
1306 m_errorMask[c_nrMETA_MM_ONS_HLT] =
true;
1311 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_DC])) {
1312 B2WARNING(
"Trigger Frame DATCON Trigger Nr mismatch");
1313 B2DEBUG(29,
"Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
1316 m_errorMask[c_nrMETA_MM_ONS_DC] =
true;
1321 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_DC])) {
1322 B2WARNING(
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
1323 B2DEBUG(29,
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
1328 m_errorMask[c_nrMETA_MM_ONS_DC] =
true;
1336 m_suppressErrorMask[c_nrHLTROI_MAGIC],
1337 m_suppressErrorMask[c_nrMERGER_TRIGNR]);
1338 dhc.
check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1339 if (Frame_Number != 0) {
1340 if (!(m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"ONSEN TRG Frame must be the first one.");
1341 m_errorMask[c_nrEVENT_STRUCT] =
true;
1344 if (isUnfiltered_event) m_sendunfiltered++;
1349 if (!(m_suppressErrorMask[c_nrDHC_UNKNOWN])) B2WARNING(
"UNKNOWN DHC frame type");
1350 m_errorMask[c_nrDHC_UNKNOWN] =
true;
1351 if (m_verbose) hw->
print();
1355 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
1356 if (!(m_suppressErrorMask[c_nrFRAME_TNR_MM])) {
1357 B2WARNING(
"Frame TrigNr != ONSEN Trig Nr");
1358 B2DEBUG(29,
"Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame <<
" != $" << eventNrOfOnsenTrgFrame);
1360 m_errorMask[c_nrFRAME_TNR_MM] =
true;
1363 if (Frame_Number == 0) {
1365 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1366 if (!m_formatBonnDAQ) {
1367 if (!(m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"First frame is not a ONSEN Trigger frame");
1368 m_errorMask[c_nrONSEN_TRG_FIRST] =
true;
1373 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1374 if (!(m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"More than one ONSEN Trigger frame");
1375 m_errorMask[c_nrONSEN_TRG_FIRST] =
true;
1379 if (!m_formatBonnDAQ) {
1380 if (Frame_Number == 1) {
1382 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1383 if (!(m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"Second frame is not a DHC start of subevent frame");
1384 m_errorMask[c_nrDHC_START_SECOND] =
true;
1388 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1389 if (!(m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"More than one DHC start of subevent frame");
1390 m_errorMask[c_nrDHC_START_SECOND] =
true;
1395 if (Frame_Number == Frames_in_event - 1) {
1397 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
1398 if (!(m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING(
"Last frame is not a DHC end of subevent frame");
1399 m_errorMask[c_nrDHC_END_MISS] =
true;
1403 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
1404 if (!(m_suppressErrorMask[c_nrDHE_ACTIVE]) || !(m_suppressErrorMask[c_nrDHE_START_WO_END])
1405 || !(m_suppressErrorMask[c_nrDHE_END_WO_START])) {
1406 B2WARNING(
"The number of DHE Start/End does not match the number of active DHE in DHC Header!");
1407 B2DEBUG(29,
"The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
1408 " Start: " << countedDHEStartFrames <<
" End: " << countedDHEEndFrames <<
" Mask: $" << hex << mask_active_dhe <<
" in Event Nr " <<
1409 eventNrOfThisFrame);
1411 if (countedDHEStartFrames == countedDHEEndFrames) m_errorMask[c_nrDHE_ACTIVE] =
true;
1412 if (countedDHEStartFrames > countedDHEEndFrames) m_errorMask[c_nrDHE_START_WO_END] =
true;
1413 if (countedDHEStartFrames < countedDHEEndFrames) m_errorMask[c_nrDHE_END_WO_START] =
true;
1418 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
1419 if (!(m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING(
"More than one DHC end of subevent frame");
1420 m_errorMask[c_nrDHC_END_DBL] =
true;
1424 if (!m_formatBonnDAQ) {
1426 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1427 if (!(m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING(
"Third frame is not a DHE start frame");
1428 m_errorMask[c_nrDHE_START_THIRD] =
true;
1432 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1434 countedBytesInDHC += len;
1435 countedBytesInDHE += len;
1437 B2DEBUG(29,
"DHC/DHE $" << hex << countedBytesInDHC <<
", $" << hex << countedBytesInDHE);
1440 int PXDUnpackerModule::nr5bits(
int i)
1443 const int lut[32] = {
1444 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1445 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5
1447 return lut[i & 0x1F];
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask This should be the OR of error masks of all sub-objects (DHC, DHE)
PXDDAQDHEStatus & dhe_back()
Returns PXDDAQDHEStatus for last 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
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.
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask.
PXDDAQDHPStatus & dhp_back()
Returns PXDDAQDHPStatus for the last DHP.
auto addCM(PXDDAQDHPComMode &daqcm)
Add Common Mode information.
void setEndErrorInfo(uint32_t e)
set erroinfo from the DHE END
PXDDAQDHPStatus & newDHP(Args &&... params)
New DHP information.
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)
PXDDAQDHCStatus & newDHC(Args &&... params)
Add new DHC information.
size_t dhc_size() const
Returns number of DHCs.
PXDDAQDHCStatus & dhc_back()
Returns PXDDAQDHCStatus for last DHC.
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
virtual int * data(void)
get pointer to data
virtual int size() const
get size of buffer in 32 Bit words
Class to uniquely identify a any structure of the PXD and SVD.
Class to store variables with their name which were sent to the logging service.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
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_uint32_t ubig32_t
define alias ubig32_t
boost::endian::big_uint16_t ubig16_t
define alias ubig16_t
Abstract base class for different kinds of events.
unsigned int getDHEId(void) const
get DHE Id (from word0)
void print(void) const
print
unsigned int get_words(void) const
get words
unsigned int getDHEId(void) const
get DHE Id
unsigned int getErrorInfo(void) const
get error info
void print(void) const
print
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)
void print(void) const
print
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
void print(void) const
print
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DDHP port (from word0)
void print(void) const
print
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
void print(void) const
print
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)
void print(void) const
print
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