27 LogTrace(
"L1T") <<
"Writing MP7 link header";
31 LogTrace(
"L1T") <<
"Writing CTP7 link header";
38 LogTrace(
"L1T") <<
"Writing meaningless link header";
46 unsigned int wordsPerBx = payloadWordsPerBx;
51 unsigned int nBxBlocks = payload_.size() / wordsPerBx;
52 for (
size_t bxCtr = 0; bxCtr < nBxBlocks; ++bxCtr) {
53 size_t startIdx = bxCtr * wordsPerBx;
54 auto startBxBlock = payload_.cbegin() + startIdx;
57 bxBlocks.emplace_back(startBxBlock, startBxBlock + wordsPerBx);
59 bxBlocks.emplace_back(bxCtr, nBxBlocks, startBxBlock, startBxBlock + wordsPerBx);
67 if (end_ - data_ < getHeaderSize()) {
68 LogDebug(
"L1T") <<
"Reached end of payload";
69 return std::unique_ptr<Block>();
72 if (data_[0] == 0xffffffff) {
73 LogDebug(
"L1T") <<
"Skipping padding word";
80 if (end_ - data_ <
header.getSize()) {
81 edm::LogError(
"L1T") <<
"Expecting a block size of " <<
header.getSize() <<
" but only " << (end_ - data_)
82 <<
" words remaining";
83 return std::unique_ptr<Block>();
86 LogTrace(
"L1T") <<
"Creating block with size " <<
header.getSize();
88 auto res = std::make_unique<Block>(
header, data_, data_ + header.getSize());
89 data_ += header.getSize();
108 LogTrace(
"L1T") <<
"Getting header from " << std::hex << std::setw(8) << *
data_;
114 const uint16_t* data16 =
reinterpret_cast<const uint16_t*
>(
data);
115 const uint16_t* end16 =
reinterpret_cast<const uint16_t*
>(
end);
118 edm::LogError(
"L1T") <<
"MTF7 payload smaller than allowed!";
121 ((data16[0] >> 12) != 0x9) || ((data16[1] >> 12) != 0x9) || ((data16[2] >> 12) != 0x9) ||
122 ((data16[3] >> 12) != 0x9) || ((data16[4] >> 12) != 0xA) || ((data16[5] >> 12) != 0xA) ||
123 ((data16[6] >> 12) != 0xA) || ((data16[7] >> 12) != 0xA) || ((data16[8] >> 15) != 0
x1) ||
124 ((data16[9] >> 15) != 0x0) || ((data16[10] >> 15) != 0x0) || ((data16[11] >> 15) != 0x0)) {
128 ((data16[12] >> 15) != 0) || ((data16[13] >> 15) != 1) || ((data16[14] >> 15) != 0) ||
129 ((data16[15] >> 15) != 0)) {
130 edm::LogError(
"L1T") <<
"MTF7 payload has invalid counter block!";
136 for (
int i = 4;
i < 1590;
i++) {
137 if (((data16[4 *
i + 0] >> 12) == 0xF) && ((data16[4 *
i + 1] >> 12) == 0xF) &&
138 ((data16[4 *
i + 2] >> 12) == 0xF) && ((data16[4 *
i + 3] >> 12) == 0xF) &&
139 ((data16[4 *
i + 4] >> 12) == 0xE) && ((data16[4 *
i + 5] >> 12) == 0xE) &&
140 ((data16[4 *
i + 6] >> 12) == 0xE) &&
141 ((data16[4 *
i + 7] >> 12) == 0xE)) {
142 algo_ = (((data16[4 *
i + 2] >> 4) & 0x3F) << 9);
143 algo_ |= (((data16[4 *
i + 2] >> 0) & 0x0F) << 5);
144 algo_ |= (((data16[4 *
i + 4] >> 0) & 0x1F) << 0);
149 edm::LogError(
"L1T") <<
"MTF7 payload has no valid EMTF firmware version!";
155 unsigned int mask = 0;
156 for (; length > 0; length--)
157 mask = (mask << 4) | 0xf;
161 count += (
p & mask) == pattern;
175 return std::unique_ptr<Block>();
177 const uint16_t* data16 =
reinterpret_cast<const uint16_t*
>(
data_);
178 const uint16_t* end16 =
reinterpret_cast<const uint16_t*
>(
end_);
186 for (
int j = 0;
j < 4; ++
j) {
188 pattern |= (data16[
n] >> 15) <<
n;
189 payload.push_back(data16[
n]);
192 if (
count(pattern, i + 1) == 1 and
valid(pattern))
196 if (not
valid(pattern)) {
198 return std::unique_ptr<Block>();
201 data_ += (i + 1) * 2;
206 :
Payload(data, end), amcHeader_(amcHeader) {
207 if (not(*
data_ == 0xA110CA7E)) {
224 unsigned blockId = 0;
229 unsigned blockSize = 192;
235 LogDebug(
"L1T") <<
"Reached end of payload";
236 return std::unique_ptr<Block>();
239 edm::LogWarning(
"L1T") <<
"CTP7 with more bunch crossings than expected";
246 <<
" words remaining";
247 return std::unique_ptr<Block>();
250 LogTrace(
"L1T") <<
"Creating block with size " <<
header.getSize();
252 auto res = std::make_unique<Block>(
header,
data_, data_ + header.getSize());
253 data_ += header.getSize();
BlockHeader getHeader() override
MP7Payload(const uint32_t *data, const uint32_t *end, bool legacy_mc=false)
static constexpr unsigned max_block_length_
unsigned getHeaderSize() const override
static constexpr unsigned header_size
int count(unsigned int pattern, unsigned int length) const
virtual std::unique_ptr< Block > getBlock()
static constexpr unsigned counter_size
bool valid(unsigned int pattern) const
MTF7Payload(const uint32_t *data, const uint32_t *end)
std::vector< BxBlock > BxBlocks
CTP7Payload(const uint32_t *data, const uint32_t *end, amc::Header amcHeader)
BlockHeader getHeader() override
static constexpr unsigned trailer_size
BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const
char data[epos_bytes_allocation]
std::unique_ptr< Block > getBlock() override
static const std::vector< unsigned int > block_patterns_
std::unique_ptr< Block > getBlock() override