60 m_daqGtInputTag(pSet.getParameter<
edm::
InputTag>(
"DaqGtInputTag")),
65 m_daqGtFedId(pSet.getUntrackedParameter<
int>(
"DaqGtFedId",
FEDNumbering::MAXTriggerGTPFEDID)),
68 m_activeBoardsMaskGt(pSet.getParameter<unsigned
int>(
"ActiveBoardsMask")),
76 m_unpackBxInEvent(pSet.getParameter<
int>(
"UnpackBxInEvent")),
81 m_lowSkipBxInEvent(0),
82 m_uppSkipBxInEvent(0),
89 m_verbosity(pSet.getUntrackedParameter<
int>(
"Verbosity", 0)),
94 produces<L1GlobalTriggerReadoutRecord>();
95 produces<L1MuGMTReadoutCollection>();
97 produces<std::vector<L1MuRegionalCand> >(
"DT");
98 produces<std::vector<L1MuRegionalCand> >(
"CSC");
99 produces<std::vector<L1MuRegionalCand> >(
"RPCb");
100 produces<std::vector<L1MuRegionalCand> >(
"RPCf");
101 produces<std::vector<L1MuGMTCand> >();
113 <<
"\nMask for active boards (hex format): " << std::hex
125 <<
"\nWARNING: Number of bunch crossing to be unpacked rounded to: " <<
m_unpackBxInEvent 126 <<
"\n The number must be an odd number!\n" 141 static const char*
const kComm1 =
142 "# input tag for GT readout collection: \n" 143 "# source = hardware record, \n" 144 "# l1GtPack = GT packer (DigiToRaw)";
146 static const char*
const kComm2 =
147 "# FED Id for GT DAQ record \n" 148 "# default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc";
150 static const char*
const kComm3 =
151 "# mask for active boards (actually 16 bits) \n" 152 "# if bit is zero, the corresponding board will not be unpacked \n" 153 "# default: no board masked";
154 desc.add<
unsigned int>(
"ActiveBoardsMask", 0xFFFF)->setComment(kComm3);
155 static const char*
const kComm4 =
156 "# number of 'bunch crossing in the event' (bxInEvent) to be unpacked \n" 157 "# symmetric around L1Accept (bxInEvent = 0): \n" 158 "# 1 (bxInEvent = 0); 3 (F 0 1) (standard record); 5 (E F 0 1 2) (debug record) \n" 159 "# even numbers (except 0) 'rounded' to the nearest lower odd number \n" 160 "# negative value: unpack all available bxInEvent \n" 161 "# if more bxInEvent than available are required, unpack what exists and write a warning";
162 desc.add<
int>(
"UnpackBxInEvent", -1)->setComment(kComm4);
163 desc.addUntracked<
int>(
"Verbosity", 0);
164 descriptions.
add(
"l1GlobalTriggerRawToDigi",
desc);
183 const std::vector<L1GtBoard> boardMaps = l1GtBM->
gtBoardMaps();
184 int boardMapsSize = boardMaps.size();
186 typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
191 std::vector<L1GtBoard> gtRecordMap;
192 gtRecordMap.reserve(boardMapsSize);
194 for (
int iPos = 0; iPos < boardMapsSize; ++iPos) {
195 for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
196 if (itBoard->gtPositionDaqRecord() == iPos) {
197 gtRecordMap.push_back(*itBoard);
211 <<
"\nWarning: FEDRawDataCollection with input tag " <<
m_daqGtInputTag 212 <<
"\nrequested in configuration, but not found in the event." 213 <<
"\nQuit unpacking this event" << std::endl;
224 int gtSize = raw.
size();
227 const unsigned char* ptrGt = raw.
data();
230 const unsigned char* endPtrGt = ptrGt + gtSize;
234 LogTrace(
"L1GlobalTriggerRawToDigi") <<
"\n Size of raw data: " << gtSize <<
"\n" << std::endl;
236 std::ostringstream myCoutStream;
239 LogTrace(
"L1GlobalTriggerRawToDigi") <<
"\n Dump FEDRawData\n" << myCoutStream.str() <<
"\n" << std::endl;
245 if ((ptrGt + headerSize) > endPtrGt) {
253 FEDTrailer cmsTrailer(ptrGt + gtSize - headerSize);
264 edm::LogError(
"L1GlobalTriggerRawToDigi") <<
"\nError: Pointer after GTFE greater than end pointer." 265 <<
"\n Put empty products in the event!" 266 <<
"\n Quit unpacking this event." << std::endl;
273 bool gtfeUnpacked =
false;
275 for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
276 if (itBoard->gtBoardType() ==
GTFE) {
278 if (itBoard->gtPositionDaqRecord() == 1) {
284 std::ostringstream myCoutStream;
286 LogTrace(
"L1GlobalTriggerRawToDigi") << myCoutStream.str() <<
"\n" << std::endl;
295 <<
"\nWarning: GTFE block found in raw data does not follow header." 296 <<
"\nAssumed start position of the block is wrong!" 297 <<
"\nQuit unpacking this event" << std::endl;
311 <<
"\nWarning: no GTFE block found in raw data." 312 <<
"\nCan not find the record length (BxInEvent) and the active boards!" 313 <<
"\nQuit unpacking this event" << std::endl;
333 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\nActive boards before masking: 0x" << std::hex
334 << std::setw(
sizeof(activeBoardsGtInitial) * 2) << std::setfill(
'0')
335 << activeBoardsGtInitial <<
std::dec << std::setfill(
' ')
336 <<
"\nActive boards after masking: 0x" << std::hex
337 << std::setw(
sizeof(activeBoardsGt) * 2) << std::setfill(
'0') << activeBoardsGt
338 <<
std::dec << std::setfill(
' ') <<
" \n" 344 int numberFdlBoards = 0;
345 int numberPsbBoards = 0;
347 for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
348 int iActiveBit = itBoard->gtBitDaqActiveBoards();
349 bool activeBoardToUnpack =
false;
351 if (iActiveBit >= 0) {
352 activeBoardToUnpack = activeBoardsGt & (1 << iActiveBit);
358 if (activeBoardToUnpack) {
359 switch (itBoard->gtBoardType()) {
381 LogDebug(
"L1GlobalTriggerRawToDigi")
382 <<
"\nBoard of type " << itBoard->gtBoardType() <<
" not expected in record.\n" 406 std::unique_ptr<L1GlobalTriggerReadoutRecord> gtReadoutRecord(
424 for (CItBoardMaps itBoard = gtRecordMap.begin(); itBoard != gtRecordMap.end(); ++itBoard) {
425 int iActiveBit = itBoard->gtBitDaqActiveBoards();
427 bool activeBoardToUnpack =
false;
428 bool activeBoardInitial =
false;
430 int altNrBxBoardVal = -1;
432 if (iActiveBit >= 0) {
433 activeBoardInitial = activeBoardsGtInitial & (1 << iActiveBit);
434 activeBoardToUnpack = activeBoardsGt & (1 << iActiveBit);
436 altNrBxBoardVal = (altNrBxBoardInitial & (1 << iActiveBit)) >> iActiveBit;
438 if (altNrBxBoardVal == 1) {
440 }
else if (altNrBxBoardVal == 0) {
445 <<
"\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal <<
" for board " << std::hex
446 << (itBoard->gtBoardId()) <<
std::dec <<
"\n iActiveBit = " << iActiveBit
447 <<
"\n altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial <<
std::dec 448 <<
"\n activeBoardsGt = 0x" << std::hex << activeBoardsGt <<
std::dec 449 <<
"\n activeBoardInitial = " << activeBoardInitial
450 <<
"\n activeBoardToUnpack = " << activeBoardToUnpack <<
"\n Set altNrBxBoardVal tentatively to " 462 LogDebug(
"L1GlobalTriggerRawToDigi")
463 <<
"\nWARNING: Number of available bunch crosses for board" << (itBoard->gtBoardId())
465 <<
" ) \n is smaller than the number of bunch crosses requested to be unpacked (" <<
m_unpackBxInEvent 488 LogDebug(
"L1GlobalTriggerRawToDigi")
489 <<
"\nNo bxInEvent required to be unpacked from " <<
m_totalBxInEvent <<
" bunch crosses available." 521 if (!activeBoardInitial) {
523 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\nBoard of type " << itBoard->gtBoardName() <<
" with index " 524 << itBoard->gtBoardIndex() <<
" not active initially in raw data.\n" 531 switch (itBoard->gtBoardType()) {
538 <<
"\nError: Pointer after FDL " << iFdl <<
" greater than end pointer." 539 <<
"\n Put empty products in the event!" 540 <<
"\n Quit unpacking this event." << std::endl;
548 if (activeBoardToUnpack) {
563 std::ostringstream myCoutStream;
565 LogTrace(
"L1GlobalTriggerRawToDigi") << myCoutStream.str() <<
"\n" << std::endl;
584 <<
"\nError: Pointer after PSB " << iPsb <<
" greater than end pointer." 585 <<
"\n Put empty products in the event!" 586 <<
"\n Quit unpacking this event." << std::endl;
594 if (activeBoardToUnpack) {
603 std::ostringstream myCoutStream;
605 LogTrace(
"L1GlobalTriggerRawToDigi") << myCoutStream.str() <<
"\n" << std::endl;
618 unsigned int gmtRecordSize = 136;
623 if ((ptrGt + gmtCollSize) > endPtrGt) {
624 edm::LogError(
"L1GlobalTriggerRawToDigi") <<
"\nError: Pointer after GMT " 625 <<
" greater than end pointer." 626 <<
"\n Put empty products in the event!" 627 <<
"\n Quit unpacking this event." << std::endl;
635 if (activeBoardToUnpack) {
639 ptrGt += gmtCollSize;
644 LogDebug(
"L1GlobalTriggerRawToDigi")
645 <<
"\nBoard of type " << itBoard->gtBoardType() <<
" not expected in record.\n" 665 if ((ptrGt + trailerSize) > endPtrGt) {
666 edm::LogError(
"L1GlobalTriggerRawToDigi") <<
"\nError: Pointer after trailer " 667 <<
" greater than end pointer." 668 <<
"\n Put empty products in the event!" 669 <<
"\n Quit unpacking this event." << std::endl;
680 std::ostringstream myCoutStream;
681 gtReadoutRecord->print(myCoutStream);
682 LogTrace(
"L1GlobalTriggerRawToDigi") <<
"\n The following L1 GT DAQ readout record was unpacked.\n" 683 << myCoutStream.str() <<
"\n" 701 std::ostringstream myCoutStream;
706 myCoutStream << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0') << std::setw(16) <<
payload[iWord]
707 <<
std::dec << std::setfill(
' ') <<
"\n" 710 myCoutStream <<
" Event_type: " << std::hex <<
" hex: " 711 <<
" " << std::setw(1) << std::setfill(
'0') << cmsHeader.
triggerType() << std::setfill(
' ')
714 myCoutStream <<
" LVL1_Id: " << std::hex <<
" hex: " 715 <<
"" << std::setw(6) << std::setfill(
'0') << cmsHeader.
lvl1ID() << std::setfill(
' ') <<
std::dec 716 <<
" dec: " << cmsHeader.
lvl1ID() << std::endl;
718 myCoutStream <<
" BX_Id: " << std::hex <<
" hex: " 719 <<
" " << std::setw(3) << std::setfill(
'0') << cmsHeader.
bxID() << std::setfill(
' ') <<
std::dec 720 <<
" dec: " << cmsHeader.
bxID() << std::endl;
722 myCoutStream <<
" Source_Id: " << std::hex <<
" hex: " 723 <<
" " << std::setw(3) << std::setfill(
'0') << cmsHeader.
sourceID() << std::setfill(
' ') <<
std::dec 724 <<
" dec: " << cmsHeader.
sourceID() << std::endl;
726 myCoutStream <<
" FOV: " << std::hex <<
" hex: " 727 <<
" " << std::setw(1) << std::setfill(
'0') << cmsHeader.
version() << std::setfill(
' ') <<
std::dec 728 <<
" dec: " << cmsHeader.
version() << std::endl;
730 myCoutStream <<
" H: " << std::hex <<
" hex: " 731 <<
" " << std::setw(1) << std::setfill(
'0') << cmsHeader.
moreHeaders() << std::setfill(
' ')
734 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\n CMS Header \n" << myCoutStream.str() <<
"\n" << std::endl;
741 const unsigned char* psbPtr,
749 int psbSize = psbWord.
getSize();
750 int psbWords = psbSize / uLength;
754 for (
int iWord = 0; iWord < psbWords; ++iWord) {
768 LogTrace(
"L1GlobalTriggerRawToDigi") << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0')
776 std::unique_ptr<L1MuGMTReadoutCollection>& gmtrc,
783 const unsigned int gmtRecordSize32 = 34;
785 std::unique_ptr<std::vector<L1MuRegionalCand> > DTCands(
new std::vector<L1MuRegionalCand>);
786 std::unique_ptr<std::vector<L1MuRegionalCand> > CSCCands(
new std::vector<L1MuRegionalCand>);
787 std::unique_ptr<std::vector<L1MuRegionalCand> > RPCbCands(
new std::vector<L1MuRegionalCand>);
788 std::unique_ptr<std::vector<L1MuRegionalCand> > RPCfCands(
new std::vector<L1MuRegionalCand>);
789 std::unique_ptr<std::vector<L1MuGMTCand> > GMTCands(
new std::vector<L1MuGMTCand>);
791 const unsigned*
p = (
const unsigned*)chp;
802 for (
int iWord = 0; iWord < 17; iWord++) {
803 LogTrace(
"L1GlobalTriggerRawToDigi") << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0')
804 << std::setw(16) << *bp++ <<
std::dec << std::setfill(
' ') << std::endl;
814 if (((*
p) >> 15) & 1) {
822 for (
int im = 0; im < 16; im++) {
824 unsigned waux = *
p++;
825 waux = (waux & 0xffff00ff) | ((~waux) & 0x0000ff00);
828 if (im >= 4 && im < 8)
830 if (im >= 8 && im < 12)
838 DTCands->push_back(
cand);
839 if (im >= 4 && im < 8)
840 RPCbCands->push_back(
cand);
841 if (im >= 8 && im < 12)
842 CSCCands->push_back(
cand);
844 RPCfCands->push_back(
cand);
848 unsigned char* prank = (
unsigned char*)(
p + 12);
850 for (
int im = 0; im < 12; im++) {
851 unsigned waux = *
p++;
852 unsigned raux = im < 8 ? *prank++ : 0;
864 GMTCands->push_back(
cand);
871 gmtrc->addRecord(gmtrr);
875 p += gmtRecordSize32;
898 std::ostringstream myCoutStream;
903 myCoutStream << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0') << std::setw(16) <<
payload[iWord]
904 <<
std::dec << std::setfill(
' ') <<
"\n" 907 myCoutStream <<
" Event_length: " << std::hex <<
" hex: " 908 <<
"" << std::setw(6) << std::setfill(
'0') << cmsTrailer.
fragmentLength() << std::setfill(
' ')
911 myCoutStream <<
" CRC: " << std::hex <<
" hex: " 912 <<
" " << std::setw(4) << std::setfill(
'0') << cmsTrailer.
crc() << std::setfill(
' ') <<
std::dec 913 <<
" dec: " << cmsTrailer.
crc() << std::endl;
915 myCoutStream <<
" Event_status: " << std::hex <<
" hex: " 916 <<
" " << std::setw(2) << std::setfill(
'0') << cmsTrailer.
evtStatus() << std::setfill(
' ')
919 myCoutStream <<
" TTS_bits: " << std::hex <<
" hex: " 920 <<
" " << std::setw(1) << std::setfill(
'0') << cmsTrailer.
ttsBits() << std::setfill(
' ')
923 myCoutStream <<
" More trailers: " << std::hex <<
" hex: " 924 <<
" " << std::setw(1) << std::setfill(
'0') << cmsTrailer.
moreTrailers() << std::setfill(
' ')
927 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\n CMS Trailer \n" << myCoutStream.str() <<
"\n" << std::endl;
937 std::unique_ptr<std::vector<L1MuRegionalCand> > DTCands(
new std::vector<L1MuRegionalCand>);
938 std::unique_ptr<std::vector<L1MuRegionalCand> > CSCCands(
new std::vector<L1MuRegionalCand>);
939 std::unique_ptr<std::vector<L1MuRegionalCand> > RPCbCands(
new std::vector<L1MuRegionalCand>);
940 std::unique_ptr<std::vector<L1MuRegionalCand> > RPCfCands(
new std::vector<L1MuRegionalCand>);
941 std::unique_ptr<std::vector<L1MuGMTCand> > GMTCands(
new std::vector<L1MuGMTCand>);
957 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\nDump FED raw data.\n" << std::endl;
962 int gtWords = gtSize / uLength;
963 LogTrace(
"L1GlobalTriggerRawToDigi") <<
"\nFED GT words (" << wLength <<
" bits):" << gtWords <<
"\n" << std::endl;
968 myCout << std::setw(4) <<
i <<
" " << std::hex << std::setfill(
'0') << std::setw(16) <<
payload[
i] <<
std::dec 969 << std::setfill(
' ') << std::endl;
const L1MuTriggerScales * m_TriggerScales
muon trigger scales to convert unpacked data into physical quantities
const L1MuScale * getGMTEtaScale() const
get the GMT eta scale
void setBxInEvent(int bxie)
const cms_uint16_t altNrBxBoard() const
get/set alternative for number of BX per board
virtual void print(std::ostream &myCout) const
pretty print the content of a L1GtfeWord
void reset()
reset the content of a L1GtPsbWord
const edm::ESGetToken< L1GtBoardMaps, L1GtBoardMapsRcd > m_l1GtBMToken
EventSetup Token for L1GtBoardMaps.
const cms_uint16_t recordLength1() const
get/set record length for alternative 1
const unsigned int getSize() const
get the size of the PSB block in GT DAQ record (in multiple of 8 bits)
const unsigned int getSize() const
get the size of the GTFE block in GT DAQ record (in multiple of 8 bits)
void unpackHeader(const unsigned char *, FEDHeader &)
block unpackers
cms_uint16_t m_activeBoardsMaskGt
mask for active boards
uint8_t ttsBits() const
Current value of the Trigger Throttling System bits.
void produce(edm::Event &, const edm::EventSetup &) override
static const int UnitLength
one unit in the word is UnitLength bits
void setGMTBrlCand(int nr, L1MuGMTExtendedCand const &cand)
set GMT barrel candidate
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
T const * product() const
int m_recordLength0
total Bx's in the event, obtained from GTFE block
void setBData(cms_uint16_t bDataVal, int iB)
~L1GlobalTriggerRawToDigi() override
destructor
void setGMTFwdCand(int nr, L1MuGMTExtendedCand const &cand)
set GMT forward candidate
void unpack(const unsigned char *fdlPtr)
size_t size() const
Lenght of the data buffer in bytes.
void setInputCand(int nr, unsigned data)
set Input muon
void unpackPSB(const edm::EventSetup &, const unsigned char *, L1GtPsbWord &)
const L1MuScale * getPhiScale() const
get the phi scale
Log< level::Error, false > LogError
void setRecordLength(cms_uint16_t recordLengthValue)
virtual float getCenter(unsigned packed) const =0
get the center of bin represented by packed
const L1MuScale * getPtScale() const
get the Pt scale
static const int WordLength
GT DAQ record organized in words of WordLength bits.
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
const cms_uint16_t recordLength() const
get/set record length for alternative 0
const edm::ESGetToken< L1MuTriggerScales, L1MuTriggerScalesRcd > m_trigScalesToken
EventSetup Token for L1MuTriggerScales.
void setEventNr(cms_uint32_t eventNrValue)
void setBxNr(cms_uint16_t bxNrValue)
virtual void reset()
reset the content of a L1GtfeWord
const L1MuTriggerPtScale * m_TriggerPtScale
T const * product() const
void print(std::ostream &myCout) const
pretty print
void setBoardId(cms_uint16_t boardIdValue)
int m_recordLength1
corresponding to alternative 1 in altNrBxBoard()
const L1MuScale * getRegionalEtaScale(int isys) const
get the regioanl muon trigger eta scale, isys = 0(DT), 1(bRPC), 2(CSC), 3(fwdRPC) ...
void setLumiSegmentNr(const cms_uint16_t &lumiSegmentNrValue)
edm::InputTag m_daqGtInputTag
input tags for GT DAQ record
void setBxInEvent(int bxInEventValue)
int m_verbosity
verbosity level
void reset()
reset the content of a L1GtFdlWord
uint16_t crc() const
Cyclic Redundancy Code of the event fragment including header and trailer.
unsigned short cms_uint16_t
void setRecordLength1(cms_uint16_t recordLengthValue)
const std::vector< L1GtBoard > & gtBoardMaps() const
get / set / print the L1 GT board map
L1GlobalTriggerRawToDigi(const edm::ParameterSet &)
constructor(s)
uint8_t evtStatus() const
Event fragment status information.
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
const cms_uint16_t lumiSegmentNr() const
get/set luminosity segment number of the actual bx
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
L1GtFdlWord * m_gtFdlWord
Log< level::Info, false > LogInfo
L1GtPsbWord * m_gtPsbWord
int m_totalBxInEvent
number of Bx for a board, obtained from GTFE block (record length & alternative)
void setActiveBoards(cms_uint16_t activeBoardsValue)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void setBxNr(int bxnr)
set counters
void unpackTrailer(const unsigned char *, FEDTrailer &)
unpack trailer word
const unsigned int getSize() const
get the size of the FDL block in GT DAQ record (in multiple of 8 bits)
void unpackGMT(const unsigned char *, std::unique_ptr< L1MuGMTReadoutCollection > &, edm::Event &)
unpack the GMT record
void setLocalBxNr(cms_uint16_t localBxNrValue)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
void print(std::ostream &myCout) const
pretty print the content of a L1GtFdlWord
void setGMTCand(int nr, L1MuGMTExtendedCand const &cand)
set GMT candidate (does not store rank)
unsigned long long cms_uint64_t
const cms_uint16_t activeBoards() const
get/set boards contributing to EVM respectively DAQ record
Log< level::Warning, false > LogWarning
void produceEmptyProducts(edm::Event &)
produce empty products in case of problems
const edm::ESGetToken< L1MuTriggerPtScale, L1MuTriggerPtScaleRcd > m_trigPtScaleToken
EventSetup Token for L1MuTriggerPtScale.
void setAData(cms_uint16_t aDataVal, int iA)
virtual void unpack(const unsigned char *gtfePtr)
bool moreTrailers() const
void dumpFedRawData(const unsigned char *, int, std::ostream &)
dump FED raw data