Skip to content

Commit

Permalink
Merge pull request cms-sw#128 from yulunmiao/digi_SOA_flag
Browse files Browse the repository at this point in the history
Add flags to digi SoA & fix SoA alignment
  • Loading branch information
IzaakWN authored Aug 2, 2024
2 parents be2511d + be54b0a commit 6cf9779
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 49 deletions.
14 changes: 14 additions & 0 deletions DataFormats/HGCalDigi/interface/HGCalRawDataDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ namespace hgcal {
SLINK_STATUS_MASK = 0xffff,
SLINK_STATUS_POS = 0,
};

enum DIGI_FLAG {
//Flags for normal ECON-D
FULL_READOUT = 0x0000,
ZS_ADCm1 = 0x0001,
ZS_ToA = 0x0002,
ZS_ToA_ADCm1 = 0x0003,
Invalid = 0x0004,
//Flags for passthrough ECON-D
Normal = 0x8000,
Characterization = 0x8001,
//Flag for digi not in raw data
NotAvailable = 0xFFFF
};
} // namespace hgcal

#endif
18 changes: 17 additions & 1 deletion EventFilter/HGCalRawToDigi/interface/HGCalUnpacker.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#ifndef EventFilter_HGCalRawToDigi_HGCalUnpacker_h
#define EventFilter_HGCalRawToDigi_HGCalUnpacker_h

#include "DataFormats/HGCalDigi/interface/HGCalRawDataDefinitions.h"
#include "DataFormats/FEDRawData/interface/FEDRawData.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiHost.h"
#include "DataFormats/HGCalDigi/interface/HGCalECONDInfoHost.h"
Expand Down Expand Up @@ -130,7 +131,22 @@ class HGCalUnpacker {
0b1111111111,
0b1111111111,
0b1111111111};

constexpr static uint16_t flags_[16] = {hgcal::DIGI_FLAG::ZS_ToA,
hgcal::DIGI_FLAG::ZS_ToA_ADCm1,
hgcal::DIGI_FLAG::ZS_ToA,
hgcal::DIGI_FLAG::ZS_ADCm1,
hgcal::DIGI_FLAG::FULL_READOUT,
hgcal::DIGI_FLAG::FULL_READOUT,
hgcal::DIGI_FLAG::FULL_READOUT,
hgcal::DIGI_FLAG::FULL_READOUT,
hgcal::DIGI_FLAG::Invalid,
hgcal::DIGI_FLAG::Invalid,
hgcal::DIGI_FLAG::Invalid,
hgcal::DIGI_FLAG::Invalid,
hgcal::DIGI_FLAG::FULL_READOUT,
hgcal::DIGI_FLAG::FULL_READOUT,
hgcal::DIGI_FLAG::FULL_READOUT,
hgcal::DIGI_FLAG::FULL_READOUT};
constexpr static uint32_t erxBodyBits_[16] = {24, 16, 24, 24, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32};

// HGCalUnpackerConfig config_;
Expand Down
4 changes: 4 additions & 0 deletions EventFilter/HGCalRawToDigi/plugins/HGCalRawToDigi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiHost.h"
#include "DataFormats/HGCalDigi/interface/HGCalECONDInfoHost.h"
#include "DataFormats/HGCalDigi/interface/HGCalRawDataDefinitions.h"

#include "CondFormats/DataRecord/interface/HGCalElectronicsMappingRcd.h"
#include "CondFormats/HGCalObjects/interface/HGCalMappingModuleIndexer.h"
Expand Down Expand Up @@ -112,6 +113,9 @@ void HGCalRawToDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
// retrieve the FED raw data
const auto& raw_data = iEvent.get(fedRawToken_);

for(int32_t i=0; i < digis.view().metadata().size();i++){
digis.view()[i].flags() = hgcal::DIGI_FLAG::NotAvailable;
}
for (unsigned fedId = 0; fedId < moduleIndexer_.nfeds_; ++fedId) {
const auto& fed_data = raw_data.FEDData(fedId);
if (fed_data.size() == 0)
Expand Down
90 changes: 42 additions & 48 deletions EventFilter/HGCalRawToDigi/src/HGCalUnpacker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
hgcaldigi::HGCalDigiHost& digis,
hgcaldigi::HGCalECONDInfoHost& econdInfo,
bool headerOnlyMode) {
// number of non-CM channels (= 37)
constexpr uint16_t maxChPerErxNonCM = HGCalMappingCellIndexer::maxChPerErx_ - 2;

// ReadoutSequence object for this FED
const auto& fedReadoutSequence = moduleIndexer.fedReadoutSequences_[fedId];
// Configuration object for this FED
Expand Down Expand Up @@ -51,10 +48,10 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,

const auto* ptr = header;
for (unsigned iword = 0; ptr < trailer; ++iword) {
LogDebug("[HGCalUnpacker]") << std::setw(8) << iword << ": 0x" << std::hex << std::setfill('0') << std::setw(16) << *ptr << " ("
<< std::setfill('0') << std::setw(8) << *(reinterpret_cast<const uint32_t*>(ptr) + 1) << " "
<< std::setfill('0') << std::setw(8) << *reinterpret_cast<const uint32_t*>(ptr) << ")" << std::dec
;
LogDebug("[HGCalUnpacker]") << std::setw(8) << iword << ": 0x" << std::hex << std::setfill('0') << std::setw(16)
<< *ptr << " (" << std::setfill('0') << std::setw(8)
<< *(reinterpret_cast<const uint32_t*>(ptr) + 1) << " " << std::setfill('0')
<< std::setw(8) << *reinterpret_cast<const uint32_t*>(ptr) << ")" << std::dec;
++ptr;
}

Expand Down Expand Up @@ -84,11 +81,12 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
for (uint32_t captureblockIdx = 0; captureblockIdx < HGCalMappingModuleIndexer::maxCBperFED_ && ptr < trailer - 2;
captureblockIdx++) {
// check capture block header (64b)
LogDebug("[HGCalUnpacker]") << "@" << std::setw(8) << std::distance(header, ptr) << ": 0x" << std::hex << std::setfill('0')
<< std::setw(16) << *ptr << std::dec;
LogDebug("[HGCalUnpacker]") << "@" << std::setw(8) << std::distance(header, ptr) << ": 0x" << std::hex
<< std::setfill('0') << std::setw(16) << *ptr << std::dec;
auto cb_header = *ptr;
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx << ", cb_header = " << std::hex
<< std::setfill('0') << std::setw(16) << cb_header << std::dec;
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
<< ", cb_header = " << std::hex << std::setfill('0') << std::setw(16) << cb_header
<< std::dec;
// sanity check
if (((cb_header >> (BACKEND_FRAME::CAPTUREBLOCK_RESERVED_POS + 32)) & BACKEND_FRAME::CAPTUREBLOCK_RESERVED_MASK) !=
fedConfig.cbHeaderMarker) {
Expand All @@ -105,27 +103,26 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
++ptr;
// parse Capture Block body (ECON-Ds)
for (uint32_t econdIdx = 0; econdIdx < HGCalMappingModuleIndexer::maxECONDperCB_; econdIdx++) {

auto econd_pkt_status = (cb_header >> (3 * econdIdx)) & 0b111;
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx << ", econdIdx = " << econdIdx
<< ", econd_pkt_status = " << econd_pkt_status;
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
<< ", econdIdx = " << econdIdx << ", econd_pkt_status = " << econd_pkt_status;
if (econd_pkt_status != backend::ECONDPacketStatus::InactiveECOND) {
// always increment the global ECON-D index (unless inactive/unconnected)
globalECONDIdx++;
}

bool pkt_exists =
(econd_pkt_status == backend::ECONDPacketStatus::Normal) ||
(econd_pkt_status == backend::ECONDPacketStatus::PayloadCRCError) ||
(econd_pkt_status == backend::ECONDPacketStatus::EventIDMismatch) ||
(fedConfig.mismatchPassthroughMode && econd_pkt_status == backend::ECONDPacketStatus::BCIDOrbitIDMismatch);
(econd_pkt_status == backend::ECONDPacketStatus::Normal) ||
(econd_pkt_status == backend::ECONDPacketStatus::PayloadCRCError) ||
(econd_pkt_status == backend::ECONDPacketStatus::EventIDMismatch) ||
(fedConfig.mismatchPassthroughMode && econd_pkt_status == backend::ECONDPacketStatus::BCIDOrbitIDMismatch);
if (!pkt_exists) {
continue;
continue;
}

// ECON-D header (two 32b words)
LogDebug("[HGCalUnpacker]") << "@" << std::setw(8) << std::distance(header, ptr) << ": 0x" << std::hex << std::setfill('0')
<< std::setw(16) << *ptr << std::dec;
LogDebug("[HGCalUnpacker]") << "@" << std::setw(8) << std::distance(header, ptr) << ": 0x" << std::hex
<< std::setfill('0') << std::setw(16) << *ptr << std::dec;
auto econd_headers = to_32b_words(ptr);
uint32_t ECONDdenseIdx = moduleIndexer.getIndexForModule(fedId, globalECONDIdx);
econdInfo.view()[ECONDdenseIdx].location() = (uint32_t)(ptr - header);
Expand All @@ -134,10 +131,10 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
fedConfig.econds[globalECONDIdx].headerMarker) {
econdInfo.view()[ECONDdenseIdx].exception() = 3;

//DO NOT THROW!! just flag as exception and try to continue
//DO NOT THROW!! just flag as exception and try to continue
//throw cms::Exception("CorruptData")
// << "Expected a ECON-D header at word " << std::dec << (uint32_t)(ptr - header) << "/0x" << std::hex
// << (uint32_t)(ptr - header) << " (marker: 0x" << fedConfig.econds[globalECONDIdx].headerMarker
// << (uint32_t)(ptr - header) << " (marker: 0x" << fedConfig.econds[globalECONDIdx].headerMarker
// << "), got 0x" << econd_headers[0] << ".";
}
++ptr;
Expand All @@ -156,16 +153,17 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
econdInfo.view()[ECONDdenseIdx].payloadLength() = (uint16_t)econd_payload_length;
econdInfo.view()[ECONDdenseIdx].econdFlag() = (uint8_t)econdFlag;
econdInfo.view()[ECONDdenseIdx].exception() = 0;

// convert ECON-D packets into 32b words -- need to swap the order of the two 32b words in the 64b word
auto econd_payload = to_econd_payload(ptr, econd_payload_length);

// forward ptr to the next ECON-D; use integer division with (... + 1) / 2 to round up
ptr += (econd_payload_length + 1) / 2;

LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx << ", econdIdx = " << econdIdx
<< ", econd_headers = " << std::hex << std::setfill('0') << std::setw(8) << econd_headers[0] << " "
<< econd_headers[1] << std::dec << ", econd_payload_length = " << econd_payload_length;
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
<< ", econdIdx = " << econdIdx << ", econd_headers = " << std::hex
<< std::setfill('0') << std::setw(8) << econd_headers[0] << " " << econd_headers[1]
<< std::dec << ", econd_payload_length = " << econd_payload_length;

//quality check for ECON-D (no need to check again econd_pkt_status here again)
if ((((econd_headers[0] >> ECOND_FRAME::HT_POS) & ECOND_FRAME::HT_MASK) >= 0b10) ||
Expand All @@ -189,8 +187,8 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
if ((enabledErx >> erxIdx & 1) == 0) {
continue;
}
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx << ", econdIdx = " << econdIdx
<< ", erxIdx=" << erxIdx;
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
<< ", econdIdx = " << econdIdx << ", erxIdx=" << erxIdx;

// check if the eRx sub-packet is empty (the "F" flag in the eRx sub-packet header)
if (((econd_payload[iword] >> ECOND_FRAME::ERXFORMAT_POS) & ECOND_FRAME::ERXFORMAT_MASK) == 1) {
Expand All @@ -203,18 +201,17 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
uint16_t cmSum = ((econd_payload[iword] >> ECOND_FRAME::COMMONMODE0_POS) & ECOND_FRAME::COMMONMODE0_MASK) +
((econd_payload[iword + 1] >> ECOND_FRAME::COMMONMODE1_POS) & ECOND_FRAME::COMMONMODE1_MASK);
uint64_t erxHeader = ((uint64_t)econd_payload[iword] << 32) | ((uint64_t)econd_payload[iword + 1]);
LogDebug("[HGCalUnpacker]") << "erx_headers = 0x" << std::hex << std::setfill('0') << std::setw(16) << erxHeader
<< ", cmSum = " << std::dec << cmSum;
LogDebug("[HGCalUnpacker]") << "erx_headers = 0x" << std::hex << std::setfill('0') << std::setw(16)
<< erxHeader << ", cmSum = " << std::dec << cmSum;
iword += 2;

// parse erx body (channel data)
uint32_t iBit = 0;
for (uint32_t channelIdx = 0; channelIdx < maxChPerErxNonCM; channelIdx++) {
for (uint32_t channelIdx = 0; channelIdx < HGCalMappingCellIndexer::maxChPerErx_; channelIdx++) {
uint32_t denseIdx = moduleIndexer.getIndexForModuleData(fedId, globalECONDIdx, erxIdx, channelIdx);

// check if the channel has data
if (((erxHeader >> channelIdx) & 1) == 0) {
//digis.view()[denseIdx].flags() = FIXME! set flag as suppressed
continue;
}

Expand Down Expand Up @@ -246,8 +243,8 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
if ((enabledErx >> erxIdx & 1) == 0) {
continue;
}
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx << ", econdIdx = " << econdIdx
<< ", erxIdx=" << erxIdx;
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
<< ", econdIdx = " << econdIdx << ", erxIdx=" << erxIdx;

// check if the eRx sub-packet is empty (the "F" flag in the eRx sub-packet header)
if (((econd_payload[iword] >> ECOND_FRAME::ERXFORMAT_POS) & ECOND_FRAME::ERXFORMAT_MASK) == 1) {
Expand All @@ -260,17 +257,16 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
uint16_t cmSum = ((econd_payload[iword] >> ECOND_FRAME::COMMONMODE0_POS) & ECOND_FRAME::COMMONMODE0_MASK) +
((econd_payload[iword + 1] >> ECOND_FRAME::COMMONMODE1_POS) & ECOND_FRAME::COMMONMODE1_MASK);
uint64_t erxHeader = ((uint64_t)econd_payload[iword] << 32) | ((uint64_t)econd_payload[iword + 1]);
LogDebug("[HGCalUnpacker]") << "erx_headers = 0x" << std::hex << std::setfill('0') << std::setw(16) << erxHeader
<< ", cmSum = " << std::dec << cmSum;
LogDebug("[HGCalUnpacker]") << "erx_headers = 0x" << std::hex << std::setfill('0') << std::setw(16)
<< erxHeader << ", cmSum = " << std::dec << cmSum;
iword += 2;

// parse erx body (channel data)
for (uint32_t channelIdx = 0; channelIdx < maxChPerErxNonCM; channelIdx++) {
for (uint32_t channelIdx = 0; channelIdx < HGCalMappingCellIndexer::maxChPerErx_; channelIdx++) {
uint32_t denseIdx = moduleIndexer.getIndexForModuleData(fedId, globalECONDIdx, erxIdx, channelIdx);

// check if the channel has data
if (((erxHeader >> channelIdx) & 1) == 0) {
//digis.view()[denseIdx].flags() = FIXME! set flag as suppressed
if (((erxHeader >> channelIdx) & 1) == 0) {
continue;
}

Expand All @@ -283,9 +279,8 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
digis.view()[denseIdx].tot() = (econd_payload[iword] >> 10) & 0b1111111111;
digis.view()[denseIdx].toa() = econd_payload[iword] & 0b1111111111;
digis.view()[denseIdx].cm() = cmSum;
digis.view()[denseIdx].flags() = 0;

} else {
digis.view()[denseIdx].flags() = hgcal::DIGI_FLAG::Characterization;
} else {
//not characteristic mode
digis.view()[denseIdx].tctp() = (econd_payload[iword] >> 30) & 0b11;

Expand All @@ -299,22 +294,21 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
}
digis.view()[denseIdx].toa() = econd_payload[iword] & 0b1111111111;
digis.view()[denseIdx].cm() = cmSum;
digis.view()[denseIdx].flags() = 0;
digis.view()[denseIdx].flags() = hgcal::DIGI_FLAG::Normal;
}
iword += 1;
}
}
}
// end of ECON-D parsing
if (iword != econd_payload_length - 1) {
econdInfo.view()[ECONDdenseIdx].exception() = 5;
//SHOULD NOT THROW!!!!
econdInfo.view()[ECONDdenseIdx].exception() = 5;
//SHOULD NOT THROW!!!!
//throw cms::Exception("CorruptData")
// << "Mismatch between unpacked and expected ECON-D #" << (int)globalECONDIdx << " payload length\n"
// << " unpacked payload length=" << iword + 1 << "\n"
// << " expected payload length=" << econd_payload_length;
}

}
// skip the padding word as capture blocks are padded to 128b
if (std::distance(ptr, header) % 2) {
Expand Down

0 comments on commit 6cf9779

Please sign in to comment.