10 #define EDM_ML_DEBUG 1
40 <<
"Found AMC13 trailer with:"
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);
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)
63 edm::LogInfo(
"AMC") <<
"Adding board " << board <<
" with payload size " << load.size()
64 <<
" as payload #" << amc_no;
79 std::map<int, int> amc_index;
85 <<
"Invalid header for AMC13 packet: "
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;
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);
191 unsigned int maxblocks = 0;
202 unsigned int words = 0;
204 unsigned int maxblocks = 0;
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;
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
tuple start
Check for commandline option errors.
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static const unsigned int LV1_mask
static void writeCRC(const uint64_t *start, uint64_t *end)
unsigned int size() const
unsigned int getCRC() const
unsigned int blocks() const
bool check(unsigned int crc, unsigned int block, unsigned int lv1_id, unsigned int bx) const
static const unsigned int CRC_mask
static const unsigned int BlkNo_mask
int bunchCrossing() const
static const unsigned int BX_mask
bool write(const edm::Event &ev, unsigned char *ptr, unsigned int skip, unsigned int size) const
Trailer(const uint64_t *data)
std::vector< amc::Packet > payload_
unsigned int getBX() const
unsigned int getBlock() const
bool check(const std::string &)
static const unsigned int BX_shift
unsigned int getLV1ID() const
unsigned long long uint64_t
void add(unsigned int amc_no, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector< uint64_t > &load)
static const unsigned int LV1_shift
static const unsigned int BlkNo_shift
bool parse(const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc=false)
static const unsigned int CRC_shift
tuple size
Write out results.