53 : m_evmGtFedId(pSet.getUntrackedParameter<int>(
"EvmGtFedId",
FEDNumbering::MINTriggerGTPFEDID)),
55 m_evmGtInputTag(pSet.getParameter<edm::
InputTag>(
"EvmGtInputTag")),
57 m_activeBoardsMaskGt(pSet.getParameter<unsigned int>(
"ActiveBoardsMask")),
61 m_verbosity(pSet.getUntrackedParameter<int>(
"Verbosity", 0)),
65 LogDebug(
"L1GTEvmDigiToRaw") <<
"\nMask for active boards (hex format): " << std::hex
69 <<
"\nFED Id for EVM GT record: " <<
m_evmGtFedId <<
" \n"
73 produces<FEDRawDataCollection>();
91 const std::vector<L1GtBoard> boardMaps = l1GtBM->gtBoardMaps();
92 int boardMapsSize = boardMaps.size();
94 typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
99 std::vector<L1GtBoard> gtRecordMap;
100 gtRecordMap.reserve(boardMapsSize);
102 for (
int iPos = 0; iPos < boardMapsSize; ++iPos) {
103 for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
104 if (itBoard->gtPositionEvmRecord() == iPos) {
105 gtRecordMap.push_back(*itBoard);
115 if (!gtReadoutRecord.
isValid()) {
116 edm::LogWarning(
"L1GTEvmDigiToRaw") <<
"\nWarning: L1GlobalTriggerEvmReadoutRecord with input tag "
118 <<
"\nrequested in configuration, but not found in the event."
119 <<
"\nQuit packing this event" << std::endl;
128 std::ostringstream myCoutStream;
129 gtReadoutRecord->print(myCoutStream);
130 LogTrace(
"L1GTEvmDigiToRaw") <<
"\n The following L1 GT EVM readout record will be packed.\n"
131 <<
" Some boards could be disabled before packing,"
132 <<
" see detailed board packing.\n"
133 << myCoutStream.str() <<
"\n"
159 LogDebug(
"L1GTEvmDigiToRaw") <<
"\nActive boards before masking(hex format): " << std::hex
160 << std::setw(
sizeof(activeBoardsGtInitial) * 2) << std::setfill(
'0')
161 << activeBoardsGtInitial <<
std::dec << std::setfill(
' ')
162 <<
"\nActive boards after masking(hex format): " << std::hex
163 << std::setw(
sizeof(activeBoardsGt) * 2) << std::setfill(
'0') << activeBoardsGt
164 <<
std::dec << std::setfill(
' ') <<
" \n"
170 unsigned int gtDataSize = 0;
172 unsigned int headerSize = 8;
173 gtDataSize += headerSize;
175 for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
176 if (itBoard->gtBoardType() ==
GTFE) {
177 gtDataSize += gtfeBlock.
getSize();
181 int iActiveBit = itBoard->gtBitEvmActiveBoards();
182 bool activeBoardToPack =
false;
184 int altNrBxBoardVal = -1;
186 if (iActiveBit >= 0) {
187 activeBoardToPack = activeBoardsGt & (1 << iActiveBit);
189 altNrBxBoardVal = (altNrBxBoardInitial & (1 << iActiveBit)) >> iActiveBit;
191 if (altNrBxBoardVal == 1) {
193 }
else if (altNrBxBoardVal == 0) {
198 <<
"\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal <<
" for board " << std::hex
199 << (itBoard->gtBoardId()) <<
std::dec <<
"\n iActiveBit = " << iActiveBit
200 <<
"\n altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial <<
std::dec
201 <<
"\n activeBoardsGt = 0x" << std::hex << activeBoardsGt <<
std::dec
202 <<
"\n activeBoardToPack = " << activeBoardToPack <<
"\n Set altNrBxBoardVal tentatively to "
203 << recordLength0 <<
"\n Job may crash or produce wrong results!\n\n"
214 if (activeBoardToPack) {
215 switch (itBoard->gtBoardType()) {
229 gtDataSize += tcsBlock.
getSize();
247 unsigned int trailerSize = 8;
248 gtDataSize += trailerSize;
252 gtRawData.
resize(gtDataSize);
256 unsigned char* ptrGt = gtRawData.
data();
257 unsigned char* ptrGtBegin = gtRawData.
data();
260 LogDebug(
"L1GTEvmDigiToRaw") <<
"\n Size of raw data: " << gtRawData.
size() <<
"\n" << std::endl;
271 for (CItBoardMaps itBoard = gtRecordMap.begin(); itBoard != gtRecordMap.end(); ++itBoard) {
272 if (itBoard->gtBoardType() ==
GTFE) {
273 packGTFE(evSetup, ptrGt, gtfeBlock, activeBoardsGt);
276 std::ostringstream myCoutStream;
277 gtfeBlock.
print(myCoutStream);
278 LogTrace(
"L1GTEvmDigiToRaw") << myCoutStream.str() <<
"\n" << std::endl;
288 int iActiveBit = itBoard->gtBitEvmActiveBoards();
289 bool activeBoardToPack =
false;
291 int altNrBxBoardVal = -1;
293 if (iActiveBit >= 0) {
294 activeBoardToPack = activeBoardsGt & (1 << iActiveBit);
296 altNrBxBoardVal = (altNrBxBoardInitial & (1 << iActiveBit)) >> iActiveBit;
298 if (altNrBxBoardVal == 1) {
300 }
else if (altNrBxBoardVal == 0) {
305 <<
"\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal <<
" for board " << std::hex
306 << (itBoard->gtBoardId()) <<
std::dec <<
"\n iActiveBit = " << iActiveBit
307 <<
"\n altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial <<
std::dec
308 <<
"\n activeBoardsGt = 0x" << std::hex << activeBoardsGt <<
std::dec
309 <<
"\n activeBoardToPack = " << activeBoardToPack <<
"\n Set altNrBxBoardVal tentatively to "
310 << recordLength0 <<
"\n Job may crash or produce wrong results!\n\n"
325 if (activeBoardToPack) {
327 LogDebug(
"L1GTEvmDigiToRaw") <<
"\nBoard " << std::hex <<
"0x" << (itBoard->gtBoardId()) <<
std::dec
328 <<
"\n Number of bunch crosses in the record: " <<
m_totalBxInEvent <<
" = "
334 switch (itBoard->gtBoardType()) {
336 L1TcsWord tcsBlock = gtReadoutRecord->tcsWord();
337 packTCS(evSetup, ptrGt, tcsBlock);
340 std::ostringstream myCoutStream;
341 tcsBlock.
print(myCoutStream);
342 LogTrace(
"L1GTEvmDigiToRaw") << myCoutStream.str() <<
"\n" << std::endl;
350 L1GtFdlWord fdlBlock = gtReadoutRecord->gtFdlWord(iBxInEvent);
351 packFDL(evSetup, ptrGt, fdlBlock);
354 std::ostringstream myCoutStream;
355 fdlBlock.
print(myCoutStream);
356 LogTrace(
"L1GTEvmDigiToRaw") << myCoutStream.str() <<
"\n" << std::endl;
384 int triggerTypeVal = 0;
387 int lvl1IdVal = iEvent.
id().
event();
392 if ((bxCross & 0xFFF) == bxCross) {
397 LogDebug(
"L1GTEvmDigiToRaw") <<
"\nBunch cross number [hex] = " << std::hex << bxCross
398 <<
"\n larger than 12 bits. Set to 0! \n"
402 int bxIdVal = bxCrossHw;
413 bool moreHeadersVal =
false;
417 gtFEDHeader.
set(ptrGt, triggerTypeVal, lvl1IdVal, bxIdVal, sourceIdVal, versionVal, moreHeadersVal);
422 unsigned char* ptrGt,
426 LogDebug(
"L1GTEvmDigiToRaw") <<
"\nPacking GTFE \n" << std::endl;
432 int nrWord64 = gtfeBlock.
getSize() / uLength;
433 std::vector<cms_uint64_t> tmpWord64;
434 tmpWord64.resize(nrWord64);
436 for (
int iWord = 0; iWord < nrWord64; ++iWord) {
437 tmpWord64[iWord] = 0x0000000000000000ULL;
441 for (
int iWord = 0; iWord < nrWord64; ++iWord) {
460 for (
int iWord = 0; iWord < nrWord64; ++iWord) {
461 *pw++ = tmpWord64[iWord];
464 LogTrace(
"L1GTEvmDigiToRaw") << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0') << std::setw(16)
465 << tmpWord64[iWord] <<
std::dec << std::setfill(
' ') << std::endl;
473 LogDebug(
"L1GTEvmDigiToRaw") <<
"\nPacking TCS \n" << std::endl;
479 int nrWord64 = tcsBlock.
getSize() / uLength;
480 std::vector<cms_uint64_t> tmpWord64;
481 tmpWord64.resize(nrWord64);
483 for (
int iWord = 0; iWord < nrWord64; ++iWord) {
484 tmpWord64[iWord] = 0x0000000000000000ULL;
488 for (
int iWord = 0; iWord < nrWord64; ++iWord) {
509 for (
int iWord = 0; iWord < nrWord64; ++iWord) {
510 *pw++ = tmpWord64[iWord];
513 LogTrace(
"L1GTEvmDigiToRaw") << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0') << std::setw(16)
514 << tmpWord64[iWord] <<
std::dec << std::setfill(
' ') << std::endl;
522 LogDebug(
"L1GTEvmDigiToRaw") <<
"\nPacking FDL \n" << std::endl;
528 int nrWord64 = fdlBlock.
getSize() / uLength;
529 std::vector<cms_uint64_t> tmpWord64;
530 tmpWord64.resize(nrWord64);
532 for (
int iWord = 0; iWord < nrWord64; ++iWord) {
533 tmpWord64[iWord] = 0x0000000000000000ULL;
537 for (
int iWord = 0; iWord < nrWord64; ++iWord) {
565 for (
int iWord = 0; iWord < nrWord64; ++iWord) {
566 *pw++ = tmpWord64[iWord];
569 LogTrace(
"L1GTEvmDigiToRaw") << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0') << std::setw(16)
570 << tmpWord64[iWord] <<
std::dec << std::setfill(
' ') << std::endl;
580 int lengthVal = dataSize / 8;
586 int evtStatusVal = 0;
594 bool moreTrailersVal =
false;
597 gtFEDTrailer.
set(ptrGt, lengthVal, crcVal, evtStatusVal, ttsBitsVal, moreTrailersVal);
EventNumber_t event() const
void packHeader(unsigned char *, edm::Event &)
block packers -------——
const bool m_isDebugEnabled
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void setRecordLength1Word64(cms_uint64_t &word64, int iWord)
void setBoardIdWord64(cms_uint64_t &word64, int iWord)
void setNoAlgoWord64(cms_uint64_t &word64, const int iWord)
void setBxNrWord64(cms_uint64_t &word64, int iWord)
int m_totalBxInEvent
total Bx's in the event, obtained from GTFE block
void setGtDecisionWordBWord64(cms_uint64_t &word64, const int iWord)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
static const int UnitLength
one unit in the word is UnitLength bits
cms_uint16_t m_activeBoardsMaskGt
mask for active boards
const edm::InputTag m_evmGtInputTag
int m_bstLengthBytes
length of BST record (in bytes)
int bunchCrossing() const
void setBoardIdWord64(cms_uint64_t &word64, const int iWord)
void setLumiSegmentNrWord64(cms_uint64_t &word64, const int iWord)
const int m_verbosity
verbosity level
void setActiveBoardsWord64(cms_uint64_t &word64, int iWord)
const unsigned int bstLengthBytes() const
get the size of the BST block
void setSetupVersionWord64(cms_uint64_t &word64, int iWord)
void setAssignedPartitionsWord64(cms_uint64_t &word64, int iWord)
const unsigned int getSize() const
get the size of the FDL block in GT DAQ record (in multiple of 8 bits)
void setOrbitNrWord64(cms_uint64_t &word64, const int iWord)
const cms_uint16_t altNrBxBoard() const
get/set alternative for number of BX per board
size_t size() const
Lenght of the data buffer in bytes.
void setOrbitNrWord64(cms_uint64_t &word64, int iWord)
void setGtTechnicalTriggerWordWord64(cms_uint64_t &word64, const int iWord)
void setBstWord64(cms_uint64_t &word64, int iB, const int iWord)
const unsigned int getSize() const
get the size of the GTFE block in GT EVM record (in multiple of 8 bits)
void setTriggerTypeWord64(cms_uint64_t &word64, int iWord)
void packTrailer(unsigned char *, unsigned char *, int)
pack trailer word
const cms_uint16_t recordLength() const
get/set record length for alternative 0
void setGtPrescaleFactorIndexTechWord64(cms_uint64_t &word64, const int iWord)
void print(std::ostream &myCout) const
pretty print the content of a L1TcsWord
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
void resize(size_t newsize)
void setBxInEventWord64(cms_uint64_t &word64, const int iWord)
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
void setPhysicsDeclaredWord64(cms_uint64_t &word64, const int iWord)
void setEventNrWord64(cms_uint64_t &word64, const int iWord)
unsigned short cms_uint16_t
void print(std::ostream &myCout) const override
pretty print the content of a L1GtfeExtWord
void packGTFE(const edm::EventSetup &, unsigned char *, L1GtfeExtWord &, cms_uint16_t activeBoardsGtValue)
void setBxNrWord64(cms_uint64_t &word64, const int iWord)
void setBoardIdWord64(cms_uint64_t &word64, int iWord)
void setLuminositySegmentNrWord64(cms_uint64_t &word64, int iWord)
const cms_uint16_t activeBoards() const
get/set boards contributing to EVM respectively DAQ record
void print(std::ostream &myCout) const
pretty print the content of a L1GtFdlWord
void setAltNrBxBoardWord64(cms_uint64_t &word64, int iWord)
void packTCS(const edm::EventSetup &evSetup, unsigned char *ptrGt, L1TcsWord &tcsBlock)
pack the TCS block
void setGtDecisionWordExtendedWord64(cms_uint64_t &word64, const int iWord)
void setLocalBxNrWord64(cms_uint64_t &word64, const int iWord)
void setGtDecisionWordAWord64(cms_uint64_t &word64, const int iWord)
const unsigned int getSize() const
get the size of the TCS block in GT EVM record (in multiple of 8 bits)
void setEventNrWord64(cms_uint64_t &word64, int iWord)
void setPartRunNrWord64(cms_uint64_t &word64, int iWord)
void setBxNrWord64(cms_uint64_t &word64, int iWord)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
void produce(edm::Event &, const edm::EventSetup &) override
loop over events
void setPartTrigNrWord64(cms_uint64_t &word64, int iWord)
void packFDL(const edm::EventSetup &, unsigned char *, L1GtFdlWord &)
pack FDL blocks for various bunch crosses
void setFinalORWord64(cms_uint64_t &word64, const int iWord)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
L1GTEvmDigiToRaw(const edm::ParameterSet &)
constructor(s)
unsigned long long cms_uint64_t
Log< level::Warning, false > LogWarning
void setDaqNrWord64(cms_uint64_t &word64, int iWord)
void setTotalTriggerNrWord64(cms_uint64_t &word64, int iWord)
void setGtPrescaleFactorIndexAlgoWord64(cms_uint64_t &word64, const int iWord)
const cms_uint16_t recordLength1() const
get/set record length for alternative 1
const edm::ESGetToken< L1GtBoardMaps, L1GtBoardMapsRcd > m_l1GtBMToken
EventSetup Token for L1GtBoardMaps.
void setRecordLengthWord64(cms_uint64_t &word64, int iWord)
const edm::EDGetTokenT< L1GlobalTriggerEvmReadoutRecord > m_evmGtInputToken
input tag for GT EVM record
void setStatusWord64(cms_uint64_t &word64, int iWord)