11 #include <pxd/unpacking/PXDRawDataDefinitions.h>
12 #include <pxd/unpacking/PXDRawDataStructs.h>
13 #include <pxd/unpacking/PXDMappingLookup.h>
14 #include <pxd/modules/pxdUnpacking/PXDUnpackerOTModule.h>
15 #include <framework/datastore/DataStore.h>
16 #include <framework/logging/Logger.h>
17 #include <framework/datastore/StoreObjPtr.h>
19 #include <boost/spirit/home/support/detail/endian.hpp>
24 using namespace Belle2::PXD::PXDError;
26 using namespace boost::spirit::endian;
47 setDescription(
"Unpack Raw PXD Hits from ONSEN data stream");
48 setPropertyFlags(c_ParallelProcessingCertified);
50 addParam(
"RawPXDsName", m_RawPXDsName,
"The name of the StoreArray of RawPXDs to be processed", std::string(
""));
51 addParam(
"PXDRawHitsName", m_PXDRawHitsName,
"The name of the StoreArray of generated PXDRawHits", std::string(
""));
52 addParam(
"PXDDAQEvtStatsName", m_PXDDAQEvtStatsName,
"The name of the StoreObjPtr of generated PXDDAQEvtStats", std::string(
""));
53 addParam(
"PXDRawAdcsName", m_PXDRawAdcsName,
"The name of the StoreArray of generated PXDRawAdcs", std::string(
""));
54 addParam(
"PXDRawROIsName", m_PXDRawROIsName,
"The name of the StoreArray of generated PXDRawROIs", std::string(
""));
55 addParam(
"DoNotStore", m_doNotStore,
"only unpack and check, but do not store",
false);
56 addParam(
"CriticalErrorMask", m_criticalErrorMask,
"Set error mask which stops processing by returning false by task", (uint64_t)0);
57 addParam(
"SuppressErrorMask", m_suppressErrorMask,
"Set mask for errors msgs which are not printed", (uint64_t)getSilenceMask());
58 addParam(
"ForceMapping", m_forceMapping,
"Force Mapping even if DHH bit is NOT requesting it",
false);
59 addParam(
"ForceNoMapping", m_forceNoMapping,
"Force NO Mapping even if DHH bit is requesting it",
false);
60 addParam(
"CheckPaddingCRC", m_checkPaddingCRC,
"Check for susp. padding (debug option, many false positive)",
false);
61 addParam(
"MaxDHPFrameDiff", m_maxDHPFrameDiff,
"Maximum DHP Frame Nr Difference w/o reporting error", 2u);
62 addParam(
"FormatBonnDAQ", m_formatBonnDAQ,
"ONSEN or BonnDAQ format",
false);
63 addParam(
"Verbose", m_verbose,
"Turn on extra verbosity for log-level debug",
false);
64 addParam(
"ContinueOnError", m_continueOnError,
"Continue package depacking on error (for debugging)",
false);
73 m_errorSkipPacketMask = c_DHE_CRC | c_FIX_SIZE;
76 void PXDUnpackerOTModule::initialize()
79 m_eventMetaData.isRequired();
81 m_storeRawPXD.isOptional(m_RawPXDsName);
84 m_storeRawHits.registerInDataStore(m_PXDRawHitsName, DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered);
85 m_storeRawAdc.registerInDataStore(m_PXDRawAdcsName, DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered);
86 m_storeROIs.registerInDataStore(m_PXDRawROIsName, DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered);
87 m_storeDAQEvtStats.registerInDataStore(m_PXDDAQEvtStatsName, DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered);
90 B2DEBUG(29,
"ForceMapping: " << m_forceMapping);
91 B2DEBUG(29,
"ForceNoMapping: " << m_forceNoMapping);
92 B2DEBUG(29,
"CheckPaddingCRC: " << m_checkPaddingCRC);
93 B2DEBUG(29,
"MaxDHPFrameDiff: " << m_maxDHPFrameDiff);
98 m_unpackedEventsCount = 0;
99 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) m_errorCounter[i] = 0;
103 void PXDUnpackerOTModule::terminate()
106 string errstr =
"Statistic ( ;";
107 errstr += to_string(m_unpackedEventsCount) +
";";
108 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) { errstr += to_string(m_errorCounter[i]) +
";"; flag |= m_errorCounter[i];}
110 B2RESULT(
"PXD Unpacker --> Error Statistics (counted once per event!) in Events: " << m_unpackedEventsCount);
111 B2RESULT(errstr +
" )");
112 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
113 if (m_errorCounter[i]) {
114 B2RESULT(getPXDBitErrorName(i) <<
": " << m_errorCounter[i]);
118 B2RESULT(
"PXD Unpacker --> No Error found in Events: " << m_unpackedEventsCount);
120 B2RESULT(
"Statistic 2: !Accepted: " << m_notaccepted <<
" SendROIs: " << m_sendrois <<
" Unfiltered: " << m_sendunfiltered);
123 void PXDUnpackerOTModule::event()
125 m_storeDAQEvtStats.create(c_NO_ERROR);
128 m_errorMaskEvent = 0;
130 m_meta_event_nr = m_eventMetaData->getEvent();
132 if (!m_storeRawPXD) {
133 m_errorMask |= c_NO_PXD;
135 int nRaws = m_storeRawPXD.getEntries();
137 B2DEBUG(29,
"PXD Unpacker --> RawPXD Objects in event: " <<
LogVar(
"Objects", nRaws));
140 m_meta_run_nr = m_eventMetaData->getRun();
141 m_meta_subrun_nr = m_eventMetaData->getSubrun();
142 m_meta_experiment = m_eventMetaData->getExperiment();
143 m_meta_time = m_eventMetaData->getTime();
144 m_meta_ticks = (
unsigned int)std::round((m_meta_time % 1000000000ull) * 0.127216);
145 m_meta_sec = (
unsigned int)(m_meta_time / 1000000000ull) & 0x1FFFF;
148 for (
auto& it : m_storeRawPXD) {
150 B2DEBUG(29,
"PXD Unpacker --> Unpack Objects: ");
152 unpack_rawpxd(it, inx++);
155 if (nRaws == 0) m_errorMask |= c_NO_PXD;
157 m_errorMaskEvent |= m_errorMask;
158 m_storeDAQEvtStats->setErrorMask(m_errorMaskEvent);
160 m_unpackedEventsCount++;
163 for (
unsigned int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
164 if (m_errorMaskEvent & j) m_errorCounter[i]++;
169 if ((m_criticalErrorMask & m_errorMaskEvent) != 0) B2ERROR(
"Error in PXD unpacking" <<
LogVar(
"event nr", m_meta_event_nr));
170 setReturnValue(0 == (m_criticalErrorMask & m_errorMaskEvent));
173 void PXDUnpackerOTModule::unpack_rawpxd(
RawPXD& px,
int inx)
181 m_errorMaskPacket = 0;
184 if (px.
size() <= 0 || px.
size() > 16 * 1024 * 1024) {
185 if (!(m_suppressErrorMask & c_PACKET_SIZE)) {
186 B2WARNING(
"PXD Unpacker --> invalid packet size" <<
187 LogVar(
"size [32bit words] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << px.
size()).str()));
189 m_errorMask |= c_PACKET_SIZE;
192 std::vector<unsigned int> data(px.
size());
193 fullsize = px.
size() * 4;
194 std::copy_n(px.
data(), px.
size(), data.begin());
197 if (!(m_suppressErrorMask & c_PACKET_SIZE)) {
198 B2WARNING(
"Data is to small to hold a valid Header! Will not unpack anything." <<
LogVar(
"size [32bit words] $",
199 static_cast < std::ostringstream &&
>(std::ostringstream() << hex << fullsize).str()));
201 m_errorMask |= c_PACKET_SIZE;
205 if (data[0] != 0xCAFEBABE && data[0] != 0xBEBAFECA) {
206 if (!(m_suppressErrorMask & c_MAGIC)) {
207 B2WARNING(
"Magic invalid: Will not unpack anything. Header corrupted." <<
208 LogVar(
"Header Magic $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << data[0]).str()));
210 m_errorMask |= c_MAGIC;
215 Frames_in_event = ((ubig32_t*)data.data())[1];
216 if (Frames_in_event < 0 || Frames_in_event > 256) {
217 if (!(m_suppressErrorMask & c_FRAME_NR)) {
218 B2WARNING(
"Number of Frames invalid: Will not unpack anything. Header corrupted!" <<
LogVar(
"Frames in event", Frames_in_event));
220 m_errorMask |= c_FRAME_NR;
223 if (Frames_in_event < 3) {
224 if (!(m_suppressErrorMask & c_NR_FRAMES_TO_SMALL)) {
225 B2WARNING(
"Number of Frames too small: It cannot contain anything useful." <<
LogVar(
"Frames in event", Frames_in_event));
227 m_errorMask |= c_NR_FRAMES_TO_SMALL;
232 B2DEBUG(29,
"PXD Unpacker --> data[0]: <-- Magic $" << hex << data[0]);
233 B2DEBUG(29,
"PXD Unpacker --> data[1]: <-- #Frames $" << hex << data[1]);
234 if (data[1] >= 1 && fullsize < 12) B2DEBUG(29,
"PXD Unpacker --> data[2]: <-- Frame 1 len $" << hex << data[2]);
235 if (data[1] >= 2 && fullsize < 16) B2DEBUG(29,
"PXD Unpacker --> data[3]: <-- Frame 2 len $" << hex << data[3]);
236 if (data[1] >= 3 && fullsize < 20) B2DEBUG(29,
"PXD Unpacker --> data[4]: <-- Frame 3 len $" << hex << data[4]);
237 if (data[1] >= 4 && fullsize < 24) B2DEBUG(29,
"PXD Unpacker --> data[5]: <-- Frame 4 len $" << hex << data[5]);
240 unsigned int* tableptr;
243 unsigned int* dataptr;
244 dataptr = &tableptr[Frames_in_event];
245 datafullsize = fullsize - 2 * 4 - Frames_in_event * 4;
248 for (
int j = 0; j < Frames_in_event; j++) {
251 lo = ((ubig32_t*)tableptr)[j];
253 if (!(m_suppressErrorMask & c_FRAME_SIZE)) {
254 B2WARNING(
"size of frame invalid");
255 B2DEBUG(29,
"size of frame invalid: " << j <<
"size " << lo <<
" at byte offset in dataptr " << ll);
257 m_errorMask |= c_FRAME_SIZE;
260 if (ll + lo > datafullsize) {
261 if (!(m_suppressErrorMask & c_FRAME_SIZE)) {
262 B2WARNING(
"Frames exceed packet size");
263 B2DEBUG(29,
"Frames exceed packet size: " << j <<
" size " << lo <<
" at byte offset in dataptr " << ll <<
" of datafullsize " <<
264 datafullsize <<
" of fullsize " << fullsize);
266 m_errorMask |= c_FRAME_SIZE;
270 if (!(m_suppressErrorMask & c_FRAME_SIZE)) {
271 B2WARNING(
"SKIP Frame with Data with not MOD 4 length");
272 B2DEBUG(29,
"SKIP Frame with Data with not MOD 4 length " <<
" ( $" << hex << lo <<
" ) ");
274 ll += (lo + 3) & 0xFFFFFFFC;
275 m_errorMask |= c_FRAME_SIZE;
277 B2DEBUG(29,
"unpack DHE(C) frame: " << j <<
" with size " << lo <<
" at byte offset in dataptr " << ll);
278 unpack_dhc_frame(ll + (
char*)dataptr, lo, j, Frames_in_event, daqpktstat);
281 m_errorMaskDHE |= m_errorMask;
282 m_errorMaskDHC |= m_errorMask;
283 m_errorMaskPacket |= m_errorMask;
284 m_errorMaskEvent |= m_errorMask;
287 if (!m_continueOnError && (m_errorMaskPacket & m_errorSkipPacketMask) != 0) {
298 void PXDUnpackerOTModule::unpack_dhp_raw(
void* data,
unsigned int frame_len,
unsigned int dhe_ID,
unsigned dhe_DHPport,
302 ubig16_t* dhp_pix = (ubig16_t*)data;
312 if (frame_len != 0xC008) {
313 if (!(m_suppressErrorMask & c_FIX_SIZE)) B2WARNING(
"Frame size unsupported for RAW ADC frame! $" <<
314 LogVar(
"size [bytes] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << frame_len).str()));
315 m_errorMask |= c_FIX_SIZE;
318 unsigned int dhp_header_type = 0;
320 unsigned int dhp_dhe_id = 0;
321 unsigned int dhp_dhp_id = 0;
323 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
325 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
326 dhp_dhp_id = dhp_pix[2] & 0x0003;
328 if (dhe_ID != dhp_dhe_id) {
329 if (!(m_suppressErrorMask & c_DHE_DHP_DHEID)) {
330 B2WARNING(
"DHE ID in DHE and DHP header differ");
331 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
333 m_errorMask |= c_DHE_DHP_DHEID;
335 if (dhe_DHPport != dhp_dhp_id) {
336 if (!(m_suppressErrorMask & c_DHE_DHP_PORT)) {
337 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
338 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
340 m_errorMask |= c_DHE_DHP_PORT;
343 if (dhp_header_type != EDHPFrameHeaderDataType::c_RAW) {
344 if (!(m_suppressErrorMask & c_HEADERTYPE_INV)) {
345 B2WARNING(
"Header type invalid for this kind of DHE frame");
346 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
348 m_errorMask |= c_HEADERTYPE_INV;
353 B2DEBUG(29,
"Raw ADC Data");
355 m_storeRawAdc.appendNew(vxd_id, data, frame_len);
358 void PXDUnpackerOTModule::unpack_fce([[maybe_unused]]
unsigned short* data, [[maybe_unused]]
unsigned int length,
359 [[maybe_unused]]
VxdID vxd_id)
368 B2WARNING(
"FCE (Cluster) Packet have not yet been tested with real HW clusters. Dont assume that this code is working!");
403 void PXDUnpackerOTModule::dump_dhp(
void* data,
unsigned int frame_len)
406 unsigned int w = frame_len / 2;
407 ubig16_t* d = (ubig16_t*)data;
409 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- ");
411 auto dhp_header_type = (d[2] & 0xE000) >> 13;
412 auto dhp_reserved = (d[2] & 0x1F00) >> 8;
413 auto dhp_dhe_id = (d[2] & 0x00FC) >> 2;
414 auto dhp_dhp_id = d[2] & 0x0003;
416 B2WARNING(
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
417 B2WARNING(
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
418 B2WARNING(
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
419 B2WARNING(
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
420 for (
unsigned int i = 4; i < w; i++) {
421 B2WARNING(
"DHP DATA $" << hex << d[i]);
423 B2WARNING(
"DHP CRC $" << hex << d[w] <<
",$" << hex << d[w + 1]);
426 void PXDUnpackerOTModule::dump_roi(
void* data,
unsigned int frame_len)
429 unsigned int w = frame_len / 4;
430 ubig32_t* d = (ubig32_t*)data;
432 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- Len $" << hex
435 for (
unsigned int i = 0; i < w; i++) {
436 B2WARNING(
"ROI DATA $" << hex << d[i]);
438 B2WARNING(
"ROI CRC $" << hex << d[w]);
441 void PXDUnpackerOTModule::unpack_dhp(
void* data,
unsigned int frame_len,
unsigned int dhe_first_readout_frame_id_lo,
442 unsigned int dhe_ID,
unsigned dhe_DHPport,
unsigned dhe_reformat,
VxdID vxd_id,
445 unsigned int nr_words = frame_len / 2;
446 bool printflag =
false;
447 ubig16_t* dhp_pix = (ubig16_t*)data;
449 unsigned int dhp_readout_frame_lo = 0;
450 unsigned int dhp_header_type = 0;
451 unsigned int dhp_reserved = 0;
452 unsigned int dhp_dhe_id = 0;
453 unsigned int dhp_dhp_id = 0;
454 unsigned int wrap = 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_DHP_SIZE)) B2WARNING(
"DHP frame size error (too small)" <<
LogVar(
"Nr words", nr_words));
464 m_errorMask |= c_DHP_SIZE;
469 B2DEBUG(29,
"HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] <<
" -- ");
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;
479 B2DEBUG(29,
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
480 B2DEBUG(29,
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
481 B2DEBUG(29,
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
482 B2DEBUG(29,
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
485 if (dhe_ID != dhp_dhe_id) {
486 if (!(m_suppressErrorMask & c_DHE_DHP_DHEID)) {
487 B2WARNING(
"DHE ID in DHE and DHP header differ");
488 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
490 m_errorMask |= c_DHE_DHP_DHEID;
492 if (dhe_DHPport != dhp_dhp_id) {
493 if (!(m_suppressErrorMask & c_DHE_DHP_PORT)) {
494 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
495 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
497 m_errorMask |= c_DHE_DHP_PORT;
500 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
501 if (!(m_suppressErrorMask & c_HEADERTYPE_INV)) {
502 B2WARNING(
"Header type invalid for this kind of DHE frame");
503 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
505 m_errorMask |= c_HEADERTYPE_INV;
512 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
514 B2DEBUG(29,
"DHP Frame Nr | $" << hex << dhp_readout_frame_lo <<
" ( " << dec << dhp_readout_frame_lo <<
" ) ");
554 m_last_dhp_readout_frame_lo[dhp_dhp_id] = dhp_readout_frame_lo;
557 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
559 if (!(m_suppressErrorMask & c_DHP_DBL_HEADER)) {
560 B2WARNING(
"DHP data: seems to be double header! skipping.");
561 B2DEBUG(29,
"DHP data: seems to be double header! skipping." <<
LogVar(
"Length",
564 m_errorMask |= c_DHP_DBL_HEADER;
570 for (
unsigned int i = 4; i < nr_words ; i++) {
573 B2DEBUG(29,
"-- $" << hex << dhp_pix[i] <<
" -- " << dec << i);
575 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
578 if (!(m_suppressErrorMask & c_DHP_ROW_WO_PIX)) B2WARNING(
"DHP Unpacking: Row w/o Pix");
579 m_errorMask |= c_DHP_ROW_WO_PIX;
582 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
583 dhp_cm = dhp_pix[i] & 0x3F;
584 if (last_gate != -1 && (
int)dhp_row / 4 < last_gate) {
588 last_gate = dhp_row / 4;
591 B2WARNING(
"DHP data loss (CM=63) in " <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhp_dhp_id));
593 m_errorMask |= c_DHH_MISC_ERROR;
605 B2DEBUG(29,
"SetRow: $" << hex << dhp_row <<
" CM $" << hex << dhp_cm);
608 if (!(m_suppressErrorMask & c_DHP_PIX_WO_ROW)) B2WARNING(
"DHP Unpacking: Pix without Row!!! skip dhp data ");
609 m_errorMask |= c_DHP_PIX_WO_ROW;
614 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
615 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
616 unsigned int v_cellID, u_cellID;
618 if (dhp_row >= 768) {
619 if (!(m_suppressErrorMask & c_ROW_OVERFLOW)) B2WARNING(
"DHP ROW Overflow " <<
LogVar(
"Row", dhp_row));
620 m_errorMask |= c_ROW_OVERFLOW;
624 if ((dhe_reformat == 0 && !m_forceNoMapping) || m_forceMapping) {
627 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
629 PXDMappingLookup::map_rc_to_uv_IF_OB(v_cellID, u_cellID, dhp_dhp_id, dhe_ID);
631 PXDMappingLookup::map_rc_to_uv_IB_OF(v_cellID, u_cellID, dhp_dhp_id, dhe_ID);
634 u_cellID = dhp_col + 64 * dhp_dhp_id;
636 if (u_cellID >= 250) {
637 if (!(m_suppressErrorMask & c_COL_OVERFLOW)) {
638 B2WARNING(
"DHP COL Overflow (unconnected drain lines)");
639 B2DEBUG(29,
"DHP COL Overflow (unconnected drain lines) " << u_cellID <<
", reformat " << dhe_reformat <<
", dhpcol " << dhp_col <<
640 ", id " << dhp_dhp_id);
642 m_errorMask |= c_COL_OVERFLOW;
644 dhp_adc = dhp_pix[i] & 0xFF;
646 B2DEBUG(29,
"SetPix: Row $" << hex << dhp_row <<
" Col $" << hex << dhp_col <<
" ADC $" << hex << dhp_adc
647 <<
" CM $" << hex << dhp_cm);
651 B2WARNING(
"DHE Event truncation in DHE " << dhe_ID <<
" DHP " << dhp_dhp_id);
656 if (!m_doNotStore) m_storeRawHits.appendNew(vxd_id, v_cellID, u_cellID, dhp_adc,
657 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo + wrap) & 0x3F);
665 B2DEBUG(29,
"(DHE) DHE_ID $" << hex << dhe_ID <<
" (DHE) DHP ID $" << hex << dhe_DHPport <<
" (DHP) DHE_ID $" << hex << dhp_dhe_id
666 <<
" (DHP) DHP ID $" << hex << dhp_dhp_id);
677 int PXDUnpackerOTModule::nr5bits(
int i)
680 const int lut[32] = {
681 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
682 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5
684 return lut[i & 0x1F];
687 void PXDUnpackerOTModule::unpack_dhc_frame(
void* data,
const int len,
const int Frame_Number,
const int Frames_in_event,
693 static unsigned int eventNrOfOnsenTrgFrame = 0;
694 static int countedBytesInDHC = 0;
695 static bool cancheck_countedBytesInDHC =
false;
696 static int countedBytesInDHE = 0;
697 static bool cancheck_countedBytesInDHE =
false;
698 static int countedDHEStartFrames = 0;
699 static int countedDHEEndFrames = 0;
700 static int mask_active_dhe = 0;
701 static int nr_active_dhe =
703 static int mask_active_dhp = 0;
704 static int found_mask_active_dhp = 0;
705 static int found_good_mask_active_dhp = 0;
706 static unsigned int dhe_first_readout_frame_id_lo = 0;
707 static unsigned int dhe_first_triggergate = 0;
708 static unsigned int currentDHCID = 0xFFFFFFFF;
709 static unsigned int currentDHEID = 0xFFFFFFFF;
710 static unsigned int currentVxdId = 0;
711 static bool isFakedData_event =
false;
712 static bool isUnfiltered_event =
false;
715 if (Frame_Number == 0) {
718 eventNrOfOnsenTrgFrame = 0;
719 countedDHEStartFrames = 0;
720 countedDHEEndFrames = 0;
721 countedBytesInDHC = 0;
722 cancheck_countedBytesInDHC =
false;
723 countedBytesInDHE = 0;
724 cancheck_countedBytesInDHE =
false;
725 currentDHCID = 0xFFFFFFFF;
726 currentDHEID = 0xFFFFFFFF;
728 isUnfiltered_event =
false;
729 isFakedData_event =
false;
733 found_mask_active_dhp = 0;
734 found_good_mask_active_dhp = 0;
747 if (len != s && s != 0) {
748 if (!(m_suppressErrorMask & c_FIX_SIZE)) {
749 B2WARNING(
"Fixed frame type size does not match specs" <<
LogVar(
"expected length",
750 len) <<
LogVar(
"length in data", s));
752 m_errorMask |= c_FIX_SIZE;
753 if (!m_continueOnError)
return;
759 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
760 if (!m_continueOnError && (m_errorMask & c_DHE_CRC) != 0) {
765 unsigned int eventNrOfThisFrame = dhc.getEventNrLo();
766 int frame_type = dhc.getFrameType();
768 if (Frame_Number == 0) {
769 if (m_formatBonnDAQ) {
770 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
771 if (!(m_suppressErrorMask & c_EVENT_STRUCT)) B2WARNING(
"This looks not like BonnDAQ format.");
772 m_errorMask |= c_EVENT_STRUCT;
776 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
777 if (!(m_suppressErrorMask & c_EVENT_STRUCT))
778 B2WARNING(
"This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
779 m_errorMask |= c_EVENT_STRUCT;
785 if (!m_formatBonnDAQ) {
786 if (Frame_Number == 1) {
787 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
788 isFakedData_event = dhc.data_dhc_start_frame->isFakedData();
794 if ((eventNrOfThisFrame & 0xFFFF) != (m_meta_event_nr & 0xFFFF)) {
795 if (!isFakedData_event) {
796 if (!(m_suppressErrorMask & c_META_MM)) {
797 B2WARNING(
"Event Numbers do not match for this frame");
798 B2DEBUG(29,
"Event Numbers do not match for this frame" <<
799 LogVar(
"Event nr in frame $",
static_cast < std::ostringstream
800 &&
>(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
801 LogVar(
"Event nr in MetaInfo (bits masked) $",
802 static_cast < std::ostringstream &&
>(std::ostringstream() << hex << m_meta_event_nr).str()));
804 m_errorMask |= c_META_MM;
809 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
810 if (countedDHEStartFrames != countedDHEEndFrames + 1)
811 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
812 if (!(m_suppressErrorMask & c_DATA_OUTSIDE)) B2WARNING(
"Data Frame outside a DHE START/END");
813 m_errorMask |= c_DATA_OUTSIDE;
823 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
824 m_errorMask |= c_HEADER_ERR;
827 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
828 m_errorMask |= c_HEADER_ERR_GHOST;
832 switch (frame_type) {
833 case EDHCFrameHeaderDataType::c_DHP_RAW: {
835 if (m_verbose) dhc.data_direct_readout_frame_raw->print();
836 if (currentDHEID != dhc.data_direct_readout_frame_raw->getDHEId()) {
837 if (!(m_suppressErrorMask & c_DHE_START_ID)) {
838 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
839 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
840 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
841 &&
>(std::ostringstream() << hex << dhc.data_direct_readout_frame_raw->getDHEId()).str()) <<
842 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
844 m_errorMask |= c_DHE_START_ID;
846 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
847 if ((found_mask_active_dhp & (1 << dhc.data_direct_readout_frame->getDHPPort())) != 0) {
848 B2ERROR(
"Second DHP data packet (MEMDUMP) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
849 dhc.data_direct_readout_frame->getDHPPort()));
852 found_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
854 unpack_dhp_raw(data, len - 4,
855 dhc.data_direct_readout_frame->getDHEId(),
856 dhc.data_direct_readout_frame->getDHPPort(),
861 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
863 cancheck_countedBytesInDHC =
false;
864 cancheck_countedBytesInDHE =
false;
866 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
868 if (m_verbose) dhc.data_direct_readout_frame->print();
869 if (isUnfiltered_event) {
870 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP) m_errorMask |= c_SENDALL_TYPE;
872 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD) m_errorMask |= c_NOTSENDALL_TYPE;
877 if (currentDHEID != dhc.data_direct_readout_frame_raw->getDHEId()) {
878 if (!(m_suppressErrorMask & c_DHE_START_ID)) {
879 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
880 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
881 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
882 &&
>(std::ostringstream() << hex << dhc.data_direct_readout_frame_raw->getDHEId()).str()) <<
883 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
885 m_errorMask |= c_DHE_START_ID;
887 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
888 if ((found_mask_active_dhp & (1 << dhc.data_direct_readout_frame->getDHPPort())) != 0) {
889 B2ERROR(
"Second DHP data packet for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP", dhc.data_direct_readout_frame->getDHPPort()));
891 found_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
892 found_good_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
896 unpack_dhp(data, len - 4,
897 dhe_first_readout_frame_id_lo,
898 dhc.data_direct_readout_frame->getDHEId(),
899 dhc.data_direct_readout_frame->getDHPPort(),
900 dhc.data_direct_readout_frame->getDataReformattedFlag(),
901 currentVxdId, daqpktstat);
905 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
907 cancheck_countedBytesInDHC =
false;
908 cancheck_countedBytesInDHE =
false;
910 case EDHCFrameHeaderDataType::c_FCE_RAW: {
911 if (!(m_suppressErrorMask & c_UNEXPECTED_FRAME_TYPE)) B2WARNING(
"Unexpected Frame Type (Clustering FCE)");
912 m_errorMask |= c_UNEXPECTED_FRAME_TYPE;
913 if (m_verbose) hw->
print();
914 if (isUnfiltered_event) {
915 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
917 m_errorMask |= c_SENDALL_TYPE;
920 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
922 m_errorMask |= c_NOTSENDALL_TYPE;
926 if (currentDHEID != dhc.data_direct_readout_frame_raw->getDHEId()) {
927 if (!(m_suppressErrorMask & c_DHE_START_ID)) {
928 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
929 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
930 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
931 &&
>(std::ostringstream() << hex << dhc.data_direct_readout_frame_raw->getDHEId()).str()) <<
932 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
934 m_errorMask |= c_DHE_START_ID;
936 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
937 if ((found_mask_active_dhp & (1 << dhc.data_direct_readout_frame->getDHPPort())) != 0) {
938 B2ERROR(
"Second DHP data packet (FCE) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
939 dhc.data_direct_readout_frame->getDHPPort()));
941 found_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
943 B2DEBUG(29,
"UNPACK FCE FRAME with len $" << hex << len);
944 unpack_fce((
unsigned short*) data, len - 4, currentVxdId);
948 case EDHCFrameHeaderDataType::c_COMMODE: {
950 if (!(m_suppressErrorMask & c_UNEXPECTED_FRAME_TYPE)) B2WARNING(
"Unexpected Frame Type (COMMODE)");
951 m_errorMask |= c_UNEXPECTED_FRAME_TYPE;
953 if (m_verbose) hw->
print();
954 if (currentDHEID != dhc.data_commode_frame->getDHEId()) {
955 if (!(m_suppressErrorMask & c_DHE_START_ID)) {
956 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
957 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
958 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
959 &&
>(std::ostringstream() << hex << dhc.data_commode_frame->getDHEId()).str()) <<
960 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
962 m_errorMask |= c_DHE_START_ID;
964 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
967 case EDHCFrameHeaderDataType::c_DHC_START: {
968 countedBytesInDHC = 0;
969 cancheck_countedBytesInDHC =
true;
970 if (isFakedData_event != dhc.data_dhc_start_frame->isFakedData()) {
971 if (!(m_suppressErrorMask & c_FAKE_NO_FAKE_DATA)) B2WARNING(
"DHC START mixed Fake/no Fake event.");
972 m_errorMask |= c_FAKE_NO_FAKE_DATA;
974 if (dhc.data_dhc_start_frame->isFakedData()) {
975 if (!(m_suppressErrorMask & c_FAKE_NO_DATA_TRIG)) B2WARNING(
"Faked DHC START Data -> trigger without Data!");
976 m_errorMask |= c_FAKE_NO_DATA_TRIG;
978 if (m_verbose) dhc.data_dhc_start_frame->print();
982 currentDHEID = 0xFFFFFFFF;
984 currentDHCID = dhc.data_dhc_start_frame->get_dhc_id();
985 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
987 if (m_formatBonnDAQ) eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
989 if (!isFakedData_event) {
992 if (dhc.data_dhc_start_frame->get_experiment() != m_meta_experiment) {
993 if (!(m_suppressErrorMask & c_META_MM_DHC_ERS)) {
994 B2WARNING(
"DHC-Meta Experiment number mismatch");
995 B2DEBUG(29,
"DHC-Meta Experiment number mismatch" <<
997 dhc.data_dhc_start_frame->get_experiment()) <<
998 LogVar(
"META exp nr" , m_meta_experiment));
1000 m_errorMask |= c_META_MM_DHC_ERS;
1002 if (dhc.data_dhc_start_frame->get_run() != m_meta_run_nr) {
1003 if (!(m_suppressErrorMask & c_META_MM_DHC_ERS)) {
1004 B2WARNING(
"DHC-Meta Run number mismatch");
1005 B2DEBUG(29,
"DHC-Meta Run number mismatch" <<
1007 dhc.data_dhc_start_frame->get_run()) <<
1008 LogVar(
"META run nr", m_meta_run_nr));
1010 m_errorMask |= c_META_MM_DHC_ERS;
1012 if (dhc.data_dhc_start_frame->get_subrun() != m_meta_subrun_nr) {
1013 if (!(m_suppressErrorMask & c_META_MM_DHC_ERS)) {
1014 B2WARNING(
"DHC-Meta Sub-Run number mismatch");
1015 B2DEBUG(29,
"DHC-Meta Sub-Run number mismatch" <<
1017 dhc.data_dhc_start_frame->get_subrun()) <<
1018 LogVar(
"META subrun nr", m_meta_subrun_nr));
1020 m_errorMask |= c_META_MM_DHC_ERS;
1022 if ((((
unsigned int)dhc.data_dhc_start_frame->getEventNrHi() << 16) | dhc.data_dhc_start_frame->getEventNrLo()) !=
1023 (m_meta_event_nr & 0xFFFFFFFF)) {
1024 if (!(m_suppressErrorMask & c_META_MM_DHC)) {
1025 B2WARNING(
"DHC-Meta 32 bit event number mismatch");
1026 B2DEBUG(29,
"DHC-Meta 32 bit event number mismatch" <<
1027 LogVar(
"DHC trigger nr", (((
unsigned int) dhc.data_dhc_start_frame->getEventNrHi() << 16) |
1028 dhc.data_dhc_start_frame->getEventNrLo())) <<
1029 LogVar(
"META trigger nr" , (
unsigned int)(m_meta_event_nr & 0xFFFFFFFF)));
1031 m_errorMask |= c_META_MM_DHC;
1033 uint32_t trig_ticks = (((
unsigned int)dhc.data_dhc_start_frame->time_tag_mid & 0x7FFF) << 12) | ((
unsigned int)
1034 dhc.data_dhc_start_frame->time_tag_lo_and_type >> 4);
1035 uint32_t trig_sec = (dhc.data_dhc_start_frame->time_tag_hi * 2) ;
1036 if (dhc.data_dhc_start_frame->time_tag_mid & 0x8000) trig_sec++;
1038 if ((trig_ticks - m_meta_ticks) != 0 || (trig_sec - m_meta_sec) != 0) {
1039 m_errorMask |= c_META_MM_DHC_TT;
1040 if (!(m_suppressErrorMask & c_META_MM_DHC_TT)) {
1041 B2WARNING(
"DHC-Meta TimeTag mismatch");
1042 B2DEBUG(29,
"DHC-Meta TimeTag mismatch" <<
1043 LogVar(
"Header Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() <<
1044 hex << dhc.data_dhc_start_frame->time_tag_hi <<
"." <<
1045 dhc.data_dhc_start_frame->time_tag_mid <<
"." <<
1046 dhc.data_dhc_start_frame->time_tag_lo_and_type).str()) <<
1047 LogVar(
"Meta Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << m_meta_time).str()) <<
1048 LogVar(
"Trigger Type",
static_cast < std::ostringstream
1049 &&
>(std::ostringstream() << hex << (dhc.data_dhc_start_frame->time_tag_lo_and_type & 0xF)).str()) <<
1050 LogVar(
"Meta seconds: $" ,
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << m_meta_sec).str()) <<
1051 LogVar(
"DHC seconds $" ,
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_sec).str()) <<
1052 LogVar(
"Seconds difference $" ,
static_cast < std::ostringstream
1053 &&
>(std::ostringstream() << hex << (trig_sec - m_meta_sec)).str()) <<
1054 LogVar(
"Meta ticks from 127MHz $" ,
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << m_meta_ticks).str()) <<
1055 LogVar(
"DHC ticks from 127MHz $" ,
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_ticks).str()) <<
1056 LogVar(
"Tick difference $" ,
static_cast < std::ostringstream
1057 &&
>(std::ostringstream() << hex << (trig_ticks - m_meta_ticks)).str()));
1060 B2DEBUG(29,
"DHC TT: $" << hex << dhc.data_dhc_start_frame->time_tag_hi <<
"." << dhc.data_dhc_start_frame->time_tag_mid <<
"." <<
1061 dhc.data_dhc_start_frame->time_tag_lo_and_type <<
" META " << m_meta_time <<
" TRG Type " <<
1062 (dhc.data_dhc_start_frame->time_tag_lo_and_type & 0xF));
1065 mask_active_dhe = dhc.data_dhc_start_frame->get_active_dhe_mask();
1066 nr_active_dhe = nr5bits(mask_active_dhe);
1068 m_errorMaskDHC = m_errorMask;
1069 daqpktstat.
newDHC(currentDHCID, m_errorMask);
1075 case EDHCFrameHeaderDataType::c_DHE_START: {
1076 countedBytesInDHE = 0;
1077 cancheck_countedBytesInDHE =
true;
1078 m_last_dhp_readout_frame_lo[0] = -1;
1079 m_last_dhp_readout_frame_lo[1] = -1;
1080 m_last_dhp_readout_frame_lo[2] = -1;
1081 m_last_dhp_readout_frame_lo[3] = -1;
1082 if (m_verbose) dhc.data_dhe_start_frame->print();
1083 dhe_first_readout_frame_id_lo = dhc.data_dhe_start_frame->getStartFrameNr();
1084 dhe_first_triggergate = dhc.data_dhe_start_frame->
getTriggerGate();
1085 if (currentDHEID != 0xFFFFFFFF && (currentDHEID & 0xFFFF) >= dhc.data_dhe_start_frame->getDHEId()) {
1086 if (!(m_suppressErrorMask & c_DHE_WRONG_ID_SEQ)) {
1087 B2WARNING(
"DHH IDs are not in expected order");
1088 B2DEBUG(29,
"DHH IDs are not in expected order" <<
1089 LogVar(
"Previous ID", (currentDHEID & 0xFFFF)) <<
1090 LogVar(
"Current ID", dhc.data_dhe_start_frame->getDHEId()));
1092 m_errorMask |= c_DHE_WRONG_ID_SEQ;
1094 currentDHEID = dhc.data_dhe_start_frame->getDHEId();
1095 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
1097 if (countedDHEStartFrames > countedDHEEndFrames) {
1098 if (!(m_suppressErrorMask & c_DHE_START_WO_END)) B2WARNING(
"DHE_START without DHE_END");
1099 m_errorMask |= c_DHE_START_WO_END;
1101 countedDHEStartFrames++;
1103 found_mask_active_dhp = 0;
1104 found_good_mask_active_dhp = 0;
1105 mask_active_dhp = dhc.data_dhe_start_frame->getActiveDHPMask();
1107 if ((((
unsigned int)dhc.data_dhe_start_frame->getEventNrHi() << 16) | dhc.data_dhe_start_frame->getEventNrLo()) != (
unsigned int)(
1108 m_meta_event_nr & 0xFFFFFFFF)) {
1109 if (!(m_suppressErrorMask & c_META_MM_DHE)) {
1110 B2WARNING(
"DHE START trigger mismatch in EVT32b/HI WORD");
1111 B2DEBUG(29,
"DHE START trigger mismatch in EVT32b/HI WORD" <<
1112 LogVar(
"DHE Start trigger nr", (dhc.data_dhe_start_frame->getEventNrHi() << 16) | dhc.data_dhe_start_frame->getEventNrLo()) <<
1113 LogVar(
"Meta trigger nr", (m_meta_event_nr & 0xFFFFFFFF)));
1115 m_errorMask |= c_META_MM_DHE;
1120 if (currentDHEID == 0) {
1121 if (!(m_suppressErrorMask & c_DHE_ID_INVALID)) B2WARNING(
"DHE ID is invalid=0 (not initialized)");
1122 m_errorMask |= c_DHE_ID_INVALID;
1132 unsigned short sensor, ladder, layer;
1133 sensor = (currentDHEID & 0x1) + 1;
1134 ladder = (currentDHEID & 0x1E) >> 1;
1135 layer = ((currentDHEID & 0x20) >> 5) + 1;
1136 currentVxdId =
VxdID(layer, ladder, sensor);
1137 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
1138 if (!(m_suppressErrorMask & c_DHE_ID_INVALID)) {
1139 B2WARNING(
"DHE ID is invalid");
1140 B2DEBUG(29,
"DHE ID is invalid" <<
1141 LogVar(
"DHE ID", currentDHEID) <<
1142 LogVar(
"Layer", layer) <<
1143 LogVar(
"Ladder", ladder) <<
1144 LogVar(
"Sensor", sensor));
1146 m_errorMask |= c_DHE_ID_INVALID;
1150 m_errorMaskDHE = m_errorMask;
1153 daqpktstat.
dhc_back().
newDHE(currentVxdId, currentDHEID, m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
1157 case EDHCFrameHeaderDataType::c_GHOST:
1158 if (m_verbose) dhc.data_ghost_frame->print();
1159 if (currentDHEID != dhc.data_ghost_frame->getDHEId()) {
1160 if (!(m_suppressErrorMask & c_DHE_START_ID)) {
1161 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1162 B2DEBUG(29,
"Start ID $" << hex << currentDHEID <<
" != $" << dhc.data_ghost_frame->getDHEId());
1164 m_errorMask |= c_DHE_START_ID;
1167 if ((found_mask_active_dhp & (1 << dhc.data_ghost_frame->getDHPPort())) != 0) {
1168 B2ERROR(
"Second DHP data packet (GHOST) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP", dhc.data_ghost_frame->getDHPPort()));
1170 found_mask_active_dhp |= 1 << dhc.data_ghost_frame->getDHPPort();
1174 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
1177 case EDHCFrameHeaderDataType::c_DHC_END: {
1178 if (dhc.data_dhc_end_frame->isFakedData() != isFakedData_event) {
1179 if (!(m_suppressErrorMask & c_FAKE_NO_FAKE_DATA)) B2WARNING(
"DHC END mixed Fake/no Fake event.");
1180 m_errorMask |= c_FAKE_NO_FAKE_DATA;
1182 if (dhc.data_dhc_end_frame->isFakedData()) {
1183 if (!(m_suppressErrorMask & c_FAKE_NO_DATA_TRIG)) B2WARNING(
"Faked DHC END Data -> trigger without Data!");
1184 m_errorMask |= c_FAKE_NO_DATA_TRIG;
1186 if (m_verbose) dhc.data_dhc_end_frame->print();
1189 if (!isFakedData_event) {
1190 if (dhc.data_dhc_end_frame->get_dhc_id() != currentDHCID) {
1191 if (!(m_suppressErrorMask & c_DHC_DHCID_START_END_MM)) {
1192 B2WARNING(
"DHC ID Mismatch between Start and End");
1193 B2DEBUG(29,
"DHC ID Mismatch between Start and End $" << std::hex <<
1194 currentDHCID <<
"!=$" << dhc.data_dhc_end_frame->get_dhc_id());
1196 m_errorMask |= c_DHC_DHCID_START_END_MM;
1199 w = dhc.data_dhc_end_frame->get_words() * 4;
1200 if (cancheck_countedBytesInDHC) {
1201 if (countedBytesInDHC != w) {
1202 if (!(m_suppressErrorMask & c_DHC_WIE)) {
1203 B2WARNING(
"Number of Words in DHC END does not match");
1204 B2DEBUG(29,
"Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC <<
" != DHC END $" << hex << w);
1206 m_errorMask |= c_DHC_WIE;
1209 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHC <<
" == DHC END $" << hex << w);
1215 if (dhc.data_dhc_end_frame->getErrorInfo() != 0) {
1216 if (!(m_suppressErrorMask & c_DHH_END_ERRORBITS)) B2ERROR(
"DHC END Error Info set to $" << hex <<
1217 dhc.data_dhc_end_frame->getErrorInfo());
1218 m_errorMask |= c_DHH_END_ERRORBITS;
1220 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
1221 m_errorMaskDHC |= m_errorMask;
1229 daqpktstat.
dhc_back().
setCounters(dhc.data_dhc_end_frame->get_words() * 4, countedBytesInDHC);
1233 currentDHEID = 0xFFFFFFFF;
1234 currentDHCID = 0xFFFFFFFF;
1238 case EDHCFrameHeaderDataType::c_DHE_END: {
1239 if (m_verbose) dhc.data_dhe_end_frame->print();
1240 if (currentDHEID != dhc.data_dhe_end_frame->getDHEId()) {
1241 if (!(m_suppressErrorMask & c_DHE_START_END_ID)) {
1242 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1243 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID <<
" != $" <<
1244 dhc.data_dhe_end_frame->getDHEId());
1246 m_errorMask |= c_DHE_START_END_ID;
1249 if (dhc.data_dhe_end_frame->getErrorInfo() != 0) {
1250 if (!(m_suppressErrorMask & c_DHH_END_ERRORBITS)) B2ERROR(
"DHE END Error Info set to $" << hex <<
1251 dhc.data_dhe_end_frame->getErrorInfo());
1252 m_errorMask |= c_DHH_END_ERRORBITS;
1254 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
1255 if (found_mask_active_dhp != mask_active_dhp) {
1256 if (!(m_suppressErrorMask & c_DHP_ACTIVE)) {
1257 B2WARNING(
"DHE_END: DHP active mask differs from found data");
1258 B2DEBUG(29,
"DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp <<
" != $" << hex <<
1259 found_mask_active_dhp
1260 <<
" mask of found dhp/ghost frames");
1262 m_errorMask |= c_DHP_ACTIVE;
1264 countedDHEEndFrames++;
1265 if (countedDHEStartFrames < countedDHEEndFrames) {
1267 if (!(m_suppressErrorMask & c_DHE_END_WO_START)) B2WARNING(
"DHE_END without DHE_START");
1268 m_errorMask |= c_DHE_END_WO_START;
1272 w = dhc.data_dhe_end_frame->get_words() * 2;
1273 if (cancheck_countedBytesInDHE) {
1274 if (countedBytesInDHE != w) {
1275 if (!(m_suppressErrorMask & c_DHE_WIE)) {
1276 B2WARNING(
"Number of Words in DHE END does not match");
1277 B2DEBUG(29,
"Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE <<
" != DHE END $" << hex << w);
1279 m_errorMask |= c_DHE_WIE;
1282 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHE <<
" == DHE END $" << hex << w);
1287 m_errorMaskDHE |= m_errorMask;
1302 currentDHEID |= 0xFF000000;
1306 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
1307 if (m_verbose) dhc.data_onsen_roi_frame->print();
1308 m_errorMask |= dhc.data_onsen_roi_frame->check_error(len, m_suppressErrorMask & c_ROI_PACKET_INV_SIZE);
1309 m_errorMask |= dhc.data_onsen_roi_frame->check_inner_crc(len - 4);
1310 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
1311 if (!m_doNotStore) {
1315 if (len >= dhc.data_onsen_roi_frame->
getMinSize()) {
1321 l = (len - dhc.data_onsen_roi_frame->
getMinSize()) / 8;
1323 m_storeROIs.appendNew(l, &((
unsigned int*) data)[1]);
1327 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
1328 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
1330 if (!(m_suppressErrorMask & c_META_MM_ONS_HLT)) {
1331 B2WARNING(
"Trigger Frame HLT Trigger Nr mismatch");
1332 B2DEBUG(29,
"Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
1335 m_errorMask |= c_META_MM_ONS_HLT;
1340 if (!(m_suppressErrorMask & c_META_MM_ONS_HLT)) {
1341 B2WARNING(
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
1342 B2DEBUG(29,
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
1347 m_errorMask |= c_META_MM_ONS_HLT;
1352 if (!(m_suppressErrorMask & c_META_MM_ONS_DC)) {
1353 B2WARNING(
"Trigger Frame DATCON Trigger Nr mismatch");
1354 B2DEBUG(29,
"Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
1357 m_errorMask |= c_META_MM_ONS_DC;
1362 if (!(m_suppressErrorMask & c_META_MM_ONS_DC)) {
1363 B2WARNING(
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
1364 B2DEBUG(29,
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
1369 m_errorMask |= c_META_MM_ONS_DC;
1376 m_errorMask |= dhc.
data_onsen_trigger_frame->check_error(m_suppressErrorMask & c_NO_DATCON, m_suppressErrorMask & c_HLTROI_MAGIC,
1377 m_suppressErrorMask & c_MERGER_TRIGNR);
1378 m_errorMask |= dhc.check_crc(m_suppressErrorMask & c_DHE_CRC);
1379 if (Frame_Number != 0) {
1380 if (!(m_suppressErrorMask & c_EVENT_STRUCT)) B2WARNING(
"ONSEN TRG Frame must be the first one.");
1381 m_errorMask |= c_EVENT_STRUCT;
1384 if (isUnfiltered_event) m_sendunfiltered++;
1389 if (!(m_suppressErrorMask & c_DHC_UNKNOWN)) B2WARNING(
"UNKNOWN DHC frame type");
1390 m_errorMask |= c_DHC_UNKNOWN;
1391 if (m_verbose) hw->
print();
1395 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
1396 if (!(m_suppressErrorMask & c_FRAME_TNR_MM)) {
1397 B2WARNING(
"Frame TrigNr != ONSEN Trig Nr");
1398 B2DEBUG(29,
"Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame <<
" != $" << eventNrOfOnsenTrgFrame);
1400 m_errorMask |= c_FRAME_TNR_MM;
1403 if (Frame_Number == 0) {
1405 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1406 if (!m_formatBonnDAQ) {
1407 if (!(m_suppressErrorMask & c_ONSEN_TRG_FIRST)) B2WARNING(
"First frame is not a ONSEN Trigger frame");
1408 m_errorMask |= c_ONSEN_TRG_FIRST;
1413 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1414 if (!(m_suppressErrorMask & c_ONSEN_TRG_FIRST)) B2WARNING(
"More than one ONSEN Trigger frame");
1415 m_errorMask |= c_ONSEN_TRG_FIRST;
1419 if (!m_formatBonnDAQ) {
1420 if (Frame_Number == 1) {
1422 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1423 if (!(m_suppressErrorMask & c_DHC_START_SECOND)) B2WARNING(
"Second frame is not a DHC start of subevent frame");
1424 m_errorMask |= c_DHC_START_SECOND;
1428 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1429 if (!(m_suppressErrorMask & c_DHC_START_SECOND)) B2WARNING(
"More than one DHC start of subevent frame");
1430 m_errorMask |= c_DHC_START_SECOND;
1435 if (Frame_Number == Frames_in_event - 1) {
1437 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
1438 if (!(m_suppressErrorMask & c_DHC_END_MISS)) B2WARNING(
"Last frame is not a DHC end of subevent frame");
1439 m_errorMask |= c_DHC_END_MISS;
1443 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
1444 if (!(m_suppressErrorMask & c_DHE_ACTIVE) || !(m_suppressErrorMask & c_DHE_START_WO_END)
1445 || !(m_suppressErrorMask & c_DHE_END_WO_START)) {
1446 B2WARNING(
"The number of DHE Start/End does not match the number of active DHE in DHC Header!");
1447 B2DEBUG(29,
"The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
1448 " Start: " << countedDHEStartFrames <<
" End: " << countedDHEEndFrames <<
" Mask: $" << hex << mask_active_dhe <<
" in Event Nr " <<
1449 eventNrOfThisFrame);
1451 if (countedDHEStartFrames == countedDHEEndFrames) m_errorMask |= c_DHE_ACTIVE;
1452 if (countedDHEStartFrames > countedDHEEndFrames) m_errorMask |= c_DHE_START_WO_END;
1453 if (countedDHEStartFrames < countedDHEEndFrames) m_errorMask |= c_DHE_END_WO_START;
1458 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
1459 if (!(m_suppressErrorMask & c_DHC_END_DBL)) B2WARNING(
"More than one DHC end of subevent frame");
1460 m_errorMask |= c_DHC_END_DBL;
1464 if (!m_formatBonnDAQ) {
1466 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1467 if (!(m_suppressErrorMask & c_DHE_START_THIRD)) B2WARNING(
"Third frame is not a DHE start frame");
1468 m_errorMask |= c_DHE_START_THIRD;
1472 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1474 countedBytesInDHC += len;
1475 countedBytesInDHE += len;
1477 B2DEBUG(29,
"DHC/DHE $" << hex << countedBytesInDHC <<
", $" << hex << countedBytesInDHE);