Skip to content

Commit 6953b9f

Browse files
authored
Merge pull request #48449 from hqucms/dev/hgcal-unpacker-update
[HGCAL] Update HGCal unpacker to handle flexible fedId assignment
2 parents 8e70124 + ea18065 commit 6953b9f

File tree

3 files changed

+57
-19
lines changed

3 files changed

+57
-19
lines changed

EventFilter/HGCalRawToDigi/plugins/HGCalRawToDigi.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ void HGCalRawToDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
104104
//serial unpacking calls
105105
if (doSerial_) {
106106
for (unsigned fedId = 0; fedId < moduleIndexer.fedCount(); ++fedId) {
107+
const auto& frs = moduleIndexer.getFEDReadoutSequences()[fedId];
108+
if (frs.readoutTypes_.empty()) {
109+
continue;
110+
}
107111
const auto& fed_data = raw_data.FEDData(fedId);
108112
fedPacketInfo.view()[fedId].FEDPayload() = fed_data.size();
109113
if (fed_data.size() == 0)
@@ -116,6 +120,10 @@ void HGCalRawToDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
116120
else {
117121
oneapi::tbb::this_task_arena::isolate([&]() {
118122
oneapi::tbb::parallel_for(0U, moduleIndexer.fedCount(), [&](unsigned fedId) {
123+
const auto& frs = moduleIndexer.getFEDReadoutSequences()[fedId];
124+
if (frs.readoutTypes_.empty()) {
125+
return;
126+
}
119127
const auto& fed_data = raw_data.FEDData(fedId);
120128
fedPacketInfo.view()[fedId].FEDPayload() = fed_data.size();
121129
if (fed_data.size() == 0)

EventFilter/HGCalRawToDigi/src/HGCalUnpacker.cc

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <iostream>
44
#include <iterator>
55
#include <vector>
6+
#include <bitset>
67

78
#include "CondFormats/HGCalObjects/interface/HGCalMappingCellIndexer.h"
89
#include "CondFormats/HGCalObjects/interface/HGCalMappingModuleIndexer.h"
@@ -50,7 +51,7 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
5051
// Others: big endianness
5152
const auto* const header = reinterpret_cast<const uint64_t*>(fed_data.data());
5253
const auto* const trailer = reinterpret_cast<const uint64_t*>(fed_data.data() + fed_data.size());
53-
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << " nwords (64b) = " << std::distance(header, trailer);
54+
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", nwords (64b) = " << std::distance(header, trailer);
5455
const auto* ptr = header;
5556

5657
#ifdef EDM_ML_DEBUG
@@ -77,7 +78,7 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
7778
<< "), got 0x" << std::hex
7879
<< ((slink_header >> (BACKEND_FRAME::SLINK_BOE_POS + 32)) &
7980
BACKEND_FRAME::SLINK_BOE_MASK)
80-
<< " from " << slink_header << ".";
81+
<< " from word = 0x" << std::hex << slink_header << ".";
8182
return (0x1 << hgcaldigi::FEDUnpackingFlags::ErrorSLinkHeader);
8283
}
8384

@@ -130,12 +131,13 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
130131
// parse Capture Block body (ECON-Ds)
131132
for (uint32_t econdIdx = 0; econdIdx < HGCalMappingModuleIndexer::maxECONDperCB_; econdIdx++) {
132133
auto econd_pkt_status = (cb_header >> (3 * econdIdx)) & 0b111;
133-
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
134-
<< ", econdIdx = " << econdIdx << ", econd_pkt_status = " << econd_pkt_status;
135134
if (econd_pkt_status != backend::ECONDPacketStatus::InactiveECOND) {
136135
// always increment the global ECON-D index (unless inactive/unconnected)
137136
globalECONDIdx++;
138137
}
138+
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
139+
<< ", econdIdx = " << econdIdx << ", globalECONDIdx = " << (int)globalECONDIdx
140+
<< ", econd_pkt_status = " << econd_pkt_status;
139141
hasActiveCBFlags = (econd_pkt_status != backend::ECONDPacketStatus::Normal) &&
140142
(econd_pkt_status != backend::ECONDPacketStatus::InactiveECOND);
141143
bool pkt_exists =
@@ -155,21 +157,23 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
155157
econdPacketInfo.view()[ECONDdenseIdx].location() = (uint32_t)(ptr - header);
156158
const auto econd_payload_length = ((econd_headers[0] >> ECOND_FRAME::PAYLOAD_POS) & ECOND_FRAME::PAYLOAD_MASK);
157159

158-
// sanity check
160+
// ECON-D header marker check
159161
if (((econd_headers[0] >> ECOND_FRAME::HEADER_POS) & ECOND_FRAME::HEADER_MASK) !=
160162
fedConfig.econds[globalECONDIdx].headerMarker) {
161163
econdPacketInfo.view()[ECONDdenseIdx].exception() = 3;
162164
edm::LogWarning("[HGCalUnpacker]")
163165
<< "Expected a ECON-D header at word " << std::dec << (uint32_t)(ptr - header) << "/0x" << std::hex
164-
<< (uint32_t)(ptr - header) << " (marker: 0x" << fedConfig.econds[globalECONDIdx].headerMarker
165-
<< "), got 0x" << econd_headers[0] << " and payload=" << econd_payload_length << ".";
166+
<< (uint32_t)(ptr - header) << ", word = 0x" << econd_headers[0] << " (expected marker: 0x"
167+
<< fedConfig.econds[globalECONDIdx].headerMarker << ", got marker: 0x"
168+
<< ((econd_headers[0] >> ECOND_FRAME::HEADER_POS) & ECOND_FRAME::HEADER_MASK)
169+
<< "), and econd_payload_length = " << std::dec << econd_payload_length << ".";
166170
return (0x1 << hgcaldigi::FEDUnpackingFlags::ErrorECONDHeader) |
167171
(hasActiveCBFlags << hgcaldigi::FEDUnpackingFlags::ActiveCaptureBlockFlags);
168172
}
169173

170174
// Compute ECON-D trailer CRC
171175
bool crcvalid = hgcal::econdCRCAnalysis(ptr, 0, econd_payload_length);
172-
LogDebug("[HGCalUnpacker]") << "crc value " << crcvalid;
176+
LogDebug("[HGCalUnpacker]") << "CRC valid = " << crcvalid;
173177
++ptr;
174178

175179
if (!crcvalid) {
@@ -184,7 +188,7 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
184188
if (econd_payload_length > 469) {
185189
econdPacketInfo.view()[ECONDdenseIdx].exception() = 4;
186190
edm::LogWarning("[HGCalUnpacker]")
187-
<< "Unpacked payload length=" << econd_payload_length << " exceeds the maximal length=469";
191+
<< "Unpacked payload length=" << econd_payload_length << " exceeds the maximal length (=469)";
188192
return (0x1 << hgcaldigi::FEDUnpackingFlags::ECONDPayloadLengthOverflow) |
189193
(hasActiveCBFlags << hgcaldigi::FEDUnpackingFlags::ActiveCaptureBlockFlags);
190194
}
@@ -203,7 +207,13 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
203207
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
204208
<< ", econdIdx = " << econdIdx << ", econd_headers = " << std::hex
205209
<< std::setfill('0') << std::setw(8) << econd_headers[0] << " " << econd_headers[1]
206-
<< std::dec << ", econd_payload_length = " << econd_payload_length;
210+
<< ", econd_payload_length = " << std::dec << econd_payload_length << ", "
211+
<< "H/T = 0b"
212+
<< std::bitset<2>((econd_headers[0] >> ECOND_FRAME::HT_POS) & ECOND_FRAME::HT_MASK)
213+
<< ", E/B/O = 0b"
214+
<< std::bitset<2>((econd_headers[0] >> ECOND_FRAME::EBO_POS) & ECOND_FRAME::EBO_MASK)
215+
<< ", M = " << ((econd_headers[0] >> ECOND_FRAME::BITM_POS) & 0b1);
216+
207217
//quality check for ECON-D (check econd_pkt_status here for error in trailer CRC)
208218
if ((((econd_headers[0] >> ECOND_FRAME::HT_POS) & ECOND_FRAME::HT_MASK) >= 0b10) ||
209219
(((econd_headers[0] >> ECOND_FRAME::EBO_POS) & ECOND_FRAME::EBO_MASK) >= 0b10) ||
@@ -221,22 +231,23 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
221231
unsigned iword = 0;
222232
if (!pass_through_mode) {
223233
// Standard ECON-D
224-
LogDebug("[HGCalUnpacker]") << "Standard ECON-D, erxMax=" << erxMax << "enabledErx= " << enabledErx;
234+
LogDebug("[HGCalUnpacker]") << "Standard ECON-D, erxMax = " << erxMax << ", enabledErx = 0b"
235+
<< std::bitset<12>(enabledErx);
225236
for (uint32_t erxIdx = 0; erxIdx < erxMax; erxIdx++) {
226237
// check if the eRx is enabled
227238
if ((enabledErx >> erxIdx & 1) == 0) {
228239
continue;
229240
}
230241
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
231-
<< ", econdIdx = " << econdIdx << ", erxIdx=" << erxIdx;
242+
<< ", econdIdx = " << econdIdx << ", erxIdx = " << erxIdx;
232243

233244
econdPacketInfo.view()[ECONDdenseIdx].cm()(erxIdx, 0) =
234245
(econd_payload[iword] >> ECOND_FRAME::COMMONMODE0_POS) & ECOND_FRAME::COMMONMODE0_MASK;
235246
econdPacketInfo.view()[ECONDdenseIdx].cm()(erxIdx, 1) =
236247
(econd_payload[iword] >> ECOND_FRAME::COMMONMODE1_POS) & ECOND_FRAME::COMMONMODE1_MASK;
237248
// check if the eRx sub-packet is empty (the "F" flag in the eRx sub-packet header)
238249
if (((econd_payload[iword] >> ECOND_FRAME::ERXFORMAT_POS) & ECOND_FRAME::ERXFORMAT_MASK) == 1) {
239-
LogDebug("[HGCalUnpacker]") << "eRx " << erxIdx << " is empty";
250+
LogDebug("[HGCalUnpacker]") << "eRxIdx = " << erxIdx << " is empty";
240251
iword += 1; // length of an empty eRx header (32 bits)
241252
continue; // go to the next eRx
242253
}
@@ -273,6 +284,15 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
273284
digis.view()[denseIdx].cm() = cmSum;
274285
digis.view()[denseIdx].flags() = 0;
275286
iBit += erxBodyBits_[code];
287+
288+
LogDebug("[HGCalUnpacker]") << "channelIdx = " << channelIdx << ", denseIdx = " << denseIdx
289+
<< ", tctp = " << uint16_t(digis.view()[denseIdx].tctp())
290+
<< ", adcm1 = " << digis.view()[denseIdx].adcm1()
291+
<< ", adc = " << digis.view()[denseIdx].adc()
292+
<< ", tot = " << digis.view()[denseIdx].tot()
293+
<< ", toa = " << digis.view()[denseIdx].toa()
294+
<< ", cm = " << digis.view()[denseIdx].cm() << std::hex
295+
<< ", flags = " << digis.view()[denseIdx].flags();
276296
}
277297
iword += iBit / 32;
278298
if (iBit % 32 != 0) {
@@ -281,7 +301,8 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
281301
}
282302
} else {
283303
// Passthrough ECON-D
284-
LogDebug("[HGCalUnpacker]") << "Passthrough ECON-D, erxMax=" << erxMax << "enabledErx= " << enabledErx;
304+
LogDebug("[HGCalUnpacker]") << "Passthrough ECON-D, erxMax = " << erxMax << ", enabledErx = 0b"
305+
<< std::bitset<12>(enabledErx);
285306
for (uint32_t erxIdx = 0; erxIdx < erxMax; erxIdx++) {
286307
// check if the eRx is enabled
287308
if ((enabledErx >> erxIdx & 1) == 0) {
@@ -296,7 +317,7 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
296317
(econd_payload[iword] >> ECOND_FRAME::COMMONMODE1_POS) & ECOND_FRAME::COMMONMODE1_MASK;
297318
// check if the eRx sub-packet is empty (the "F" flag in the eRx sub-packet header)
298319
if (((econd_payload[iword] >> ECOND_FRAME::ERXFORMAT_POS) & ECOND_FRAME::ERXFORMAT_MASK) == 1) {
299-
LogDebug("[HGCalUnpacker]") << "eRx " << erxIdx << " is empty";
320+
LogDebug("[HGCalUnpacker]") << "erxIdx = " << erxIdx << " is empty";
300321
iword += 1; // length of an empty eRx header (32 bits)
301322
continue; // go to the next eRx
302323
}
@@ -344,8 +365,16 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
344365
digis.view()[denseIdx].cm() = cmSum;
345366
digis.view()[denseIdx].flags() = hgcal::DIGI_FLAG::Normal;
346367
}
347-
348368
iword += 1;
369+
370+
LogDebug("[HGCalUnpacker]") << "channelIdx = " << channelIdx << ", denseIdx = " << denseIdx
371+
<< ", tctp = " << uint16_t(digis.view()[denseIdx].tctp())
372+
<< ", adcm1 = " << digis.view()[denseIdx].adcm1()
373+
<< ", adc = " << digis.view()[denseIdx].adc()
374+
<< ", tot = " << digis.view()[denseIdx].tot()
375+
<< ", toa = " << digis.view()[denseIdx].toa()
376+
<< ", cm = " << digis.view()[denseIdx].cm() << std::hex
377+
<< ", flags = " << digis.view()[denseIdx].flags();
349378
}
350379
}
351380
}
@@ -371,9 +400,9 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
371400
if (ptr + 2 != trailer) {
372401
uint32_t ECONDdenseIdx = moduleIndexer.getIndexForModule(fedId, 0);
373402
econdPacketInfo.view()[ECONDdenseIdx].exception() = 6;
374-
edm::LogWarning("[HGCalUnpacker]") << "Error finding the S-link trailer, expected at" << std::dec
403+
edm::LogWarning("[HGCalUnpacker]") << "Error finding the S-link trailer, expected at " << std::dec
375404
<< (uint32_t)(trailer - header) << "/0x" << std::hex
376-
<< (uint32_t)(trailer - header) << "Unpacked trailer at" << std::dec
405+
<< (uint32_t)(trailer - header) << ", unpacked trailer at " << std::dec
377406
<< (uint32_t)(trailer - header + 2) << "/0x" << std::hex
378407
<< (uint32_t)(ptr - header + 2);
379408
return (0x1 << hgcaldigi::FEDUnpackingFlags::ErrorSLinkTrailer) |

RecoLocalCalo/HGCalRecAlgos/plugins/HGCalConfigurationESProducer.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class HGCalConfigurationESProducer : public edm::ESProducer, public edm::EventSe
9797
// follow indexing by HGCalMappingModuleIndexer
9898
// HGCalConfiguration = container class holding FED structs of ECON-D structs of eRx structs
9999
std::unique_ptr<HGCalConfiguration> config_ = std::make_unique<HGCalConfiguration>();
100+
config_->feds.resize(moduleMap.getMaxFEDSize());
100101
for (std::size_t fedid = 0; fedid < moduleMap.getMaxFEDSize(); ++fedid) {
101102
// sanity checks
102103
if (moduleMap.getFEDReadoutSequences()[fedid].readoutTypes_.empty()) // check if FED exists (non-empty)
@@ -153,7 +154,7 @@ class HGCalConfigurationESProducer : public edm::ESProducer, public edm::EventSe
153154
fed.econds[imod] = mod; // add to FED's vector<HGCalECONDConfig> of ECON-D modules
154155
}
155156

156-
config_->feds.push_back(fed); // add to config's vector of HGCalFedConfig FEDs
157+
config_->feds[fedid] = fed; // add to config's vector of HGCalFedConfig FEDs
157158
}
158159

159160
// consistency check

0 commit comments

Comments
 (0)