10 #define EDM_ML_DEBUG 1 30 (
static_cast<uint64_t>(blk & BlkNo_mask) << BlkNo_shift) |
31 (
static_cast<uint64_t>(lv1 & LV1_mask) << LV1_shift) |
32 (
static_cast<uint64_t>(bx & BX_mask) << BX_shift);
38 if ((crc != 0 && crc != getCRC()) || block != getBlock() || (lv1_id & LV1_mask) != getLV1ID() || (bx & BX_mask) != getBX()) {
40 <<
"Found AMC13 trailer with:" 41 <<
"\n\tBX " << getBX() <<
", LV1 ID " << getLV1ID() <<
", block # " << getBlock()
42 <<
", CRC " << std::hex << std::setw(8) << std::setfill(
'0') << getCRC() <<
std::dec 44 <<
"\n\tBX " << (bx & BX_mask) <<
", LV1 ID " << (lv1_id & LV1_mask) <<
", block # " << block
45 <<
", CRC " << std::hex << std::setw(8) << std::setfill(
'0') << crc;
54 std::string dstring(reinterpret_cast<const char*>(start), reinterpret_cast<const char*>(end) + 4);
57 *end = ((*end) & ~(
uint64_t(CRC_mask) << CRC_shift)) | (
static_cast<uint64_t>(crc & CRC_mask) << CRC_shift);
61 Packet::add(
unsigned int amc_no,
unsigned int board,
unsigned int lv1id,
unsigned int orbit,
unsigned int bx,
const std::vector<uint64_t>&
load,
unsigned int user)
63 edm::LogInfo(
"AMC") <<
"Adding board " << board <<
" with payload size " << load.size()
64 <<
" as payload #" << amc_no;
66 payload_.push_back(
amc::Packet(amc_no, board, lv1id, orbit, bx, load, user));
79 std::map<int, int> amc_index;
83 if (!header_.check()) {
85 <<
"Invalid header for AMC13 packet: " 86 <<
"format version " << header_.getFormatVersion()
87 <<
", " << header_.getNumberOfAMCs()
92 if (size < 2 + header_.getNumberOfAMCs())
97 for (
unsigned int i = 0;
i < header_.getNumberOfAMCs(); ++
i) {
99 amc_index[payload_.back().blockHeader().getAMCNumber()] =
i;
102 unsigned int tot_size = 0;
103 unsigned int tot_nblocks = 0;
104 unsigned int maxblocks = 0;
106 bool check_crc =
false;
107 for (
const auto&
amc: payload_) {
108 tot_size +=
amc.blockHeader().getSize();
109 tot_nblocks +=
amc.blockHeader().getBlocks();
110 maxblocks =
std::max(maxblocks,
amc.blockHeader().getBlocks());
112 if (
amc.blockHeader().validCRC())
116 unsigned int words = tot_size +
122 <<
"Encountered AMC 13 packet with " 123 << size <<
" words, " 125 << words <<
" words: " 126 << tot_size <<
" payload words, " 127 << tot_nblocks <<
" AMC header words, and 2 AMC 13 header words.";
133 for (
auto&
amc: payload_) {
134 amc.addPayload(data,
amc.blockHeader().getBlockSize());
135 data +=
amc.blockHeader().getBlockSize();
142 std::string check(reinterpret_cast<const char*>(start), reinterpret_cast<const char*>(data) - 4);
145 LogDebug(
"L1T") <<
"checking data checksum of " << std::hex << crc <<
std::dec;
148 t.
check(crc, 0, lv1, bx);
151 for (
unsigned int b = 1;
b < maxblocks; ++
b) {
153 std::vector<amc::BlockHeader> headers;
159 for (
const auto&
amc: headers) {
160 payload_[amc_index[
amc.getAMCNumber()]].addPayload(data,
amc.getBlockSize());
161 data +=
amc.getBlockSize();
170 std::string check(reinterpret_cast<const char*>(start), reinterpret_cast<const char*>(data) - 4);
173 LogDebug(
"L1T") <<
"checking data checksum of " << std::hex << crc <<
std::dec;
181 for (
auto&
amc: payload_) {
182 amc.finalize(lv1, bx, legacy_mc, mtf7_mode);
191 unsigned int maxblocks = 0;
193 for (
const auto&
amc: payload_)
202 unsigned int words = 0;
204 unsigned int maxblocks = 0;
206 for (
const auto&
amc: payload_) {
207 words +=
amc.header().getSize();
208 blocks +=
amc.blocks();
214 return words + blocks + maxblocks * 2;
220 if (size < this->
size() * 8)
228 for (
unsigned int b = 0;
b <
blocks(); ++
b) {
231 std::vector<uint64_t> block_headers;
232 std::vector<uint64_t> block_load;
233 for (
const auto&
amc: payload_) {
235 <<
"Considering block " <<
b 236 <<
" for payload " <<
amc.blockHeader().getBoardID()
237 <<
" with size " <<
amc.size()
238 <<
" and " <<
amc.blocks() <<
" blocks";
239 if (
amc.blocks() <
b + 1)
242 block_headers.push_back(
amc.blockHeader(
b));
243 auto words =
amc.block(
b);
244 block_load.insert(block_load.end(), words.begin(), words.end());
250 <<
"Writing header for AMC13 packet: " 251 <<
"format version " <<
h.getFormatVersion()
252 <<
", " <<
h.getNumberOfAMCs()
253 <<
" AMC packets, orbit " <<
h.getOrbitNumber();
258 block_headers.insert(block_headers.end(), block_load.begin(), block_load.end());
259 for (
const auto& word: block_headers)
EventNumber_t event() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static void writeCRC(const uint64_t *start, uint64_t *end)
unsigned int size() const
unsigned int blocks() const
bool check(unsigned int crc, unsigned int block, unsigned int lv1_id, unsigned int bx) const
int bunchCrossing() const
void add(unsigned int amc_no, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector< uint64_t > &load, unsigned int user=0)
bool write(const edm::Event &ev, unsigned char *ptr, unsigned int skip, unsigned int size) const
Trailer(const uint64_t *data)
unsigned long long uint64_t
bool parse(const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false)
char data[epos_bytes_allocation]