CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/L1GlobalTrigger/src/L1GtPsbWord.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "DataFormats/L1GlobalTrigger/interface/L1GtPsbWord.h"
00019 
00020 // system include files
00021 #include <iomanip>
00022 
00023 // user include files
00024 #include "FWCore/Utilities/interface/EDMException.h"
00025 
00026 
00027 // constructors
00028 
00029 // empty constructor, all members set to zero;
00030 L1GtPsbWord::L1GtPsbWord()
00031 {
00032 
00033     m_boardId = 0;
00034     m_bxInEvent = 0;
00035     m_bxNr = 0;
00036     m_eventNr = 0;
00037 
00038     for (int iA = 0; iA < NumberAData; ++iA) {
00039         m_aData[iA] = 0;
00040     }
00041 
00042     for (int iB = 0; iB < NumberBData; ++iB) {
00043         m_bData[iB] = 0;
00044     }
00045 
00046     m_localBxNr = 0;
00047 
00048 }
00049 
00050 // constructor from unpacked values;
00051 L1GtPsbWord::L1GtPsbWord(
00052     boost::uint16_t boardIdValue,
00053     int bxInEventValue,
00054     boost::uint16_t bxNrValue,
00055     boost::uint32_t eventNrValue,
00056     boost::uint16_t aDataValue[NumberAData],
00057     boost::uint16_t bDataValue[NumberBData],
00058     boost::uint16_t localBxNrValue
00059 )
00060 {
00061 
00062     m_boardId = boardIdValue;
00063     m_bxInEvent = bxInEventValue;
00064     m_bxNr = bxNrValue;
00065     m_eventNr = eventNrValue;
00066 
00067     for (int iA = 0; iA < NumberAData; ++iA) {
00068         m_aData[iA] = aDataValue[iA];
00069     }
00070 
00071     for (int iB = 0; iB < NumberBData; ++iB) {
00072         m_bData[iB] = bDataValue[iB];
00073     }
00074 
00075     m_localBxNr = localBxNrValue;
00076 
00077 }
00078 
00079 // destructor
00080 L1GtPsbWord::~L1GtPsbWord()
00081 {
00082 
00083     // empty now
00084 
00085 }
00086 
00087 // equal operator
00088 bool L1GtPsbWord::operator==(const L1GtPsbWord& result) const
00089 {
00090 
00091     if (m_boardId != result.m_boardId) {
00092         return false;
00093     }
00094     if (m_bxInEvent != result.m_bxInEvent) {
00095         return false;
00096     }
00097     if (m_bxNr != result.m_bxNr) {
00098         return false;
00099     }
00100     if (m_eventNr != result.m_eventNr) {
00101         return false;
00102     }
00103 
00104     for (int iA = 0; iA < NumberAData; ++iA) {        
00105         if (m_aData[iA] != result.m_aData[iA]) {
00106             return false;
00107         }    
00108     }
00109 
00110     for (int iB = 0; iB < NumberBData; ++iB) {
00111         if (m_bData[iB] != result.m_bData[iB]) {
00112             return false;
00113         }
00114     }
00115     
00116     if (m_localBxNr != result.m_localBxNr) {
00117         return false;
00118     }
00119 
00120     // all members identical
00121     return true;
00122 
00123 }
00124 
00125 // unequal operator
00126 bool L1GtPsbWord::operator!=(const L1GtPsbWord& result) const
00127 {
00128 
00129     return !( result == *this);
00130 
00131 }
00132 
00133 
00134 // methods
00135 
00136 // set the BoardId value from a 64-bits word, having the index iWord
00137 // in the GTFE raw record
00138 void L1GtPsbWord::setBoardId(const boost::uint64_t& word64, int iWord)
00139 {
00140     if (iWord == BoardIdWord) {
00141         m_boardId = (word64 & BoardIdMask) >> BoardIdShift;
00142     }
00143 
00144 }
00145 
00146 // set the BoardId value in a 64-bits word, having the index iWord
00147 // in the GTFE raw record
00148 void L1GtPsbWord::setBoardIdWord64(boost::uint64_t& word64, int iWord)
00149 {
00150 
00151     if (iWord == BoardIdWord) {
00152         word64 = word64 | (static_cast<boost::uint64_t> (m_boardId) << BoardIdShift);
00153     }
00154 
00155 }
00156 
00157 
00158 // set the BxInEvent value from a 64-bits word, having the index iWord
00159 // in the GTFE raw record
00160 void L1GtPsbWord::setBxInEvent(const boost::uint64_t& word64, int iWord)
00161 {
00162     if (iWord == BxInEventWord) {
00163         int baseValue = 16; // using hexadecimal values;
00164         int hexBxInEvent = (word64 & BxInEventMask) >> BxInEventShift;
00165         m_bxInEvent = (hexBxInEvent + baseValue/2)%baseValue - baseValue/2;
00166     }
00167 
00168 }
00169 
00170 // set the BxInEvent value in a 64-bits word, having the index iWord
00171 // in the GTFE raw record
00172 void L1GtPsbWord::setBxInEventWord64(boost::uint64_t& word64, int iWord)
00173 {
00174 
00175     if (iWord == BxInEventWord) {
00176         int baseValue = 16; // using hexadecimal values;
00177         int hexBxInEvent = (m_bxInEvent + baseValue)%baseValue;
00178         word64 = word64 | (static_cast<boost::uint64_t> (hexBxInEvent)
00179                            << BxInEventShift);
00180     }
00181 
00182 }
00183 
00184 
00185 // set the BxNr value from a 64-bits word, having the index iWord in the GTFE raw record
00186 void L1GtPsbWord::setBxNr(const boost::uint64_t& word64, int iWord)
00187 {
00188 
00189     if (iWord == BxNrWord) {
00190         m_bxNr = (word64 & BxNrMask) >> BxNrShift;
00191     }
00192 
00193 }
00194 
00195 // set the BxNr value in a 64-bits word, having the index iWord
00196 // in the GTFE raw record
00197 void L1GtPsbWord::setBxNrWord64(boost::uint64_t& word64, int iWord)
00198 {
00199 
00200     if (iWord == BxNrWord) {
00201         word64 = word64 | (static_cast<boost::uint64_t> (m_bxNr) << BxNrShift);
00202     }
00203 
00204 }
00205 
00206 
00207 // set the EventNr value from a 64-bits word, having the index iWord in the GTFE raw record
00208 void L1GtPsbWord::setEventNr(const boost::uint64_t& word64, int iWord)
00209 {
00210     if (iWord == EventNrWord) {
00211         m_eventNr = (word64 & EventNrMask) >> EventNrShift;
00212     }
00213 
00214 }
00215 
00216 // set the EventNr value in a 64-bits word, having the index iWord
00217 // in the GTFE raw record
00218 void L1GtPsbWord::setEventNrWord64(boost::uint64_t& word64, int iWord)
00219 {
00220 
00221     if (iWord == EventNrWord) {
00222         word64 = word64 | (static_cast<boost::uint64_t> (m_eventNr) << EventNrShift);
00223     }
00224 
00225 }
00226 
00227 
00228 // get/set A_DATA_CH_IA
00229 
00230 const boost::uint16_t L1GtPsbWord::aData(int iA) const
00231 {
00232 
00233     if (iA < 0 || iA > NumberAData) {
00234         throw cms::Exception("aDataIndexError")
00235         << "\nError: index for A_DATA array out of range. Allowed range: [0, "
00236         << NumberAData << ") " << std::endl;
00237 
00238     } else {
00239         return m_aData[iA];
00240     }
00241 
00242 }
00243 
00244 void L1GtPsbWord::setAData(boost::uint16_t aDataVal, int iA)
00245 {
00246 
00247     if (iA < 0 || iA > NumberAData) {
00248         throw cms::Exception("aDataIndexError")
00249         << "\nError: index for A_DATA array out of range. Allowed range: [0, "
00250         << NumberAData << ") " << std::endl;
00251 
00252     } else {
00253         m_aData[iA] = aDataVal;
00254     }
00255 
00256 }
00257 
00258 // set the AData value from a 64-bits word, having the index iWord
00259 // in the GTFE raw record
00260 void L1GtPsbWord::setAData(const boost::uint64_t& word64, int iWord)
00261 {
00262 
00263     int sizeW64 = sizeof(word64)*8;
00264     int nSubWords = sizeW64/DataCHSize;
00265 
00266     if (iWord == ADataCH0Word) {
00267 
00268         for (int i = 0; i < nSubWords; ++i) {
00269             int dataShift = i*DataCHSize;
00270             m_aData[i] = (word64 & (DataCHMask << dataShift)) >> dataShift;
00271 
00272             //            LogTrace("L1GtPsbWord")
00273             //            << "\n  A_Data_CH" << i << " = "
00274             //            << m_aData[i]
00275             //            << std::endl;
00276 
00277         }
00278 
00279     } else if (iWord == ADataCH4Word) {
00280 
00281         for (int i = 0; i < nSubWords; ++i) {
00282             int dataShift = i*DataCHSize;
00283             m_aData[i + nSubWords] = (word64 & (DataCHMask << dataShift)) >> dataShift;
00284 
00285             //            LogTrace("L1GtPsbWord")
00286             //            << "\n  A_Data_CH" << i + nSubWords << " = "
00287             //            << m_aData[i]
00288             //            << std::endl;
00289         }
00290 
00291     }
00292 
00293 }
00294 
00295 // set the AData value in a 64-bits word, having the index iWord
00296 // in the GTFE raw record
00297 void L1GtPsbWord::setADataWord64(boost::uint64_t& word64, int iWord)
00298 {
00299 
00300     int sizeW64 = sizeof(word64)*8;
00301     int nSubWords = sizeW64/DataCHSize;
00302 
00303     if (iWord == ADataCH0Word) {
00304 
00305         for (int i = 0; i < nSubWords; ++i) {
00306             int dataShift = i*DataCHSize;
00307             word64 = word64 | (static_cast<boost::uint64_t> (m_aData[i]) << dataShift);
00308         }
00309 
00310     }
00311     else if (iWord == ADataCH4Word) {
00312 
00313         for (int i = 0; i < nSubWords; ++i) {
00314             int dataShift = i*DataCHSize;
00315             word64 = word64 |
00316                      (static_cast<boost::uint64_t> (m_aData[i + nSubWords]) << dataShift);
00317         }
00318 
00319     }
00320 
00321 }
00322 
00323 // get/set B_DATA_CH_IB
00324 
00325 const boost::uint16_t L1GtPsbWord::bData(int iB) const
00326 {
00327 
00328     if (iB < 0 || iB > NumberBData) {
00329         throw cms::Exception("bDataIndexError")
00330         << "\nError: index for B_DATA array out of range. Allowed range: [0, "
00331         << NumberBData << ") " << std::endl;
00332 
00333     } else {
00334         return m_bData[iB];
00335     }
00336 
00337 }
00338 
00339 void L1GtPsbWord::setBData(boost::uint16_t bDataVal, int iB)
00340 {
00341 
00342     if (iB < 0 || iB > NumberBData) {
00343         throw cms::Exception("bDataIndexError")
00344         << "\nError: index for B_DATA array out of range. Allowed range: [0, "
00345         << NumberBData << ") " << std::endl;
00346 
00347     } else {
00348         m_bData[iB] = bDataVal;
00349     }
00350 
00351 }
00352 
00353 // set the BData value from a 64-bits word, having the index iWord
00354 // in the GTFE raw record
00355 void L1GtPsbWord::setBData(const boost::uint64_t& word64, int iWord)
00356 {
00357 
00358     int sizeW64 = sizeof(word64)*8;
00359     int nSubWords = sizeW64/DataCHSize;
00360 
00361     if (iWord == BDataCH0Word) {
00362 
00363         for (int i = 0; i < nSubWords; ++i) {
00364             int dataShift = i*DataCHSize;
00365             m_bData[i] = (word64 & (DataCHMask << dataShift)) >> dataShift;
00366         }
00367 
00368     } else if (iWord == BDataCH4Word) {
00369 
00370         for (int i = 0; i < nSubWords; ++i) {
00371             int dataShift = i*DataCHSize;
00372             m_bData[i + nSubWords] = (word64 & (DataCHMask << dataShift)) >> dataShift;
00373         }
00374 
00375     }
00376 
00377 }
00378 
00379 // set the BData value in a 64-bits word, having the index iWord
00380 // in the GTFE raw record
00381 void L1GtPsbWord::setBDataWord64(boost::uint64_t& word64, int iWord)
00382 {
00383 
00384     int sizeW64 = sizeof(word64)*8;
00385     int nSubWords = sizeW64/DataCHSize;
00386 
00387     if (iWord == BDataCH0Word) {
00388 
00389         for (int i = 0; i < nSubWords; ++i) {
00390             int dataShift = i*DataCHSize;
00391             word64 = word64 | (static_cast<boost::uint64_t> (m_bData[i]) << dataShift);
00392         }
00393 
00394     }
00395     else if (iWord == BDataCH4Word) {
00396 
00397         for (int i = 0; i < nSubWords; ++i) {
00398             int dataShift = i*DataCHSize;
00399             word64 = word64 |
00400                      (static_cast<boost::uint64_t> (m_bData[i + nSubWords]) << dataShift);
00401         }
00402 
00403     }
00404 
00405 }
00406 
00407 
00408 // set the LocalBxNr value from a 64-bits word,
00409 // having the index iWord in the GTFE raw record
00410 void L1GtPsbWord::setLocalBxNr(const boost::uint64_t& word64, int iWord)
00411 {
00412     if (iWord == LocalBxNrWord) {
00413         m_localBxNr = (word64 & LocalBxNrMask) >> LocalBxNrShift;
00414     }
00415 
00416 }
00417 
00418 // set the LocalBxNr value in a 64-bits word, having the index iWord
00419 // in the GTFE raw record
00420 void L1GtPsbWord::setLocalBxNrWord64(boost::uint64_t& word64, int iWord)
00421 {
00422 
00423     if (iWord == LocalBxNrWord) {
00424         word64 = word64 | (static_cast<boost::uint64_t> (m_localBxNr)
00425                            << LocalBxNrShift);
00426     }
00427 
00428 }
00429 
00430 
00431 
00432 
00433 // reset the content of a L1GtPsbWord
00434 void L1GtPsbWord::reset()
00435 {
00436 
00437     m_boardId = 0;
00438     m_bxInEvent = 0;
00439     m_bxNr = 0;
00440     m_eventNr = 0;
00441 
00442     for (int iA = 0; iA < NumberAData; ++iA) {
00443         m_aData[iA] = 0;
00444     }
00445 
00446     for (int iB = 0; iB < NumberBData; ++iB) {
00447         m_bData[iB] = 0;
00448     }
00449 
00450     m_localBxNr = 0;
00451 
00452 }
00453 
00454 // pretty print
00455 void L1GtPsbWord::print(std::ostream& myCout) const
00456 {
00457 
00458     myCout << "\n L1GtPsbWord::print \n" << std::endl;
00459 
00460     myCout << "  Board Id:  "
00461     << std::hex << " hex:     " << std::setw(4) << std::setfill('0') << m_boardId
00462     << std::setfill(' ')
00463     << std::dec << " dec: " << m_boardId
00464     << std::endl;
00465 
00466     int baseValue = 16; // using hexadecimal values;
00467     int hexBxInEvent = (m_bxInEvent + baseValue)%baseValue;
00468 
00469     myCout << "  BxInEvent: "
00470     << std::hex << " hex:     " << "   " << std::setw(1) << hexBxInEvent
00471     << std::dec << " dec: " << m_bxInEvent
00472     << std::endl;
00473 
00474     myCout << "  BxNr:      "
00475     << std::hex << " hex:     "  << " " << std::setw(3) << std::setfill('0') << m_bxNr
00476     << std::setfill(' ')
00477     << std::dec << " dec: " << m_bxNr
00478     << std::endl;
00479 
00480 
00481     myCout << "  EventNr:   "
00482     << std::hex << " hex: " << "  " << std::setw(6) << std::setfill('0') << m_eventNr
00483     << std::setfill(' ')
00484     << std::dec << " dec: " << m_eventNr
00485     << std::endl;
00486 
00487     int sizeW64 = 64;
00488     int dataBlocksPerLine = sizeW64/DataCHSize; // 4x16 bits per line
00489 
00490     myCout << "\n        "
00491     << "A_Data_CH3 "
00492     << "A_Data_CH2 "
00493     << "A_Data_CH1 "
00494     << "A_Data_CH0 " << "\n"
00495     << std::hex << "  hex:  " << std::setfill('0');
00496 
00497     for (int i = 0; i < dataBlocksPerLine; ++i) {
00498 
00499         int iCh = dataBlocksPerLine - (i + 1); // reverse
00500         myCout << std::setw(4) <<  m_aData[iCh] << "       ";
00501 
00502     }
00503 
00504     myCout << "\n"
00505     << std::dec << "  dec:  ";
00506 
00507     for (int i = 0; i < dataBlocksPerLine; ++i) {
00508 
00509         int iCh = dataBlocksPerLine - (i + 1); // reverse
00510         myCout << std::setw(5) <<  m_aData[iCh] << "      ";
00511 
00512     }
00513 
00514     myCout << "\n\n        "
00515     << "A_Data_CH7 "
00516     << "A_Data_CH6 "
00517     << "A_Data_CH5 "
00518     << "A_Data_CH4 " << "\n"
00519     << std::hex << "  hex:  " << std::setfill('0');
00520 
00521     for (int i = 0; i < dataBlocksPerLine; ++i) {
00522 
00523         int iCh = dataBlocksPerLine - (i + 1); // reverse
00524         myCout << std::setw(4) <<  m_aData[iCh + dataBlocksPerLine] << "       ";
00525 
00526     }
00527 
00528     myCout << "\n"
00529     << std::dec << "  dec:  ";
00530 
00531     for (int i = 0; i < dataBlocksPerLine; ++i) {
00532 
00533         int iCh = dataBlocksPerLine - (i + 1); // reverse
00534         myCout << std::setw(5) <<  m_aData[iCh + dataBlocksPerLine] << "      ";
00535 
00536     }
00537 
00538     myCout << std::endl;
00539 
00540     myCout << "\n        "
00541     << "B_Data_CH3 "
00542     << "B_Data_CH2 "
00543     << "B_Data_CH1 "
00544     << "B_Data_CH0 " << "\n"
00545     << std::hex << "  hex:  " << std::setfill('0');
00546 
00547     for (int i = 0; i < dataBlocksPerLine; ++i) {
00548 
00549         int iCh = dataBlocksPerLine - (i + 1); // reverse
00550         myCout << std::setw(4) <<  m_bData[iCh] << "       ";
00551 
00552     }
00553 
00554     myCout << "\n"
00555     << std::dec << "  dec:  ";
00556 
00557     for (int i = 0; i < dataBlocksPerLine; ++i) {
00558 
00559         int iCh = dataBlocksPerLine - (i + 1); // reverse
00560         myCout << std::setw(5) <<  m_bData[iCh] << "      ";
00561 
00562     }
00563 
00564     myCout << "\n\n        "
00565     << "B_Data_CH7 "
00566     << "B_Data_CH6 "
00567     << "B_Data_CH5 "
00568     << "B_Data_CH4 " << "\n"
00569     << std::hex << "  hex:  " << std::setfill('0');
00570 
00571     for (int i = 0; i < dataBlocksPerLine; ++i) {
00572 
00573         int iCh = dataBlocksPerLine - (i + 1); // reverse
00574         myCout << std::setw(4) <<  m_bData[iCh + dataBlocksPerLine] << "       ";
00575 
00576     }
00577 
00578     myCout << "\n"
00579     << std::dec << "  dec:  ";
00580 
00581     for (int i = 0; i < dataBlocksPerLine; ++i) {
00582 
00583         int iCh = dataBlocksPerLine - (i + 1); // reverse
00584         myCout << std::setw(5) <<  m_bData[iCh + dataBlocksPerLine] << "      ";
00585 
00586     }
00587 
00588     myCout << "\n" << std::endl;
00589 
00590     myCout << "  LocalBxNr: "
00591     << std::hex << " hex:     "  << " " << std::setw(3) << std::setfill('0') << m_localBxNr
00592     << std::setfill(' ')
00593     << std::dec << " dec: " << m_localBxNr
00594     << std::endl;
00595 
00596 }
00597 
00598 // static class members
00599 const int L1GtPsbWord::NumberAData;
00600 const int L1GtPsbWord::NumberBData;
00601