44 #include <boost/algorithm/string.hpp> 137 rxPacketReader_(iConfig.getUntrackedParameter<
std::
string>(
"rxFile",
"rx_summary.txt"), iConfig.getUntrackedParameter<
int>(
"rxHeaderFrames", 1), 0, iConfig.getUntrackedParameter<
int>(
"rxKeyLink", 0)),
138 txPacketReader_(iConfig.getUntrackedParameter<
std::
string>(
"txFile",
"tx_summary.txt"), iConfig.getUntrackedParameter<
int>(
"txHeaderFrames", 1), 0, iConfig.getUntrackedParameter<
int>(
"txKeyLink", 0)),
141 iBoard_(iConfig.getUntrackedParameter<
int>(
"boardOffset", 0)),
142 boardId_(iConfig.getUntrackedParameter<
std::vector<
int> >(
"boardId")),
144 fedId_(iConfig.getUntrackedParameter<
int>(
"fedId", 1)),
145 evType_(iConfig.getUntrackedParameter<
int>(
"eventType", 1)),
146 fwVer_(iConfig.getUntrackedParameter<
int>(
"fwVersion", 1)),
151 produces<FEDRawDataCollection>();
155 edm::LogError(
"L1T") <<
"Different number of boards in Rx and Tx files";
181 std::vector<edm::ParameterSet> vpset = iConfig.
getUntrackedParameter< std::vector<edm::ParameterSet> >(
"blocks");
184 edm::LogError(
"L1T") <<
"Wrong number of block specs " << vpset.size();
192 std::vector<int>
rx = vpset.at(
i).getUntrackedParameter< std::vector<int> >(
"rxBlockLength");
196 for (
unsigned j=0; j<rx.size(); ++j) {
204 std::vector<int> tx = vpset.at(
i).getUntrackedParameter< std::vector<int> >(
"txBlockLength");
207 for (
unsigned j=0; j<tx.size(); ++j) {
252 for (
unsigned iBoard=0; iBoard<
nBoard_; ++iBoard) {
287 std::vector<Block>
blocks;
290 for (
unsigned link=0; link<
rxBlockLength_.at(iBoard).size(); ++link) {
292 unsigned id = link*2;
295 if (size==0)
continue;
297 std::vector<uint32_t>
data;
302 for (
unsigned i=0;
i<
rxIndex_.at(iBoard);
i++) itr++;
304 LogDebug(
"L1T") <<
"Found packet [" << itr->first_ <<
", " << itr->last_ <<
"]";
305 LogDebug(
"L1T") <<
"Link " << link <<
" has " << itr->links_.find(link)->second.size() <<
" frames";
307 for (
unsigned iFrame=0; iFrame<itr->links_.find(link)->second.size(); ++iFrame) {
308 uint64_t d = itr->links_.find(link)->second.at(iFrame);
316 LogDebug(
"L1T") <<
"Frame " << iFrame <<
" : " << std::hex <<
d;
317 if ((d & 0x100000000) > 0) data.push_back( d & 0xffffffff );
322 LogDebug(
"L1T") <<
"Board " << iBoard <<
" block " <<
id <<
", size " << data.size();
325 blocks.push_back(block);
330 for (
unsigned link=0; link<
txBlockLength_.at(iBoard).size(); ++link) {
332 unsigned id = (link*2)+1;
335 if (size==0)
continue;
337 LogDebug(
"L1T") <<
"Block " <<
id <<
" expecting size " <<
size;
339 std::vector<uint32_t>
data;
344 for (
unsigned i=0;
i<
txIndex_.at(iBoard);
i++) itr++;
346 LogDebug(
"L1T") <<
"Found packet [" << itr->first_ <<
", " << itr->last_ <<
"]";
347 LogDebug(
"L1T") <<
"Link " << link <<
" has " << itr->links_.find(link)->second.size() <<
" frames";
349 for (
unsigned iFrame=0; iFrame<itr->links_.find(link)->second.size(); ++iFrame) {
350 uint64_t d = itr->links_.find(link)->second.at(iFrame);
359 LogDebug(
"L1T") <<
"Frame " << iFrame <<
" : " << std::hex <<
d;
360 if ((d & 0x100000000) > 0) data.push_back( d & 0xffffffff );
365 LogDebug(
"L1T") <<
"Board " << iBoard <<
" block " <<
id <<
", size " << data.size();
369 blocks.push_back(block);
382 LogDebug(
"L1T") <<
"Board " << iBoard <<
", read " << blocks.size() <<
" blocks";
392 LogDebug(
"L1T") <<
"Formatting Board " << iBoard;
394 std::vector<uint32_t> load32;
400 for (
const auto&
block: blocks) {
401 LogDebug(
"L1T") <<
"Adding block " <<
block.header().getID() <<
" with size " <<
block.payload().size();
405 std::stringstream
s(
"");
406 s <<
"Block content:" << std::endl << std::hex << std::setfill(
'0');
407 for (
const auto& word:
load)
408 s << std::setw(8) << word << std::endl;
412 load32.push_back(
block.header().raw());
413 load32.insert(load32.end(), load.begin(), load.end());
416 LogDebug(
"L1T") <<
"Converting payload " << iBoard;
418 std::vector<uint64_t> load64;
419 for (
unsigned int i = 0;
i < load32.size();
i += 2) {
421 if (
i + 1 < load32.size())
422 word |= static_cast<uint64_t>(load32[
i + 1]) << 32;
423 load64.push_back(word);
426 LogDebug(
"L1T") <<
"Creating AMC packet " << iBoard;
429 amc13.
add(iBoard,
boardId_.at(iBoard), 0, 0, 0, load64);
442 unsigned char * payload_start =
payload;
445 auto evtId = iEvent.
id().
event();
455 payload += amc13.
size() * 8;
MP7FileReader rxFileReader_
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
const_iterator begin() const
std::vector< std::vector< int > > rxBlockLength_
unsigned nFramesPerEvent_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::vector< std::vector< int > > txBlockLength_
#define DEFINE_FWK_MODULE(type)
MP7FileReader txFileReader_
unsigned int size() const
MP7PacketReader txPacketReader_
int bunchCrossing() const
const FileData & get(size_t k) const
data getter via index
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
static void set(unsigned char *trailer, int evt_lgth, int crc, int evt_stat, int tts, bool T=false)
Set all fields in the trailer.
size_t size() const
Lenght of the data buffer in bytes.
std::vector< Block > getBlocks(int iAmc)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
size_t size() const
number of rawdata objects stored
const PacketData & get(size_t i)
payload
payload postfix for testing
void addDefault(ParameterSetDescription const &psetDescription)
void resize(size_t newsize)
MP7BufferDumpToRaw(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< unsigned > rxIndex_
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
void formatAMC(amc13::Packet &amc13, const std::vector< Block > &blocks, int iAmc)
~MP7BufferDumpToRaw() override
std::vector< unsigned > txIndex_
unsigned long long uint64_t
std::vector< Packet >::const_iterator const_iterator
char data[epos_bytes_allocation]
std::vector< int > boardId_
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
MP7PacketReader rxPacketReader_
const std::vector< uint64_t > & link(uint32_t i) const
void formatRaw(edm::Event &iEvent, amc13::Packet &amc13, FEDRawData &fed_data)