Go to the documentation of this file.00001
00017
00018 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeExtWord.h"
00019
00020
00021 #include <iomanip>
00022
00023
00024 #include "FWCore/Utilities/interface/EDMException.h"
00025
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00028
00029 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00030 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00031
00032
00033
00034
00035
00036 L1GtfeExtWord::L1GtfeExtWord() :
00037 L1GtfeWord() {
00038
00039
00040
00041 }
00042
00043
00044 L1GtfeExtWord::L1GtfeExtWord(int bstSizeBytes) :
00045 L1GtfeWord() {
00046
00047 m_bst.resize(bstSizeBytes);
00048
00049 }
00050
00051
00052
00053 L1GtfeExtWord::L1GtfeExtWord(
00054 boost::uint16_t boardIdValue, boost::uint16_t recordLength1Value,
00055 boost::uint16_t recordLengthValue, boost::uint16_t bxNrValue,
00056 boost::uint32_t setupVersionValue, boost::uint16_t activeBoardsValue,
00057 boost::uint16_t altNrBxBoardValue, boost::uint32_t totalTriggerNrValue,
00058 std::vector<boost::uint16_t> bstValue, boost::uint16_t bstSourceValue) :
00059 L1GtfeWord(
00060 boardIdValue, recordLength1Value, recordLengthValue, bxNrValue, setupVersionValue,
00061 activeBoardsValue, altNrBxBoardValue, totalTriggerNrValue), m_bst(bstValue),
00062 m_bstSource(bstSourceValue)
00063
00064 {
00065
00066
00067 }
00068
00069
00070 L1GtfeExtWord::~L1GtfeExtWord() {
00071
00072
00073
00074 }
00075
00076
00077 bool L1GtfeExtWord::operator==(const L1GtfeExtWord& result) const
00078 {
00079
00080
00081
00082 const L1GtfeWord gtfeResult = result;
00083 const L1GtfeWord gtfeThis = *this;
00084
00085 if (gtfeThis != gtfeResult) {
00086 return false;
00087 }
00088
00089
00090
00091
00092 for (unsigned int iB = 0; iB < m_bst.size(); ++iB) {
00093 if(m_bst[iB] != result.m_bst[iB]) {
00094 return false;
00095 }
00096 }
00097
00098 if ( m_bstSource != result.m_bstSource) {
00099 return false;
00100 }
00101
00102
00103 return true;
00104
00105 }
00106
00107
00108 bool L1GtfeExtWord::operator!=(const L1GtfeExtWord& result) const
00109 {
00110
00111 return !( result == *this);
00112
00113 }
00114
00115
00116
00117 const boost::uint64_t L1GtfeExtWord::gpsTime() const
00118 {
00119
00120 boost::uint64_t gpst = 0ULL;
00121
00122
00123 int bstSize = m_bst.size();
00124 if (GpsTimeLastBlock >= bstSize) {
00125 return gpst;
00126 }
00127
00128 for (int iB = GpsTimeFirstBlock; iB <= GpsTimeLastBlock; ++iB) {
00129
00130
00131 const int scaledIB = iB - GpsTimeFirstBlock;
00132 const int BstShift = BstBitSize*scaledIB;
00133
00134 gpst = gpst |
00135 ( (static_cast<boost::uint64_t> (m_bst[iB])) << BstShift );
00136
00137 }
00138
00139 return gpst;
00140 }
00141
00142 void L1GtfeExtWord::setGpsTime(const boost::uint64_t gpsTimeValue) {
00143
00144
00145 int bstSize = m_bst.size();
00146 if (GpsTimeLastBlock >= bstSize) {
00147
00148 edm::LogError("L1GtfeExtWord") << "Error: BST message length "
00149 << bstSize << " smaller than the required GpsTimeLastBlock "
00150 << GpsTimeLastBlock << "\n Cannot set GpsTime" << std::endl;
00151
00152 return;
00153 }
00154
00155 for (int iB = GpsTimeFirstBlock; iB <= GpsTimeLastBlock; ++iB) {
00156
00157
00158 const int scaledIB = iB - GpsTimeFirstBlock;
00159 const int BstShift = BstBitSize*scaledIB;
00160 const boost::uint64_t BstMask = 0x0000000000000000ULL | (BstBlockMask << BstShift);
00161
00162 m_bst[iB] = static_cast<boost::uint16_t> ((gpsTimeValue & BstMask) >> BstShift);
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 }
00175
00176 }
00177
00178 const boost::uint16_t L1GtfeExtWord::bstMasterStatus() const
00179 {
00180
00181 boost::uint16_t bms = 0;
00182
00183
00184 int bstSize = m_bst.size();
00185 if (BstMasterStatusLastBlock >= bstSize) {
00186 return bms;
00187 }
00188
00189 for (int iB = BstMasterStatusFirstBlock; iB <= BstMasterStatusLastBlock; ++iB) {
00190
00191
00192 const int scaledIB = iB - BstMasterStatusFirstBlock;
00193 const int BstShift = BstBitSize*scaledIB;
00194
00195 bms = bms | ( m_bst[iB] << BstShift );
00196
00197 }
00198
00199 return bms;
00200 }
00201
00202
00203 const boost::uint32_t L1GtfeExtWord::turnCountNumber() const
00204 {
00205
00206 boost::uint32_t tcn = 0;
00207
00208
00209 int bstSize = m_bst.size();
00210 if (TurnCountNumberLastBlock >= bstSize) {
00211 return tcn;
00212 }
00213
00214 for (int iB = TurnCountNumberFirstBlock; iB <= TurnCountNumberLastBlock; ++iB) {
00215
00216
00217 const int scaledIB = iB - TurnCountNumberFirstBlock;
00218 const int BstShift = BstBitSize*scaledIB;
00219
00220 tcn = tcn |
00221 ( (static_cast<boost::uint32_t> (m_bst[iB])) << BstShift );
00222
00223 }
00224
00225 return tcn;
00226 }
00227
00228 const boost::uint32_t L1GtfeExtWord::lhcFillNumber() const
00229 {
00230
00231 boost::uint32_t lhcfn = 0;
00232
00233
00234 int bstSize = m_bst.size();
00235 if (LhcFillNumberLastBlock >= bstSize) {
00236 return lhcfn;
00237 }
00238
00239 for (int iB = LhcFillNumberFirstBlock; iB <= LhcFillNumberLastBlock; ++iB) {
00240
00241
00242 const int scaledIB = iB - LhcFillNumberFirstBlock;
00243 const int BstShift = BstBitSize*scaledIB;
00244
00245 lhcfn = lhcfn |
00246 ( (static_cast<boost::uint32_t> (m_bst[iB])) << BstShift );
00247
00248 }
00249
00250 return lhcfn;
00251 }
00252
00253 const boost::uint16_t L1GtfeExtWord::beamMode() const
00254 {
00255
00256 boost::uint16_t bm = 0;
00257
00258
00259 int bstSize = m_bst.size();
00260 if (BeamModeLastBlock >= bstSize) {
00261 return bm;
00262 }
00263
00264 for (int iB = BeamModeFirstBlock; iB <= BeamModeLastBlock; ++iB) {
00265
00266
00267 const int scaledIB = iB - BeamModeFirstBlock;
00268 const int BstShift = BstBitSize*scaledIB;
00269
00270 bm = bm | ( m_bst[iB] << BstShift );
00271
00272 }
00273
00274 return bm;
00275 }
00276
00277 const boost::uint16_t L1GtfeExtWord::particleTypeBeam1() const
00278 {
00279
00280 boost::uint16_t ptb = 0;
00281
00282
00283 int bstSize = m_bst.size();
00284 if (ParticleTypeBeam1LastBlock >= bstSize) {
00285 return ptb;
00286 }
00287
00288 for (int iB = ParticleTypeBeam1FirstBlock; iB <= ParticleTypeBeam1LastBlock; ++iB) {
00289
00290
00291 const int scaledIB = iB - ParticleTypeBeam1FirstBlock;
00292 const int BstShift = BstBitSize*scaledIB;
00293
00294 ptb = ptb | ( m_bst[iB] << BstShift );
00295
00296 }
00297
00298 return ptb;
00299 }
00300
00301 const boost::uint16_t L1GtfeExtWord::particleTypeBeam2() const
00302 {
00303
00304 boost::uint16_t ptb = 0;
00305
00306
00307 int bstSize = m_bst.size();
00308 if (ParticleTypeBeam2LastBlock >= bstSize) {
00309 return ptb;
00310 }
00311
00312 for (int iB = ParticleTypeBeam2FirstBlock; iB <= ParticleTypeBeam2LastBlock; ++iB) {
00313
00314
00315 const int scaledIB = iB - ParticleTypeBeam2FirstBlock;
00316 const int BstShift = BstBitSize*scaledIB;
00317
00318 ptb = ptb | ( m_bst[iB] << BstShift );
00319
00320 }
00321
00322 return ptb;
00323
00324 }
00325
00326 const boost::uint16_t L1GtfeExtWord::beamMomentum() const
00327 {
00328
00329 boost::uint16_t bm = 0;
00330
00331
00332 int bstSize = m_bst.size();
00333 if (BeamMomentumLastBlock >= bstSize) {
00334 return bm;
00335 }
00336
00337 for (int iB = BeamMomentumFirstBlock; iB <= BeamMomentumLastBlock; ++iB) {
00338
00339
00340 const int scaledIB = iB - BeamMomentumFirstBlock;
00341 const int BstShift = BstBitSize*scaledIB;
00342
00343 bm = bm | ( m_bst[iB] << BstShift );
00344
00345 }
00346
00347 return bm;
00348 }
00349
00350 const boost::uint32_t L1GtfeExtWord::totalIntensityBeam1() const
00351 {
00352
00353 boost::uint32_t tib = 0;
00354
00355
00356 int bstSize = m_bst.size();
00357 if (TotalIntensityBeam1LastBlock >= bstSize) {
00358 return tib;
00359 }
00360
00361 for (int iB = TotalIntensityBeam1FirstBlock; iB <= TotalIntensityBeam1LastBlock; ++iB) {
00362
00363
00364 const int scaledIB = iB - TotalIntensityBeam1FirstBlock;
00365 const int BstShift = BstBitSize*scaledIB;
00366
00367 tib = tib |
00368 ( (static_cast<boost::uint32_t> (m_bst[iB])) << BstShift );
00369
00370 }
00371
00372 return tib;
00373 }
00374
00375 const boost::uint32_t L1GtfeExtWord::totalIntensityBeam2() const
00376 {
00377
00378 boost::uint32_t tib = 0;
00379
00380
00381 int bstSize = m_bst.size();
00382 if (TotalIntensityBeam2LastBlock >= bstSize) {
00383 return tib;
00384 }
00385
00386 for (int iB = TotalIntensityBeam2FirstBlock; iB <= TotalIntensityBeam2LastBlock; ++iB) {
00387
00388
00389 const int scaledIB = iB - TotalIntensityBeam2FirstBlock;
00390 const int BstShift = BstBitSize*scaledIB;
00391
00392 tib = tib |
00393 ( (static_cast<boost::uint32_t> (m_bst[iB])) << BstShift );
00394
00395 }
00396
00397 return tib;
00398 }
00399
00400
00401
00402 const uint16_t L1GtfeExtWord::bst(int iB) const
00403 {
00404
00405 int NumberBstBlocks = m_bst.size();
00406
00407 if (iB < 0 || iB >= NumberBstBlocks) {
00408 throw cms::Exception("BstIndexError")
00409 << "\nError: index for BST array out of range. Allowed range: [0, "
00410 << NumberBstBlocks << ") " << std::endl;
00411
00412 } else {
00413 return m_bst[iB];
00414 }
00415
00416 }
00417
00418 void L1GtfeExtWord::setBst(const uint16_t bstVal, const int iB)
00419 {
00420
00421 int NumberBstBlocks = m_bst.size();
00422
00423 if (iB < 0 || iB >= NumberBstBlocks) {
00424 throw cms::Exception("BstIndexError")
00425 << "\nError: index for BST array out of range. Allowed range: [0, "
00426 << NumberBstBlocks << ") " << std::endl;
00427
00428 } else {
00429 m_bst[iB] = bstVal;
00430 }
00431
00432 }
00433
00434
00435 void L1GtfeExtWord::setBst(const boost::uint64_t& word64, const int iB)
00436 {
00437
00438
00439 const int scaledIB = iB%(sizeof(word64)*8/BstBitSize);
00440 const int BstShift = BstBitSize*scaledIB;
00441 const boost::uint64_t BstMask = 0x0000000000000000ULL | (BstBlockMask << BstShift);
00442
00443 m_bst[iB] = static_cast<boost::uint16_t> ((word64 & BstMask) >> BstShift);
00444
00445 }
00446
00447
00448
00449 void L1GtfeExtWord::setBstWord64(boost::uint64_t& word64, int iB, int iWord)
00450 {
00451
00452
00453 const int scaledIB = iB%(sizeof(word64)*8/BstBitSize);
00454 const int BstShift = BstBitSize*scaledIB;
00455 const int BstWord = iB/(sizeof(word64)*8/BstBitSize) + BstFirstWord;
00456
00457 if (iWord == BstWord) {
00458 word64 = word64 |
00459 (static_cast<boost::uint64_t> (m_bst[iB]) << BstShift);
00460 }
00461
00462
00463 }
00464
00465
00466
00467 void L1GtfeExtWord::setBstSource(const boost::uint64_t& word64) {
00468
00469 m_bstSource = (word64 & BstSourceMask) >> BstSourceShift;
00470
00471 }
00472
00473
00474
00475 void L1GtfeExtWord::setBstSourceWord64(boost::uint64_t& word64, const int iWord) {
00476
00477
00478 int gtfeSize = this->getSize();
00479
00480 int BstSourceWord = gtfeSize/8 - 1;
00481
00482 if (iWord == BstSourceWord) {
00483 word64 = word64 | (static_cast<boost::uint64_t> (m_bstSource)
00484 << BstSourceShift);
00485 }
00486
00487 }
00488
00489
00490
00491 const unsigned int L1GtfeExtWord::getSize() const {
00492
00493 L1GtfeWord gtfeWord;
00494 unsigned int gtfeSize = gtfeWord.getSize();
00495
00496 unsigned int gtfeExtSize;
00497
00498
00499 unsigned int bytesBstWriter = 2;
00500
00501
00502
00503 unsigned int bstSize = m_bst.size();
00504
00505 if ( (bstSize +bytesBstWriter )%8 == 0) {
00506 gtfeExtSize = gtfeSize + bstSize + bytesBstWriter;
00507 }
00508 else {
00509 gtfeExtSize = gtfeSize + bstSize + bytesBstWriter + (8 - (bstSize + bytesBstWriter)%8 );
00510 }
00511
00512 return gtfeExtSize;
00513 }
00514
00515
00516
00517
00518 void L1GtfeExtWord::resize(int bstSizeBytes) {
00519
00520 m_bst.resize(bstSizeBytes);
00521
00522 }
00523
00524
00525 void L1GtfeExtWord::reset()
00526 {
00527
00528 L1GtfeWord::reset();
00529 m_bst.clear();
00530
00531 }
00532
00533
00534 void L1GtfeExtWord::print(std::ostream& myCout) const
00535 {
00536
00537 myCout << "\n L1GtfeExtWord::print \n" << std::endl;
00538
00539 int sizeW64 = 64;
00540 int dataBlocksPerLine = sizeW64/8;
00541
00542 L1GtfeWord::print(myCout);
00543
00544 int NumberBstBlocks = m_bst.size();
00545
00546 myCout << "\n BST ";
00547 for (int iB = 0; iB < NumberBstBlocks; ++iB) {
00548
00549 myCout << "\n" << std::hex << " hex: ";
00550
00551 for (int jB = iB; jB < dataBlocksPerLine + iB; ++jB) {
00552
00553 if (jB >= NumberBstBlocks) {
00554 break;
00555 }
00556
00557 myCout
00558 << std::setw(2) << std::setfill('0') << m_bst[jB]
00559 << " " << std::setfill(' ');
00560 }
00561
00562 myCout << "\n"<< std::dec << " dec: " ;
00563
00564 for (int jB = iB; jB < dataBlocksPerLine + iB; ++jB) {
00565
00566 if (jB >= NumberBstBlocks) {
00567 break;
00568 }
00569
00570 myCout
00571 << std::setw(3) << std::setfill('0') << m_bst[jB]
00572 << " " << std::setfill(' ');
00573 }
00574
00575 myCout << std::endl;
00576
00577 iB += dataBlocksPerLine - 1;
00578 }
00579
00580 myCout << "\n BST source [hex]: " << std::hex << std::setw(4) << std::setfill('0')
00581 << m_bstSource << std::endl;
00582
00583 }
00584
00585 void L1GtfeExtWord::unpack(const unsigned char* gtfePtr)
00586 {
00587 LogDebug("L1GtfeExtWord")
00588 << "\nUnpacking GTFE block.\n"
00589 << std::endl;
00590
00591 L1GtfeWord::unpack(gtfePtr);
00592
00593
00594 L1GtfeWord gtfeWord;
00595 const unsigned char* gtfeExtPtr = gtfePtr + gtfeWord.getSize();
00596
00597 const boost::uint64_t* payload =
00598 reinterpret_cast<boost::uint64_t*>(const_cast<unsigned char*>(gtfeExtPtr));
00599
00600 int BlockSizeExt = this->getSize()/8;
00601 int NumberBstBlocks = m_bst.size();
00602
00603 if (edm::isDebugEnabled() ) {
00604
00605 for (int iWord = BstFirstWord; iWord < BlockSizeExt; ++iWord) {
00606
00607 int jWord = iWord - BstFirstWord;
00608 LogTrace("L1GtfeExtWord")
00609 << std::setw(4) << iWord << " "
00610 << std::hex << std::setfill('0')
00611 << std::setw(16) << payload[jWord]
00612 << std::dec << std::setfill(' ')
00613 << std::endl;
00614
00615 }
00616 }
00617
00618 int blocksPerWord = sizeof(boost::uint64_t)*8/BstBitSize;
00619
00620 for (int iB = 0; iB < NumberBstBlocks; ++iB) {
00621
00622
00623 int BstWord = iB/blocksPerWord;
00624
00625 setBst(payload[BstWord], iB);
00626
00627 }
00628
00629 }
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639 const int L1GtfeExtWord::BstFirstWord = 2;
00640
00641
00642 const int L1GtfeExtWord::BstBitSize = 8;
00643
00644
00645
00646 const boost::uint64_t L1GtfeExtWord::BstBlockMask = 0xFFULL;
00647
00648
00649
00650 const int L1GtfeExtWord::GpsTimeFirstBlock = 0;
00651 const int L1GtfeExtWord::GpsTimeLastBlock = 7;
00652
00653 const int L1GtfeExtWord::BstMasterStatusFirstBlock = 17;
00654 const int L1GtfeExtWord::BstMasterStatusLastBlock = 17;
00655
00656 const int L1GtfeExtWord::TurnCountNumberFirstBlock = 18;
00657 const int L1GtfeExtWord::TurnCountNumberLastBlock = 21;
00658
00659 const int L1GtfeExtWord::LhcFillNumberFirstBlock = 22;
00660 const int L1GtfeExtWord::LhcFillNumberLastBlock = 25;
00661
00662 const int L1GtfeExtWord::BeamModeFirstBlock = 26;
00663 const int L1GtfeExtWord::BeamModeLastBlock = 27;
00664
00665 const int L1GtfeExtWord::ParticleTypeBeam1FirstBlock = 28;
00666 const int L1GtfeExtWord::ParticleTypeBeam1LastBlock = 28;
00667
00668 const int L1GtfeExtWord::ParticleTypeBeam2FirstBlock = 29;
00669 const int L1GtfeExtWord::ParticleTypeBeam2LastBlock = 29;
00670
00671 const int L1GtfeExtWord::BeamMomentumFirstBlock = 30;
00672 const int L1GtfeExtWord::BeamMomentumLastBlock = 31;
00673
00674 const int L1GtfeExtWord::TotalIntensityBeam1FirstBlock = 32;
00675 const int L1GtfeExtWord::TotalIntensityBeam1LastBlock = 35;
00676
00677 const int L1GtfeExtWord::TotalIntensityBeam2FirstBlock = 36;
00678 const int L1GtfeExtWord::TotalIntensityBeam2LastBlock = 39;
00679
00680
00681 const boost::uint64_t L1GtfeExtWord::BstSourceMask = 0xFFFF000000000000ULL;
00682 const int L1GtfeExtWord::BstSourceShift = 48;
00683
00684
00685