9#include <pxd/unpacking/PXDRawDataDefinitions.h>
10#include <pxd/unpacking/PXDRawDataStructs.h>
11#include <pxd/unpacking/PXDMappingLookup.h>
12#include <pxd/modules/pxdUnpacking/PXDUnpackerModule.h>
13#include <framework/datastore/DataStore.h>
14#include <framework/logging/Logger.h>
15#include <framework/datastore/StoreObjPtr.h>
20using namespace Belle2::PXD::PXDError;
45 addParam(
"RawPXDsName",
m_RawPXDsName,
"The name of the StoreArray of RawPXDs to be processed", std::string(
""));
63 addParam(
"Verbose",
m_verbose,
"Turn on extra verbosity for log-level debug",
false);
101 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++)
m_errorCounter[i] = 0;
109 else B2FATAL(
"Cannot get PXD Firmware version from db");
118 string errstr =
"Statistic ( ;";
122 B2RESULT(
"PXD Unpacker --> Error Statistics (counted once per event!) in Events: " <<
m_unpackedEventsCount);
123 B2RESULT(errstr +
" )");
124 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
149 B2DEBUG(29,
"PXD Unpacker --> RawPXD Objects in event: " <<
LogVar(
"Objects", nRaws));
162 B2DEBUG(29,
"PXD Unpacker --> Unpack Objects: ");
174 for (
unsigned int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
195 if (px.
size() <= 0 || px.
size() > 16 * 1024 * 1024) {
197 B2WARNING(
"PXD Unpacker --> invalid packet size" <<
198 LogVar(
"size [32bit words] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << px.
size()).str()));
203 std::vector<unsigned int> data(px.
size());
204 fullsize = px.
size() * 4;
205 std::copy_n(px.
data(), px.
size(), data.begin());
209 B2WARNING(
"Data is to small to hold a valid Header! Will not unpack anything." <<
LogVar(
"size [32bit words] $",
210 static_cast < std::ostringstream &&
>(std::ostringstream() << hex << fullsize).str()));
216 if (data[0] != 0xCAFEBABE && data[0] != 0xBEBAFECA) {
218 B2WARNING(
"Magic invalid: Will not unpack anything. Header corrupted." <<
219 LogVar(
"Header Magic $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << data[0]).str()));
226 Frames_in_event = ((
ubig32_t*)data.data())[1];
227 if (Frames_in_event < 0 || Frames_in_event > 256) {
229 B2WARNING(
"Number of Frames invalid: Will not unpack anything. Header corrupted!" <<
LogVar(
"Frames in event", Frames_in_event));
234 if (Frames_in_event < 3) {
236 B2WARNING(
"Number of Frames too small: It cannot contain anything useful." <<
LogVar(
"Frames in event", Frames_in_event));
243 B2DEBUG(29,
"PXD Unpacker --> data[0]: <-- Magic $" << hex << data[0]);
244 B2DEBUG(29,
"PXD Unpacker --> data[1]: <-- #Frames $" << hex << data[1]);
245 if (data[1] >= 1 && fullsize < 12) B2DEBUG(29,
"PXD Unpacker --> data[2]: <-- Frame 1 len $" << hex << data[2]);
246 if (data[1] >= 2 && fullsize < 16) B2DEBUG(29,
"PXD Unpacker --> data[3]: <-- Frame 2 len $" << hex << data[3]);
247 if (data[1] >= 3 && fullsize < 20) B2DEBUG(29,
"PXD Unpacker --> data[4]: <-- Frame 3 len $" << hex << data[4]);
248 if (data[1] >= 4 && fullsize < 24) B2DEBUG(29,
"PXD Unpacker --> data[5]: <-- Frame 4 len $" << hex << data[5]);
251 unsigned int* tableptr;
254 unsigned int* dataptr;
255 dataptr = &tableptr[Frames_in_event];
256 datafullsize = fullsize - 2 * 4 - Frames_in_event * 4;
259 for (
int j = 0; j < Frames_in_event; j++) {
265 B2WARNING(
"size of frame invalid");
266 B2DEBUG(29,
"size of frame invalid: " << j <<
"size " << lo <<
" at byte offset in dataptr " << ll);
271 if (ll + lo > datafullsize) {
273 B2WARNING(
"Frames exceed packet size");
274 B2DEBUG(29,
"Frames exceed packet size: " << j <<
" size " << lo <<
" at byte offset in dataptr " << ll <<
" of datafullsize " <<
275 datafullsize <<
" of fullsize " << fullsize);
282 B2WARNING(
"SKIP Frame with Data with not MOD 4 length");
283 B2DEBUG(29,
"SKIP Frame with Data with not MOD 4 length " <<
" ( $" << hex << lo <<
" ) ");
285 ll += (lo + 3) & 0xFFFFFFFC;
288 B2DEBUG(29,
"unpack DHE(C) frame: " << j <<
" with size " << lo <<
" at byte offset in dataptr " << ll);
296 B2FATAL(
"Firmware Version not supported " <<
m_firmware);
331 if (frame_len != 0xC008) {
332 if (!(
m_suppressErrorMask[c_nrFIX_SIZE])) B2WARNING(
"Frame size unsupported for RAW ADC frame! $" <<
333 LogVar(
"size [bytes] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << frame_len).str())
334 <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhe_DHPport));
338 unsigned int dhp_header_type = 0;
340 unsigned int dhp_dhe_id = 0;
341 unsigned int dhp_dhp_id = 0;
343 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
345 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
346 dhp_dhp_id = dhp_pix[2] & 0x0003;
348 if (dhe_ID != dhp_dhe_id) {
350 B2WARNING(
"DHE ID in DHE and DHP header differ");
351 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
355 if (dhe_DHPport != dhp_dhp_id) {
357 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
358 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
363 if (dhp_header_type != EDHPFrameHeaderDataType::c_RAW) {
365 B2WARNING(
"Header type invalid for this kind of DHE frame");
366 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
373 B2DEBUG(29,
"Raw ADC Data");
379 [[maybe_unused]]
VxdID vxd_id)
388 B2WARNING(
"FCE (Cluster) Packet have not yet been tested with real HW clusters. Dont assume that this code is working!");
426 unsigned int w = frame_len / 2;
429 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- ");
431 auto dhp_header_type = (d[2] & 0xE000) >> 13;
432 auto dhp_reserved = (d[2] & 0x1F00) >> 8;
433 auto dhp_dhe_id = (d[2] & 0x00FC) >> 2;
434 auto dhp_dhp_id = d[2] & 0x0003;
436 B2WARNING(
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
437 B2WARNING(
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
438 B2WARNING(
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
439 B2WARNING(
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
440 for (
unsigned int i = 4; i < w; i++) {
441 B2WARNING(
"DHP DATA $" << hex << d[i]);
443 B2WARNING(
"DHP CRC $" << hex << d[w] <<
",$" << hex << d[w + 1]);
449 unsigned int w = frame_len / 4;
452 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- Len $" << hex
455 for (
unsigned int i = 0; i < w; i++) {
456 B2WARNING(
"ROI DATA $" << hex << d[i]);
458 B2WARNING(
"ROI CRC $" << hex << d[w]);
462 unsigned int dhe_ID,
unsigned dhe_DHPport,
unsigned dhe_reformat,
VxdID vxd_id,
465 unsigned int nr_words = frame_len / 2;
468 unsigned int dhp_readout_frame_lo = 0;
469 unsigned int dhp_header_type = 0;
470 unsigned int dhp_reserved = 0;
471 unsigned int dhp_dhe_id = 0;
472 unsigned int dhp_dhp_id = 0;
475 unsigned int dhp_row = 0, dhp_col = 0, dhp_cm = 0;
477 bool rowflag =
false;
478 bool pixelflag =
true;
486 B2DEBUG(29,
"HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] <<
" -- ");
488 B2DEBUG(29,
"DHP Header | $" << hex << dhp_pix[2] <<
" ( " << dec << dhp_pix[2] <<
" ) ");
489 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
490 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
491 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
492 dhp_dhp_id = dhp_pix[2] & 0x0003;
494 B2DEBUG(29,
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
495 B2DEBUG(29,
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
496 B2DEBUG(29,
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
497 B2DEBUG(29,
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
499 if (dhe_ID != dhp_dhe_id) {
501 B2WARNING(
"DHE ID in DHE and DHP header differ");
502 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
506 if (dhe_DHPport != dhp_dhp_id) {
508 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
509 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
514 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
516 B2WARNING(
"Header type invalid for this kind of DHE frame");
517 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
526 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
527 B2DEBUG(29,
"DHP Frame Nr | $" << hex << dhp_readout_frame_lo <<
" ( " << dec << dhp_readout_frame_lo <<
" ) ");
572 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
575 B2WARNING(
"DHP data: seems to be double header! skipping.");
576 B2DEBUG(29,
"DHP data: seems to be double header! skipping." <<
LogVar(
"Length",
585 for (
unsigned int i = 4; i < nr_words ; i++) {
587 B2DEBUG(29,
"-- $" << hex << dhp_pix[i] <<
" -- " << dec << i);
589 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
596 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
597 dhp_cm = dhp_pix[i] & 0x3F;
599 B2WARNING(
"DHP data loss (CM=63) in " <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhp_dhp_id));
612 B2DEBUG(29,
"SetRow: $" << hex << dhp_row <<
" CM $" << hex << dhp_cm);
615 if (!(
m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING(
"DHP Unpacking: Pix without Row!!! skip dhp data ");
621 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
622 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
623 unsigned int v_cellID, u_cellID;
625 if (dhp_row >= 768) {
634 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
641 u_cellID = dhp_col + 64 * dhp_dhp_id;
643 if (u_cellID >= 250) {
645 B2WARNING(
"DHP COL Overflow (unconnected drain lines)");
646 B2DEBUG(29,
"DHP COL Overflow (unconnected drain lines) " << u_cellID <<
", reformat " << dhe_reformat <<
", dhpcol " << dhp_col <<
647 ", id " << dhp_dhp_id);
651 auto dhp_adc = dhp_pix[i] & 0xFF;
652 B2DEBUG(29,
"SetPix: Row $" << hex << dhp_row <<
" Col $" << hex << dhp_col <<
" ADC $" << hex << dhp_adc
653 <<
" CM $" << hex << dhp_cm);
664 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) & 0x3F);
670 B2DEBUG(29,
"(DHE) DHE_ID $" << hex << dhe_ID <<
" (DHE) DHP ID $" << hex << dhe_DHPport <<
" (DHP) DHE_ID $" << hex << dhp_dhe_id
671 <<
" (DHP) DHP ID $" << hex << dhp_dhp_id);
682 unsigned int dhe_ID,
unsigned dhe_DHPport,
unsigned dhe_reformat,
VxdID vxd_id,
685 unsigned int nr_words = frame_len / 2;
688 unsigned int dhp_readout_frame_lo = 0;
689 unsigned int dhp_header_type = 0;
690 unsigned int dhp_reserved = 0;
691 unsigned int dhp_dhe_id = 0;
692 unsigned int dhp_dhp_id = 0;
693 unsigned int wrap = 0;
697 unsigned int dhp_row = 0, dhp_col = 0, dhp_cm = 0;
699 bool rowflag =
false;
700 bool pixelflag =
true;
708 B2DEBUG(29,
"HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] <<
" -- ");
710 B2DEBUG(29,
"DHP Header | $" << hex << dhp_pix[2] <<
" ( " << dec << dhp_pix[2] <<
" ) ");
711 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
712 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
713 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
714 dhp_dhp_id = dhp_pix[2] & 0x0003;
716 B2DEBUG(29,
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
717 B2DEBUG(29,
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
718 B2DEBUG(29,
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
719 B2DEBUG(29,
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
721 if (dhe_ID != dhp_dhe_id) {
723 B2WARNING(
"DHE ID in DHE and DHP header differ");
724 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
728 if (dhe_DHPport != dhp_dhp_id) {
730 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
731 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
736 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
738 B2WARNING(
"Header type invalid for this kind of DHE frame");
739 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
748 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
749 B2DEBUG(29,
"DHP Frame Nr | $" << hex << dhp_readout_frame_lo <<
" ( " << dec << dhp_readout_frame_lo <<
" ) ");
792 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
795 B2WARNING(
"DHP data: seems to be double header! skipping.");
796 B2DEBUG(29,
"DHP data: seems to be double header! skipping." <<
LogVar(
"Length",
805 for (
unsigned int i = 4; i < nr_words ; i++) {
807 B2DEBUG(29,
"-- $" << hex << dhp_pix[i] <<
" -- " << dec << i);
809 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
816 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
817 dhp_cm = dhp_pix[i] & 0x3F;
818 if (last_gate != -1 && (
int)dhp_row / 4 < last_gate) {
822 last_gate = dhp_row / 4;
825 B2WARNING(
"DHP data loss (CM=63) in " <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhp_dhp_id));
838 B2DEBUG(29,
"SetRow: $" << hex << dhp_row <<
" CM $" << hex << dhp_cm);
841 if (!(
m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING(
"DHP Unpacking: Pix without Row!!! skip dhp data ");
847 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
848 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
849 unsigned int v_cellID, u_cellID;
851 if (dhp_row >= 768) {
860 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
867 u_cellID = dhp_col + 64 * dhp_dhp_id;
869 if (u_cellID >= 250) {
871 B2WARNING(
"DHP COL Overflow (unconnected drain lines)");
872 B2DEBUG(29,
"DHP COL Overflow (unconnected drain lines) " << u_cellID <<
", reformat " << dhe_reformat <<
", dhpcol " << dhp_col <<
873 ", id " << dhp_dhp_id);
877 auto dhp_adc = dhp_pix[i] & 0xFF;
878 B2DEBUG(29,
"SetPix: Row $" << hex << dhp_row <<
" Col $" << hex << dhp_col <<
" ADC $" << hex << dhp_adc
879 <<
" CM $" << hex << dhp_cm);
891 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo + wrap) & 0x3F);
897 B2DEBUG(29,
"(DHE) DHE_ID $" << hex << dhe_ID <<
" (DHE) DHP ID $" << hex << dhe_DHPport <<
" (DHP) DHE_ID $" << hex << dhp_dhe_id
898 <<
" (DHP) DHP ID $" << hex << dhp_dhp_id);
915 static unsigned int eventNrOfOnsenTrgFrame = 0;
916 static int countedBytesInDHC = 0;
917 static bool cancheck_countedBytesInDHC =
false;
918 static int countedBytesInDHE = 0;
919 static bool cancheck_countedBytesInDHE =
false;
920 static int countedDHEStartFrames = 0;
921 static int countedDHEEndFrames = 0;
922 static int mask_active_dhe = 0;
923 static int nr_active_dhe =
925 static int mask_active_dhp = 0;
926 static int found_mask_active_dhp = 0;
927 static unsigned int dhe_first_readout_frame_id_lo = 0;
929 static unsigned int dhe_first_triggergate = 0;
930 static unsigned int currentDHCID = 0xFFFFFFFF;
931 static unsigned int currentDHEID = 0xFFFFFFFF;
932 static unsigned int currentVxdId = 0;
933 static bool isFakedData_event =
false;
934 static bool isUnfiltered_event =
false;
937 if (Frame_Number == 0) {
940 eventNrOfOnsenTrgFrame = 0;
941 countedDHEStartFrames = 0;
942 countedDHEEndFrames = 0;
943 countedBytesInDHC = 0;
944 cancheck_countedBytesInDHC =
false;
945 countedBytesInDHE = 0;
946 cancheck_countedBytesInDHE =
false;
947 currentDHCID = 0xFFFFFFFF;
948 currentDHEID = 0xFFFFFFFF;
950 isUnfiltered_event =
false;
951 isFakedData_event =
false;
955 found_mask_active_dhp = 0;
968 if (len != s && s != 0) {
970 B2WARNING(
"Fixed frame type size does not match specs" <<
LogVar(
"expected length",
971 len) <<
LogVar(
"length in data", s));
989 if (Frame_Number == 0) {
991 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
992 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"This looks not like BonnDAQ format.");
997 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
999 B2WARNING(
"This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
1007 if (Frame_Number == 1) {
1008 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1016 if (!isFakedData_event) {
1018 B2WARNING(
"Event Numbers do not match for this frame");
1019 B2DEBUG(29,
"Event Numbers do not match for this frame" <<
1020 LogVar(
"Event nr in frame $",
static_cast < std::ostringstream
1021 &&
>(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
1022 LogVar(
"Event nr in MetaInfo (bits masked) $",
1023 static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_event_nr).str()));
1030 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
1031 if (countedDHEStartFrames != countedDHEEndFrames + 1)
1032 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1033 if (!(
m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING(
"Data Frame outside a DHE START/END");
1044 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
1048 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
1053 switch (frame_type) {
1054 case EDHCFrameHeaderDataType::c_DHP_RAW: {
1059 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1060 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1061 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1063 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1077 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
1079 cancheck_countedBytesInDHC =
false;
1080 cancheck_countedBytesInDHE =
false;
1082 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
1085 if (isUnfiltered_event) {
1086 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP)
m_errorMask[c_nrSENDALL_TYPE] =
true;
1088 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD)
m_errorMask[c_nrNOTSENDALL_TYPE] =
true;
1095 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1096 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1097 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1099 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1109 dhe_first_readout_frame_id_lo,
1113 currentVxdId, daqpktstat);
1117 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
1119 cancheck_countedBytesInDHC =
false;
1120 cancheck_countedBytesInDHE =
false;
1122 case EDHCFrameHeaderDataType::c_FCE_RAW: {
1123 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (Clustering FCE)");
1126 if (isUnfiltered_event) {
1127 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
1132 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
1140 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1141 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1142 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1144 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1151 B2DEBUG(29,
"UNPACK FCE FRAME with len $" << hex << len);
1152 unpack_fce((
unsigned short*) data, len - 4, currentVxdId);
1156 case EDHCFrameHeaderDataType::c_COMMODE: {
1158 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (COMMODE)");
1164 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1165 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1166 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1168 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1175 case EDHCFrameHeaderDataType::c_DHC_START: {
1176 countedBytesInDHC = 0;
1177 cancheck_countedBytesInDHC =
true;
1179 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC START mixed Fake/no Fake event.");
1183 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC START Data -> trigger without Data!");
1190 currentDHEID = 0xFFFFFFFF;
1197 if (!isFakedData_event) {
1202 B2WARNING(
"DHC-Meta Experiment number mismatch");
1203 B2DEBUG(29,
"DHC-Meta Experiment number mismatch" <<
1212 B2WARNING(
"DHC-Meta Run number mismatch");
1213 B2DEBUG(29,
"DHC-Meta Run number mismatch" <<
1222 B2WARNING(
"DHC-Meta Sub-Run number mismatch");
1223 B2DEBUG(29,
"DHC-Meta Sub-Run number mismatch" <<
1233 B2WARNING(
"DHC-Meta 32 bit event number mismatch");
1234 B2DEBUG(29,
"DHC-Meta 32 bit event number mismatch" <<
1249 B2WARNING(
"DHC-Meta TimeTag mismatch");
1250 B2DEBUG(29,
"DHC-Meta TimeTag mismatch" <<
1251 LogVar(
"Header Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() <<
1255 LogVar(
"Meta Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_time).str()) <<
1256 LogVar(
"Trigger Type",
static_cast < std::ostringstream
1258 LogVar(
"Meta seconds: $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_sec).str()) <<
1259 LogVar(
"DHC seconds $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_sec).str()) <<
1260 LogVar(
"Seconds difference $",
static_cast < std::ostringstream
1261 &&
>(std::ostringstream() << hex << (trig_sec -
m_meta_sec)).str()) <<
1262 LogVar(
"Meta ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_ticks).str()) <<
1263 LogVar(
"DHC ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_ticks).str()) <<
1264 LogVar(
"Tick difference $",
static_cast < std::ostringstream
1265 &&
>(std::ostringstream() << hex << (trig_ticks -
m_meta_ticks)).str()));
1274 nr_active_dhe =
nr5bits(mask_active_dhe);
1283 case EDHCFrameHeaderDataType::c_DHE_START: {
1284 countedBytesInDHE = 0;
1285 cancheck_countedBytesInDHE =
true;
1295 B2WARNING(
"DHH IDs are not in expected order");
1296 B2DEBUG(29,
"DHH IDs are not in expected order" <<
1297 LogVar(
"Previous ID", (currentDHEID & 0xFFFF)) <<
1305 if (countedDHEStartFrames > countedDHEEndFrames) {
1309 countedDHEStartFrames++;
1311 found_mask_active_dhp = 0;
1317 B2WARNING(
"DHE START trigger mismatch in EVT32b/HI WORD");
1318 B2DEBUG(29,
"DHE START trigger mismatch in EVT32b/HI WORD" <<
1327 if (currentDHEID == 0) {
1328 if (!(
m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING(
"DHE ID is invalid=0 (not initialized)");
1339 unsigned short sensor, ladder, layer;
1340 sensor = (currentDHEID & 0x1) + 1;
1341 ladder = (currentDHEID & 0x1E) >> 1;
1342 layer = ((currentDHEID & 0x20) >> 5) + 1;
1343 currentVxdId =
VxdID(layer, ladder, sensor);
1344 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
1346 B2WARNING(
"DHE ID is invalid");
1347 B2DEBUG(29,
"DHE ID is invalid" <<
1348 LogVar(
"DHE ID", currentDHEID) <<
1349 LogVar(
"Layer", layer) <<
1350 LogVar(
"Ladder", ladder) <<
1351 LogVar(
"Sensor", sensor));
1360 daqpktstat.
dhc_back().
newDHE(currentVxdId, currentDHEID,
m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
1364 case EDHCFrameHeaderDataType::c_GHOST:
1368 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1381 case EDHCFrameHeaderDataType::c_DHC_END: {
1383 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC END mixed Fake/no Fake event.");
1387 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC END Data -> trigger without Data!");
1393 if (!isFakedData_event) {
1396 B2WARNING(
"DHC ID Mismatch between Start and End");
1397 B2DEBUG(29,
"DHC ID Mismatch between Start and End $" << std::hex <<
1404 if (cancheck_countedBytesInDHC) {
1405 if (countedBytesInDHC != w) {
1407 B2WARNING(
"Number of Words in DHC END does not match");
1408 B2DEBUG(29,
"Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC <<
" != DHC END $" << hex << w);
1413 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHC <<
" == DHC END $" << hex << w);
1420 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHC END Error Info set to $" << hex <<
1437 currentDHEID = 0xFFFFFFFF;
1438 currentDHCID = 0xFFFFFFFF;
1442 case EDHCFrameHeaderDataType::c_DHE_END: {
1446 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1447 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID <<
" != $" <<
1454 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHE END Error Info set to $" << hex <<
1459 if (found_mask_active_dhp != mask_active_dhp) {
1461 B2WARNING(
"DHE_END: DHP active mask differs from found data");
1462 B2DEBUG(29,
"DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp <<
" != $" << hex <<
1463 found_mask_active_dhp
1464 <<
" mask of found dhp/ghost frames");
1468 countedDHEEndFrames++;
1469 if (countedDHEStartFrames < countedDHEEndFrames) {
1477 if (cancheck_countedBytesInDHE) {
1478 if (countedBytesInDHE != w) {
1480 B2WARNING(
"Number of Words in DHE END does not match");
1481 B2DEBUG(29,
"Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE <<
" != DHE END $" << hex << w);
1486 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHE <<
" == DHE END $" << hex << w);
1505 currentDHEID |= 0xFF000000;
1509 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
1526 m_storeROIs.appendNew(l, &((
unsigned int*) data)[1]);
1530 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
1531 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
1534 B2WARNING(
"Trigger Frame HLT Trigger Nr mismatch");
1535 B2DEBUG(29,
"Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
1544 B2WARNING(
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
1545 B2DEBUG(29,
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
1556 B2WARNING(
"Trigger Frame DATCON Trigger Nr mismatch");
1557 B2DEBUG(29,
"Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
1566 B2WARNING(
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
1567 B2DEBUG(29,
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
1582 if (Frame_Number != 0) {
1583 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"ONSEN TRG Frame must be the first one.");
1598 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
1600 B2WARNING(
"Frame TrigNr != ONSEN Trig Nr");
1601 B2DEBUG(29,
"Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame <<
" != $" << eventNrOfOnsenTrgFrame);
1606 if (Frame_Number == 0) {
1608 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1610 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"First frame is not a ONSEN Trigger frame");
1616 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1617 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"More than one ONSEN Trigger frame");
1623 if (Frame_Number == 1) {
1625 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1626 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"Second frame is not a DHC start of subevent frame");
1631 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1632 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"More than one DHC start of subevent frame");
1638 if (Frame_Number == Frames_in_event - 1) {
1640 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
1641 if (!(
m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING(
"Last frame is not a DHC end of subevent frame");
1646 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
1649 B2WARNING(
"The number of DHE Start/End does not match the number of active DHE in DHC Header!");
1650 B2DEBUG(29,
"The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
1651 " Start: " << countedDHEStartFrames <<
" End: " << countedDHEEndFrames <<
" Mask: $" << hex << mask_active_dhe <<
" in Event Nr " <<
1652 eventNrOfThisFrame);
1654 if (countedDHEStartFrames == countedDHEEndFrames)
m_errorMask[c_nrDHE_ACTIVE] =
true;
1655 if (countedDHEStartFrames > countedDHEEndFrames)
m_errorMask[c_nrDHE_START_WO_END] =
true;
1656 if (countedDHEStartFrames < countedDHEEndFrames)
m_errorMask[c_nrDHE_END_WO_START] =
true;
1661 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
1662 if (!(
m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING(
"More than one DHC end of subevent frame");
1669 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1670 if (!(
m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING(
"Third frame is not a DHE start frame");
1675 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1677 countedBytesInDHC += len;
1678 countedBytesInDHE += len;
1680 B2DEBUG(29,
"DHC/DHE $" << hex << countedBytesInDHC <<
", $" << hex << countedBytesInDHE);
1690 static unsigned int eventNrOfOnsenTrgFrame = 0;
1691 static int countedBytesInDHC = 0;
1692 static bool cancheck_countedBytesInDHC =
false;
1693 static int countedBytesInDHE = 0;
1694 static bool cancheck_countedBytesInDHE =
false;
1695 static int countedDHEStartFrames = 0;
1696 static int countedDHEEndFrames = 0;
1697 static int mask_active_dhe = 0;
1698 static int nr_active_dhe =
1700 static int mask_active_dhp = 0;
1701 static int found_mask_active_dhp = 0;
1702 static int found_good_mask_active_dhp = 0;
1703 static unsigned int dhe_first_readout_frame_id_lo = 0;
1705 static unsigned int dhe_first_triggergate = 0;
1706 static unsigned int currentDHCID = 0xFFFFFFFF;
1707 static unsigned int currentDHEID = 0xFFFFFFFF;
1708 static unsigned int currentVxdId = 0;
1709 static bool isFakedData_event =
false;
1710 static bool isUnfiltered_event =
false;
1713 if (Frame_Number == 0) {
1716 eventNrOfOnsenTrgFrame = 0;
1717 countedDHEStartFrames = 0;
1718 countedDHEEndFrames = 0;
1719 countedBytesInDHC = 0;
1720 cancheck_countedBytesInDHC =
false;
1721 countedBytesInDHE = 0;
1722 cancheck_countedBytesInDHE =
false;
1723 currentDHCID = 0xFFFFFFFF;
1724 currentDHEID = 0xFFFFFFFF;
1726 isUnfiltered_event =
false;
1727 isFakedData_event =
false;
1728 mask_active_dhe = 0;
1730 mask_active_dhp = 0;
1731 found_mask_active_dhp = 0;
1732 found_good_mask_active_dhp = 0;
1745 if (len != s && s != 0) {
1747 B2WARNING(
"Fixed frame type size does not match specs" <<
LogVar(
"expected length",
1748 len) <<
LogVar(
"length in data", s));
1766 if (Frame_Number == 0) {
1768 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1769 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"This looks not like BonnDAQ format.");
1774 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1776 B2WARNING(
"This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
1784 if (Frame_Number == 1) {
1785 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1793 if (!isFakedData_event) {
1795 B2WARNING(
"Event Numbers do not match for this frame");
1796 B2DEBUG(29,
"Event Numbers do not match for this frame" <<
1797 LogVar(
"Event nr in frame $",
static_cast < std::ostringstream
1798 &&
>(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
1799 LogVar(
"Event nr in MetaInfo (bits masked) $",
1800 static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_event_nr).str()));
1807 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
1808 if (countedDHEStartFrames != countedDHEEndFrames + 1)
1809 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1810 if (!(
m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING(
"Data Frame outside a DHE START/END");
1821 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
1828 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
1833 switch (frame_type) {
1834 case EDHCFrameHeaderDataType::c_DHP_RAW: {
1839 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1840 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1841 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1843 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1849 B2ERROR(
"Second DHP data packet (MEMDUMP) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
1862 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
1864 cancheck_countedBytesInDHC =
false;
1865 cancheck_countedBytesInDHE =
false;
1867 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
1870 if (isUnfiltered_event) {
1871 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP)
m_errorMask[c_nrSENDALL_TYPE] =
true;
1873 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD)
m_errorMask[c_nrNOTSENDALL_TYPE] =
true;
1880 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1881 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1882 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1884 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1898 dhe_first_readout_frame_id_lo,
1902 currentVxdId, daqpktstat);
1906 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
1908 cancheck_countedBytesInDHC =
false;
1909 cancheck_countedBytesInDHE =
false;
1911 case EDHCFrameHeaderDataType::c_FCE_RAW: {
1912 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (Clustering FCE)");
1915 if (isUnfiltered_event) {
1916 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
1921 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
1929 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1930 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1931 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1933 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1939 B2ERROR(
"Second DHP data packet (FCE) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
1944 B2DEBUG(29,
"UNPACK FCE FRAME with len $" << hex << len);
1945 unpack_fce((
unsigned short*) data, len - 4, currentVxdId);
1949 case EDHCFrameHeaderDataType::c_COMMODE: {
1952 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (COMMODE)");
1958 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1959 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1960 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1962 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1969 case EDHCFrameHeaderDataType::c_DHC_START: {
1970 countedBytesInDHC = 0;
1971 cancheck_countedBytesInDHC =
true;
1973 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC START mixed Fake/no Fake event.");
1977 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC START Data -> trigger without Data!");
1984 currentDHEID = 0xFFFFFFFF;
1991 if (!isFakedData_event) {
1996 B2WARNING(
"DHC-Meta Experiment number mismatch");
1997 B2DEBUG(29,
"DHC-Meta Experiment number mismatch" <<
2006 B2WARNING(
"DHC-Meta Run number mismatch");
2007 B2DEBUG(29,
"DHC-Meta Run number mismatch" <<
2016 B2WARNING(
"DHC-Meta Sub-Run number mismatch");
2017 B2DEBUG(29,
"DHC-Meta Sub-Run number mismatch" <<
2027 B2WARNING(
"DHC-Meta 32 bit event number mismatch");
2028 B2DEBUG(29,
"DHC-Meta 32 bit event number mismatch" <<
2043 B2WARNING(
"DHC-Meta TimeTag mismatch");
2044 B2DEBUG(29,
"DHC-Meta TimeTag mismatch" <<
2045 LogVar(
"Header Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() <<
2049 LogVar(
"Meta Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_time).str()) <<
2050 LogVar(
"Trigger Type",
static_cast < std::ostringstream
2052 LogVar(
"Meta seconds: $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_sec).str()) <<
2053 LogVar(
"DHC seconds $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_sec).str()) <<
2054 LogVar(
"Seconds difference $",
static_cast < std::ostringstream
2055 &&
>(std::ostringstream() << hex << (trig_sec -
m_meta_sec)).str()) <<
2056 LogVar(
"Meta ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_ticks).str()) <<
2057 LogVar(
"DHC ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_ticks).str()) <<
2058 LogVar(
"Tick difference $",
static_cast < std::ostringstream
2059 &&
>(std::ostringstream() << hex << (trig_ticks -
m_meta_ticks)).str()));
2068 nr_active_dhe =
nr5bits(mask_active_dhe);
2077 case EDHCFrameHeaderDataType::c_DHE_START: {
2078 countedBytesInDHE = 0;
2079 cancheck_countedBytesInDHE =
true;
2089 B2WARNING(
"DHH IDs are not in expected order");
2090 B2DEBUG(29,
"DHH IDs are not in expected order" <<
2091 LogVar(
"Previous ID", (currentDHEID & 0xFFFF)) <<
2099 if (countedDHEStartFrames > countedDHEEndFrames) {
2103 countedDHEStartFrames++;
2105 found_mask_active_dhp = 0;
2106 found_good_mask_active_dhp = 0;
2112 B2WARNING(
"DHE START trigger mismatch in EVT32b/HI WORD");
2113 B2DEBUG(29,
"DHE START trigger mismatch in EVT32b/HI WORD" <<
2122 if (currentDHEID == 0) {
2123 if (!(
m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING(
"DHE ID is invalid=0 (not initialized)");
2134 unsigned short sensor, ladder, layer;
2135 sensor = (currentDHEID & 0x1) + 1;
2136 ladder = (currentDHEID & 0x1E) >> 1;
2137 layer = ((currentDHEID & 0x20) >> 5) + 1;
2138 currentVxdId =
VxdID(layer, ladder, sensor);
2139 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
2141 B2WARNING(
"DHE ID is invalid");
2142 B2DEBUG(29,
"DHE ID is invalid" <<
2143 LogVar(
"DHE ID", currentDHEID) <<
2144 LogVar(
"Layer", layer) <<
2145 LogVar(
"Ladder", ladder) <<
2146 LogVar(
"Sensor", sensor));
2155 daqpktstat.
dhc_back().
newDHE(currentVxdId, currentDHEID,
m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
2159 case EDHCFrameHeaderDataType::c_GHOST:
2163 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
2177 case EDHCFrameHeaderDataType::c_DHC_END: {
2179 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC END mixed Fake/no Fake event.");
2183 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC END Data -> trigger without Data!");
2189 if (!isFakedData_event) {
2192 B2WARNING(
"DHC ID Mismatch between Start and End");
2193 B2DEBUG(29,
"DHC ID Mismatch between Start and End $" << std::hex <<
2200 if (cancheck_countedBytesInDHC) {
2201 if (countedBytesInDHC != w) {
2203 B2WARNING(
"Number of Words in DHC END does not match");
2204 B2DEBUG(29,
"Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC <<
" != DHC END $" << hex << w);
2209 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHC <<
" == DHC END $" << hex << w);
2216 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHC END Error Info set to $" << hex <<
2233 currentDHEID = 0xFFFFFFFF;
2234 currentDHCID = 0xFFFFFFFF;
2238 case EDHCFrameHeaderDataType::c_DHE_END: {
2242 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
2243 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID <<
" != $" <<
2256 if (found_mask_active_dhp != mask_active_dhp) {
2258 B2WARNING(
"DHE_END: DHP active mask differs from found data");
2259 B2DEBUG(29,
"DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp <<
" != $" << hex <<
2260 found_mask_active_dhp
2261 <<
" mask of found dhp/ghost frames");
2265 countedDHEEndFrames++;
2266 if (countedDHEStartFrames < countedDHEEndFrames) {
2274 if (cancheck_countedBytesInDHE) {
2275 if (countedBytesInDHE != w) {
2277 B2WARNING(
"Number of Words in DHE END does not match");
2278 B2DEBUG(29,
"Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE <<
" != DHE END $" << hex << w);
2283 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHE <<
" == DHE END $" << hex << w);
2303 currentDHEID |= 0xFF000000;
2307 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
2324 m_storeROIs.appendNew(l, &((
unsigned int*) data)[1]);
2328 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
2329 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
2332 B2WARNING(
"Trigger Frame HLT Trigger Nr mismatch");
2333 B2DEBUG(29,
"Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
2342 B2WARNING(
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
2343 B2DEBUG(29,
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
2354 B2WARNING(
"Trigger Frame DATCON Trigger Nr mismatch");
2355 B2DEBUG(29,
"Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
2364 B2WARNING(
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
2365 B2DEBUG(29,
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
2380 if (Frame_Number != 0) {
2381 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"ONSEN TRG Frame must be the first one.");
2396 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
2398 B2WARNING(
"Frame TrigNr != ONSEN Trig Nr");
2399 B2DEBUG(29,
"Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame <<
" != $" << eventNrOfOnsenTrgFrame);
2404 if (Frame_Number == 0) {
2406 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
2408 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"First frame is not a ONSEN Trigger frame");
2414 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
2415 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"More than one ONSEN Trigger frame");
2421 if (Frame_Number == 1) {
2423 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
2424 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"Second frame is not a DHC start of subevent frame");
2429 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
2430 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"More than one DHC start of subevent frame");
2436 if (Frame_Number == Frames_in_event - 1) {
2438 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
2439 if (!(
m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING(
"Last frame is not a DHC end of subevent frame");
2444 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
2447 B2WARNING(
"The number of DHE Start/End does not match the number of active DHE in DHC Header!");
2448 B2DEBUG(29,
"The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
2449 " Start: " << countedDHEStartFrames <<
" End: " << countedDHEEndFrames <<
" Mask: $" << hex << mask_active_dhe <<
" in Event Nr " <<
2450 eventNrOfThisFrame);
2452 if (countedDHEStartFrames == countedDHEEndFrames)
m_errorMask[c_nrDHE_ACTIVE] =
true;
2453 if (countedDHEStartFrames > countedDHEEndFrames)
m_errorMask[c_nrDHE_START_WO_END] =
true;
2454 if (countedDHEStartFrames < countedDHEEndFrames)
m_errorMask[c_nrDHE_END_WO_START] =
true;
2459 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
2460 if (!(
m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING(
"More than one DHC end of subevent frame");
2467 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
2468 if (!(
m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING(
"Third frame is not a DHE start frame");
2473 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
2475 countedBytesInDHC += len;
2476 countedBytesInDHE += len;
2478 B2DEBUG(29,
"DHC/DHE $" << hex << countedBytesInDHC <<
", $" << hex << countedBytesInDHE);
2484 const int lut[32] = {
2485 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
2486 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5
2488 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_uint32_t ubig32_t
define alias ubig32_t
boost::endian::big_uint16_t ubig16_t
define alias ubig16_t
Abstract base class for different kinds of events.
unsigned int getDHEId(void) const
get DHE Id (from word0)
void print(void) const
print
unsigned int get_words(void) const
get words
unsigned int getDHEId(void) const
get DHE Id
unsigned int getErrorInfo(void) const
get error info
void print(void) const
print
unsigned int getDHEId(void) const
get DHE Id (from word0)
unsigned short getEventNrLo(void) const
get trigger_nr_lo
unsigned short getTriggerGate(void) const
trigger gate (updated to 8 bit, before 10!)
unsigned short getStartFrameNr(void) const
last DHP frame before trigger
unsigned short getEventNrHi(void) const
get trigger_nr_hi
unsigned int getActiveDHPMask(void) const
get Active DHP Mask (from word0)
void print(void) const
print
bool getDataReformattedFlag(void) const
get DataReformattedFlag (from word0)
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DHP Port (from word0)
void print(void) const
print
unsigned int get_words(void) const
get words
bool isFakedData(void) const
is faked data
unsigned int get_dhc_id(void) const
get dhc id (from word0)
unsigned int getErrorInfo(void) const
get error info
void print(void) const
print
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DDHP port (from word0)
void print(void) const
print
unsigned int check_inner_crc(PXDErrorFlags &, unsigned int) const
check inner crc (currently not implemented/needed)
void check_error(PXDErrorFlags &errormask, int length, bool ignore_inv_size_flag=false) const
check error and return error mask
int getMinSize(void) const
4 byte header, ROIS (n*8), 4 byte copy of inner CRC, 4 byte outer CRC
void print(void) const
print
unsigned short get_subrun1(void) const
get subrun1 (from trigtag1)
unsigned int get_trig_nr1(void) const
get trignr1
bool is_SendUnfiltered(void) const
is sendUnfiltered
bool is_SendROIs(void) const
is sendROIs
void check_error(PXDErrorFlags &errormask, bool ignore_datcon_flag=false, bool ignore_hltroi_magic_flag=false, bool ignore_merger_mm_flag=false) const
check error and return error mask
unsigned short get_run2(void) const
get run2 (from trigtag2)
bool is_fake_datcon(void) const
is fake datcon
unsigned short get_experiment1(void) const
get experiment1 (from trigtag1)
unsigned int get_trig_nr2(void) const
get trignr2
unsigned short get_experiment2(void) const
get experiment2
unsigned short get_subrun2(void) const
get subrun2 (from trigtag2)
bool is_Accepted(void) const
is accepted
unsigned short get_run1(void) const
get run1 (from trigtag1)
void print(void) const
print
unsigned short get_gated_isher(void) const
get gated_isher (from word0)
unsigned short get_subrun(void) const
get subrun (from run_subrun)
unsigned short get_run(void) const
get run (from run_subrun)
unsigned short get_dhc_id(void) const
get dhc_id (from word0)
const ubig16_t time_tag_hi
time_tag_hi
const ubig16_t time_tag_mid
time_tag_mid
bool isFakedData(void) const
isFakedData
unsigned short getEventNrLo(void) const
get trigger_nr_lo
unsigned short get_experiment(void) const
get experiment (from exp_run)
unsigned short get_gated_flag(void) const
get gated_flag (from word0)
unsigned short get_active_dhe_mask(void) const
get active_dhe_mask (from word0)
const ubig16_t time_tag_lo_and_type
time_tag_lo_and_type
unsigned short getEventNrHi(void) const
get trigger_nr_hi