Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:29

0001 /**
0002  * \class L1GtfeWord
0003  *
0004  *
0005  * Description: L1 Global Trigger - GTFE words in the readout record.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  * \author: Vasile Mihai Ghete - HEPHY Vienna
0011  *
0012  *
0013  */
0014 
0015 // this class header
0016 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeWord.h"
0017 
0018 // system include files
0019 #include <iomanip>
0020 
0021 // user include files
0022 
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0025 
0026 // constructors
0027 
0028 // empty constructor, all members set to zero;
0029 L1GtfeWord::L1GtfeWord()
0030     : m_boardId(0),
0031       m_recordLength1(0),
0032       m_recordLength(0),
0033       m_bxNr(0),
0034       m_setupVersion(0),
0035       m_activeBoards(0),
0036       m_altNrBxBoard(0),
0037       m_totalTriggerNr(0) {
0038   // empty
0039 }
0040 
0041 // constructor from unpacked values;
0042 L1GtfeWord::L1GtfeWord(cms_uint16_t boardIdValue,
0043                        cms_uint16_t recordLength1Value,
0044                        cms_uint16_t recordLengthValue,
0045                        cms_uint16_t bxNrValue,
0046                        cms_uint32_t setupVersionValue,
0047                        cms_uint16_t activeBoardsValue,
0048                        cms_uint16_t altNrBxBoardValue,
0049                        cms_uint32_t totalTriggerNrValue)
0050     : m_boardId(boardIdValue),
0051       m_recordLength1(recordLength1Value),
0052       m_recordLength(recordLengthValue),
0053       m_bxNr(bxNrValue),
0054       m_setupVersion(setupVersionValue),
0055       m_activeBoards(activeBoardsValue),
0056       m_altNrBxBoard(altNrBxBoardValue),
0057       m_totalTriggerNr(totalTriggerNrValue)
0058 
0059 {
0060   // empty
0061 }
0062 
0063 // destructor
0064 L1GtfeWord::~L1GtfeWord() {
0065   // empty now
0066 }
0067 
0068 // equal operator
0069 bool L1GtfeWord::operator==(const L1GtfeWord& result) const {
0070   if (m_boardId != result.m_boardId) {
0071     return false;
0072   }
0073 
0074   if (m_recordLength1 != result.m_recordLength1) {
0075     return false;
0076   }
0077 
0078   if (m_recordLength != result.m_recordLength) {
0079     return false;
0080   }
0081 
0082   if (m_bxNr != result.m_bxNr) {
0083     return false;
0084   }
0085 
0086   if (m_setupVersion != result.m_setupVersion) {
0087     return false;
0088   }
0089 
0090   if (m_activeBoards != result.m_activeBoards) {
0091     return false;
0092   }
0093 
0094   if (m_altNrBxBoard != result.m_altNrBxBoard) {
0095     return false;
0096   }
0097 
0098   if (m_totalTriggerNr != result.m_totalTriggerNr) {
0099     return false;
0100   }
0101 
0102   // all members identical
0103   return true;
0104 }
0105 
0106 // unequal operator
0107 bool L1GtfeWord::operator!=(const L1GtfeWord& result) const { return !(result == *this); }
0108 
0109 // methods
0110 
0111 // set the BoardId value from a 64-bits word
0112 void L1GtfeWord::setBoardId(const cms_uint64_t& word64) { m_boardId = (word64 & BoardIdMask) >> BoardIdShift; }
0113 
0114 // set the BoardId value in a 64-bits word, having the index iWord
0115 // in the GTFE raw record
0116 void L1GtfeWord::setBoardIdWord64(cms_uint64_t& word64, int iWord) {
0117   if (iWord == BoardIdWord) {
0118     word64 = word64 | (static_cast<cms_uint64_t>(m_boardId) << BoardIdShift);
0119   }
0120 }
0121 
0122 // set the RecordLength1 value from a 64-bits word
0123 void L1GtfeWord::setRecordLength1(const cms_uint64_t& word64) {
0124   m_recordLength1 = (word64 & RecordLength1Mask) >> RecordLength1Shift;
0125 }
0126 
0127 // set the RecordLength1 value in a 64-bits word, having the index iWord
0128 // in the GTFE raw record
0129 void L1GtfeWord::setRecordLength1Word64(cms_uint64_t& word64, int iWord) {
0130   if (iWord == RecordLength1Word) {
0131     word64 = word64 | (static_cast<cms_uint64_t>(m_recordLength1) << RecordLength1Shift);
0132   }
0133 }
0134 
0135 // set the RecordLength value from a 64-bits word
0136 void L1GtfeWord::setRecordLength(const cms_uint64_t& word64) {
0137   m_recordLength = (word64 & RecordLengthMask) >> RecordLengthShift;
0138 }
0139 
0140 // set the RecordLength value in a 64-bits word, having the index iWord
0141 // in the GTFE raw record
0142 void L1GtfeWord::setRecordLengthWord64(cms_uint64_t& word64, int iWord) {
0143   if (iWord == RecordLengthWord) {
0144     word64 = word64 | (static_cast<cms_uint64_t>(m_recordLength) << RecordLengthShift);
0145   }
0146 }
0147 
0148 // set the BxNr value from a 64-bits word
0149 void L1GtfeWord::setBxNr(const cms_uint64_t& word64) { m_bxNr = (word64 & BxNrMask) >> BxNrShift; }
0150 
0151 // set the BxNr value in a 64-bits word, having the index iWord
0152 // in the GTFE raw record
0153 void L1GtfeWord::setBxNrWord64(cms_uint64_t& word64, int iWord) {
0154   if (iWord == BxNrWord) {
0155     word64 = word64 | (static_cast<cms_uint64_t>(m_bxNr) << BxNrShift);
0156   }
0157 }
0158 
0159 // set the SetupVersion value from a 64-bits word
0160 void L1GtfeWord::setSetupVersion(const cms_uint64_t& word64) {
0161   m_setupVersion = (word64 & SetupVersionMask) >> SetupVersionShift;
0162 }
0163 
0164 // set the SetupVersion value in a 64-bits word, having the index iWord
0165 // in the GTFE raw record
0166 void L1GtfeWord::setSetupVersionWord64(cms_uint64_t& word64, int iWord) {
0167   if (iWord == SetupVersionWord) {
0168     word64 = word64 | (static_cast<cms_uint64_t>(m_setupVersion) << SetupVersionShift);
0169   }
0170 }
0171 
0172 // get / set BST flag: 0 or 1 - via setup version (no private member)
0173 const int L1GtfeWord::bstFlag() const {
0174   int bstFlagValue = 0;
0175   bstFlagValue = static_cast<int>(m_setupVersion & BstFlagMask);
0176 
0177   return bstFlagValue;
0178 }
0179 
0180 void L1GtfeWord::setBstFlag(const int bstFlagValue) {
0181   m_setupVersion = m_setupVersion | (static_cast<cms_uint32_t>(bstFlagValue) & BstFlagMask);
0182 }
0183 
0184 // set the ActiveBoards value from a 64-bits word
0185 void L1GtfeWord::setActiveBoards(const cms_uint64_t& word64) {
0186   m_activeBoards = (word64 & ActiveBoardsMask) >> ActiveBoardsShift;
0187 }
0188 
0189 // set the ActiveBoards value in a 64-bits word, having the index iWord
0190 // in the GTFE raw record
0191 void L1GtfeWord::setActiveBoardsWord64(cms_uint64_t& word64, int iWord) {
0192   if (iWord == ActiveBoardsWord) {
0193     word64 = word64 | (static_cast<cms_uint64_t>(m_activeBoards) << ActiveBoardsShift);
0194   }
0195 }
0196 
0197 // set the ActiveBoards value in a 64-bits word, having the index iWord
0198 // in the GTFE raw record from the value activeBoardsValue
0199 void L1GtfeWord::setActiveBoardsWord64(cms_uint64_t& word64, int iWord, cms_int16_t activeBoardsValue) {
0200   if (iWord == ActiveBoardsWord) {
0201     word64 = word64 | (static_cast<cms_uint64_t>(activeBoardsValue) << ActiveBoardsShift);
0202   }
0203 }
0204 
0205 // set the AltNrBxBoard value from a 64-bits word
0206 void L1GtfeWord::setAltNrBxBoard(const cms_uint64_t& word64) {
0207   m_altNrBxBoard = (word64 & AltNrBxBoardMask) >> AltNrBxBoardShift;
0208 }
0209 
0210 // set the AltNrBxBoard value in a 64-bits word, having the index iWord
0211 // in the GTFE raw record
0212 void L1GtfeWord::setAltNrBxBoardWord64(cms_uint64_t& word64, int iWord) {
0213   if (iWord == AltNrBxBoardWord) {
0214     word64 = word64 | (static_cast<cms_uint64_t>(m_altNrBxBoard) << AltNrBxBoardShift);
0215   }
0216 }
0217 
0218 // set the AltNrBxBoard value in a 64-bits word, having the index iWord
0219 // in the GTFE raw record from the value altNrBxBoardValue
0220 void L1GtfeWord::setAltNrBxBoardWord64(cms_uint64_t& word64, int iWord, cms_int16_t altNrBxBoardValue) {
0221   if (iWord == AltNrBxBoardWord) {
0222     word64 = word64 | (static_cast<cms_uint64_t>(altNrBxBoardValue) << AltNrBxBoardShift);
0223   }
0224 }
0225 
0226 // set the TotalTriggerNr value from a 64-bits word
0227 void L1GtfeWord::setTotalTriggerNr(const cms_uint64_t& word64) {
0228   m_totalTriggerNr = (word64 & TotalTriggerNrMask) >> TotalTriggerNrShift;
0229 }
0230 
0231 // set the TotalTriggerNr value in a 64-bits word, having the index iWord
0232 // in the GTFE raw record
0233 void L1GtfeWord::setTotalTriggerNrWord64(cms_uint64_t& word64, int iWord) {
0234   if (iWord == TotalTriggerNrWord) {
0235     word64 = word64 | (static_cast<cms_uint64_t>(m_totalTriggerNr) << TotalTriggerNrShift);
0236   }
0237 }
0238 
0239 // reset the content of a L1GtfeWord
0240 void L1GtfeWord::reset() {
0241   m_boardId = 0;
0242   m_recordLength1 = 0;
0243   m_recordLength = 0;
0244   m_bxNr = 0;
0245   m_setupVersion = 0;
0246   //
0247   m_activeBoards = 0;
0248   m_altNrBxBoard = 0;
0249   m_totalTriggerNr = 0;
0250 }
0251 
0252 // pretty print the content of a L1GtfeWord
0253 void L1GtfeWord::print(std::ostream& myCout) const {
0254   myCout << "\n L1GtfeWord::print \n" << std::endl;
0255 
0256   myCout << "  BoardId:              " << std::hex << " hex: "
0257          << "      " << std::setw(2) << std::setfill('0') << m_boardId << std::setfill(' ') << std::dec
0258          << " dec: " << m_boardId << std::endl;
0259 
0260   myCout << "  BX for alternative 1: " << std::hex << " hex: "
0261          << "       " << std::setw(1) << m_recordLength1 << std::dec << " dec: " << m_recordLength1 << std::endl;
0262 
0263   myCout << "  BX for alternative 0: " << std::hex << " hex: "
0264          << "       " << std::setw(1) << m_recordLength << std::dec << " dec: " << m_recordLength << std::endl;
0265 
0266   myCout << "  BxNr:                 " << std::hex << " hex: "
0267          << "     " << std::setw(3) << std::setfill('0') << m_bxNr << std::setfill(' ') << std::dec
0268          << " dec: " << m_bxNr << std::endl;
0269 
0270   myCout << "  SetupVersion:         " << std::hex << " hex: " << std::setw(8) << std::setfill('0') << m_setupVersion
0271          << std::setfill(' ') << std::dec << " dec: " << m_setupVersion << std::endl;
0272 
0273   //
0274 
0275   myCout << "  ActiveBoards:         " << std::hex << " hex: "
0276          << "    " << std::setw(4) << std::setfill('0') << m_activeBoards << std::setfill(' ') << std::dec
0277          << " dec: " << m_activeBoards << std::endl;
0278 
0279   myCout << "  AltNrBxBoard:         " << std::hex << " hex: "
0280          << "    " << std::setw(4) << std::setfill('0') << m_altNrBxBoard << std::setfill(' ') << std::dec
0281          << " dec: " << m_altNrBxBoard << std::endl;
0282 
0283   myCout << "  TotalTriggerNr:       " << std::hex << " hex: " << std::setw(8) << std::setfill('0') << m_totalTriggerNr
0284          << std::setfill(' ') << std::dec << " dec: " << m_totalTriggerNr << std::endl;
0285 }
0286 
0287 // unpack GTFE
0288 // gtfePtr pointer to the beginning of the GTFE block in the raw data
0289 
0290 void L1GtfeWord::unpack(const unsigned char* gtfePtr) {
0291   LogDebug("L1GtfeWord") << "\nUnpacking GTFE block.\n" << std::endl;
0292 
0293   const cms_uint64_t* payload = reinterpret_cast<cms_uint64_t const*>(gtfePtr);
0294 
0295   setBoardId(payload[BoardIdWord]);
0296   setRecordLength1(payload[RecordLength1Word]);
0297   setRecordLength(payload[RecordLengthWord]);
0298   setBxNr(payload[BxNrWord]);
0299   setSetupVersion(payload[SetupVersionWord]);
0300   setActiveBoards(payload[ActiveBoardsWord]);
0301   setAltNrBxBoard(payload[AltNrBxBoardWord]);
0302   setTotalTriggerNr(payload[TotalTriggerNrWord]);
0303 
0304   if (edm::isDebugEnabled()) {
0305     for (int iWord = 0; iWord < BlockSize; ++iWord) {
0306       LogTrace("L1GtfeWord") << std::setw(4) << iWord << "  " << std::hex << std::setfill('0') << std::setw(16)
0307                              << payload[iWord] << std::dec << std::setfill(' ') << std::endl;
0308     }
0309   }
0310 }
0311 
0312 // static class members
0313 
0314 // block description in the raw GT record
0315 
0316 // block size in 64bits words
0317 const int L1GtfeWord::BlockSize = 2;  // 2 x 64bits
0318 
0319 const int L1GtfeWord::BoardIdWord = 0;
0320 const int L1GtfeWord::RecordLength1Word = 0;
0321 const int L1GtfeWord::RecordLengthWord = 0;
0322 const int L1GtfeWord::BxNrWord = 0;
0323 const int L1GtfeWord::SetupVersionWord = 0;
0324 
0325 const cms_uint64_t L1GtfeWord::BoardIdMask = 0xFF00000000000000ULL;
0326 const cms_uint64_t L1GtfeWord::RecordLength1Mask = 0x00F0000000000000ULL;
0327 const cms_uint64_t L1GtfeWord::RecordLengthMask = 0x000F000000000000ULL;
0328 const cms_uint64_t L1GtfeWord::BxNrMask = 0x00000FFF00000000ULL;
0329 const cms_uint64_t L1GtfeWord::SetupVersionMask = 0x00000000FFFFFFFFULL;
0330 
0331 const cms_uint32_t L1GtfeWord::BstFlagMask = 0x0001;
0332 
0333 // shifts could be computed from masks...
0334 const int L1GtfeWord::BoardIdShift = 56;
0335 const int L1GtfeWord::RecordLength1Shift = 52;
0336 const int L1GtfeWord::RecordLengthShift = 48;
0337 const int L1GtfeWord::BxNrShift = 32;
0338 const int L1GtfeWord::SetupVersionShift = 0;
0339 
0340 //
0341 const int L1GtfeWord::ActiveBoardsWord = 1;
0342 const int L1GtfeWord::AltNrBxBoardWord = 1;
0343 const int L1GtfeWord::TotalTriggerNrWord = 1;
0344 
0345 const cms_uint64_t L1GtfeWord::ActiveBoardsMask = 0xFFFF000000000000ULL;
0346 const cms_uint64_t L1GtfeWord::AltNrBxBoardMask = 0x0000FFFF00000000ULL;
0347 const cms_uint64_t L1GtfeWord::TotalTriggerNrMask = 0x00000000FFFFFFFFULL;
0348 
0349 const int L1GtfeWord::ActiveBoardsShift = 48;
0350 const int L1GtfeWord::AltNrBxBoardShift = 32;
0351 const int L1GtfeWord::TotalTriggerNrShift = 0;