9#include <pxd/modules/pxdUnpacking/PXDUnpackerModule.h>
10#include <pxd/unpacking/PXDRawDataDefinitions.h>
11#include <pxd/unpacking/PXDRawDataStructs.h>
12#include <pxd/unpacking/PXDMappingLookup.h>
13#include <rawdata/dataobjects/RawPXD.h>
14#include <pxd/dataobjects/PXDRawHit.h>
15#include <pxd/dataobjects/PXDRawAdc.h>
16#include <pxd/dataobjects/PXDRawROIs.h>
17#include <framework/dataobjects/EventMetaData.h>
18#include <pxd/dbobjects/PXDDHHFirmwareVersionPar.h>
19#include <vxd/dataobjects/VxdID.h>
21#include <framework/logging/Logger.h>
26using namespace Belle2::PXD::PXDError;
51 addParam(
"RawPXDsName",
m_RawPXDsName,
"The name of the StoreArray of RawPXDs to be processed", std::string(
""));
69 addParam(
"Verbose",
m_verbose,
"Turn on extra verbosity for log-level debug",
false);
107 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++)
m_errorCounter[i] = 0;
115 else B2FATAL(
"Cannot get PXD Firmware version from db");
124 string errstr =
"Statistic ( ;";
128 B2RESULT(
"PXD Unpacker --> Error Statistics (counted once per event!) in Events: " <<
m_unpackedEventsCount);
129 B2RESULT(errstr +
" )");
130 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
155 B2DEBUG(29,
"PXD Unpacker --> RawPXD Objects in event: " <<
LogVar(
"Objects", nRaws));
168 B2DEBUG(29,
"PXD Unpacker --> Unpack Objects: ");
180 for (
unsigned int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
201 if (px.
size() <= 0 || px.
size() > 16 * 1024 * 1024) {
203 B2WARNING(
"PXD Unpacker --> invalid packet size" <<
204 LogVar(
"size [32bit words] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << px.
size()).str()));
209 std::vector<unsigned int> data(px.
size());
210 fullsize = px.
size() * 4;
211 std::copy_n(px.
data(), px.
size(), data.begin());
215 B2WARNING(
"Data is to small to hold a valid Header! Will not unpack anything." <<
LogVar(
"size [32bit words] $",
216 static_cast < std::ostringstream &&
>(std::ostringstream() << hex << fullsize).str()));
222 if (data[0] != 0xCAFEBABE && data[0] != 0xBEBAFECA) {
224 B2WARNING(
"Magic invalid: Will not unpack anything. Header corrupted." <<
225 LogVar(
"Header Magic $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << data[0]).str()));
232 Frames_in_event = ((
ubig32_t*)data.data())[1];
233 if (Frames_in_event < 0 || Frames_in_event > 256) {
235 B2WARNING(
"Number of Frames invalid: Will not unpack anything. Header corrupted!" <<
LogVar(
"Frames in event", Frames_in_event));
240 if (Frames_in_event < 3) {
242 B2WARNING(
"Number of Frames too small: It cannot contain anything useful." <<
LogVar(
"Frames in event", Frames_in_event));
249 B2DEBUG(29,
"PXD Unpacker --> data[0]: <-- Magic $" << hex << data[0]);
250 B2DEBUG(29,
"PXD Unpacker --> data[1]: <-- #Frames $" << hex << data[1]);
251 if (data[1] >= 1 && fullsize < 12) B2DEBUG(29,
"PXD Unpacker --> data[2]: <-- Frame 1 len $" << hex << data[2]);
252 if (data[1] >= 2 && fullsize < 16) B2DEBUG(29,
"PXD Unpacker --> data[3]: <-- Frame 2 len $" << hex << data[3]);
253 if (data[1] >= 3 && fullsize < 20) B2DEBUG(29,
"PXD Unpacker --> data[4]: <-- Frame 3 len $" << hex << data[4]);
254 if (data[1] >= 4 && fullsize < 24) B2DEBUG(29,
"PXD Unpacker --> data[5]: <-- Frame 4 len $" << hex << data[5]);
257 unsigned int* tableptr;
260 unsigned int* dataptr;
261 dataptr = &tableptr[Frames_in_event];
262 datafullsize = fullsize - 2 * 4 - Frames_in_event * 4;
265 for (
int j = 0; j < Frames_in_event; j++) {
271 B2WARNING(
"size of frame invalid");
272 B2DEBUG(29,
"size of frame invalid: " << j <<
"size " << lo <<
" at byte offset in dataptr " << ll);
277 if (ll + lo > datafullsize) {
279 B2WARNING(
"Frames exceed packet size");
280 B2DEBUG(29,
"Frames exceed packet size: " << j <<
" size " << lo <<
" at byte offset in dataptr " << ll <<
" of datafullsize " <<
281 datafullsize <<
" of fullsize " << fullsize);
288 B2WARNING(
"SKIP Frame with Data with not MOD 4 length");
289 B2DEBUG(29,
"SKIP Frame with Data with not MOD 4 length " <<
" ( $" << hex << lo <<
" ) ");
291 ll += (lo + 3) & 0xFFFFFFFC;
294 B2DEBUG(29,
"unpack DHE(C) frame: " << j <<
" with size " << lo <<
" at byte offset in dataptr " << ll);
302 B2FATAL(
"Firmware Version not supported " <<
m_firmware);
337 if (frame_len != 0xC008) {
338 if (!(
m_suppressErrorMask[c_nrFIX_SIZE])) B2WARNING(
"Frame size unsupported for RAW ADC frame! $" <<
339 LogVar(
"size [bytes] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << frame_len).str())
340 <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhe_DHPport));
344 unsigned int dhp_header_type = 0;
346 unsigned int dhp_dhe_id = 0;
347 unsigned int dhp_dhp_id = 0;
349 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
351 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
352 dhp_dhp_id = dhp_pix[2] & 0x0003;
354 if (dhe_ID != dhp_dhe_id) {
356 B2WARNING(
"DHE ID in DHE and DHP header differ");
357 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
361 if (dhe_DHPport != dhp_dhp_id) {
363 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
364 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
369 if (dhp_header_type != EDHPFrameHeaderDataType::c_RAW) {
371 B2WARNING(
"Header type invalid for this kind of DHE frame");
372 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
379 B2DEBUG(29,
"Raw ADC Data");
385 [[maybe_unused]]
VxdID vxd_id)
394 B2WARNING(
"FCE (Cluster) Packet have not yet been tested with real HW clusters. Dont assume that this code is working!");
432 unsigned int w = frame_len / 2;
435 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- ");
437 auto dhp_header_type = (d[2] & 0xE000) >> 13;
438 auto dhp_reserved = (d[2] & 0x1F00) >> 8;
439 auto dhp_dhe_id = (d[2] & 0x00FC) >> 2;
440 auto dhp_dhp_id = d[2] & 0x0003;
442 B2WARNING(
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
443 B2WARNING(
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
444 B2WARNING(
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
445 B2WARNING(
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
446 for (
unsigned int i = 4; i < w; i++) {
447 B2WARNING(
"DHP DATA $" << hex << d[i]);
449 B2WARNING(
"DHP CRC $" << hex << d[w] <<
",$" << hex << d[w + 1]);
455 unsigned int w = frame_len / 4;
458 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- Len $" << hex
461 for (
unsigned int i = 0; i < w; i++) {
462 B2WARNING(
"ROI DATA $" << hex << d[i]);
464 B2WARNING(
"ROI CRC $" << hex << d[w]);
468 unsigned int dhe_ID,
unsigned dhe_DHPport,
unsigned dhe_reformat,
VxdID vxd_id,
471 unsigned int nr_words = frame_len / 2;
474 unsigned int dhp_readout_frame_lo = 0;
475 unsigned int dhp_header_type = 0;
476 unsigned int dhp_reserved = 0;
477 unsigned int dhp_dhe_id = 0;
478 unsigned int dhp_dhp_id = 0;
481 unsigned int dhp_row = 0, dhp_col = 0, dhp_cm = 0;
483 bool rowflag =
false;
484 bool pixelflag =
true;
492 B2DEBUG(29,
"HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] <<
" -- ");
494 B2DEBUG(29,
"DHP Header | $" << hex << dhp_pix[2] <<
" ( " << dec << dhp_pix[2] <<
" ) ");
495 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
496 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
497 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
498 dhp_dhp_id = dhp_pix[2] & 0x0003;
500 B2DEBUG(29,
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
501 B2DEBUG(29,
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
502 B2DEBUG(29,
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
503 B2DEBUG(29,
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
505 if (dhe_ID != dhp_dhe_id) {
507 B2WARNING(
"DHE ID in DHE and DHP header differ");
508 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
512 if (dhe_DHPport != dhp_dhp_id) {
514 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
515 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
520 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
522 B2WARNING(
"Header type invalid for this kind of DHE frame");
523 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
532 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
533 B2DEBUG(29,
"DHP Frame Nr | $" << hex << dhp_readout_frame_lo <<
" ( " << dec << dhp_readout_frame_lo <<
" ) ");
578 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
581 B2WARNING(
"DHP data: seems to be double header! skipping.");
582 B2DEBUG(29,
"DHP data: seems to be double header! skipping." <<
LogVar(
"Length",
591 for (
unsigned int i = 4; i < nr_words ; i++) {
593 B2DEBUG(29,
"-- $" << hex << dhp_pix[i] <<
" -- " << dec << i);
595 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
602 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
603 dhp_cm = dhp_pix[i] & 0x3F;
605 B2WARNING(
"DHP data loss (CM=63) in " <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhp_dhp_id));
618 B2DEBUG(29,
"SetRow: $" << hex << dhp_row <<
" CM $" << hex << dhp_cm);
621 if (!(
m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING(
"DHP Unpacking: Pix without Row!!! skip dhp data ");
627 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
628 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
629 unsigned int v_cellID, u_cellID;
631 if (dhp_row >= 768) {
640 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
647 u_cellID = dhp_col + 64 * dhp_dhp_id;
649 if (u_cellID >= 250) {
651 B2WARNING(
"DHP COL Overflow (unconnected drain lines)");
652 B2DEBUG(29,
"DHP COL Overflow (unconnected drain lines) " << u_cellID <<
", reformat " << dhe_reformat <<
", dhpcol " << dhp_col <<
653 ", id " << dhp_dhp_id);
657 auto dhp_adc = dhp_pix[i] & 0xFF;
658 B2DEBUG(29,
"SetPix: Row $" << hex << dhp_row <<
" Col $" << hex << dhp_col <<
" ADC $" << hex << dhp_adc
659 <<
" CM $" << hex << dhp_cm);
670 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) & 0x3F);
676 B2DEBUG(29,
"(DHE) DHE_ID $" << hex << dhe_ID <<
" (DHE) DHP ID $" << hex << dhe_DHPport <<
" (DHP) DHE_ID $" << hex << dhp_dhe_id
677 <<
" (DHP) DHP ID $" << hex << dhp_dhp_id);
688 unsigned int dhe_ID,
unsigned dhe_DHPport,
unsigned dhe_reformat,
VxdID vxd_id,
691 unsigned int nr_words = frame_len / 2;
694 unsigned int dhp_readout_frame_lo = 0;
695 unsigned int dhp_header_type = 0;
696 unsigned int dhp_reserved = 0;
697 unsigned int dhp_dhe_id = 0;
698 unsigned int dhp_dhp_id = 0;
699 unsigned int wrap = 0;
703 unsigned int dhp_row = 0, dhp_col = 0, dhp_cm = 0;
705 bool rowflag =
false;
706 bool pixelflag =
true;
714 B2DEBUG(29,
"HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] <<
" -- ");
716 B2DEBUG(29,
"DHP Header | $" << hex << dhp_pix[2] <<
" ( " << dec << dhp_pix[2] <<
" ) ");
717 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
718 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
719 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
720 dhp_dhp_id = dhp_pix[2] & 0x0003;
722 B2DEBUG(29,
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
723 B2DEBUG(29,
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
724 B2DEBUG(29,
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
725 B2DEBUG(29,
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
727 if (dhe_ID != dhp_dhe_id) {
729 B2WARNING(
"DHE ID in DHE and DHP header differ");
730 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
734 if (dhe_DHPport != dhp_dhp_id) {
736 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
737 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
742 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
744 B2WARNING(
"Header type invalid for this kind of DHE frame");
745 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
754 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
755 B2DEBUG(29,
"DHP Frame Nr | $" << hex << dhp_readout_frame_lo <<
" ( " << dec << dhp_readout_frame_lo <<
" ) ");
798 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
801 B2WARNING(
"DHP data: seems to be double header! skipping.");
802 B2DEBUG(29,
"DHP data: seems to be double header! skipping." <<
LogVar(
"Length",
811 for (
unsigned int i = 4; i < nr_words ; i++) {
813 B2DEBUG(29,
"-- $" << hex << dhp_pix[i] <<
" -- " << dec << i);
815 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
822 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
823 dhp_cm = dhp_pix[i] & 0x3F;
824 if (last_gate != -1 && (
int)dhp_row / 4 < last_gate) {
828 last_gate = dhp_row / 4;
831 B2WARNING(
"DHP data loss (CM=63) in " <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhp_dhp_id));
844 B2DEBUG(29,
"SetRow: $" << hex << dhp_row <<
" CM $" << hex << dhp_cm);
847 if (!(
m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING(
"DHP Unpacking: Pix without Row!!! skip dhp data ");
853 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
854 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
855 unsigned int v_cellID, u_cellID;
857 if (dhp_row >= 768) {
866 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
873 u_cellID = dhp_col + 64 * dhp_dhp_id;
875 if (u_cellID >= 250) {
877 B2WARNING(
"DHP COL Overflow (unconnected drain lines)");
878 B2DEBUG(29,
"DHP COL Overflow (unconnected drain lines) " << u_cellID <<
", reformat " << dhe_reformat <<
", dhpcol " << dhp_col <<
879 ", id " << dhp_dhp_id);
883 auto dhp_adc = dhp_pix[i] & 0xFF;
884 B2DEBUG(29,
"SetPix: Row $" << hex << dhp_row <<
" Col $" << hex << dhp_col <<
" ADC $" << hex << dhp_adc
885 <<
" CM $" << hex << dhp_cm);
897 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo + wrap) & 0x3F);
903 B2DEBUG(29,
"(DHE) DHE_ID $" << hex << dhe_ID <<
" (DHE) DHP ID $" << hex << dhe_DHPport <<
" (DHP) DHE_ID $" << hex << dhp_dhe_id
904 <<
" (DHP) DHP ID $" << hex << dhp_dhp_id);
921 static unsigned int eventNrOfOnsenTrgFrame = 0;
922 static int countedBytesInDHC = 0;
923 static bool cancheck_countedBytesInDHC =
false;
924 static int countedBytesInDHE = 0;
925 static bool cancheck_countedBytesInDHE =
false;
926 static int countedDHEStartFrames = 0;
927 static int countedDHEEndFrames = 0;
928 static int mask_active_dhe = 0;
929 static int nr_active_dhe =
931 static int mask_active_dhp = 0;
932 static int found_mask_active_dhp = 0;
933 static unsigned int dhe_first_readout_frame_id_lo = 0;
935 static unsigned int dhe_first_triggergate = 0;
936 static unsigned int currentDHCID = 0xFFFFFFFF;
937 static unsigned int currentDHEID = 0xFFFFFFFF;
938 static unsigned int currentVxdId = 0;
939 static bool isFakedData_event =
false;
940 static bool isUnfiltered_event =
false;
943 if (Frame_Number == 0) {
946 eventNrOfOnsenTrgFrame = 0;
947 countedDHEStartFrames = 0;
948 countedDHEEndFrames = 0;
949 countedBytesInDHC = 0;
950 cancheck_countedBytesInDHC =
false;
951 countedBytesInDHE = 0;
952 cancheck_countedBytesInDHE =
false;
953 currentDHCID = 0xFFFFFFFF;
954 currentDHEID = 0xFFFFFFFF;
956 isUnfiltered_event =
false;
957 isFakedData_event =
false;
961 found_mask_active_dhp = 0;
974 if (len != s && s != 0) {
976 B2WARNING(
"Fixed frame type size does not match specs" <<
LogVar(
"expected length",
977 len) <<
LogVar(
"length in data", s));
995 if (Frame_Number == 0) {
997 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
998 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"This looks not like BonnDAQ format.");
1003 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1005 B2WARNING(
"This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
1013 if (Frame_Number == 1) {
1014 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1022 if (!isFakedData_event) {
1024 B2WARNING(
"Event Numbers do not match for this frame");
1025 B2DEBUG(29,
"Event Numbers do not match for this frame" <<
1026 LogVar(
"Event nr in frame $",
static_cast < std::ostringstream
1027 &&
>(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
1028 LogVar(
"Event nr in MetaInfo (bits masked) $",
1029 static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_event_nr).str()));
1036 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
1037 if (countedDHEStartFrames != countedDHEEndFrames + 1)
1038 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1039 if (!(
m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING(
"Data Frame outside a DHE START/END");
1050 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
1054 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
1059 switch (frame_type) {
1060 case EDHCFrameHeaderDataType::c_DHP_RAW: {
1065 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1066 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1067 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1069 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1083 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
1085 cancheck_countedBytesInDHC =
false;
1086 cancheck_countedBytesInDHE =
false;
1088 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
1091 if (isUnfiltered_event) {
1092 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP)
m_errorMask[c_nrSENDALL_TYPE] =
true;
1094 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD)
m_errorMask[c_nrNOTSENDALL_TYPE] =
true;
1101 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1102 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1103 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1105 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1115 dhe_first_readout_frame_id_lo,
1119 currentVxdId, daqpktstat);
1123 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
1125 cancheck_countedBytesInDHC =
false;
1126 cancheck_countedBytesInDHE =
false;
1128 case EDHCFrameHeaderDataType::c_FCE_RAW: {
1129 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (Clustering FCE)");
1132 if (isUnfiltered_event) {
1133 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
1138 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
1146 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1147 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1148 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1150 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1157 B2DEBUG(29,
"UNPACK FCE FRAME with len $" << hex << len);
1158 unpack_fce((
unsigned short*) data, len - 4, currentVxdId);
1162 case EDHCFrameHeaderDataType::c_COMMODE: {
1164 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (COMMODE)");
1170 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1171 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1172 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1174 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1181 case EDHCFrameHeaderDataType::c_DHC_START: {
1182 countedBytesInDHC = 0;
1183 cancheck_countedBytesInDHC =
true;
1185 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC START mixed Fake/no Fake event.");
1189 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC START Data -> trigger without Data!");
1196 currentDHEID = 0xFFFFFFFF;
1203 if (!isFakedData_event) {
1208 B2WARNING(
"DHC-Meta Experiment number mismatch");
1209 B2DEBUG(29,
"DHC-Meta Experiment number mismatch" <<
1218 B2WARNING(
"DHC-Meta Run number mismatch");
1219 B2DEBUG(29,
"DHC-Meta Run number mismatch" <<
1228 B2WARNING(
"DHC-Meta Sub-Run number mismatch");
1229 B2DEBUG(29,
"DHC-Meta Sub-Run number mismatch" <<
1239 B2WARNING(
"DHC-Meta 32 bit event number mismatch");
1240 B2DEBUG(29,
"DHC-Meta 32 bit event number mismatch" <<
1255 B2WARNING(
"DHC-Meta TimeTag mismatch");
1256 B2DEBUG(29,
"DHC-Meta TimeTag mismatch" <<
1257 LogVar(
"Header Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() <<
1261 LogVar(
"Meta Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_time).str()) <<
1262 LogVar(
"Trigger Type",
static_cast < std::ostringstream
1264 LogVar(
"Meta seconds: $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_sec).str()) <<
1265 LogVar(
"DHC seconds $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_sec).str()) <<
1266 LogVar(
"Seconds difference $",
static_cast < std::ostringstream
1267 &&
>(std::ostringstream() << hex << (trig_sec -
m_meta_sec)).str()) <<
1268 LogVar(
"Meta ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_ticks).str()) <<
1269 LogVar(
"DHC ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_ticks).str()) <<
1270 LogVar(
"Tick difference $",
static_cast < std::ostringstream
1271 &&
>(std::ostringstream() << hex << (trig_ticks -
m_meta_ticks)).str()));
1280 nr_active_dhe =
nr5bits(mask_active_dhe);
1289 case EDHCFrameHeaderDataType::c_DHE_START: {
1290 countedBytesInDHE = 0;
1291 cancheck_countedBytesInDHE =
true;
1301 B2WARNING(
"DHH IDs are not in expected order");
1302 B2DEBUG(29,
"DHH IDs are not in expected order" <<
1303 LogVar(
"Previous ID", (currentDHEID & 0xFFFF)) <<
1311 if (countedDHEStartFrames > countedDHEEndFrames) {
1315 countedDHEStartFrames++;
1317 found_mask_active_dhp = 0;
1323 B2WARNING(
"DHE START trigger mismatch in EVT32b/HI WORD");
1324 B2DEBUG(29,
"DHE START trigger mismatch in EVT32b/HI WORD" <<
1333 if (currentDHEID == 0) {
1334 if (!(
m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING(
"DHE ID is invalid=0 (not initialized)");
1345 unsigned short sensor, ladder, layer;
1346 sensor = (currentDHEID & 0x1) + 1;
1347 ladder = (currentDHEID & 0x1E) >> 1;
1348 layer = ((currentDHEID & 0x20) >> 5) + 1;
1349 currentVxdId =
VxdID(layer, ladder, sensor);
1350 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
1352 B2WARNING(
"DHE ID is invalid");
1353 B2DEBUG(29,
"DHE ID is invalid" <<
1354 LogVar(
"DHE ID", currentDHEID) <<
1355 LogVar(
"Layer", layer) <<
1356 LogVar(
"Ladder", ladder) <<
1357 LogVar(
"Sensor", sensor));
1366 daqpktstat.
dhc_back().
newDHE(currentVxdId, currentDHEID,
m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
1370 case EDHCFrameHeaderDataType::c_GHOST:
1374 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1387 case EDHCFrameHeaderDataType::c_DHC_END: {
1389 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC END mixed Fake/no Fake event.");
1393 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC END Data -> trigger without Data!");
1399 if (!isFakedData_event) {
1402 B2WARNING(
"DHC ID Mismatch between Start and End");
1403 B2DEBUG(29,
"DHC ID Mismatch between Start and End $" << std::hex <<
1410 if (cancheck_countedBytesInDHC) {
1411 if (countedBytesInDHC != w) {
1413 B2WARNING(
"Number of Words in DHC END does not match");
1414 B2DEBUG(29,
"Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC <<
" != DHC END $" << hex << w);
1419 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHC <<
" == DHC END $" << hex << w);
1426 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHC END Error Info set to $" << hex <<
1443 currentDHEID = 0xFFFFFFFF;
1444 currentDHCID = 0xFFFFFFFF;
1448 case EDHCFrameHeaderDataType::c_DHE_END: {
1452 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1453 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID <<
" != $" <<
1460 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHE END Error Info set to $" << hex <<
1465 if (found_mask_active_dhp != mask_active_dhp) {
1467 B2WARNING(
"DHE_END: DHP active mask differs from found data");
1468 B2DEBUG(29,
"DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp <<
" != $" << hex <<
1469 found_mask_active_dhp
1470 <<
" mask of found dhp/ghost frames");
1474 countedDHEEndFrames++;
1475 if (countedDHEStartFrames < countedDHEEndFrames) {
1483 if (cancheck_countedBytesInDHE) {
1484 if (countedBytesInDHE != w) {
1486 B2WARNING(
"Number of Words in DHE END does not match");
1487 B2DEBUG(29,
"Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE <<
" != DHE END $" << hex << w);
1492 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHE <<
" == DHE END $" << hex << w);
1511 currentDHEID |= 0xFF000000;
1515 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
1532 m_storeROIs.appendNew(l, &((
unsigned int*) data)[1]);
1536 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
1537 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
1540 B2WARNING(
"Trigger Frame HLT Trigger Nr mismatch");
1541 B2DEBUG(29,
"Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
1550 B2WARNING(
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
1551 B2DEBUG(29,
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
1562 B2WARNING(
"Trigger Frame DATCON Trigger Nr mismatch");
1563 B2DEBUG(29,
"Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
1572 B2WARNING(
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
1573 B2DEBUG(29,
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
1588 if (Frame_Number != 0) {
1589 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"ONSEN TRG Frame must be the first one.");
1604 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
1606 B2WARNING(
"Frame TrigNr != ONSEN Trig Nr");
1607 B2DEBUG(29,
"Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame <<
" != $" << eventNrOfOnsenTrgFrame);
1612 if (Frame_Number == 0) {
1614 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1616 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"First frame is not a ONSEN Trigger frame");
1622 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1623 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"More than one ONSEN Trigger frame");
1629 if (Frame_Number == 1) {
1631 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1632 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"Second frame is not a DHC start of subevent frame");
1637 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1638 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"More than one DHC start of subevent frame");
1644 if (Frame_Number == Frames_in_event - 1) {
1646 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
1647 if (!(
m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING(
"Last frame is not a DHC end of subevent frame");
1652 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
1655 B2WARNING(
"The number of DHE Start/End does not match the number of active DHE in DHC Header!");
1656 B2DEBUG(29,
"The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
1657 " Start: " << countedDHEStartFrames <<
" End: " << countedDHEEndFrames <<
" Mask: $" << hex << mask_active_dhe <<
" in Event Nr " <<
1658 eventNrOfThisFrame);
1660 if (countedDHEStartFrames == countedDHEEndFrames)
m_errorMask[c_nrDHE_ACTIVE] =
true;
1661 if (countedDHEStartFrames > countedDHEEndFrames)
m_errorMask[c_nrDHE_START_WO_END] =
true;
1662 if (countedDHEStartFrames < countedDHEEndFrames)
m_errorMask[c_nrDHE_END_WO_START] =
true;
1667 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
1668 if (!(
m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING(
"More than one DHC end of subevent frame");
1675 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1676 if (!(
m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING(
"Third frame is not a DHE start frame");
1681 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1683 countedBytesInDHC += len;
1684 countedBytesInDHE += len;
1686 B2DEBUG(29,
"DHC/DHE $" << hex << countedBytesInDHC <<
", $" << hex << countedBytesInDHE);
1696 static unsigned int eventNrOfOnsenTrgFrame = 0;
1697 static int countedBytesInDHC = 0;
1698 static bool cancheck_countedBytesInDHC =
false;
1699 static int countedBytesInDHE = 0;
1700 static bool cancheck_countedBytesInDHE =
false;
1701 static int countedDHEStartFrames = 0;
1702 static int countedDHEEndFrames = 0;
1703 static int mask_active_dhe = 0;
1704 static int nr_active_dhe =
1706 static int mask_active_dhp = 0;
1707 static int found_mask_active_dhp = 0;
1708 static int found_good_mask_active_dhp = 0;
1709 static unsigned int dhe_first_readout_frame_id_lo = 0;
1711 static unsigned int dhe_first_triggergate = 0;
1712 static unsigned int currentDHCID = 0xFFFFFFFF;
1713 static unsigned int currentDHEID = 0xFFFFFFFF;
1714 static unsigned int currentVxdId = 0;
1715 static bool isFakedData_event =
false;
1716 static bool isUnfiltered_event =
false;
1719 if (Frame_Number == 0) {
1722 eventNrOfOnsenTrgFrame = 0;
1723 countedDHEStartFrames = 0;
1724 countedDHEEndFrames = 0;
1725 countedBytesInDHC = 0;
1726 cancheck_countedBytesInDHC =
false;
1727 countedBytesInDHE = 0;
1728 cancheck_countedBytesInDHE =
false;
1729 currentDHCID = 0xFFFFFFFF;
1730 currentDHEID = 0xFFFFFFFF;
1732 isUnfiltered_event =
false;
1733 isFakedData_event =
false;
1734 mask_active_dhe = 0;
1736 mask_active_dhp = 0;
1737 found_mask_active_dhp = 0;
1738 found_good_mask_active_dhp = 0;
1751 if (len != s && s != 0) {
1753 B2WARNING(
"Fixed frame type size does not match specs" <<
LogVar(
"expected length",
1754 len) <<
LogVar(
"length in data", s));
1772 if (Frame_Number == 0) {
1774 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1775 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"This looks not like BonnDAQ format.");
1780 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1782 B2WARNING(
"This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
1790 if (Frame_Number == 1) {
1791 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1799 if (!isFakedData_event) {
1801 B2WARNING(
"Event Numbers do not match for this frame");
1802 B2DEBUG(29,
"Event Numbers do not match for this frame" <<
1803 LogVar(
"Event nr in frame $",
static_cast < std::ostringstream
1804 &&
>(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
1805 LogVar(
"Event nr in MetaInfo (bits masked) $",
1806 static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_event_nr).str()));
1813 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
1814 if (countedDHEStartFrames != countedDHEEndFrames + 1)
1815 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1816 if (!(
m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING(
"Data Frame outside a DHE START/END");
1827 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
1834 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
1839 switch (frame_type) {
1840 case EDHCFrameHeaderDataType::c_DHP_RAW: {
1845 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1846 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1847 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1849 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1855 B2ERROR(
"Second DHP data packet (MEMDUMP) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
1868 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
1870 cancheck_countedBytesInDHC =
false;
1871 cancheck_countedBytesInDHE =
false;
1873 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
1876 if (isUnfiltered_event) {
1877 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP)
m_errorMask[c_nrSENDALL_TYPE] =
true;
1879 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD)
m_errorMask[c_nrNOTSENDALL_TYPE] =
true;
1886 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1887 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1888 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1890 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1904 dhe_first_readout_frame_id_lo,
1908 currentVxdId, daqpktstat);
1912 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
1914 cancheck_countedBytesInDHC =
false;
1915 cancheck_countedBytesInDHE =
false;
1917 case EDHCFrameHeaderDataType::c_FCE_RAW: {
1918 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (Clustering FCE)");
1921 if (isUnfiltered_event) {
1922 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
1927 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
1935 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1936 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1937 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1939 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1945 B2ERROR(
"Second DHP data packet (FCE) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
1950 B2DEBUG(29,
"UNPACK FCE FRAME with len $" << hex << len);
1951 unpack_fce((
unsigned short*) data, len - 4, currentVxdId);
1955 case EDHCFrameHeaderDataType::c_COMMODE: {
1958 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (COMMODE)");
1964 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1965 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1966 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1968 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1975 case EDHCFrameHeaderDataType::c_DHC_START: {
1976 countedBytesInDHC = 0;
1977 cancheck_countedBytesInDHC =
true;
1979 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC START mixed Fake/no Fake event.");
1983 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC START Data -> trigger without Data!");
1990 currentDHEID = 0xFFFFFFFF;
1997 if (!isFakedData_event) {
2002 B2WARNING(
"DHC-Meta Experiment number mismatch");
2003 B2DEBUG(29,
"DHC-Meta Experiment number mismatch" <<
2012 B2WARNING(
"DHC-Meta Run number mismatch");
2013 B2DEBUG(29,
"DHC-Meta Run number mismatch" <<
2022 B2WARNING(
"DHC-Meta Sub-Run number mismatch");
2023 B2DEBUG(29,
"DHC-Meta Sub-Run number mismatch" <<
2033 B2WARNING(
"DHC-Meta 32 bit event number mismatch");
2034 B2DEBUG(29,
"DHC-Meta 32 bit event number mismatch" <<
2049 B2WARNING(
"DHC-Meta TimeTag mismatch");
2050 B2DEBUG(29,
"DHC-Meta TimeTag mismatch" <<
2051 LogVar(
"Header Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() <<
2055 LogVar(
"Meta Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_time).str()) <<
2056 LogVar(
"Trigger Type",
static_cast < std::ostringstream
2058 LogVar(
"Meta seconds: $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_sec).str()) <<
2059 LogVar(
"DHC seconds $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_sec).str()) <<
2060 LogVar(
"Seconds difference $",
static_cast < std::ostringstream
2061 &&
>(std::ostringstream() << hex << (trig_sec -
m_meta_sec)).str()) <<
2062 LogVar(
"Meta ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_ticks).str()) <<
2063 LogVar(
"DHC ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_ticks).str()) <<
2064 LogVar(
"Tick difference $",
static_cast < std::ostringstream
2065 &&
>(std::ostringstream() << hex << (trig_ticks -
m_meta_ticks)).str()));
2074 nr_active_dhe =
nr5bits(mask_active_dhe);
2083 case EDHCFrameHeaderDataType::c_DHE_START: {
2084 countedBytesInDHE = 0;
2085 cancheck_countedBytesInDHE =
true;
2095 B2WARNING(
"DHH IDs are not in expected order");
2096 B2DEBUG(29,
"DHH IDs are not in expected order" <<
2097 LogVar(
"Previous ID", (currentDHEID & 0xFFFF)) <<
2105 if (countedDHEStartFrames > countedDHEEndFrames) {
2109 countedDHEStartFrames++;
2111 found_mask_active_dhp = 0;
2112 found_good_mask_active_dhp = 0;
2118 B2WARNING(
"DHE START trigger mismatch in EVT32b/HI WORD");
2119 B2DEBUG(29,
"DHE START trigger mismatch in EVT32b/HI WORD" <<
2128 if (currentDHEID == 0) {
2129 if (!(
m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING(
"DHE ID is invalid=0 (not initialized)");
2140 unsigned short sensor, ladder, layer;
2141 sensor = (currentDHEID & 0x1) + 1;
2142 ladder = (currentDHEID & 0x1E) >> 1;
2143 layer = ((currentDHEID & 0x20) >> 5) + 1;
2144 currentVxdId =
VxdID(layer, ladder, sensor);
2145 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
2147 B2WARNING(
"DHE ID is invalid");
2148 B2DEBUG(29,
"DHE ID is invalid" <<
2149 LogVar(
"DHE ID", currentDHEID) <<
2150 LogVar(
"Layer", layer) <<
2151 LogVar(
"Ladder", ladder) <<
2152 LogVar(
"Sensor", sensor));
2161 daqpktstat.
dhc_back().
newDHE(currentVxdId, currentDHEID,
m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
2165 case EDHCFrameHeaderDataType::c_GHOST:
2169 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
2183 case EDHCFrameHeaderDataType::c_DHC_END: {
2185 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC END mixed Fake/no Fake event.");
2189 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC END Data -> trigger without Data!");
2195 if (!isFakedData_event) {
2198 B2WARNING(
"DHC ID Mismatch between Start and End");
2199 B2DEBUG(29,
"DHC ID Mismatch between Start and End $" << std::hex <<
2206 if (cancheck_countedBytesInDHC) {
2207 if (countedBytesInDHC != w) {
2209 B2WARNING(
"Number of Words in DHC END does not match");
2210 B2DEBUG(29,
"Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC <<
" != DHC END $" << hex << w);
2215 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHC <<
" == DHC END $" << hex << w);
2222 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHC END Error Info set to $" << hex <<
2239 currentDHEID = 0xFFFFFFFF;
2240 currentDHCID = 0xFFFFFFFF;
2244 case EDHCFrameHeaderDataType::c_DHE_END: {
2248 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
2249 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID <<
" != $" <<
2262 if (found_mask_active_dhp != mask_active_dhp) {
2264 B2WARNING(
"DHE_END: DHP active mask differs from found data");
2265 B2DEBUG(29,
"DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp <<
" != $" << hex <<
2266 found_mask_active_dhp
2267 <<
" mask of found dhp/ghost frames");
2271 countedDHEEndFrames++;
2272 if (countedDHEStartFrames < countedDHEEndFrames) {
2280 if (cancheck_countedBytesInDHE) {
2281 if (countedBytesInDHE != w) {
2283 B2WARNING(
"Number of Words in DHE END does not match");
2284 B2DEBUG(29,
"Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE <<
" != DHE END $" << hex << w);
2289 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHE <<
" == DHE END $" << hex << w);
2309 currentDHEID |= 0xFF000000;
2313 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
2330 m_storeROIs.appendNew(l, &((
unsigned int*) data)[1]);
2334 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
2335 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
2338 B2WARNING(
"Trigger Frame HLT Trigger Nr mismatch");
2339 B2DEBUG(29,
"Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
2348 B2WARNING(
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
2349 B2DEBUG(29,
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
2360 B2WARNING(
"Trigger Frame DATCON Trigger Nr mismatch");
2361 B2DEBUG(29,
"Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
2370 B2WARNING(
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
2371 B2DEBUG(29,
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
2386 if (Frame_Number != 0) {
2387 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"ONSEN TRG Frame must be the first one.");
2402 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
2404 B2WARNING(
"Frame TrigNr != ONSEN Trig Nr");
2405 B2DEBUG(29,
"Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame <<
" != $" << eventNrOfOnsenTrgFrame);
2410 if (Frame_Number == 0) {
2412 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
2414 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"First frame is not a ONSEN Trigger frame");
2420 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
2421 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"More than one ONSEN Trigger frame");
2427 if (Frame_Number == 1) {
2429 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
2430 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"Second frame is not a DHC start of subevent frame");
2435 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
2436 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"More than one DHC start of subevent frame");
2442 if (Frame_Number == Frames_in_event - 1) {
2444 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
2445 if (!(
m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING(
"Last frame is not a DHC end of subevent frame");
2450 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
2453 B2WARNING(
"The number of DHE Start/End does not match the number of active DHE in DHC Header!");
2454 B2DEBUG(29,
"The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
2455 " Start: " << countedDHEStartFrames <<
" End: " << countedDHEEndFrames <<
" Mask: $" << hex << mask_active_dhe <<
" in Event Nr " <<
2456 eventNrOfThisFrame);
2458 if (countedDHEStartFrames == countedDHEEndFrames)
m_errorMask[c_nrDHE_ACTIVE] =
true;
2459 if (countedDHEStartFrames > countedDHEEndFrames)
m_errorMask[c_nrDHE_START_WO_END] =
true;
2460 if (countedDHEStartFrames < countedDHEEndFrames)
m_errorMask[c_nrDHE_END_WO_START] =
true;
2465 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
2466 if (!(
m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING(
"More than one DHC end of subevent frame");
2473 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
2474 if (!(
m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING(
"Third frame is not a DHE start frame");
2479 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
2481 countedBytesInDHC += len;
2482 countedBytesInDHE += len;
2484 B2DEBUG(29,
"DHC/DHE $" << hex << countedBytesInDHC <<
", $" << hex << countedBytesInDHE);
2490 const int lut[32] = {
2491 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
2492 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5
2494 return lut[i & 0x1F];
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
void setReturnValue(int value)
Sets the return value for this module as integer.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
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 setDHPFoundMask(unsigned short dhpmask)
set Mask for found DHPs with valid data
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask.
auto addCM(PXDDAQDHPComMode &daqcm)
Add Common Mode information.
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.
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.
int m_overrideFirmwareVersion
override firmware version from DB.
std::string m_PXDRawHitsName
The name of the StoreArray of PXDRawHits to be generated.
void unpack_dhc_frame_v01(void *data, const int length, const int Frame_Number, const int Frames_in_event, PXDDAQPacketStatus &daqpktstat)
==== the functions for the "old" firmware ====
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.
bool m_checkPaddingCRC
Check for susp.
PXDError::PXDErrorFlags m_errorMaskPacket
Error Mask set per packet / packet.
std::string m_RawPXDsName
The name of the StoreArray of processed RawPXDs.
void unpack_dhc_frame_v10(void *data, const int length, const int Frame_Number, const int Frames_in_event, PXDDAQPacketStatus &daqpktstat)
==== the functions for the "new" firmware ====
void unpack_dhp_v01(void *data, unsigned int length, 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.
PXDUnpackerModule()
Constructor defining the parameters.
unsigned long m_meta_event_nr
Event Number from MetaInfo.
OptionalDBObjPtr< PXDDHHFirmwareVersionPar > m_firmwareFromDB
firmware version from DB.
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.
int m_firmware
Firmware version, must be read from database on run change.
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)
PXDError::PXDErrorFlags m_criticalErrorMask
Critical error mask which defines return value of task.
void beginRun() override final
Begin Run.
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.
void unpack_dhp_raw(void *data, unsigned int length, unsigned int dhe_ID, unsigned dhe_DHPport, VxdID vxd_id)
==== more firmware version independent functions ====
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.
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.
void unpack_dhp_v10(void *data, unsigned int length, 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.
std::string m_PXDRawROIsName
The name of the StoreArray of PXDRawROIs to be generated.
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.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#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_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.
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