44 #include <boost/algorithm/string.hpp>
68 virtual void endJob()
override;
135 rxFileReader_(iConfig.getUntrackedParameter<std::
string>(
"rxFile",
"rx_summary.txt")),
136 txFileReader_(iConfig.getUntrackedParameter<std::
string>(
"txFile",
"tx_summary.txt")),
137 rxPacketReader_(iConfig.getUntrackedParameter<std::
string>(
"rxFile",
"rx_summary.txt")),
138 txPacketReader_(iConfig.getUntrackedParameter<std::
string>(
"txFile",
"tx_summary.txt")),
139 packetisedData_(iConfig.getUntrackedParameter<bool>(
"packetisedData",
true)),
140 nFramesPerEvent_(iConfig.getUntrackedParameter<int>(
"nFramesPerEvent", 6)),
141 iBoard_(iConfig.getUntrackedParameter<int>(
"boardOffset", 0)),
142 boardId_(iConfig.getUntrackedParameter<std::vector<int> >(
"boardId")),
143 mux_(iConfig.getUntrackedParameter<bool>(
"mux",
false)),
144 fedId_(iConfig.getUntrackedParameter<int>(
"fedId", 1)),
145 evType_(iConfig.getUntrackedParameter<int>(
"eventType", 1)),
146 fwVer_(iConfig.getUntrackedParameter<int>(
"fwVersion", 1)),
147 slinkHeaderSize_(iConfig.getUntrackedParameter<int>(
"lenSlinkHeader", 8)),
148 slinkTrailerSize_(iConfig.getUntrackedParameter<int>(
"lenSlinkTrailer", 8))
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();
188 rxBlockLength_.push_back(vpset.at(
i).getUntrackedParameter< std::vector<int> >(
"rxBlockLength") );
189 txBlockLength_.push_back(vpset.at(
i).getUntrackedParameter< std::vector<int> >(
"rxBlockLength") );
225 for (
unsigned iBoard=0; iBoard<
nBoard_; ++iBoard) {
231 LogDebug(
"L1T") <<
"AMC13 size " << amc13.size();
239 LogDebug(
"L1T") <<
"Packing FED ID " <<
fedId_ <<
" size " << fed_data.size();
242 iEvent.
put(raw_coll);
252 LogDebug(
"L1T") <<
"Getting blocks from board " << iBoard;
254 std::vector<Block>
blocks;
259 unsigned id =
link*2;
262 if (size==0)
continue;
264 std::vector<uint32_t>
data;
269 for (
unsigned i=0;
i<
rxIndex_.at(iBoard);
i++) itr++;
271 LogDebug(
"L1T") <<
"Found packet [" << itr->first_ <<
", " << itr->last_ <<
"]";
272 LogDebug(
"L1T") <<
"Link " <<
link <<
" has " << itr->links_.find(
link)->second.size() <<
" frames";
274 for (
unsigned iFrame=0; iFrame<itr->links_.find(
link)->second.size(); ++iFrame) {
283 if ((d & 0x100000000) > 0) data.push_back( d & 0xffffffff );
288 LogDebug(
"L1T") <<
"AMC " << iBoard <<
" block " <<
id <<
", size " << data.size();
291 blocks.push_back(block);
298 unsigned id = (
link*2)+1;
301 if (size==0)
continue;
303 std::vector<uint32_t>
data;
307 for (
unsigned i=0;
i<
txIndex_.at(iBoard);
i++) itr++;
308 for (
unsigned iFrame=itr->first_; iFrame<itr->last_; ++iFrame) {
317 if ((d & 0x100000000) > 0) data.push_back( d & 0xffffffff );
322 LogDebug(
"L1T") <<
"AMC " << iBoard <<
" block " <<
id <<
", size " << data.size();
326 blocks.push_back(block);
333 LogDebug(
"L1T") <<
"AMC " << iBoard <<
", read " << blocks.size() <<
" blocks";
343 LogDebug(
"L1T") <<
"Formatting Board " << iBoard;
345 std::vector<uint32_t> load32;
349 for (
const auto&
block: blocks) {
350 LogDebug(
"L1T") <<
"Adding block " <<
block.header().getID() <<
" with size " <<
block.payload().size();
354 std::stringstream
s(
"");
355 s <<
"Block content:" << std::endl << std::hex << std::setfill(
'0');
356 for (
const auto& word:
load)
357 s << std::setw(8) << word << std::endl;
361 load32.push_back(
block.header().raw());
362 load32.insert(load32.end(), load.begin(), load.end());
365 LogDebug(
"L1T") <<
"Converting payload " << iBoard;
367 std::vector<uint64_t> load64;
368 for (
unsigned int i = 0;
i < load32.size();
i += 2) {
370 if (
i + 1 < load32.size())
371 word |= static_cast<uint64_t>(load32[
i + 1]) << 32;
372 load64.push_back(word);
375 LogDebug(
"L1T") <<
"Creating AMC packet " << iBoard;
389 unsigned char * payload = fed_data.
data();
390 unsigned char * payload_start = payload;
393 auto evtId = iEvent.
id().
event();
404 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_
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
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.
std::vector< Block > getBlocks(int iAmc)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void beginJob() override
size_t size() const
number of rawdata objects stored
const PacketData & get(size_t i)
void addDefault(ParameterSetDescription const &psetDescription)
void resize(size_t newsize)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
MP7BufferDumpToRaw(const edm::ParameterSet &)
virtual void endJob() override
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::vector< unsigned > rxIndex_
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
bool write(const edm::Event &ev, unsigned char *ptr, unsigned int size) const
void formatAMC(amc13::Packet &amc13, const std::vector< Block > &blocks, int iAmc)
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)
volatile std::atomic< bool > shutdown_flag false
void add(unsigned int amc_no, unsigned int board, const std::vector< uint64_t > &load)
tuple size
Write out results.