12 auto format_word = [&erx, &passZS, &passZSm1, &hasToA, &char_mode](
size_t i) -> std::pair<uint32_t, uint8_t> {
13 if (
i >= erx.
tctp.size())
15 <<
"Not enough channels in eRx data payload: " <<
i <<
" >= " << erx.
tctp.size() <<
".";
17 return std::make_pair(((uint8_t)erx.
tctp.at(
i) & 0x3) << 30 | (erx.
adc.at(
i) & 0x3ff) << 20 |
18 (erx.
tot.at(
i) & 0x3ff) << 10 | (erx.
toa.at(
i) & 0x3ff),
20 switch (erx.
tctp.at(
i)) {
23 throw cms::Exception(
"HGCalEmulator") <<
"ToT status is ZeroSuppressed, but event frame does not pass ZS.";
26 return std::make_pair((0
x1 << 30) | ((erx.
adcm.at(
i) & 0x3ff) << 20) | ((erx.
adc.at(
i) & 0x3ff) << 10) |
27 (erx.
toa.at(
i) & 0x3ff),
30 return std::make_pair(((erx.
adcm.at(
i) & 0x3ff) << 10) | (erx.
adc.at(
i) & 0x3ff), 24);
34 return std::make_pair((0x3 << 20) | ((erx.
adc.at(
i) & 0x3ff) << 10) | (erx.
toa.at(
i) & 0x3ff), 24);
35 return std::make_pair((0
x1 << 10) | (erx.
adc.at(
i) & 0x3ff), 16);
38 return std::make_pair((0
x2 << 20) | ((erx.
adcm.at(
i) & 0x3ff) << 10) | (erx.
adc.at(
i) & 0x3ff), 24);
39 case ToTStatus::invalid:
40 return std::make_pair(
41 (0
x2 << 30) | ((erx.
adcm.at(
i) & 0x3ff) << 20) | ((erx.
adc.at(
i) & 0x3ff) << 10) | (erx.
toa.at(
i) & 0x3ff),
44 return std::make_pair(
45 (0x3 << 30) | ((erx.
adcm.at(
i) & 0x3ff) << 20) | ((erx.
tot.at(
i) & 0x3ff) << 10) | (erx.
toa.at(
i) & 0x3ff),
49 <<
"Invalid ToT status retrieved for channel " <<
i <<
": " << (
int)erx.
tctp.at(
i) <<
".";
53 std::vector<uint32_t>
data{0};
54 std::vector<uint32_t>::iterator it_data =
data.begin();
57 for (
size_t i = 0;
i < channel_enable.size(); ++
i) {
58 if (!channel_enable.at(
i))
60 const auto [
word, nbits] = format_word(
i);
63 it_data =
data.insert(
data.end(), 0);
67 *it_data &= ((1 << msb) - 1);
68 if (msb + nbits > 32) {
69 uint8_t nbits_word1 = 32 - msb - nbits;
70 *it_data |= (
word & ((1 << nbits_word1) - 1)) << msb;
73 *it_data |=
word << msb;
83 uint16_t common_mode0,
84 uint16_t common_mode1,
88 for (
const auto& ch : channel_enable)
89 channels_map64b |= (ch <<
i++);
95 uint8_t
stat, uint8_t hamming,
bool bitE, uint16_t common_mode0, uint16_t common_mode1,
uint64_t channels_map) {
96 std::vector<uint32_t>
header = {
107 if (chmapw0 == 0 && chmapw1 == 0) {
138 std::vector<uint32_t> words(2, 0);
160 return (progPattern & 0xffffff) << 8 | (
rr & 0x3) << 6 | (
err & 0x7) << 3 | (bufStat & 0x7) << 0;
165 uint32_t bunch_crossing,
166 uint32_t event_counter,
167 uint32_t orbit_counter,
168 const std::vector<hgcal::backend::ECONDPacketStatus>& econd_statuses) {
169 if (econd_statuses.size() > 12)
170 throw cms::Exception(
"HGCalEmulator") <<
"Invalid size for ECON-D statuses: " << econd_statuses.size() <<
".";
171 std::vector<uint32_t>
header(2, 0);
176 (econd_statuses[11] & 0x7) << 1 | ((econd_statuses[10] >> 2) & 0
x1);
177 for (
size_t i = 0;
i < 11;
i++)
178 header[1] |= (econd_statuses[
i] & 0x7) <<
i * 3;
184 uint8_t boe, uint8_t
v,
uint64_t global_event_id, uint32_t content_id, uint32_t fed_id) {
185 std::vector<uint32_t>
header(4, 0);
200 uint32_t event_length,
205 std::vector<uint32_t> trailer(4, 0);
220 return 0x0 | (l1a_fragment_cnt & 0xffff) | (l1a_subtype & 0xff) << 16 | (
e & 0x3) << 24;
224 bool fed_crc_err,
bool slinkrocket_crc_err,
bool source_id_err,
bool sync_lost,
bool fragment_trunc) {
225 return 0x0 | (fed_crc_err & 0x1) << 0 | (slinkrocket_crc_err & 0
x1) << 1 | (source_id_err & 0x1) << 2 |
226 (sync_lost & 0
x1) << 3 | (fragment_trunc & 0x1) << 4;
std::vector< ToTStatus > tctp
std::vector< uint32_t > produceERxData(const ERxChannelEnable &, const ERxData &, bool passZS, bool passZSm1, bool hasToA, bool char_mode)
std::vector< uint32_t > buildCaptureBlockHeader(uint32_t bunch_crossing, uint32_t event_counter, uint32_t orbit_counter, const std::vector< ECONDPacketStatus > &econd_statuses)
std::vector< uint32_t > eRxSubPacketHeader(uint8_t stat, uint8_t ham, bool bitE, uint16_t common_mode0, uint16_t common_mode1, const ERxChannelEnable &channel_enable)
uint32_t buildSlinkContentId(SlinkEmulationFlag, uint8_t l1a_subtype, uint16_t l1a_fragment_cnt)
std::vector< bool > ERxChannelEnable
list of channels enabled in eRx
std::vector< uint16_t > tot
std::vector< uint16_t > toa
std::vector< uint32_t > buildSlinkHeader(uint8_t boe, uint8_t v, uint64_t global_event_id, uint32_t content_id, uint32_t fed_id)
uint32_t buildIdleWord(uint8_t bufStat, uint8_t err, uint8_t rr, uint32_t progPattern)
uint16_t buildSlinkRocketStatus(bool fed_crc_err, bool slinkrocket_crc_err, bool source_id_err, bool sync_lost, bool fragment_trunc)
unsigned long long uint64_t
std::vector< uint16_t > adc
std::vector< uint32_t > buildSlinkTrailer(uint8_t eoe, uint16_t daqcrc, uint32_t event_length, uint16_t bxid, uint32_t orbit_id, uint16_t crc, uint16_t status)
char data[epos_bytes_allocation]
std::vector< uint32_t > eventPacketHeader(uint16_t header, uint16_t payload, bool bitP, bool bitE, uint8_t ht, uint8_t ebo, bool bitM, bool bitT, uint8_t hamming, uint16_t bx, uint16_t l1a, uint8_t orb, bool bitS, uint8_t RR)
std::vector< uint16_t > adcm