Skip to content

Commit f8a06f4

Browse files
committed
Record the difference of BX, L1A, and Orbit number between ECON-D and S-Link; Put all LogDebug into #ifdef EDM_ML_DEBUG
1 parent e04f43e commit f8a06f4

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

DataFormats/HGCalDigi/interface/HGCalECONDPacketInfoSoA.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ namespace hgcaldigi {
7474
// If exception found before ECON-D, this would be 0
7575
// Otherwise the payload length of the ECON-D
7676
SOA_COLUMN(uint16_t, payloadLength),
77+
// Diffrence between the BX,L1A,Orbit number in the S-Link header and the ECON-D header
78+
SOA_COLUMN(int16_t, BXdifference),
79+
SOA_COLUMN(int8_t, L1Adifference),
80+
SOA_COLUMN(int8_t, Orbitdifference),
81+
// Common modes
7782
SOA_EIGEN_COLUMN(Matrix, cm))
7883
using HGCalECONDPacketInfoSoA = HGCalECONDPacketInfoSoALayout<>;
7984
} // namespace hgcaldigi

EventFilter/HGCalRawToDigi/src/HGCalUnpacker.cc

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,24 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
4545
// Others: big endianness
4646
const auto* const header = reinterpret_cast<const uint64_t*>(fed_data.data());
4747
const auto* const trailer = reinterpret_cast<const uint64_t*>(fed_data.data() + fed_data.size());
48+
#ifdef EDM_ML_DEBUG
4849
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << " nwords (64b) = " << std::distance(header, trailer);
50+
#endif
4951
const auto* ptr = header;
5052

53+
// read L1A number from the SLink header
54+
int8_t L1ASLink = ((*(header + 1) >> BACKEND_FRAME::SLINK_GLOBAL_EVENTID_LSB_POS) &
55+
ECOND_FRAME::L1A_MASK); // use mask in ECON-D to get lowest 6 bits
56+
// read BX number and Orbit number from the SLink trailer
57+
int16_t BXSLink = ((*(trailer - 1) >> BACKEND_FRAME::SLINK_BXID_POS) &
58+
ECOND_FRAME::BX_MASK); // use mask in ECON-D to get lowest 12 bits
59+
int8_t OrbitSLink = ((*(trailer - 2) >> (BACKEND_FRAME::SLINK_ORBID_POS + 32)) &
60+
ECOND_FRAME::ORBIT_MASK); // use mask in ECON-D to get lowest 3 bits
5161
#ifdef EDM_ML_DEBUG
62+
LogDebug("[HGCalUnpacker]") << "Global BX number:" << std::dec << BXSLink;
63+
LogDebug("[HGCalUnpacker]") << "Global L1A number:" << std::dec << (int)L1ASLink;
64+
LogDebug("[HGCalUnpacker]") << "Global Orbit ID:" << std::dec << (int)OrbitSLink;
65+
5266
for (unsigned iword = 0; ptr < trailer; ++iword) {
5367
LogDebug("[HGCalUnpacker]") << std::setw(8) << iword << ": 0x" << std::hex << std::setfill('0') << std::setw(16)
5468
<< *ptr << " (" << std::setfill('0') << std::setw(8)
@@ -86,12 +100,17 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
86100
for (uint32_t captureblockIdx = 0; captureblockIdx < HGCalMappingModuleIndexer::maxCBperFED_ && ptr < trailer - 2;
87101
captureblockIdx++) {
88102
// check capture block header (64b)
103+
#ifdef EDM_ML_DEBUG
89104
LogDebug("[HGCalUnpacker]") << "@" << std::setw(8) << std::distance(header, ptr) << ": 0x" << std::hex
90105
<< std::setfill('0') << std::setw(16) << *ptr << std::dec;
106+
#endif
91107
auto cb_header = *ptr;
108+
#ifdef EDM_ML_DEBUG
92109
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
93110
<< ", cb_header = " << std::hex << std::setfill('0') << std::setw(16) << cb_header
94111
<< std::dec;
112+
#endif
113+
95114
// sanity check
96115
if (((cb_header >> (BACKEND_FRAME::CAPTUREBLOCK_RESERVED_POS + 32)) & BACKEND_FRAME::CAPTUREBLOCK_RESERVED_MASK) !=
97116
fedConfig.cbHeaderMarker) {
@@ -103,10 +122,12 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
103122
auto nToEnd = (fed_data.size() / 8 - 2) - std::distance(header, ptr);
104123
if (nToEnd == 1) {
105124
ptr++;
125+
#ifdef EDM_ML_DEBUG
106126
LogDebug("[HGCalUnpacker]")
107127
<< "fedId = " << fedId
108128
<< ", 64b padding word caught before parsing all max capture blocks, captureblockIdx = "
109129
<< captureblockIdx;
130+
#endif
110131
econdPacketInfo.view()[ECONDdenseIdx].exception() = 7;
111132
return (0x1 << hgcaldigi::FEDUnpackingFlags::ErrorCaptureBlockHeader);
112133
}
@@ -125,8 +146,10 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
125146
// parse Capture Block body (ECON-Ds)
126147
for (uint32_t econdIdx = 0; econdIdx < HGCalMappingModuleIndexer::maxECONDperCB_; econdIdx++) {
127148
auto econd_pkt_status = (cb_header >> (3 * econdIdx)) & 0b111;
149+
#ifdef EDM_ML_DEBUG
128150
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
129151
<< ", econdIdx = " << econdIdx << ", econd_pkt_status = " << econd_pkt_status;
152+
#endif
130153
if (econd_pkt_status != backend::ECONDPacketStatus::InactiveECOND) {
131154
// always increment the global ECON-D index (unless inactive/unconnected)
132155
globalECONDIdx++;
@@ -143,13 +166,33 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
143166
}
144167

145168
// ECON-D header (two 32b words)
169+
#ifdef EDM_ML_DEBUG
146170
LogDebug("[HGCalUnpacker]") << "@" << std::setw(8) << std::distance(header, ptr) << ": 0x" << std::hex
147171
<< std::setfill('0') << std::setw(16) << *ptr << std::dec;
172+
#endif
148173
auto econd_headers = to_32b_words(ptr);
149174
uint32_t ECONDdenseIdx = moduleIndexer.getIndexForModule(fedId, globalECONDIdx);
150175
econdPacketInfo.view()[ECONDdenseIdx].location() = (uint32_t)(ptr - header);
151176
const auto econd_payload_length = ((econd_headers[0] >> ECOND_FRAME::PAYLOAD_POS) & ECOND_FRAME::PAYLOAD_MASK);
152177

178+
// read BX, L1A, and Orbit number from the ECON-D header
179+
int16_t BXECOND = ((econd_headers[1] >> ECOND_FRAME::BX_POS) & ECOND_FRAME::BX_MASK);
180+
int8_t L1AECOND = ((econd_headers[1] >> ECOND_FRAME::L1A_POS) & ECOND_FRAME::L1A_MASK);
181+
int8_t OrbitECOND = ((econd_headers[1] >> ECOND_FRAME::ORBIT_POS) & ECOND_FRAME::ORBIT_MASK);
182+
// save the difference between the SLink and ECON-D BX, L1A, and Orbit numbers(ECON-D - SLink)
183+
econdPacketInfo.view()[ECONDdenseIdx].BXdifference() = BXECOND - BXSLink;
184+
econdPacketInfo.view()[ECONDdenseIdx].L1Adifference() = L1AECOND - L1ASLink;
185+
econdPacketInfo.view()[ECONDdenseIdx].Orbitdifference() = OrbitECOND - OrbitSLink;
186+
#ifdef EDM_ML_DEBUG
187+
LogDebug("[HGCalUnpacker]") << "SLink BX number:" << std::dec << BXSLink << ", ECON-D BX number:" << std::dec
188+
<< BXECOND << ", difference:" << econdPacketInfo.view()[ECONDdenseIdx].BXdifference();
189+
LogDebug("[HGCalUnpacker]") << "SLink L1A number:" << std::dec << (int)L1ASLink
190+
<< ", ECON-D L1A number:" << std::dec << (int)L1AECOND
191+
<< ", difference:" << (int)econdPacketInfo.view()[ECONDdenseIdx].L1Adifference();
192+
LogDebug("[HGCalUnpacker]") << "SLink Orbit number:" << std::dec << (int)OrbitSLink
193+
<< ", ECON-D Orbit number:" << std::dec << (int)OrbitECOND
194+
<< ", difference:" << (int)econdPacketInfo.view()[ECONDdenseIdx].Orbitdifference();
195+
#endif
153196
// sanity check
154197
if (((econd_headers[0] >> ECOND_FRAME::HEADER_POS) & ECOND_FRAME::HEADER_MASK) !=
155198
fedConfig.econds[globalECONDIdx].headerMarker) {
@@ -164,7 +207,9 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
164207

165208
// Compute ECON-D trailer CRC
166209
bool crcvalid = hgcal::econdCRCAnalysis(ptr, 0, econd_payload_length);
210+
#ifdef EDM_ML_DEBUG
167211
LogDebug("[HGCalUnpacker]") << "crc value " << crcvalid;
212+
#endif
168213
++ptr;
169214

170215
if (!crcvalid) {
@@ -195,10 +240,12 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
195240
// forward ptr to the next ECON-D; use integer division with (... + 1) / 2 to round up
196241
ptr += (econd_payload_length + 1) / 2;
197242

243+
#ifdef EDM_ML_DEBUG
198244
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
199245
<< ", econdIdx = " << econdIdx << ", econd_headers = " << std::hex
200246
<< std::setfill('0') << std::setw(8) << econd_headers[0] << " " << econd_headers[1]
201247
<< std::dec << ", econd_payload_length = " << econd_payload_length;
248+
#endif
202249
//quality check for ECON-D (check econd_pkt_status here for error in trailer CRC)
203250
if ((((econd_headers[0] >> ECOND_FRAME::HT_POS) & ECOND_FRAME::HT_MASK) >= 0b10) ||
204251
(((econd_headers[0] >> ECOND_FRAME::EBO_POS) & ECOND_FRAME::EBO_MASK) >= 0b10) ||
@@ -216,22 +263,27 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
216263
unsigned iword = 0;
217264
if (!pass_through_mode) {
218265
// Standard ECON-D
266+
#ifdef EDM_ML_DEBUG
219267
LogDebug("[HGCalUnpacker]") << "Standard ECON-D, erxMax=" << erxMax << "enabledErx= " << enabledErx;
268+
#endif
220269
for (uint32_t erxIdx = 0; erxIdx < erxMax; erxIdx++) {
221270
// check if the eRx is enabled
222271
if ((enabledErx >> erxIdx & 1) == 0) {
223272
continue;
224273
}
274+
#ifdef EDM_ML_DEBUG
225275
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
226276
<< ", econdIdx = " << econdIdx << ", erxIdx=" << erxIdx;
227-
277+
#endif
228278
econdPacketInfo.view()[ECONDdenseIdx].cm()(erxIdx, 0) =
229279
(econd_payload[iword] >> ECOND_FRAME::COMMONMODE0_POS) & ECOND_FRAME::COMMONMODE0_MASK;
230280
econdPacketInfo.view()[ECONDdenseIdx].cm()(erxIdx, 1) =
231281
(econd_payload[iword] >> ECOND_FRAME::COMMONMODE1_POS) & ECOND_FRAME::COMMONMODE1_MASK;
232282
// check if the eRx sub-packet is empty (the "F" flag in the eRx sub-packet header)
233283
if (((econd_payload[iword] >> ECOND_FRAME::ERXFORMAT_POS) & ECOND_FRAME::ERXFORMAT_MASK) == 1) {
284+
#ifdef EDM_ML_DEBUG
234285
LogDebug("[HGCalUnpacker]") << "eRx " << erxIdx << " is empty";
286+
#endif
235287
iword += 1; // length of an empty eRx header (32 bits)
236288
continue; // go to the next eRx
237289
}
@@ -240,8 +292,10 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
240292
uint16_t cmSum = ((econd_payload[iword] >> ECOND_FRAME::COMMONMODE0_POS) & ECOND_FRAME::COMMONMODE0_MASK) +
241293
((econd_payload[iword] >> ECOND_FRAME::COMMONMODE1_POS) & ECOND_FRAME::COMMONMODE1_MASK);
242294
uint64_t erxHeader = ((uint64_t)econd_payload[iword] << 32) | ((uint64_t)econd_payload[iword + 1]);
295+
#ifdef EDM_ML_DEBUG
243296
LogDebug("[HGCalUnpacker]") << "erx_headers = 0x" << std::hex << std::setfill('0') << std::setw(16)
244297
<< erxHeader << ", cmSum = " << std::dec << cmSum;
298+
#endif
245299
iword += 2;
246300

247301
// parse erx body (channel data)
@@ -276,14 +330,18 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
276330
}
277331
} else {
278332
// Passthrough ECON-D
333+
#ifdef EDM_ML_DEBUG
279334
LogDebug("[HGCalUnpacker]") << "Passthrough ECON-D, erxMax=" << erxMax << "enabledErx= " << enabledErx;
335+
#endif
280336
for (uint32_t erxIdx = 0; erxIdx < erxMax; erxIdx++) {
281337
// check if the eRx is enabled
282338
if ((enabledErx >> erxIdx & 1) == 0) {
283339
continue;
284340
}
341+
#ifdef EDM_ML_DEBUG
285342
LogDebug("[HGCalUnpacker]") << "fedId = " << fedId << ", captureblockIdx = " << captureblockIdx
286343
<< ", econdIdx = " << econdIdx << ", erxIdx=" << erxIdx;
344+
#endif
287345

288346
econdPacketInfo.view()[ECONDdenseIdx].cm()(erxIdx, 0) =
289347
(econd_payload[iword] >> ECOND_FRAME::COMMONMODE0_POS) & ECOND_FRAME::COMMONMODE0_MASK;
@@ -300,8 +358,10 @@ uint16_t HGCalUnpacker::parseFEDData(unsigned fedId,
300358
uint16_t cmSum = ((econd_payload[iword] >> ECOND_FRAME::COMMONMODE0_POS) & ECOND_FRAME::COMMONMODE0_MASK) +
301359
((econd_payload[iword] >> ECOND_FRAME::COMMONMODE1_POS) & ECOND_FRAME::COMMONMODE1_MASK);
302360
uint64_t erxHeader = ((uint64_t)econd_payload[iword] << 32) | ((uint64_t)econd_payload[iword + 1]);
361+
#ifdef EDM_ML_DEBUG
303362
LogDebug("[HGCalUnpacker]") << "erx_headers = 0x" << std::hex << std::setfill('0') << std::setw(16)
304363
<< erxHeader << ", cmSum = " << std::dec << cmSum;
364+
#endif
305365
iword += 2;
306366

307367
// parse erx body (channel data)

0 commit comments

Comments
 (0)