Skip to content

Commit

Permalink
Merge pull request cms-sw#110 from hqucms/hgcal/dev-unpacker-refactor
Browse files Browse the repository at this point in the history
[WIP] Convert ECON-D payload to 32b words
  • Loading branch information
yulunmiao authored Apr 23, 2024
2 parents 5bc8e3c + 1b9fd98 commit 962a18f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions EventFilter/HGCalRawToDigi/src/HGCalUnpacker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
return std::array<uint32_t, 2>{{ptr_32b[1], ptr_32b[0]}};
};

auto to_econd_payload = [](const uint64_t* ptr_64b, uint64_t payload_length) -> std::vector<uint32_t> {
std::vector<uint32_t> payload(payload_length, 0);
auto* ptr_32b = reinterpret_cast<const uint32_t*>(ptr_64b);
for (unsigned i = 0; i < payload_length; ++i) {
payload[i] = ptr_32b[(i % 2 == 0) ? i + 1 : i - 1];
}
return payload;
};

const auto* ptr = header;
for (unsigned iword = 0; ptr < trailer; ++iword) {
std::cout << std::setw(8) << iword << ": 0x" << std::hex << std::setfill('0') << std::setw(16) << *ptr << " ("
Expand Down Expand Up @@ -79,6 +88,9 @@ void HGCalUnpacker::parseFEDData(unsigned fedId,
<< ", econd_headers = " << std::hex << std::setfill('0') << std::setw(8) << econd_headers[0] << " "
<< econd_headers[1] << std::dec << ", econd_payload_length = " << econd_payload_length << std::endl;

// 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;
}
Expand Down

0 comments on commit 962a18f

Please sign in to comment.