77#include " CondFormats/HGCalObjects/interface/HGCalMappingCellIndexer.h"
88#include " FWCore/MessageLogger/interface/MessageLogger.h"
99#include " FWCore/Utilities/interface/Exception.h"
10-
10+ # include " EventFilter/HGCalRawToDigi/interface/UnpackerTools.h "
1111#include < array>
1212
1313using namespace hgcal ;
@@ -152,12 +152,21 @@ uint8_t HGCalUnpacker::parseFEDData(unsigned fedId,
152152 << " ), got 0x" << econd_headers[0 ] << " ." ;
153153 return UNPACKER_STAT::WrongECONDHeader;
154154 }
155+ const auto econd_payload_length = ((econd_headers[0 ] >> ECOND_FRAME::PAYLOAD_POS) & ECOND_FRAME::PAYLOAD_MASK);
156+ // Compute ECON-D trailer CRC
157+ bool crcvalid = hgcal::econdCRCAnalysis (ptr, 0 , econd_payload_length);
158+ LogDebug (" [HGCalUnpacker]" ) << " crc value " << crcvalid;
155159 ++ptr;
156160
157- econdPacketInfo.view ()[ECONDdenseIdx].cbFlag () = (uint8_t )(econd_pkt_status);
161+ if (!crcvalid) {
162+ econd_pkt_status |=
163+ backend::ECONDPacketStatus::OfflinePayloadCRCError; // If CRC errors in the trailer, update the pkt status
164+ }
165+
166+ econdPacketInfo.view ()[ECONDdenseIdx].cbFlag () = (uint16_t )(econd_pkt_status);
167+
158168 // ECON-D payload length (num of 32b words)
159169 // NOTE: in the capture blocks, ECON-D packets do not have the trailing IDLE word
160- const auto econd_payload_length = ((econd_headers[0 ] >> ECOND_FRAME::PAYLOAD_POS) & ECOND_FRAME::PAYLOAD_MASK);
161170 if (econd_payload_length > 469 ) {
162171 econdPacketInfo.view ()[ECONDdenseIdx].exception () = 4 ;
163172 edm::LogWarning (" [HGCalUnpacker]" )
@@ -180,12 +189,13 @@ uint8_t HGCalUnpacker::parseFEDData(unsigned fedId,
180189 << " , econdIdx = " << econdIdx << " , econd_headers = " << std::hex
181190 << std::setfill (' 0' ) << std::setw (8 ) << econd_headers[0 ] << " " << econd_headers[1 ]
182191 << std::dec << " , econd_payload_length = " << econd_payload_length;
183-
184- // quality check for ECON-D (no need to check again econd_pkt_status here again)
192+ // quality check for ECON-D (check econd_pkt_status here for error in trailer CRC)
185193 if ((((econd_headers[0 ] >> ECOND_FRAME::HT_POS) & ECOND_FRAME::HT_MASK) >= 0b10 ) ||
186194 (((econd_headers[0 ] >> ECOND_FRAME::EBO_POS) & ECOND_FRAME::EBO_MASK) >= 0b10 ) ||
187195 (((econd_headers[0 ] >> ECOND_FRAME::BITM_POS) & 0b1 ) == 0 ) ||
188- (((econd_headers[0 ] >> ECOND_FRAME::BITM_POS) & 0b1 ) == 0 ) || econd_payload_length == 0 || headerOnlyMode) {
196+ (((econd_headers[0 ] >> ECOND_FRAME::BITM_POS) & 0b1 ) == 0 ) || econd_payload_length == 0 ||
197+ econd_pkt_status == backend::ECONDPacketStatus::OfflinePayloadCRCError ||
198+ econd_pkt_status == backend::ECONDPacketStatus::InactiveECOND || headerOnlyMode) {
189199 continue ;
190200 }
191201
0 commit comments