9#include <pxd/unpacking/PXDRawDataDefinitions.h>
10#include <pxd/unpacking/PXDRawDataStructs.h>
11#include <pxd/unpacking/PXDMappingLookup.h>
12#include <pxd/modules/pxdUnpacking/PXDUnpackerModule.h>
13#include <framework/datastore/DataStore.h>
14#include <framework/logging/Logger.h>
15#include <framework/datastore/StoreObjPtr.h>
17#include <boost/endian/arithmetic.hpp>
22using namespace Belle2::PXD::PXDError;
47 addParam(
"RawPXDsName",
m_RawPXDsName,
"The name of the StoreArray of RawPXDs to be processed", std::string(
""));
65 addParam(
"Verbose",
m_verbose,
"Turn on extra verbosity for log-level debug",
false);
103 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++)
m_errorCounter[i] = 0;
111 else B2FATAL(
"Cannot get PXD Firmware version from db");
120 string errstr =
"Statistic ( ;";
124 B2RESULT(
"PXD Unpacker --> Error Statistics (counted once per event!) in Events: " <<
m_unpackedEventsCount);
125 B2RESULT(errstr +
" )");
126 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
151 B2DEBUG(29,
"PXD Unpacker --> RawPXD Objects in event: " <<
LogVar(
"Objects", nRaws));
164 B2DEBUG(29,
"PXD Unpacker --> Unpack Objects: ");
176 for (
unsigned int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
197 if (px.
size() <= 0 || px.
size() > 16 * 1024 * 1024) {
199 B2WARNING(
"PXD Unpacker --> invalid packet size" <<
200 LogVar(
"size [32bit words] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << px.
size()).str()));
205 std::vector<unsigned int> data(px.
size());
206 fullsize = px.
size() * 4;
207 std::copy_n(px.
data(), px.
size(), data.begin());
211 B2WARNING(
"Data is to small to hold a valid Header! Will not unpack anything." <<
LogVar(
"size [32bit words] $",
212 static_cast < std::ostringstream &&
>(std::ostringstream() << hex << fullsize).str()));
218 if (data[0] != 0xCAFEBABE && data[0] != 0xBEBAFECA) {
220 B2WARNING(
"Magic invalid: Will not unpack anything. Header corrupted." <<
221 LogVar(
"Header Magic $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << data[0]).str()));
228 Frames_in_event = ((
ubig32_t*)data.data())[1];
229 if (Frames_in_event < 0 || Frames_in_event > 256) {
231 B2WARNING(
"Number of Frames invalid: Will not unpack anything. Header corrupted!" <<
LogVar(
"Frames in event", Frames_in_event));
236 if (Frames_in_event < 3) {
238 B2WARNING(
"Number of Frames too small: It cannot contain anything useful." <<
LogVar(
"Frames in event", Frames_in_event));
245 B2DEBUG(29,
"PXD Unpacker --> data[0]: <-- Magic $" << hex << data[0]);
246 B2DEBUG(29,
"PXD Unpacker --> data[1]: <-- #Frames $" << hex << data[1]);
247 if (data[1] >= 1 && fullsize < 12) B2DEBUG(29,
"PXD Unpacker --> data[2]: <-- Frame 1 len $" << hex << data[2]);
248 if (data[1] >= 2 && fullsize < 16) B2DEBUG(29,
"PXD Unpacker --> data[3]: <-- Frame 2 len $" << hex << data[3]);
249 if (data[1] >= 3 && fullsize < 20) B2DEBUG(29,
"PXD Unpacker --> data[4]: <-- Frame 3 len $" << hex << data[4]);
250 if (data[1] >= 4 && fullsize < 24) B2DEBUG(29,
"PXD Unpacker --> data[5]: <-- Frame 4 len $" << hex << data[5]);
253 unsigned int* tableptr;
256 unsigned int* dataptr;
257 dataptr = &tableptr[Frames_in_event];
258 datafullsize = fullsize - 2 * 4 - Frames_in_event * 4;
261 for (
int j = 0; j < Frames_in_event; j++) {
267 B2WARNING(
"size of frame invalid");
268 B2DEBUG(29,
"size of frame invalid: " << j <<
"size " << lo <<
" at byte offset in dataptr " << ll);
273 if (ll + lo > datafullsize) {
275 B2WARNING(
"Frames exceed packet size");
276 B2DEBUG(29,
"Frames exceed packet size: " << j <<
" size " << lo <<
" at byte offset in dataptr " << ll <<
" of datafullsize " <<
277 datafullsize <<
" of fullsize " << fullsize);
284 B2WARNING(
"SKIP Frame with Data with not MOD 4 length");
285 B2DEBUG(29,
"SKIP Frame with Data with not MOD 4 length " <<
" ( $" << hex << lo <<
" ) ");
287 ll += (lo + 3) & 0xFFFFFFFC;
290 B2DEBUG(29,
"unpack DHE(C) frame: " << j <<
" with size " << lo <<
" at byte offset in dataptr " << ll);
298 B2FATAL(
"Firmware Version not supported " <<
m_firmware);
333 if (frame_len != 0xC008) {
334 if (!(
m_suppressErrorMask[c_nrFIX_SIZE])) B2WARNING(
"Frame size unsupported for RAW ADC frame! $" <<
335 LogVar(
"size [bytes] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << frame_len).str())
336 <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhe_DHPport));
340 unsigned int dhp_header_type = 0;
342 unsigned int dhp_dhe_id = 0;
343 unsigned int dhp_dhp_id = 0;
345 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
347 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
348 dhp_dhp_id = dhp_pix[2] & 0x0003;
350 if (dhe_ID != dhp_dhe_id) {
352 B2WARNING(
"DHE ID in DHE and DHP header differ");
353 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
357 if (dhe_DHPport != dhp_dhp_id) {
359 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
360 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
365 if (dhp_header_type != EDHPFrameHeaderDataType::c_RAW) {
367 B2WARNING(
"Header type invalid for this kind of DHE frame");
368 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
375 B2DEBUG(29,
"Raw ADC Data");
381 [[maybe_unused]]
VxdID vxd_id)
390 B2WARNING(
"FCE (Cluster) Packet have not yet been tested with real HW clusters. Dont assume that this code is working!");
428 unsigned int w = frame_len / 2;
431 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- ");
433 auto dhp_header_type = (d[2] & 0xE000) >> 13;
434 auto dhp_reserved = (d[2] & 0x1F00) >> 8;
435 auto dhp_dhe_id = (d[2] & 0x00FC) >> 2;
436 auto dhp_dhp_id = d[2] & 0x0003;
438 B2WARNING(
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
439 B2WARNING(
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
440 B2WARNING(
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
441 B2WARNING(
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
442 for (
unsigned int i = 4; i < w; i++) {
443 B2WARNING(
"DHP DATA $" << hex << d[i]);
445 B2WARNING(
"DHP CRC $" << hex << d[w] <<
",$" << hex << d[w + 1]);
451 unsigned int w = frame_len / 4;
454 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- Len $" << hex
457 for (
unsigned int i = 0; i < w; i++) {
458 B2WARNING(
"ROI DATA $" << hex << d[i]);
460 B2WARNING(
"ROI CRC $" << hex << d[w]);
464 unsigned int dhe_ID,
unsigned dhe_DHPport,
unsigned dhe_reformat,
VxdID vxd_id,
467 unsigned int nr_words = frame_len / 2;
470 unsigned int dhp_readout_frame_lo = 0;
471 unsigned int dhp_header_type = 0;
472 unsigned int dhp_reserved = 0;
473 unsigned int dhp_dhe_id = 0;
474 unsigned int dhp_dhp_id = 0;
477 unsigned int dhp_row = 0, dhp_col = 0, dhp_cm = 0;
479 bool rowflag =
false;
480 bool pixelflag =
true;
488 B2DEBUG(29,
"HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] <<
" -- ");
490 B2DEBUG(29,
"DHP Header | $" << hex << dhp_pix[2] <<
" ( " << dec << dhp_pix[2] <<
" ) ");
491 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
492 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
493 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
494 dhp_dhp_id = dhp_pix[2] & 0x0003;
496 B2DEBUG(29,
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
497 B2DEBUG(29,
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
498 B2DEBUG(29,
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
499 B2DEBUG(29,
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
501 if (dhe_ID != dhp_dhe_id) {
503 B2WARNING(
"DHE ID in DHE and DHP header differ");
504 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
508 if (dhe_DHPport != dhp_dhp_id) {
510 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
511 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
516 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
518 B2WARNING(
"Header type invalid for this kind of DHE frame");
519 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
528 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
529 B2DEBUG(29,
"DHP Frame Nr | $" << hex << dhp_readout_frame_lo <<
" ( " << dec << dhp_readout_frame_lo <<
" ) ");
574 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
577 B2WARNING(
"DHP data: seems to be double header! skipping.");
578 B2DEBUG(29,
"DHP data: seems to be double header! skipping." <<
LogVar(
"Length",
587 for (
unsigned int i = 4; i < nr_words ; i++) {
589 B2DEBUG(29,
"-- $" << hex << dhp_pix[i] <<
" -- " << dec << i);
591 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
598 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
599 dhp_cm = dhp_pix[i] & 0x3F;
601 B2WARNING(
"DHP data loss (CM=63) in " <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhp_dhp_id));
614 B2DEBUG(29,
"SetRow: $" << hex << dhp_row <<
" CM $" << hex << dhp_cm);
617 if (!(
m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING(
"DHP Unpacking: Pix without Row!!! skip dhp data ");
623 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
624 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
625 unsigned int v_cellID, u_cellID;
627 if (dhp_row >= 768) {
636 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
643 u_cellID = dhp_col + 64 * dhp_dhp_id;
645 if (u_cellID >= 250) {
647 B2WARNING(
"DHP COL Overflow (unconnected drain lines)");
648 B2DEBUG(29,
"DHP COL Overflow (unconnected drain lines) " << u_cellID <<
", reformat " << dhe_reformat <<
", dhpcol " << dhp_col <<
649 ", id " << dhp_dhp_id);
653 auto dhp_adc = dhp_pix[i] & 0xFF;
654 B2DEBUG(29,
"SetPix: Row $" << hex << dhp_row <<
" Col $" << hex << dhp_col <<
" ADC $" << hex << dhp_adc
655 <<
" CM $" << hex << dhp_cm);
666 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) & 0x3F);
672 B2DEBUG(29,
"(DHE) DHE_ID $" << hex << dhe_ID <<
" (DHE) DHP ID $" << hex << dhe_DHPport <<
" (DHP) DHE_ID $" << hex << dhp_dhe_id
673 <<
" (DHP) DHP ID $" << hex << dhp_dhp_id);
684 unsigned int dhe_ID,
unsigned dhe_DHPport,
unsigned dhe_reformat,
VxdID vxd_id,
687 unsigned int nr_words = frame_len / 2;
690 unsigned int dhp_readout_frame_lo = 0;
691 unsigned int dhp_header_type = 0;
692 unsigned int dhp_reserved = 0;
693 unsigned int dhp_dhe_id = 0;
694 unsigned int dhp_dhp_id = 0;
695 unsigned int wrap = 0;
699 unsigned int dhp_row = 0, dhp_col = 0, dhp_cm = 0;
701 bool rowflag =
false;
702 bool pixelflag =
true;
710 B2DEBUG(29,
"HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] <<
" -- ");
712 B2DEBUG(29,
"DHP Header | $" << hex << dhp_pix[2] <<
" ( " << dec << dhp_pix[2] <<
" ) ");
713 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
714 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
715 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
716 dhp_dhp_id = dhp_pix[2] & 0x0003;
718 B2DEBUG(29,
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
719 B2DEBUG(29,
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
720 B2DEBUG(29,
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
721 B2DEBUG(29,
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
723 if (dhe_ID != dhp_dhe_id) {
725 B2WARNING(
"DHE ID in DHE and DHP header differ");
726 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
730 if (dhe_DHPport != dhp_dhp_id) {
732 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
733 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
738 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
740 B2WARNING(
"Header type invalid for this kind of DHE frame");
741 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
750 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
751 B2DEBUG(29,
"DHP Frame Nr | $" << hex << dhp_readout_frame_lo <<
" ( " << dec << dhp_readout_frame_lo <<
" ) ");
794 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
797 B2WARNING(
"DHP data: seems to be double header! skipping.");
798 B2DEBUG(29,
"DHP data: seems to be double header! skipping." <<
LogVar(
"Length",
807 for (
unsigned int i = 4; i < nr_words ; i++) {
809 B2DEBUG(29,
"-- $" << hex << dhp_pix[i] <<
" -- " << dec << i);
811 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
818 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
819 dhp_cm = dhp_pix[i] & 0x3F;
820 if (last_gate != -1 && (
int)dhp_row / 4 < last_gate) {
824 last_gate = dhp_row / 4;
827 B2WARNING(
"DHP data loss (CM=63) in " <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhp_dhp_id));
840 B2DEBUG(29,
"SetRow: $" << hex << dhp_row <<
" CM $" << hex << dhp_cm);
843 if (!(
m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING(
"DHP Unpacking: Pix without Row!!! skip dhp data ");
849 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
850 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
851 unsigned int v_cellID, u_cellID;
853 if (dhp_row >= 768) {
862 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
869 u_cellID = dhp_col + 64 * dhp_dhp_id;
871 if (u_cellID >= 250) {
873 B2WARNING(
"DHP COL Overflow (unconnected drain lines)");
874 B2DEBUG(29,
"DHP COL Overflow (unconnected drain lines) " << u_cellID <<
", reformat " << dhe_reformat <<
", dhpcol " << dhp_col <<
875 ", id " << dhp_dhp_id);
879 auto dhp_adc = dhp_pix[i] & 0xFF;
880 B2DEBUG(29,
"SetPix: Row $" << hex << dhp_row <<
" Col $" << hex << dhp_col <<
" ADC $" << hex << dhp_adc
881 <<
" CM $" << hex << dhp_cm);
893 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo + wrap) & 0x3F);
899 B2DEBUG(29,
"(DHE) DHE_ID $" << hex << dhe_ID <<
" (DHE) DHP ID $" << hex << dhe_DHPport <<
" (DHP) DHE_ID $" << hex << dhp_dhe_id
900 <<
" (DHP) DHP ID $" << hex << dhp_dhp_id);
917 static unsigned int eventNrOfOnsenTrgFrame = 0;
918 static int countedBytesInDHC = 0;
919 static bool cancheck_countedBytesInDHC =
false;
920 static int countedBytesInDHE = 0;
921 static bool cancheck_countedBytesInDHE =
false;
922 static int countedDHEStartFrames = 0;
923 static int countedDHEEndFrames = 0;
924 static int mask_active_dhe = 0;
925 static int nr_active_dhe =
927 static int mask_active_dhp = 0;
928 static int found_mask_active_dhp = 0;
929 static unsigned int dhe_first_readout_frame_id_lo = 0;
931 static unsigned int dhe_first_triggergate = 0;
932 static unsigned int currentDHCID = 0xFFFFFFFF;
933 static unsigned int currentDHEID = 0xFFFFFFFF;
934 static unsigned int currentVxdId = 0;
935 static bool isFakedData_event =
false;
936 static bool isUnfiltered_event =
false;
939 if (Frame_Number == 0) {
942 eventNrOfOnsenTrgFrame = 0;
943 countedDHEStartFrames = 0;
944 countedDHEEndFrames = 0;
945 countedBytesInDHC = 0;
946 cancheck_countedBytesInDHC =
false;
947 countedBytesInDHE = 0;
948 cancheck_countedBytesInDHE =
false;
949 currentDHCID = 0xFFFFFFFF;
950 currentDHEID = 0xFFFFFFFF;
952 isUnfiltered_event =
false;
953 isFakedData_event =
false;
957 found_mask_active_dhp = 0;
970 if (len != s && s != 0) {
972 B2WARNING(
"Fixed frame type size does not match specs" <<
LogVar(
"expected length",
973 len) <<
LogVar(
"length in data", s));
991 if (Frame_Number == 0) {
993 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
994 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"This looks not like BonnDAQ format.");
999 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1001 B2WARNING(
"This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
1009 if (Frame_Number == 1) {
1010 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1018 if (!isFakedData_event) {
1020 B2WARNING(
"Event Numbers do not match for this frame");
1021 B2DEBUG(29,
"Event Numbers do not match for this frame" <<
1022 LogVar(
"Event nr in frame $",
static_cast < std::ostringstream
1023 &&
>(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
1024 LogVar(
"Event nr in MetaInfo (bits masked) $",
1025 static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_event_nr).str()));
1032 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
1033 if (countedDHEStartFrames != countedDHEEndFrames + 1)
1034 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1035 if (!(
m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING(
"Data Frame outside a DHE START/END");
1046 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
1050 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
1055 switch (frame_type) {
1056 case EDHCFrameHeaderDataType::c_DHP_RAW: {
1061 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1062 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1063 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1065 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1079 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
1081 cancheck_countedBytesInDHC =
false;
1082 cancheck_countedBytesInDHE =
false;
1084 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
1087 if (isUnfiltered_event) {
1088 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP)
m_errorMask[c_nrSENDALL_TYPE] =
true;
1090 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD)
m_errorMask[c_nrNOTSENDALL_TYPE] =
true;
1097 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1098 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1099 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1101 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1111 dhe_first_readout_frame_id_lo,
1115 currentVxdId, daqpktstat);
1119 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
1121 cancheck_countedBytesInDHC =
false;
1122 cancheck_countedBytesInDHE =
false;
1124 case EDHCFrameHeaderDataType::c_FCE_RAW: {
1125 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (Clustering FCE)");
1128 if (isUnfiltered_event) {
1129 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
1134 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
1142 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1143 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1144 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1146 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1153 B2DEBUG(29,
"UNPACK FCE FRAME with len $" << hex << len);
1154 unpack_fce((
unsigned short*) data, len - 4, currentVxdId);
1158 case EDHCFrameHeaderDataType::c_COMMODE: {
1160 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (COMMODE)");
1166 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1167 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1168 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1170 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1177 case EDHCFrameHeaderDataType::c_DHC_START: {
1178 countedBytesInDHC = 0;
1179 cancheck_countedBytesInDHC =
true;
1181 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC START mixed Fake/no Fake event.");
1185 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC START Data -> trigger without Data!");
1192 currentDHEID = 0xFFFFFFFF;
1199 if (!isFakedData_event) {
1204 B2WARNING(
"DHC-Meta Experiment number mismatch");
1205 B2DEBUG(29,
"DHC-Meta Experiment number mismatch" <<
1214 B2WARNING(
"DHC-Meta Run number mismatch");
1215 B2DEBUG(29,
"DHC-Meta Run number mismatch" <<
1224 B2WARNING(
"DHC-Meta Sub-Run number mismatch");
1225 B2DEBUG(29,
"DHC-Meta Sub-Run number mismatch" <<
1235 B2WARNING(
"DHC-Meta 32 bit event number mismatch");
1236 B2DEBUG(29,
"DHC-Meta 32 bit event number mismatch" <<
1251 B2WARNING(
"DHC-Meta TimeTag mismatch");
1252 B2DEBUG(29,
"DHC-Meta TimeTag mismatch" <<
1253 LogVar(
"Header Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() <<
1257 LogVar(
"Meta Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_time).str()) <<
1258 LogVar(
"Trigger Type",
static_cast < std::ostringstream
1260 LogVar(
"Meta seconds: $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_sec).str()) <<
1261 LogVar(
"DHC seconds $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_sec).str()) <<
1262 LogVar(
"Seconds difference $",
static_cast < std::ostringstream
1263 &&
>(std::ostringstream() << hex << (trig_sec -
m_meta_sec)).str()) <<
1264 LogVar(
"Meta ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_ticks).str()) <<
1265 LogVar(
"DHC ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_ticks).str()) <<
1266 LogVar(
"Tick difference $",
static_cast < std::ostringstream
1267 &&
>(std::ostringstream() << hex << (trig_ticks -
m_meta_ticks)).str()));
1276 nr_active_dhe =
nr5bits(mask_active_dhe);
1285 case EDHCFrameHeaderDataType::c_DHE_START: {
1286 countedBytesInDHE = 0;
1287 cancheck_countedBytesInDHE =
true;
1297 B2WARNING(
"DHH IDs are not in expected order");
1298 B2DEBUG(29,
"DHH IDs are not in expected order" <<
1299 LogVar(
"Previous ID", (currentDHEID & 0xFFFF)) <<
1307 if (countedDHEStartFrames > countedDHEEndFrames) {
1311 countedDHEStartFrames++;
1313 found_mask_active_dhp = 0;
1319 B2WARNING(
"DHE START trigger mismatch in EVT32b/HI WORD");
1320 B2DEBUG(29,
"DHE START trigger mismatch in EVT32b/HI WORD" <<
1329 if (currentDHEID == 0) {
1330 if (!(
m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING(
"DHE ID is invalid=0 (not initialized)");
1341 unsigned short sensor, ladder, layer;
1342 sensor = (currentDHEID & 0x1) + 1;
1343 ladder = (currentDHEID & 0x1E) >> 1;
1344 layer = ((currentDHEID & 0x20) >> 5) + 1;
1345 currentVxdId =
VxdID(layer, ladder, sensor);
1346 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
1348 B2WARNING(
"DHE ID is invalid");
1349 B2DEBUG(29,
"DHE ID is invalid" <<
1350 LogVar(
"DHE ID", currentDHEID) <<
1351 LogVar(
"Layer", layer) <<
1352 LogVar(
"Ladder", ladder) <<
1353 LogVar(
"Sensor", sensor));
1362 daqpktstat.
dhc_back().
newDHE(currentVxdId, currentDHEID,
m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
1366 case EDHCFrameHeaderDataType::c_GHOST:
1370 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1383 case EDHCFrameHeaderDataType::c_DHC_END: {
1385 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC END mixed Fake/no Fake event.");
1389 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC END Data -> trigger without Data!");
1395 if (!isFakedData_event) {
1398 B2WARNING(
"DHC ID Mismatch between Start and End");
1399 B2DEBUG(29,
"DHC ID Mismatch between Start and End $" << std::hex <<
1406 if (cancheck_countedBytesInDHC) {
1407 if (countedBytesInDHC != w) {
1409 B2WARNING(
"Number of Words in DHC END does not match");
1410 B2DEBUG(29,
"Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC <<
" != DHC END $" << hex << w);
1415 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHC <<
" == DHC END $" << hex << w);
1422 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHC END Error Info set to $" << hex <<
1439 currentDHEID = 0xFFFFFFFF;
1440 currentDHCID = 0xFFFFFFFF;
1444 case EDHCFrameHeaderDataType::c_DHE_END: {
1448 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1449 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID <<
" != $" <<
1456 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHE END Error Info set to $" << hex <<
1461 if (found_mask_active_dhp != mask_active_dhp) {
1463 B2WARNING(
"DHE_END: DHP active mask differs from found data");
1464 B2DEBUG(29,
"DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp <<
" != $" << hex <<
1465 found_mask_active_dhp
1466 <<
" mask of found dhp/ghost frames");
1470 countedDHEEndFrames++;
1471 if (countedDHEStartFrames < countedDHEEndFrames) {
1479 if (cancheck_countedBytesInDHE) {
1480 if (countedBytesInDHE != w) {
1482 B2WARNING(
"Number of Words in DHE END does not match");
1483 B2DEBUG(29,
"Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE <<
" != DHE END $" << hex << w);
1488 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHE <<
" == DHE END $" << hex << w);
1507 currentDHEID |= 0xFF000000;
1511 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
1528 m_storeROIs.appendNew(l, &((
unsigned int*) data)[1]);
1532 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
1533 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
1536 B2WARNING(
"Trigger Frame HLT Trigger Nr mismatch");
1537 B2DEBUG(29,
"Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
1546 B2WARNING(
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
1547 B2DEBUG(29,
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
1558 B2WARNING(
"Trigger Frame DATCON Trigger Nr mismatch");
1559 B2DEBUG(29,
"Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
1568 B2WARNING(
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
1569 B2DEBUG(29,
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
1584 if (Frame_Number != 0) {
1585 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"ONSEN TRG Frame must be the first one.");
1600 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
1602 B2WARNING(
"Frame TrigNr != ONSEN Trig Nr");
1603 B2DEBUG(29,
"Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame <<
" != $" << eventNrOfOnsenTrgFrame);
1608 if (Frame_Number == 0) {
1610 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1612 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"First frame is not a ONSEN Trigger frame");
1618 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1619 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"More than one ONSEN Trigger frame");
1625 if (Frame_Number == 1) {
1627 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1628 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"Second frame is not a DHC start of subevent frame");
1633 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1634 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"More than one DHC start of subevent frame");
1640 if (Frame_Number == Frames_in_event - 1) {
1642 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
1643 if (!(
m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING(
"Last frame is not a DHC end of subevent frame");
1648 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
1651 B2WARNING(
"The number of DHE Start/End does not match the number of active DHE in DHC Header!");
1652 B2DEBUG(29,
"The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
1653 " Start: " << countedDHEStartFrames <<
" End: " << countedDHEEndFrames <<
" Mask: $" << hex << mask_active_dhe <<
" in Event Nr " <<
1654 eventNrOfThisFrame);
1656 if (countedDHEStartFrames == countedDHEEndFrames)
m_errorMask[c_nrDHE_ACTIVE] =
true;
1657 if (countedDHEStartFrames > countedDHEEndFrames)
m_errorMask[c_nrDHE_START_WO_END] =
true;
1658 if (countedDHEStartFrames < countedDHEEndFrames)
m_errorMask[c_nrDHE_END_WO_START] =
true;
1663 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
1664 if (!(
m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING(
"More than one DHC end of subevent frame");
1671 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1672 if (!(
m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING(
"Third frame is not a DHE start frame");
1677 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1679 countedBytesInDHC += len;
1680 countedBytesInDHE += len;
1682 B2DEBUG(29,
"DHC/DHE $" << hex << countedBytesInDHC <<
", $" << hex << countedBytesInDHE);
1692 static unsigned int eventNrOfOnsenTrgFrame = 0;
1693 static int countedBytesInDHC = 0;
1694 static bool cancheck_countedBytesInDHC =
false;
1695 static int countedBytesInDHE = 0;
1696 static bool cancheck_countedBytesInDHE =
false;
1697 static int countedDHEStartFrames = 0;
1698 static int countedDHEEndFrames = 0;
1699 static int mask_active_dhe = 0;
1700 static int nr_active_dhe =
1702 static int mask_active_dhp = 0;
1703 static int found_mask_active_dhp = 0;
1704 static int found_good_mask_active_dhp = 0;
1705 static unsigned int dhe_first_readout_frame_id_lo = 0;
1707 static unsigned int dhe_first_triggergate = 0;
1708 static unsigned int currentDHCID = 0xFFFFFFFF;
1709 static unsigned int currentDHEID = 0xFFFFFFFF;
1710 static unsigned int currentVxdId = 0;
1711 static bool isFakedData_event =
false;
1712 static bool isUnfiltered_event =
false;
1715 if (Frame_Number == 0) {
1718 eventNrOfOnsenTrgFrame = 0;
1719 countedDHEStartFrames = 0;
1720 countedDHEEndFrames = 0;
1721 countedBytesInDHC = 0;
1722 cancheck_countedBytesInDHC =
false;
1723 countedBytesInDHE = 0;
1724 cancheck_countedBytesInDHE =
false;
1725 currentDHCID = 0xFFFFFFFF;
1726 currentDHEID = 0xFFFFFFFF;
1728 isUnfiltered_event =
false;
1729 isFakedData_event =
false;
1730 mask_active_dhe = 0;
1732 mask_active_dhp = 0;
1733 found_mask_active_dhp = 0;
1734 found_good_mask_active_dhp = 0;
1747 if (len != s && s != 0) {
1749 B2WARNING(
"Fixed frame type size does not match specs" <<
LogVar(
"expected length",
1750 len) <<
LogVar(
"length in data", s));
1768 if (Frame_Number == 0) {
1770 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1771 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"This looks not like BonnDAQ format.");
1776 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1778 B2WARNING(
"This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
1786 if (Frame_Number == 1) {
1787 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1795 if (!isFakedData_event) {
1797 B2WARNING(
"Event Numbers do not match for this frame");
1798 B2DEBUG(29,
"Event Numbers do not match for this frame" <<
1799 LogVar(
"Event nr in frame $",
static_cast < std::ostringstream
1800 &&
>(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
1801 LogVar(
"Event nr in MetaInfo (bits masked) $",
1802 static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_event_nr).str()));
1809 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
1810 if (countedDHEStartFrames != countedDHEEndFrames + 1)
1811 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1812 if (!(
m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING(
"Data Frame outside a DHE START/END");
1823 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
1830 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
1835 switch (frame_type) {
1836 case EDHCFrameHeaderDataType::c_DHP_RAW: {
1841 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1842 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1843 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1845 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1851 B2ERROR(
"Second DHP data packet (MEMDUMP) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
1864 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
1866 cancheck_countedBytesInDHC =
false;
1867 cancheck_countedBytesInDHE =
false;
1869 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
1872 if (isUnfiltered_event) {
1873 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP)
m_errorMask[c_nrSENDALL_TYPE] =
true;
1875 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD)
m_errorMask[c_nrNOTSENDALL_TYPE] =
true;
1882 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1883 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1884 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1886 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1900 dhe_first_readout_frame_id_lo,
1904 currentVxdId, daqpktstat);
1908 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
1910 cancheck_countedBytesInDHC =
false;
1911 cancheck_countedBytesInDHE =
false;
1913 case EDHCFrameHeaderDataType::c_FCE_RAW: {
1914 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (Clustering FCE)");
1917 if (isUnfiltered_event) {
1918 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
1923 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
1931 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1932 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1933 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1935 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1941 B2ERROR(
"Second DHP data packet (FCE) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
1946 B2DEBUG(29,
"UNPACK FCE FRAME with len $" << hex << len);
1947 unpack_fce((
unsigned short*) data, len - 4, currentVxdId);
1951 case EDHCFrameHeaderDataType::c_COMMODE: {
1954 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (COMMODE)");
1960 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1961 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
1962 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
1964 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
1971 case EDHCFrameHeaderDataType::c_DHC_START: {
1972 countedBytesInDHC = 0;
1973 cancheck_countedBytesInDHC =
true;
1975 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC START mixed Fake/no Fake event.");
1979 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC START Data -> trigger without Data!");
1986 currentDHEID = 0xFFFFFFFF;
1993 if (!isFakedData_event) {
1998 B2WARNING(
"DHC-Meta Experiment number mismatch");
1999 B2DEBUG(29,
"DHC-Meta Experiment number mismatch" <<
2008 B2WARNING(
"DHC-Meta Run number mismatch");
2009 B2DEBUG(29,
"DHC-Meta Run number mismatch" <<
2018 B2WARNING(
"DHC-Meta Sub-Run number mismatch");
2019 B2DEBUG(29,
"DHC-Meta Sub-Run number mismatch" <<
2029 B2WARNING(
"DHC-Meta 32 bit event number mismatch");
2030 B2DEBUG(29,
"DHC-Meta 32 bit event number mismatch" <<
2045 B2WARNING(
"DHC-Meta TimeTag mismatch");
2046 B2DEBUG(29,
"DHC-Meta TimeTag mismatch" <<
2047 LogVar(
"Header Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() <<
2051 LogVar(
"Meta Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_time).str()) <<
2052 LogVar(
"Trigger Type",
static_cast < std::ostringstream
2054 LogVar(
"Meta seconds: $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_sec).str()) <<
2055 LogVar(
"DHC seconds $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_sec).str()) <<
2056 LogVar(
"Seconds difference $",
static_cast < std::ostringstream
2057 &&
>(std::ostringstream() << hex << (trig_sec -
m_meta_sec)).str()) <<
2058 LogVar(
"Meta ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_ticks).str()) <<
2059 LogVar(
"DHC ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_ticks).str()) <<
2060 LogVar(
"Tick difference $",
static_cast < std::ostringstream
2061 &&
>(std::ostringstream() << hex << (trig_ticks -
m_meta_ticks)).str()));
2070 nr_active_dhe =
nr5bits(mask_active_dhe);
2079 case EDHCFrameHeaderDataType::c_DHE_START: {
2080 countedBytesInDHE = 0;
2081 cancheck_countedBytesInDHE =
true;
2091 B2WARNING(
"DHH IDs are not in expected order");
2092 B2DEBUG(29,
"DHH IDs are not in expected order" <<
2093 LogVar(
"Previous ID", (currentDHEID & 0xFFFF)) <<
2101 if (countedDHEStartFrames > countedDHEEndFrames) {
2105 countedDHEStartFrames++;
2107 found_mask_active_dhp = 0;
2108 found_good_mask_active_dhp = 0;
2114 B2WARNING(
"DHE START trigger mismatch in EVT32b/HI WORD");
2115 B2DEBUG(29,
"DHE START trigger mismatch in EVT32b/HI WORD" <<
2124 if (currentDHEID == 0) {
2125 if (!(
m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING(
"DHE ID is invalid=0 (not initialized)");
2136 unsigned short sensor, ladder, layer;
2137 sensor = (currentDHEID & 0x1) + 1;
2138 ladder = (currentDHEID & 0x1E) >> 1;
2139 layer = ((currentDHEID & 0x20) >> 5) + 1;
2140 currentVxdId =
VxdID(layer, ladder, sensor);
2141 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
2143 B2WARNING(
"DHE ID is invalid");
2144 B2DEBUG(29,
"DHE ID is invalid" <<
2145 LogVar(
"DHE ID", currentDHEID) <<
2146 LogVar(
"Layer", layer) <<
2147 LogVar(
"Ladder", ladder) <<
2148 LogVar(
"Sensor", sensor));
2157 daqpktstat.
dhc_back().
newDHE(currentVxdId, currentDHEID,
m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
2161 case EDHCFrameHeaderDataType::c_GHOST:
2165 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
2179 case EDHCFrameHeaderDataType::c_DHC_END: {
2181 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC END mixed Fake/no Fake event.");
2185 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC END Data -> trigger without Data!");
2191 if (!isFakedData_event) {
2194 B2WARNING(
"DHC ID Mismatch between Start and End");
2195 B2DEBUG(29,
"DHC ID Mismatch between Start and End $" << std::hex <<
2202 if (cancheck_countedBytesInDHC) {
2203 if (countedBytesInDHC != w) {
2205 B2WARNING(
"Number of Words in DHC END does not match");
2206 B2DEBUG(29,
"Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC <<
" != DHC END $" << hex << w);
2211 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHC <<
" == DHC END $" << hex << w);
2218 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHC END Error Info set to $" << hex <<
2235 currentDHEID = 0xFFFFFFFF;
2236 currentDHCID = 0xFFFFFFFF;
2240 case EDHCFrameHeaderDataType::c_DHE_END: {
2244 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
2245 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID <<
" != $" <<
2258 if (found_mask_active_dhp != mask_active_dhp) {
2260 B2WARNING(
"DHE_END: DHP active mask differs from found data");
2261 B2DEBUG(29,
"DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp <<
" != $" << hex <<
2262 found_mask_active_dhp
2263 <<
" mask of found dhp/ghost frames");
2267 countedDHEEndFrames++;
2268 if (countedDHEStartFrames < countedDHEEndFrames) {
2276 if (cancheck_countedBytesInDHE) {
2277 if (countedBytesInDHE != w) {
2279 B2WARNING(
"Number of Words in DHE END does not match");
2280 B2DEBUG(29,
"Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE <<
" != DHE END $" << hex << w);
2285 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHE <<
" == DHE END $" << hex << w);
2305 currentDHEID |= 0xFF000000;
2309 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
2326 m_storeROIs.appendNew(l, &((
unsigned int*) data)[1]);
2330 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
2331 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
2334 B2WARNING(
"Trigger Frame HLT Trigger Nr mismatch");
2335 B2DEBUG(29,
"Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
2344 B2WARNING(
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
2345 B2DEBUG(29,
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
2356 B2WARNING(
"Trigger Frame DATCON Trigger Nr mismatch");
2357 B2DEBUG(29,
"Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
2366 B2WARNING(
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
2367 B2DEBUG(29,
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
2382 if (Frame_Number != 0) {
2383 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"ONSEN TRG Frame must be the first one.");
2398 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
2400 B2WARNING(
"Frame TrigNr != ONSEN Trig Nr");
2401 B2DEBUG(29,
"Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame <<
" != $" << eventNrOfOnsenTrgFrame);
2406 if (Frame_Number == 0) {
2408 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
2410 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"First frame is not a ONSEN Trigger frame");
2416 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
2417 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"More than one ONSEN Trigger frame");
2423 if (Frame_Number == 1) {
2425 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
2426 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"Second frame is not a DHC start of subevent frame");
2431 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
2432 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"More than one DHC start of subevent frame");
2438 if (Frame_Number == Frames_in_event - 1) {
2440 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
2441 if (!(
m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING(
"Last frame is not a DHC end of subevent frame");
2446 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
2449 B2WARNING(
"The number of DHE Start/End does not match the number of active DHE in DHC Header!");
2450 B2DEBUG(29,
"The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
2451 " Start: " << countedDHEStartFrames <<
" End: " << countedDHEEndFrames <<
" Mask: $" << hex << mask_active_dhe <<
" in Event Nr " <<
2452 eventNrOfThisFrame);
2454 if (countedDHEStartFrames == countedDHEEndFrames)
m_errorMask[c_nrDHE_ACTIVE] =
true;
2455 if (countedDHEStartFrames > countedDHEEndFrames)
m_errorMask[c_nrDHE_START_WO_END] =
true;
2456 if (countedDHEStartFrames < countedDHEEndFrames)
m_errorMask[c_nrDHE_END_WO_START] =
true;
2461 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
2462 if (!(
m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING(
"More than one DHC end of subevent frame");
2469 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
2470 if (!(
m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING(
"Third frame is not a DHE start frame");
2475 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
2477 countedBytesInDHC += len;
2478 countedBytesInDHE += len;
2480 B2DEBUG(29,
"DHC/DHE $" << hex << countedBytesInDHC <<
", $" << hex << countedBytesInDHE);
2486 const int lut[32] = {
2487 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
2488 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5
2490 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