68 m_daqGtInputTag(pSet.getParameter<
edm::
InputTag>(
"DaqGtInputTag")),
73 m_daqGtFedId(pSet.getUntrackedParameter<
int>(
"DaqGtFedId",
FEDNumbering::MAXTriggerGTPFEDID)),
76 m_activeBoardsMaskGt(pSet.getParameter<unsigned
int>(
"ActiveBoardsMask")),
79 m_unpackBxInEvent(pSet.getParameter<
int>(
"UnpackBxInEvent")),
84 m_lowSkipBxInEvent(0),
85 m_uppSkipBxInEvent(0),
91 m_verbosity(pSet.getUntrackedParameter<
int>(
"Verbosity", 0)),
96 produces<L1GlobalTriggerReadoutRecord>();
97 produces<L1MuGMTReadoutCollection>();
99 produces<std::vector<L1MuRegionalCand> >(
"DT");
100 produces<std::vector<L1MuRegionalCand> >(
"CSC");
101 produces<std::vector<L1MuRegionalCand> >(
"RPCb");
102 produces<std::vector<L1MuRegionalCand> >(
"RPCf");
103 produces<std::vector<L1MuGMTCand> >();
115 <<
"\nMask for active boards (hex format): " << std::hex
127 <<
"\nWARNING: Number of bunch crossing to be unpacked rounded to: " <<
m_unpackBxInEvent
128 <<
"\n The number must be an odd number!\n"
143 static const char*
const kComm1 =
144 "# input tag for GT readout collection: \n"
145 "# source = hardware record, \n"
146 "# l1GtPack = GT packer (DigiToRaw)";
148 static const char*
const kComm2 =
149 "# FED Id for GT DAQ record \n"
150 "# default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc";
152 static const char*
const kComm3 =
153 "# mask for active boards (actually 16 bits) \n"
154 "# if bit is zero, the corresponding board will not be unpacked \n"
155 "# default: no board masked";
156 desc.
add<
unsigned int>(
"ActiveBoardsMask", 0xFFFF)->setComment(kComm3);
157 static const char*
const kComm4 =
158 "# number of 'bunch crossing in the event' (bxInEvent) to be unpacked \n"
159 "# symmetric around L1Accept (bxInEvent = 0): \n"
160 "# 1 (bxInEvent = 0); 3 (F 0 1) (standard record); 5 (E F 0 1 2) (debug record) \n"
161 "# even numbers (except 0) 'rounded' to the nearest lower odd number \n"
162 "# negative value: unpack all available bxInEvent \n"
163 "# if more bxInEvent than available are required, unpack what exists and write a warning";
164 desc.
add<
int>(
"UnpackBxInEvent", -1)->setComment(kComm4);
166 descriptions.
add(
"l1GlobalTriggerRawToDigi", desc);
188 const std::vector<L1GtBoard> boardMaps = l1GtBM->
gtBoardMaps();
189 int boardMapsSize = boardMaps.size();
191 typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
196 std::vector<L1GtBoard> gtRecordMap;
197 gtRecordMap.reserve(boardMapsSize);
199 for (
int iPos = 0; iPos < boardMapsSize; ++iPos) {
200 for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
201 if (itBoard->gtPositionDaqRecord() == iPos) {
202 gtRecordMap.push_back(*itBoard);
216 <<
"\nWarning: FEDRawDataCollection with input tag " <<
m_daqGtInputTag
217 <<
"\nrequested in configuration, but not found in the event."
218 <<
"\nQuit unpacking this event" << std::endl;
229 int gtSize = raw.
size();
232 const unsigned char* ptrGt = raw.
data();
235 const unsigned char* endPtrGt = ptrGt + gtSize;
239 LogTrace(
"L1GlobalTriggerRawToDigi") <<
"\n Size of raw data: " << gtSize <<
"\n" << std::endl;
241 std::ostringstream myCoutStream;
244 LogTrace(
"L1GlobalTriggerRawToDigi") <<
"\n Dump FEDRawData\n" << myCoutStream.str() <<
"\n" << std::endl;
250 if ((ptrGt + headerSize) > endPtrGt) {
258 FEDTrailer cmsTrailer(ptrGt + gtSize - headerSize);
269 edm::LogError(
"L1GlobalTriggerRawToDigi") <<
"\nError: Pointer after GTFE greater than end pointer."
270 <<
"\n Put empty products in the event!"
271 <<
"\n Quit unpacking this event." << std::endl;
278 bool gtfeUnpacked =
false;
280 for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
281 if (itBoard->gtBoardType() ==
GTFE) {
283 if (itBoard->gtPositionDaqRecord() == 1) {
289 std::ostringstream myCoutStream;
291 LogTrace(
"L1GlobalTriggerRawToDigi") << myCoutStream.str() <<
"\n" << std::endl;
300 <<
"\nWarning: GTFE block found in raw data does not follow header."
301 <<
"\nAssumed start position of the block is wrong!"
302 <<
"\nQuit unpacking this event" << std::endl;
316 <<
"\nWarning: no GTFE block found in raw data."
317 <<
"\nCan not find the record length (BxInEvent) and the active boards!"
318 <<
"\nQuit unpacking this event" << std::endl;
338 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\nActive boards before masking: 0x" << std::hex
339 << std::setw(
sizeof(activeBoardsGtInitial) * 2) << std::setfill(
'0')
340 << activeBoardsGtInitial <<
std::dec << std::setfill(
' ')
341 <<
"\nActive boards after masking: 0x" << std::hex
342 << std::setw(
sizeof(activeBoardsGt) * 2) << std::setfill(
'0') << activeBoardsGt
343 <<
std::dec << std::setfill(
' ') <<
" \n"
349 int numberGtfeBoards = 0;
350 int numberFdlBoards = 0;
351 int numberPsbBoards = 0;
352 int numberGmtBoards = 0;
353 int numberTcsBoards = 0;
354 int numberTimBoards = 0;
356 for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
357 int iActiveBit = itBoard->gtBitDaqActiveBoards();
358 bool activeBoardToUnpack =
false;
360 if (iActiveBit >= 0) {
361 activeBoardToUnpack = activeBoardsGt & (1 << iActiveBit);
367 if (activeBoardToUnpack) {
368 switch (itBoard->gtBoardType()) {
402 LogDebug(
"L1GlobalTriggerRawToDigi")
403 <<
"\nBoard of type " << itBoard->gtBoardType() <<
" not expected in record.\n"
427 std::unique_ptr<L1GlobalTriggerReadoutRecord> gtReadoutRecord(
445 for (CItBoardMaps itBoard = gtRecordMap.begin(); itBoard != gtRecordMap.end(); ++itBoard) {
446 int iActiveBit = itBoard->gtBitDaqActiveBoards();
448 bool activeBoardToUnpack =
false;
449 bool activeBoardInitial =
false;
451 int altNrBxBoardVal = -1;
453 if (iActiveBit >= 0) {
454 activeBoardInitial = activeBoardsGtInitial & (1 << iActiveBit);
455 activeBoardToUnpack = activeBoardsGt & (1 << iActiveBit);
457 altNrBxBoardVal = (altNrBxBoardInitial & (1 << iActiveBit)) >> iActiveBit;
459 if (altNrBxBoardVal == 1) {
461 }
else if (altNrBxBoardVal == 0) {
466 <<
"\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal <<
" for board " << std::hex
467 << (itBoard->gtBoardId()) <<
std::dec <<
"\n iActiveBit = " << iActiveBit
468 <<
"\n altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial <<
std::dec
469 <<
"\n activeBoardsGt = 0x" << std::hex << activeBoardsGt <<
std::dec
470 <<
"\n activeBoardInitial = " << activeBoardInitial
471 <<
"\n activeBoardToUnpack = " << activeBoardToUnpack <<
"\n Set altNrBxBoardVal tentatively to "
483 LogDebug(
"L1GlobalTriggerRawToDigi")
484 <<
"\nWARNING: Number of available bunch crosses for board" << (itBoard->gtBoardId())
486 <<
" ) \n is smaller than the number of bunch crosses requested to be unpacked (" <<
m_unpackBxInEvent
509 LogDebug(
"L1GlobalTriggerRawToDigi")
510 <<
"\nNo bxInEvent required to be unpacked from " <<
m_totalBxInEvent <<
" bunch crosses available."
542 if (!activeBoardInitial) {
544 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\nBoard of type " << itBoard->gtBoardName() <<
" with index "
545 << itBoard->gtBoardIndex() <<
" not active initially in raw data.\n"
552 switch (itBoard->gtBoardType()) {
559 <<
"\nError: Pointer after FDL " << iFdl <<
" greater than end pointer."
560 <<
"\n Put empty products in the event!"
561 <<
"\n Quit unpacking this event." << std::endl;
569 if (activeBoardToUnpack) {
584 std::ostringstream myCoutStream;
586 LogTrace(
"L1GlobalTriggerRawToDigi") << myCoutStream.str() <<
"\n" << std::endl;
605 <<
"\nError: Pointer after PSB " << iPsb <<
" greater than end pointer."
606 <<
"\n Put empty products in the event!"
607 <<
"\n Quit unpacking this event." << std::endl;
615 if (activeBoardToUnpack) {
624 std::ostringstream myCoutStream;
626 LogTrace(
"L1GlobalTriggerRawToDigi") << myCoutStream.str() <<
"\n" << std::endl;
639 unsigned int gmtRecordSize = 136;
644 if ((ptrGt + gmtCollSize) > endPtrGt) {
645 edm::LogError(
"L1GlobalTriggerRawToDigi") <<
"\nError: Pointer after GMT "
646 <<
" greater than end pointer."
647 <<
"\n Put empty products in the event!"
648 <<
"\n Quit unpacking this event." << std::endl;
656 if (activeBoardToUnpack) {
660 ptrGt += gmtCollSize;
665 LogDebug(
"L1GlobalTriggerRawToDigi")
666 <<
"\nBoard of type " << itBoard->gtBoardType() <<
" not expected in record.\n"
686 if ((ptrGt + trailerSize) > endPtrGt) {
687 edm::LogError(
"L1GlobalTriggerRawToDigi") <<
"\nError: Pointer after trailer "
688 <<
" greater than end pointer."
689 <<
"\n Put empty products in the event!"
690 <<
"\n Quit unpacking this event." << std::endl;
701 std::ostringstream myCoutStream;
702 gtReadoutRecord->print(myCoutStream);
703 LogTrace(
"L1GlobalTriggerRawToDigi") <<
"\n The following L1 GT DAQ readout record was unpacked.\n"
704 << myCoutStream.str() <<
"\n"
720 const cms_uint64_t*
payload = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(gtPtr));
722 std::ostringstream myCoutStream;
727 myCoutStream << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0') << std::setw(16) <<
payload[iWord]
728 <<
std::dec << std::setfill(
' ') <<
"\n"
731 myCoutStream <<
" Event_type: " << std::hex <<
" hex: "
732 <<
" " << std::setw(1) << std::setfill(
'0') << cmsHeader.
triggerType() << std::setfill(
' ')
735 myCoutStream <<
" LVL1_Id: " << std::hex <<
" hex: "
736 <<
"" << std::setw(6) << std::setfill(
'0') << cmsHeader.
lvl1ID() << std::setfill(
' ') <<
std::dec
737 <<
" dec: " << cmsHeader.
lvl1ID() << std::endl;
739 myCoutStream <<
" BX_Id: " << std::hex <<
" hex: "
740 <<
" " << std::setw(3) << std::setfill(
'0') << cmsHeader.
bxID() << std::setfill(
' ') <<
std::dec
741 <<
" dec: " << cmsHeader.
bxID() << std::endl;
743 myCoutStream <<
" Source_Id: " << std::hex <<
" hex: "
744 <<
" " << std::setw(3) << std::setfill(
'0') << cmsHeader.
sourceID() << std::setfill(
' ') <<
std::dec
745 <<
" dec: " << cmsHeader.
sourceID() << std::endl;
747 myCoutStream <<
" FOV: " << std::hex <<
" hex: "
748 <<
" " << std::setw(1) << std::setfill(
'0') << cmsHeader.
version() << std::setfill(
' ') <<
std::dec
749 <<
" dec: " << cmsHeader.
version() << std::endl;
751 myCoutStream <<
" H: " << std::hex <<
" hex: "
752 <<
" " << std::setw(1) << std::setfill(
'0') << cmsHeader.
moreHeaders() << std::setfill(
' ')
755 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\n CMS Header \n" << myCoutStream.str() <<
"\n" << std::endl;
762 const unsigned char* psbPtr,
770 int psbSize = psbWord.
getSize();
771 int psbWords = psbSize / uLength;
773 const cms_uint64_t*
payload = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(psbPtr));
775 for (
int iWord = 0; iWord < psbWords; ++iWord) {
789 LogTrace(
"L1GlobalTriggerRawToDigi") << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0')
797 std::unique_ptr<L1MuGMTReadoutCollection>& gmtrc,
804 const unsigned int gmtRecordSize32 = 34;
806 std::unique_ptr<std::vector<L1MuRegionalCand> > DTCands(
new std::vector<L1MuRegionalCand>);
807 std::unique_ptr<std::vector<L1MuRegionalCand> > CSCCands(
new std::vector<L1MuRegionalCand>);
808 std::unique_ptr<std::vector<L1MuRegionalCand> > RPCbCands(
new std::vector<L1MuRegionalCand>);
809 std::unique_ptr<std::vector<L1MuRegionalCand> > RPCfCands(
new std::vector<L1MuRegionalCand>);
810 std::unique_ptr<std::vector<L1MuGMTCand> > GMTCands(
new std::vector<L1MuGMTCand>);
812 const unsigned*
p = (
const unsigned*)chp;
822 const cms_uint64_t* bp = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned*>(
p));
823 for (
int iWord = 0; iWord < 17; iWord++) {
824 LogTrace(
"L1GlobalTriggerRawToDigi") << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0')
825 << std::setw(16) << *bp++ <<
std::dec << std::setfill(
' ') << std::endl;
835 if (((*
p) >> 15) & 1) {
843 for (
int im = 0; im < 16; im++) {
845 unsigned waux = *
p++;
846 waux = (waux & 0xffff00ff) | ((~waux) & 0x0000ff00);
849 if (im >= 4 && im < 8)
851 if (im >= 8 && im < 12)
859 DTCands->push_back(
cand);
860 if (im >= 4 && im < 8)
861 RPCbCands->push_back(
cand);
862 if (im >= 8 && im < 12)
863 CSCCands->push_back(
cand);
865 RPCfCands->push_back(
cand);
869 unsigned char* prank = (
unsigned char*)(
p + 12);
871 for (
int im = 0; im < 12; im++) {
872 unsigned waux = *
p++;
873 unsigned raux = im < 8 ? *prank++ : 0;
885 GMTCands->push_back(
cand);
892 gmtrc->addRecord(gmtrr);
896 p += gmtRecordSize32;
917 const cms_uint64_t*
payload = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(trlPtr));
919 std::ostringstream myCoutStream;
924 myCoutStream << std::setw(4) << iWord <<
" " << std::hex << std::setfill(
'0') << std::setw(16) <<
payload[iWord]
925 <<
std::dec << std::setfill(
' ') <<
"\n"
928 myCoutStream <<
" Event_length: " << std::hex <<
" hex: "
929 <<
"" << std::setw(6) << std::setfill(
'0') << cmsTrailer.
fragmentLength() << std::setfill(
' ')
932 myCoutStream <<
" CRC: " << std::hex <<
" hex: "
933 <<
" " << std::setw(4) << std::setfill(
'0') << cmsTrailer.
crc() << std::setfill(
' ') <<
std::dec
934 <<
" dec: " << cmsTrailer.
crc() << std::endl;
936 myCoutStream <<
" Event_status: " << std::hex <<
" hex: "
937 <<
" " << std::setw(2) << std::setfill(
'0') << cmsTrailer.
evtStatus() << std::setfill(
' ')
940 myCoutStream <<
" TTS_bits: " << std::hex <<
" hex: "
941 <<
" " << std::setw(1) << std::setfill(
'0') << cmsTrailer.
ttsBits() << std::setfill(
' ')
944 myCoutStream <<
" More trailers: " << std::hex <<
" hex: "
945 <<
" " << std::setw(1) << std::setfill(
'0') << cmsTrailer.
moreTrailers() << std::setfill(
' ')
948 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\n CMS Trailer \n" << myCoutStream.str() <<
"\n" << std::endl;
958 std::unique_ptr<std::vector<L1MuRegionalCand> > DTCands(
new std::vector<L1MuRegionalCand>);
959 std::unique_ptr<std::vector<L1MuRegionalCand> > CSCCands(
new std::vector<L1MuRegionalCand>);
960 std::unique_ptr<std::vector<L1MuRegionalCand> > RPCbCands(
new std::vector<L1MuRegionalCand>);
961 std::unique_ptr<std::vector<L1MuRegionalCand> > RPCfCands(
new std::vector<L1MuRegionalCand>);
962 std::unique_ptr<std::vector<L1MuGMTCand> > GMTCands(
new std::vector<L1MuGMTCand>);
978 LogDebug(
"L1GlobalTriggerRawToDigi") <<
"\nDump FED raw data.\n" << std::endl;
983 int gtWords = gtSize / uLength;
984 LogTrace(
"L1GlobalTriggerRawToDigi") <<
"\nFED GT words (" << wLength <<
" bits):" << gtWords <<
"\n" << std::endl;
986 const cms_uint64_t*
payload = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(gtPtr));
989 myCout << std::setw(4) <<
i <<
" " << std::hex << std::setfill(
'0') << std::setw(16) <<
payload[
i] <<
std::dec
990 << std::setfill(
' ') << std::endl;