9#include <pxd/modules/pxdUnpacking/PXDUnpackerOTModule.h>
10#include <pxd/unpacking/PXDRawDataDefinitions.h>
11#include <pxd/unpacking/PXDRawDataStructs.h>
12#include <pxd/unpacking/PXDMappingLookup.h>
13#include <pxd/dataobjects/PXDRawHit.h>
14#include <pxd/dataobjects/PXDRawAdc.h>
15#include <pxd/dataobjects/PXDRawROIs.h>
16#include <vxd/dataobjects/VxdID.h>
17#include <rawdata/dataobjects/RawPXD.h>
18#include <framework/dataobjects/EventMetaData.h>
19#include <framework/logging/Logger.h>
24using namespace Belle2::PXD::PXDError;
49 addParam(
"RawPXDsName",
m_RawPXDsName,
"The name of the StoreArray of RawPXDs to be processed", std::string(
""));
66 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;
110 string errstr =
"Statistic ( ;";
114 B2RESULT(
"PXD Unpacker --> Error Statistics (counted once per event!) in Events: " <<
m_unpackedEventsCount);
115 B2RESULT(errstr +
" )");
116 for (
int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
141 B2DEBUG(29,
"PXD Unpacker --> RawPXD Objects in event: " <<
LogVar(
"Objects", nRaws));
154 B2DEBUG(29,
"PXD Unpacker --> Unpack Objects: ");
166 for (
unsigned int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
187 if (px.
size() <= 0 || px.
size() > 16 * 1024 * 1024) {
189 B2WARNING(
"PXD Unpacker --> invalid packet size" <<
190 LogVar(
"size [32bit words] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << px.
size()).str()));
195 std::vector<unsigned int> data(px.
size());
196 fullsize = px.
size() * 4;
197 std::copy_n(px.
data(), px.
size(), data.begin());
201 B2WARNING(
"Data is to small to hold a valid Header! Will not unpack anything." <<
LogVar(
"size [32bit words] $",
202 static_cast < std::ostringstream &&
>(std::ostringstream() << hex << fullsize).str()));
208 if (data[0] != 0xCAFEBABE && data[0] != 0xBEBAFECA) {
210 B2WARNING(
"Magic invalid: Will not unpack anything. Header corrupted." <<
211 LogVar(
"Header Magic $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << data[0]).str()));
218 Frames_in_event = ((
ubig32_t*)data.data())[1];
219 if (Frames_in_event < 0 || Frames_in_event > 256) {
221 B2WARNING(
"Number of Frames invalid: Will not unpack anything. Header corrupted!" <<
LogVar(
"Frames in event", Frames_in_event));
226 if (Frames_in_event < 3) {
228 B2WARNING(
"Number of Frames too small: It cannot contain anything useful." <<
LogVar(
"Frames in event", Frames_in_event));
235 B2DEBUG(29,
"PXD Unpacker --> data[0]: <-- Magic $" << hex << data[0]);
236 B2DEBUG(29,
"PXD Unpacker --> data[1]: <-- #Frames $" << hex << data[1]);
237 if (data[1] >= 1 && fullsize < 12) B2DEBUG(29,
"PXD Unpacker --> data[2]: <-- Frame 1 len $" << hex << data[2]);
238 if (data[1] >= 2 && fullsize < 16) B2DEBUG(29,
"PXD Unpacker --> data[3]: <-- Frame 2 len $" << hex << data[3]);
239 if (data[1] >= 3 && fullsize < 20) B2DEBUG(29,
"PXD Unpacker --> data[4]: <-- Frame 3 len $" << hex << data[4]);
240 if (data[1] >= 4 && fullsize < 24) B2DEBUG(29,
"PXD Unpacker --> data[5]: <-- Frame 4 len $" << hex << data[5]);
243 unsigned int* tableptr;
246 unsigned int* dataptr;
247 dataptr = &tableptr[Frames_in_event];
248 datafullsize = fullsize - 2 * 4 - Frames_in_event * 4;
251 for (
int j = 0; j < Frames_in_event; j++) {
257 B2WARNING(
"size of frame invalid");
258 B2DEBUG(29,
"size of frame invalid: " << j <<
"size " << lo <<
" at byte offset in dataptr " << ll);
263 if (ll + lo > datafullsize) {
265 B2WARNING(
"Frames exceed packet size");
266 B2DEBUG(29,
"Frames exceed packet size: " << j <<
" size " << lo <<
" at byte offset in dataptr " << ll <<
" of datafullsize " <<
267 datafullsize <<
" of fullsize " << fullsize);
274 B2WARNING(
"SKIP Frame with Data with not MOD 4 length");
275 B2DEBUG(29,
"SKIP Frame with Data with not MOD 4 length " <<
" ( $" << hex << lo <<
" ) ");
277 ll += (lo + 3) & 0xFFFFFFFC;
280 B2DEBUG(29,
"unpack DHE(C) frame: " << j <<
" with size " << lo <<
" at byte offset in dataptr " << ll);
315 if (frame_len != 0xC008) {
316 if (!(
m_suppressErrorMask[c_nrFIX_SIZE])) B2WARNING(
"Frame size unsupported for RAW ADC frame! $" <<
317 LogVar(
"size [bytes] $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << frame_len).str())
318 <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhe_DHPport));
322 unsigned int dhp_header_type = 0;
324 unsigned int dhp_dhe_id = 0;
325 unsigned int dhp_dhp_id = 0;
327 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
329 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
330 dhp_dhp_id = dhp_pix[2] & 0x0003;
332 if (dhe_ID != dhp_dhe_id) {
334 B2WARNING(
"DHE ID in DHE and DHP header differ");
335 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
339 if (dhe_DHPport != dhp_dhp_id) {
341 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
342 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
347 if (dhp_header_type != EDHPFrameHeaderDataType::c_RAW) {
349 B2WARNING(
"Header type invalid for this kind of DHE frame");
350 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
357 B2DEBUG(29,
"Raw ADC Data");
363 [[maybe_unused]]
VxdID vxd_id)
372 B2WARNING(
"FCE (Cluster) Packet have not yet been tested with real HW clusters. Dont assume that this code is working!");
410 unsigned int w = frame_len / 2;
413 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- ");
415 auto dhp_header_type = (d[2] & 0xE000) >> 13;
416 auto dhp_reserved = (d[2] & 0x1F00) >> 8;
417 auto dhp_dhe_id = (d[2] & 0x00FC) >> 2;
418 auto dhp_dhp_id = d[2] & 0x0003;
420 B2WARNING(
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
421 B2WARNING(
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
422 B2WARNING(
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
423 B2WARNING(
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
424 for (
unsigned int i = 4; i < w; i++) {
425 B2WARNING(
"DHP DATA $" << hex << d[i]);
427 B2WARNING(
"DHP CRC $" << hex << d[w] <<
",$" << hex << d[w + 1]);
433 unsigned int w = frame_len / 4;
436 B2WARNING(
"HEADER -- $" << hex << d[0] <<
",$" << hex << d[1] <<
",$" << hex << d[2] <<
",$" << hex << d[3] <<
" -- Len $" << hex
439 for (
unsigned int i = 0; i < w; i++) {
440 B2WARNING(
"ROI DATA $" << hex << d[i]);
442 B2WARNING(
"ROI CRC $" << hex << d[w]);
446 unsigned int dhe_ID,
unsigned dhe_DHPport,
unsigned dhe_reformat,
VxdID vxd_id,
449 unsigned int nr_words = frame_len / 2;
452 unsigned int dhp_readout_frame_lo = 0;
453 unsigned int dhp_header_type = 0;
454 unsigned int dhp_reserved = 0;
455 unsigned int dhp_dhe_id = 0;
456 unsigned int dhp_dhp_id = 0;
457 unsigned int wrap = 0;
461 unsigned int dhp_row = 0, dhp_col = 0, dhp_cm = 0;
463 bool rowflag =
false;
464 bool pixelflag =
true;
472 B2DEBUG(29,
"HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] <<
" -- ");
474 B2DEBUG(29,
"DHP Header | $" << hex << dhp_pix[2] <<
" ( " << dec << dhp_pix[2] <<
" ) ");
475 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
476 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
477 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
478 dhp_dhp_id = dhp_pix[2] & 0x0003;
480 B2DEBUG(29,
"DHP type | $" << hex << dhp_header_type <<
" ( " << dec << dhp_header_type <<
" ) ");
481 B2DEBUG(29,
"DHP reserved | $" << hex << dhp_reserved <<
" ( " << dec << dhp_reserved <<
" ) ");
482 B2DEBUG(29,
"DHP DHE ID | $" << hex << dhp_dhe_id <<
" ( " << dec << dhp_dhe_id <<
" ) ");
483 B2DEBUG(29,
"DHP DHP ID | $" << hex << dhp_dhp_id <<
" ( " << dec << dhp_dhp_id <<
" ) ");
485 if (dhe_ID != dhp_dhe_id) {
487 B2WARNING(
"DHE ID in DHE and DHP header differ");
488 B2DEBUG(29,
"DHE ID in DHE and DHP header differ $" << hex << dhe_ID <<
" != $" << dhp_dhe_id);
492 if (dhe_DHPport != dhp_dhp_id) {
494 B2WARNING(
"DHP ID (Chip/Port) in DHE and DHP header differ");
495 B2DEBUG(29,
"DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport <<
" != $" << dhp_dhp_id);
500 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
502 B2WARNING(
"Header type invalid for this kind of DHE frame");
503 B2DEBUG(29,
"Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
512 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
513 B2DEBUG(29,
"DHP Frame Nr | $" << hex << dhp_readout_frame_lo <<
" ( " << dec << dhp_readout_frame_lo <<
" ) ");
556 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
559 B2WARNING(
"DHP data: seems to be double header! skipping.");
560 B2DEBUG(29,
"DHP data: seems to be double header! skipping." <<
LogVar(
"Length",
569 for (
unsigned int i = 4; i < nr_words ; i++) {
571 B2DEBUG(29,
"-- $" << hex << dhp_pix[i] <<
" -- " << dec << i);
573 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
580 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
581 dhp_cm = dhp_pix[i] & 0x3F;
582 if (last_gate != -1 && (
int)dhp_row / 4 < last_gate) {
586 last_gate = dhp_row / 4;
589 B2WARNING(
"DHP data loss (CM=63) in " <<
LogVar(
"DHE", dhe_ID) <<
LogVar(
"DHP", dhp_dhp_id));
602 B2DEBUG(29,
"SetRow: $" << hex << dhp_row <<
" CM $" << hex << dhp_cm);
605 if (!(
m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING(
"DHP Unpacking: Pix without Row!!! skip dhp data ");
611 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
612 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
613 unsigned int v_cellID, u_cellID;
615 if (dhp_row >= 768) {
624 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
631 u_cellID = dhp_col + 64 * dhp_dhp_id;
633 if (u_cellID >= 250) {
635 B2WARNING(
"DHP COL Overflow (unconnected drain lines)");
636 B2DEBUG(29,
"DHP COL Overflow (unconnected drain lines) " << u_cellID <<
", reformat " << dhe_reformat <<
", dhpcol " << dhp_col <<
637 ", id " << dhp_dhp_id);
641 auto dhp_adc = dhp_pix[i] & 0xFF;
642 B2DEBUG(29,
"SetPix: Row $" << hex << dhp_row <<
" Col $" << hex << dhp_col <<
" ADC $" << hex << dhp_adc
643 <<
" CM $" << hex << dhp_cm);
647 B2WARNING(
"DHE Event truncation in DHE " << dhe_ID <<
" DHP " << dhp_dhp_id);
653 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo + wrap) & 0x3F);
660 B2DEBUG(29,
"(DHE) DHE_ID $" << hex << dhe_ID <<
" (DHE) DHP ID $" << hex << dhe_DHPport <<
" (DHP) DHE_ID $" << hex << dhp_dhe_id
661 <<
" (DHP) DHP ID $" << hex << dhp_dhp_id);
677 static unsigned int eventNrOfOnsenTrgFrame = 0;
678 static int countedBytesInDHC = 0;
679 static bool cancheck_countedBytesInDHC =
false;
680 static int countedBytesInDHE = 0;
681 static bool cancheck_countedBytesInDHE =
false;
682 static int countedDHEStartFrames = 0;
683 static int countedDHEEndFrames = 0;
684 static int mask_active_dhe = 0;
685 static int nr_active_dhe =
687 static int mask_active_dhp = 0;
688 static int found_mask_active_dhp = 0;
689 static int found_good_mask_active_dhp = 0;
690 static unsigned int dhe_first_readout_frame_id_lo = 0;
692 static unsigned int dhe_first_triggergate = 0;
693 static unsigned int currentDHCID = 0xFFFFFFFF;
694 static unsigned int currentDHEID = 0xFFFFFFFF;
695 static unsigned int currentVxdId = 0;
696 static bool isFakedData_event =
false;
697 static bool isUnfiltered_event =
false;
700 if (Frame_Number == 0) {
703 eventNrOfOnsenTrgFrame = 0;
704 countedDHEStartFrames = 0;
705 countedDHEEndFrames = 0;
706 countedBytesInDHC = 0;
707 cancheck_countedBytesInDHC =
false;
708 countedBytesInDHE = 0;
709 cancheck_countedBytesInDHE =
false;
710 currentDHCID = 0xFFFFFFFF;
711 currentDHEID = 0xFFFFFFFF;
713 isUnfiltered_event =
false;
714 isFakedData_event =
false;
718 found_mask_active_dhp = 0;
719 found_good_mask_active_dhp = 0;
732 if (len != s && s != 0) {
734 B2WARNING(
"Fixed frame type size does not match specs" <<
LogVar(
"expected length",
735 len) <<
LogVar(
"length in data", s));
753 if (Frame_Number == 0) {
755 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
756 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"This looks not like BonnDAQ format.");
761 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
763 B2WARNING(
"This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
771 if (Frame_Number == 1) {
772 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
780 if (!isFakedData_event) {
782 B2WARNING(
"Event Numbers do not match for this frame");
783 B2DEBUG(29,
"Event Numbers do not match for this frame" <<
784 LogVar(
"Event nr in frame $",
static_cast < std::ostringstream
785 &&
>(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
786 LogVar(
"Event nr in MetaInfo (bits masked) $",
787 static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_event_nr).str()));
794 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
795 if (countedDHEStartFrames != countedDHEEndFrames + 1)
796 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
797 if (!(
m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING(
"Data Frame outside a DHE START/END");
808 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
815 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
820 switch (frame_type) {
821 case EDHCFrameHeaderDataType::c_DHP_RAW: {
826 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
827 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
828 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
830 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
836 B2ERROR(
"Second DHP data packet (MEMDUMP) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
849 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
851 cancheck_countedBytesInDHC =
false;
852 cancheck_countedBytesInDHE =
false;
854 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
857 if (isUnfiltered_event) {
858 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP)
m_errorMask[c_nrSENDALL_TYPE] =
true;
860 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD)
m_errorMask[c_nrNOTSENDALL_TYPE] =
true;
867 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
868 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
869 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
871 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
885 dhe_first_readout_frame_id_lo,
889 currentVxdId, daqpktstat);
893 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
895 cancheck_countedBytesInDHC =
false;
896 cancheck_countedBytesInDHE =
false;
898 case EDHCFrameHeaderDataType::c_FCE_RAW: {
899 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (Clustering FCE)");
902 if (isUnfiltered_event) {
903 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
908 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
916 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
917 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
918 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
920 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
926 B2ERROR(
"Second DHP data packet (FCE) for " <<
LogVar(
"DHE", currentDHEID) <<
LogVar(
"DHP",
931 B2DEBUG(29,
"UNPACK FCE FRAME with len $" << hex << len);
932 unpack_fce((
unsigned short*) data, len - 4, currentVxdId);
936 case EDHCFrameHeaderDataType::c_COMMODE: {
939 if (!(
m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING(
"Unexpected Frame Type (COMMODE)");
945 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
946 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match" <<
947 LogVar(
"DHEID in this frame $",
static_cast < std::ostringstream
949 LogVar(
"DHEID expected $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << currentDHEID).str()));
956 case EDHCFrameHeaderDataType::c_DHC_START: {
957 countedBytesInDHC = 0;
958 cancheck_countedBytesInDHC =
true;
960 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC START mixed Fake/no Fake event.");
964 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC START Data -> trigger without Data!");
971 currentDHEID = 0xFFFFFFFF;
978 if (!isFakedData_event) {
983 B2WARNING(
"DHC-Meta Experiment number mismatch");
984 B2DEBUG(29,
"DHC-Meta Experiment number mismatch" <<
993 B2WARNING(
"DHC-Meta Run number mismatch");
994 B2DEBUG(29,
"DHC-Meta Run number mismatch" <<
1003 B2WARNING(
"DHC-Meta Sub-Run number mismatch");
1004 B2DEBUG(29,
"DHC-Meta Sub-Run number mismatch" <<
1014 B2WARNING(
"DHC-Meta 32 bit event number mismatch");
1015 B2DEBUG(29,
"DHC-Meta 32 bit event number mismatch" <<
1030 B2WARNING(
"DHC-Meta TimeTag mismatch");
1031 B2DEBUG(29,
"DHC-Meta TimeTag mismatch" <<
1032 LogVar(
"Header Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() <<
1036 LogVar(
"Meta Time $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_time).str()) <<
1037 LogVar(
"Trigger Type",
static_cast < std::ostringstream
1039 LogVar(
"Meta seconds: $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_sec).str()) <<
1040 LogVar(
"DHC seconds $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_sec).str()) <<
1041 LogVar(
"Seconds difference $",
static_cast < std::ostringstream
1042 &&
>(std::ostringstream() << hex << (trig_sec -
m_meta_sec)).str()) <<
1043 LogVar(
"Meta ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex <<
m_meta_ticks).str()) <<
1044 LogVar(
"DHC ticks from 127MHz $",
static_cast < std::ostringstream &&
>(std::ostringstream() << hex << trig_ticks).str()) <<
1045 LogVar(
"Tick difference $",
static_cast < std::ostringstream
1046 &&
>(std::ostringstream() << hex << (trig_ticks -
m_meta_ticks)).str()));
1055 nr_active_dhe =
nr5bits(mask_active_dhe);
1064 case EDHCFrameHeaderDataType::c_DHE_START: {
1065 countedBytesInDHE = 0;
1066 cancheck_countedBytesInDHE =
true;
1076 B2WARNING(
"DHH IDs are not in expected order");
1077 B2DEBUG(29,
"DHH IDs are not in expected order" <<
1078 LogVar(
"Previous ID", (currentDHEID & 0xFFFF)) <<
1086 if (countedDHEStartFrames > countedDHEEndFrames) {
1090 countedDHEStartFrames++;
1092 found_mask_active_dhp = 0;
1093 found_good_mask_active_dhp = 0;
1099 B2WARNING(
"DHE START trigger mismatch in EVT32b/HI WORD");
1100 B2DEBUG(29,
"DHE START trigger mismatch in EVT32b/HI WORD" <<
1109 if (currentDHEID == 0) {
1110 if (!(
m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING(
"DHE ID is invalid=0 (not initialized)");
1121 unsigned short sensor, ladder, layer;
1122 sensor = (currentDHEID & 0x1) + 1;
1123 ladder = (currentDHEID & 0x1E) >> 1;
1124 layer = ((currentDHEID & 0x20) >> 5) + 1;
1125 currentVxdId =
VxdID(layer, ladder, sensor);
1126 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
1128 B2WARNING(
"DHE ID is invalid");
1129 B2DEBUG(29,
"DHE ID is invalid" <<
1130 LogVar(
"DHE ID", currentDHEID) <<
1131 LogVar(
"Layer", layer) <<
1132 LogVar(
"Ladder", ladder) <<
1133 LogVar(
"Sensor", sensor));
1142 daqpktstat.
dhc_back().
newDHE(currentVxdId, currentDHEID,
m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
1146 case EDHCFrameHeaderDataType::c_GHOST:
1150 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1164 case EDHCFrameHeaderDataType::c_DHC_END: {
1166 if (!(
m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING(
"DHC END mixed Fake/no Fake event.");
1170 if (!(
m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING(
"Faked DHC END Data -> trigger without Data!");
1176 if (!isFakedData_event) {
1179 B2WARNING(
"DHC ID Mismatch between Start and End");
1180 B2DEBUG(29,
"DHC ID Mismatch between Start and End $" << std::hex <<
1187 if (cancheck_countedBytesInDHC) {
1188 if (countedBytesInDHC != w) {
1190 B2WARNING(
"Number of Words in DHC END does not match");
1191 B2DEBUG(29,
"Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC <<
" != DHC END $" << hex << w);
1196 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHC <<
" == DHC END $" << hex << w);
1203 if (!(
m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR(
"DHC END Error Info set to $" << hex <<
1220 currentDHEID = 0xFFFFFFFF;
1221 currentDHCID = 0xFFFFFFFF;
1225 case EDHCFrameHeaderDataType::c_DHE_END: {
1229 B2WARNING(
"DHE ID from DHE Start and this frame do not match");
1230 B2DEBUG(29,
"DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID <<
" != $" <<
1243 if (found_mask_active_dhp != mask_active_dhp) {
1245 B2WARNING(
"DHE_END: DHP active mask differs from found data");
1246 B2DEBUG(29,
"DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp <<
" != $" << hex <<
1247 found_mask_active_dhp
1248 <<
" mask of found dhp/ghost frames");
1252 countedDHEEndFrames++;
1253 if (countedDHEStartFrames < countedDHEEndFrames) {
1261 if (cancheck_countedBytesInDHE) {
1262 if (countedBytesInDHE != w) {
1264 B2WARNING(
"Number of Words in DHE END does not match");
1265 B2DEBUG(29,
"Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE <<
" != DHE END $" << hex << w);
1270 B2DEBUG(29,
"EVT END: WIE $" << hex << countedBytesInDHE <<
" == DHE END $" << hex << w);
1290 currentDHEID |= 0xFF000000;
1294 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
1311 m_storeROIs.appendNew(l, &((
unsigned int*) data)[1]);
1315 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
1316 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
1319 B2WARNING(
"Trigger Frame HLT Trigger Nr mismatch");
1320 B2DEBUG(29,
"Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
1329 B2WARNING(
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
1330 B2DEBUG(29,
"Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
1341 B2WARNING(
"Trigger Frame DATCON Trigger Nr mismatch");
1342 B2DEBUG(29,
"Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
1351 B2WARNING(
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
1352 B2DEBUG(29,
"Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
1367 if (Frame_Number != 0) {
1368 if (!(
m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING(
"ONSEN TRG Frame must be the first one.");
1383 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
1385 B2WARNING(
"Frame TrigNr != ONSEN Trig Nr");
1386 B2DEBUG(29,
"Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame <<
" != $" << eventNrOfOnsenTrgFrame);
1391 if (Frame_Number == 0) {
1393 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1395 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"First frame is not a ONSEN Trigger frame");
1401 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1402 if (!(
m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING(
"More than one ONSEN Trigger frame");
1408 if (Frame_Number == 1) {
1410 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1411 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"Second frame is not a DHC start of subevent frame");
1416 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1417 if (!(
m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING(
"More than one DHC start of subevent frame");
1423 if (Frame_Number == Frames_in_event - 1) {
1425 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
1426 if (!(
m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING(
"Last frame is not a DHC end of subevent frame");
1431 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
1434 B2WARNING(
"The number of DHE Start/End does not match the number of active DHE in DHC Header!");
1435 B2DEBUG(29,
"The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
1436 " Start: " << countedDHEStartFrames <<
" End: " << countedDHEEndFrames <<
" Mask: $" << hex << mask_active_dhe <<
" in Event Nr " <<
1437 eventNrOfThisFrame);
1439 if (countedDHEStartFrames == countedDHEEndFrames)
m_errorMask[c_nrDHE_ACTIVE] =
true;
1440 if (countedDHEStartFrames > countedDHEEndFrames)
m_errorMask[c_nrDHE_START_WO_END] =
true;
1441 if (countedDHEStartFrames < countedDHEEndFrames)
m_errorMask[c_nrDHE_END_WO_START] =
true;
1446 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
1447 if (!(
m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING(
"More than one DHC end of subevent frame");
1454 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1455 if (!(
m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING(
"Third frame is not a DHE start frame");
1460 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1462 countedBytesInDHC += len;
1463 countedBytesInDHE += len;
1465 B2DEBUG(29,
"DHC/DHE $" << hex << countedBytesInDHC <<
", $" << hex << countedBytesInDHE);
1471 const int lut[32] = {
1472 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1473 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5
1475 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.
PXDDAQDHPStatus & dhp_back()
Returns PXDDAQDHPStatus for the last DHP.
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.
void setTruncated(void)
set Truncation
The PXD DAQ Packet Status class.
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask This should be the OR of error masks of all sub-objects (DHC, DHE)
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.
std::string m_PXDRawHitsName
The name of the StoreArray of PXDRawHits to be generated.
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.
PXDUnpackerOTModule()
Constructor defining the parameters.
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_dhp(void *data, unsigned int len, 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.
unsigned long m_meta_event_nr
Event Number from MetaInfo.
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.
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)
void unpack_dhp_raw(void *data, unsigned int len, unsigned int dhe_ID, unsigned dhe_DHPport, VxdID vxd_id)
Unpack DHP RAW data within one DHE frame (pedestals, etc)
PXDError::PXDErrorFlags m_criticalErrorMask
Critical error mask which defines return value of task.
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.
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.
void unpack_dhc_frame(void *data, const int len, const int Frame_Number, const int Frames_in_event, PXDDAQPacketStatus &daqpktstat)
Unpack one frame (within an event).
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.
std::string m_PXDRawROIsName
The name of the StoreArray of PXDRawROIs to be generated.
const dhc_ghost_frame * data_ghost_frame
data_ghost_frame
unsigned int getEventNrLo(void) const
get event nr lo (from data)
const dhc_end_frame * data_dhc_end_frame
data_dhc_end_frame
unsigned int getFixedSize(void)
get fixed size
int getFrameType(void)
get type of frame
const dhc_dhe_start_frame * data_dhe_start_frame
data_dhe_start_frame
void set(const void *d, unsigned int t)
set data and type (and length to 0)
const dhc_start_frame * data_dhc_start_frame
data_dhc_start_frame
const dhc_direct_readout_frame * data_direct_readout_frame
data_direct_readout_frame
const dhc_dhe_end_frame * data_dhe_end_frame
data_dhe_end_frame
void check_padding(PXDErrorFlags &errormask)
check padding and return it
const dhc_onsen_roi_frame * data_onsen_roi_frame
data_onsen_roi_frame
const dhc_direct_readout_frame_raw * data_direct_readout_frame_raw
data_direct_readout_frame_raw
const dhc_commode_frame * data_commode_frame
data_commode_frame
void check_crc(PXDErrorFlags &errormask, bool ignore_crc_flag=false)
check crc and return it
const dhc_onsen_trigger_frame * data_onsen_trigger_frame
data_onsen_trigger_frame
virtual int * data(void)
get pointer to data
virtual int size() const
get size of buffer in 32 Bit words
Class to uniquely identify a any structure of the PXD and SVD.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
std::tuple< uint8_t, uint16_t, uint8_t > PXDDAQDHPComMode
tuple of Chip ID (2 bit), Row (10 bit), Common Mode (6 bit)
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
boost::endian::big_uint16_t ubig16_t
define alias ubig16_t
boost::endian::big_uint32_t ubig32_t
define alias ubig32_t
Abstract base class for different kinds of events.
unsigned int getDHEId(void) const
get DHE Id (from word0)
void print(void) const
print
unsigned int get_words(void) const
get words
unsigned int getDHEId(void) const
get DHE Id
unsigned int getErrorInfo(void) const
get error info
void print(void) const
print
unsigned int getDHEId(void) const
get DHE Id (from word0)
unsigned short getEventNrLo(void) const
get trigger_nr_lo
unsigned short getTriggerGate(void) const
trigger gate (updated to 8 bit, before 10!)
unsigned short getStartFrameNr(void) const
last DHP frame before trigger
unsigned short getEventNrHi(void) const
get trigger_nr_hi
unsigned int getActiveDHPMask(void) const
get Active DHP Mask (from word0)
void print(void) const
print
bool getDataReformattedFlag(void) const
get DataReformattedFlag (from word0)
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DHP Port (from word0)
void print(void) const
print
unsigned int get_words(void) const
get words
bool isFakedData(void) const
is faked data
unsigned int get_dhc_id(void) const
get dhc id (from word0)
unsigned int getErrorInfo(void) const
get error info
void print(void) const
print
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DDHP port (from word0)
void print(void) const
print
unsigned int check_inner_crc(PXDErrorFlags &, unsigned int) const
check inner crc (currently not implemented/needed)
void check_error(PXDErrorFlags &errormask, int length, bool ignore_inv_size_flag=false) const
check error and return error mask
int getMinSize(void) const
4 byte header, ROIS (n*8), 4 byte copy of inner CRC, 4 byte outer CRC
void print(void) const
print
unsigned short get_subrun1(void) const
get subrun1 (from trigtag1)
unsigned int get_trig_nr1(void) const
get trignr1
bool is_SendUnfiltered(void) const
is sendUnfiltered
bool is_SendROIs(void) const
is sendROIs
void check_error(PXDErrorFlags &errormask, bool ignore_datcon_flag=false, bool ignore_hltroi_magic_flag=false, bool ignore_merger_mm_flag=false) const
check error and return error mask
unsigned short get_run2(void) const
get run2 (from trigtag2)
bool is_fake_datcon(void) const
is fake datcon
unsigned short get_experiment1(void) const
get experiment1 (from trigtag1)
unsigned int get_trig_nr2(void) const
get trignr2
unsigned short get_experiment2(void) const
get experiment2
unsigned short get_subrun2(void) const
get subrun2 (from trigtag2)
bool is_Accepted(void) const
is accepted
unsigned short get_run1(void) const
get run1 (from trigtag1)
void print(void) const
print
unsigned short get_gated_isher(void) const
get gated_isher (from word0)
unsigned short get_subrun(void) const
get subrun (from run_subrun)
unsigned short get_run(void) const
get run (from run_subrun)
unsigned short get_dhc_id(void) const
get dhc_id (from word0)
const ubig16_t time_tag_hi
time_tag_hi
const ubig16_t time_tag_mid
time_tag_mid
bool isFakedData(void) const
isFakedData
unsigned short getEventNrLo(void) const
get trigger_nr_lo
unsigned short get_experiment(void) const
get experiment (from exp_run)
unsigned short get_gated_flag(void) const
get gated_flag (from word0)
unsigned short get_active_dhe_mask(void) const
get active_dhe_mask (from word0)
const ubig16_t time_tag_lo_and_type
time_tag_lo_and_type
unsigned short getEventNrHi(void) const
get trigger_nr_hi