CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/EventFilter/L1GlobalTriggerRawToDigi/src/L1GTEvmDigiToRaw.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "EventFilter/L1GlobalTriggerRawToDigi/interface/L1GTEvmDigiToRaw.h"
00019 
00020 // system include files
00021 #include <vector>
00022 #include <iostream>
00023 #include <iomanip>
00024 
00025 
00026 // user include files
00027 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00028 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00029 
00030 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
00031 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00032 #include "FWCore/Utilities/interface/CRC16.h"
00033 
00034 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00035 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00036 
00037 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeWord.h"
00038 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeExtWord.h"
00039 #include "DataFormats/L1GlobalTrigger/interface/L1TcsWord.h"
00040 #include "DataFormats/L1GlobalTrigger/interface/L1GtFdlWord.h"
00041 
00042 
00043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00044 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00045 
00046 #include "FWCore/Framework/interface/EventSetup.h"
00047 #include "FWCore/Framework/interface/ESHandle.h"
00048 
00049 #include "CondFormats/L1TObjects/interface/L1GtFwd.h"
00050 #include "CondFormats/L1TObjects/interface/L1GtBoard.h"
00051 
00052 #include "CondFormats/L1TObjects/interface/L1GtBoardMaps.h"
00053 #include "CondFormats/DataRecord/interface/L1GtBoardMapsRcd.h"
00054 
00055 
00056 // constructor(s)
00057 L1GTEvmDigiToRaw::L1GTEvmDigiToRaw(const edm::ParameterSet& pSet) :
00058     m_evmGtFedId(pSet.getUntrackedParameter<int>("EvmGtFedId",
00059             FEDNumbering::MINTriggerGTPFEDID)),
00060     m_evmGtInputTag(pSet.getParameter<edm::InputTag>("EvmGtInputTag")),
00061     m_activeBoardsMaskGt(pSet.getParameter<unsigned int>("ActiveBoardsMask")),
00062     m_totalBxInEvent(0),
00063     m_minBxInEvent(0), m_maxBxInEvent(),
00064     m_verbosity(pSet.getUntrackedParameter<int> ("Verbosity", 0)),
00065     m_isDebugEnabled(edm::isDebugEnabled())
00066 
00067 
00068 
00069 {
00070 
00071     LogDebug("L1GTEvmDigiToRaw") << "\nMask for active boards (hex format): "
00072             << std::hex << std::setw(sizeof(m_activeBoardsMaskGt)*2)
00073             << std::setfill('0') << m_activeBoardsMaskGt << std::dec
00074             << std::setfill(' ') << "\nInput tag for EVM GT record: "
00075             << m_evmGtInputTag << "\nFED Id for EVM GT record: "
00076             << m_evmGtFedId << " \n" << std::endl;
00077 
00078     //
00079     produces<FEDRawDataCollection>();
00080 
00081 }
00082 
00083 // destructor
00084 L1GTEvmDigiToRaw::~L1GTEvmDigiToRaw()
00085 {
00086 
00087     // empty now
00088 
00089 }
00090 
00091 // member functions
00092 
00093 // beginning of job stuff
00094 void L1GTEvmDigiToRaw::beginJob()
00095 {
00096 
00097     // empty now
00098 
00099 }
00100 
00101 
00102 // method called to produce the data
00103 void L1GTEvmDigiToRaw::produce(edm::Event& iEvent, const edm::EventSetup& evSetup)
00104 {
00105 
00106     // define new FEDRawDataCollection
00107     // it contains ALL FEDs in an event
00108     std::auto_ptr<FEDRawDataCollection> allFedRawData(new FEDRawDataCollection);
00109 
00110     FEDRawData& gtRawData = allFedRawData->FEDData(m_evmGtFedId);
00111 
00112     // get records from EventSetup
00113 
00114     //  board maps
00115     edm::ESHandle< L1GtBoardMaps > l1GtBM;
00116     evSetup.get< L1GtBoardMapsRcd >().get( l1GtBM );
00117 
00118     const std::vector<L1GtBoard> boardMaps = l1GtBM->gtBoardMaps();
00119     int boardMapsSize = boardMaps.size();
00120 
00121     typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
00122 
00123     // create an ordered vector for the GT EVM record
00124     // header (pos 0 in record) and trailer (last position in record)
00125     // not included, as they are not in board list
00126     std::vector<L1GtBoard> gtRecordMap;
00127     gtRecordMap.reserve(boardMapsSize);
00128 
00129     for (int iPos = 0; iPos < boardMapsSize; ++iPos) {
00130         for (CItBoardMaps itBoard = boardMaps.begin(); itBoard
00131                 != boardMaps.end(); ++itBoard) {
00132 
00133             if (itBoard->gtPositionEvmRecord() == iPos) {
00134                 gtRecordMap.push_back(*itBoard);
00135                 break;
00136             }
00137 
00138         }
00139     }
00140 
00141 
00142 
00143     // get L1GlobalTriggerEvmReadoutRecord
00144     edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtReadoutRecord;
00145     iEvent.getByLabel(m_evmGtInputTag, gtReadoutRecord);
00146 
00147     if (!gtReadoutRecord.isValid()) {
00148         edm::LogWarning("L1GTEvmDigiToRaw")
00149                 << "\nWarning: L1GlobalTriggerEvmReadoutRecord with input tag " << m_evmGtInputTag
00150                 << "\nrequested in configuration, but not found in the event."
00151                 << "\nQuit packing this event" << std::endl;
00152 
00153         // put the raw data in the event
00154         iEvent.put(allFedRawData);
00155 
00156         return;
00157     }
00158 
00159     if (m_verbosity && m_isDebugEnabled) {
00160         std::ostringstream myCoutStream;
00161         gtReadoutRecord->print(myCoutStream);
00162         LogTrace("L1GTEvmDigiToRaw")
00163                 << "\n The following L1 GT EVM readout record will be packed.\n"
00164                 << " Some boards could be disabled before packing,"
00165                 << " see detailed board packing.\n"
00166                 << myCoutStream.str() << "\n"
00167                 << std::endl;
00168     }
00169 
00170     // get GTFE block
00171     L1GtfeExtWord gtfeBlock = gtReadoutRecord->gtfeWord();
00172 
00173     // get the number of Bx in the event for alternative 0 and alternative 1
00174     boost::uint16_t recordLength0 = gtfeBlock.recordLength();
00175     boost::uint16_t recordLength1 = gtfeBlock.recordLength1();
00176 
00177     // length of BST record (in bytes)
00178     m_bstLengthBytes= static_cast<int> (gtfeBlock.bstLengthBytes());
00179 
00180     // get list of active blocks from the GTFE block
00181     // and mask some blocks, if required
00182     // blocks not active are not written to the record
00183 
00184     boost::uint16_t activeBoardsGtInitial = gtfeBlock.activeBoards();
00185     boost::uint16_t altNrBxBoardInitial = gtfeBlock.altNrBxBoard();
00186 
00187     // mask some boards, if needed
00188 
00189     boost::uint16_t activeBoardsGt = activeBoardsGtInitial & m_activeBoardsMaskGt;
00190 
00191     if (m_verbosity && m_isDebugEnabled) {
00192         LogDebug("L1GTEvmDigiToRaw")
00193                 << "\nActive boards before masking(hex format): " << std::hex
00194                 << std::setw(sizeof ( activeBoardsGtInitial ) * 2) << std::setfill('0')
00195                 << activeBoardsGtInitial << std::dec << std::setfill(' ')
00196                 << "\nActive boards after masking(hex format):  " << std::hex
00197                 << std::setw(sizeof ( activeBoardsGt ) * 2) << std::setfill('0')
00198                 << activeBoardsGt << std::dec
00199                 << std::setfill(' ') << " \n"
00200                 << std::endl;
00201     }
00202 
00203     // get the size of the record
00204 
00205     unsigned int gtDataSize = 0;
00206 
00207     unsigned int headerSize = 8;
00208     gtDataSize += headerSize;
00209 
00210     for (CItBoardMaps
00211             itBoard = boardMaps.begin();
00212             itBoard != boardMaps.end(); ++itBoard) {
00213 
00214         if (itBoard->gtBoardType() == GTFE) {
00215             gtDataSize += gtfeBlock.getSize();
00216             continue;
00217         }
00218 
00219 
00220         int iActiveBit = itBoard->gtBitEvmActiveBoards();
00221         bool activeBoardToPack = false;
00222 
00223         int altNrBxBoardVal = -1;
00224 
00225         if (iActiveBit >= 0) {
00226             activeBoardToPack = activeBoardsGt & (1 << iActiveBit);
00227 
00228             altNrBxBoardVal = (altNrBxBoardInitial & ( 1 << iActiveBit )) >> iActiveBit;
00229 
00230             if (altNrBxBoardVal == 1) {
00231                 m_totalBxInEvent = recordLength1;
00232             } else if (altNrBxBoardVal == 0) {
00233                 m_totalBxInEvent = recordLength0;
00234             } else {
00235                 if (m_verbosity) {
00236                     edm::LogWarning("L1GTEvmDigiToRaw")
00237                     << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal
00238                     << " for board " << std::hex << ( itBoard->gtBoardId() ) << std::dec
00239                     << "\n  iActiveBit =            " << iActiveBit
00240                     << "\n  altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial <<  std::dec
00241                     << "\n  activeBoardsGt =      0x" << std::hex << activeBoardsGt <<  std::dec
00242                     << "\n  activeBoardToPack =   " << activeBoardToPack
00243                     << "\n Set altNrBxBoardVal tentatively to "
00244                     << recordLength0 << "\n Job may crash or produce wrong results!\n\n"
00245                     << std::endl;
00246                 }
00247 
00248                 m_totalBxInEvent = recordLength0;
00249             }
00250         } else {
00251             // board not in the ActiveBoards for the record
00252             continue;
00253         }
00254 
00255         if (activeBoardToPack) {
00256 
00257             switch (itBoard->gtBoardType()) {
00258                 case GTFE: {
00259                         // size already added;
00260                     }
00261 
00262                     break;
00263                 case FDL: {
00264                         L1GtFdlWord fdlBlock;
00265                         gtDataSize += m_totalBxInEvent*fdlBlock.getSize();
00266                     }
00267 
00268                     break;
00269                 case TCS: {
00270                         L1TcsWord tcsBlock;
00271                         gtDataSize += tcsBlock.getSize();
00272                     }
00273 
00274                     break;
00275                 case TIM: {
00276                         // not considered
00277                     }
00278 
00279                     break;
00280                 default: {
00281                         // do nothing, all blocks are given in GtBoardType enum
00282                     }
00283 
00284                     break;
00285             }
00286         }
00287 
00288     }
00289 
00290 
00291     unsigned int trailerSize = 8;
00292     gtDataSize += trailerSize;
00293 
00294     // resize, GT raw data record has variable length,
00295     // depending on active boards (read in GTFE)
00296     gtRawData.resize(gtDataSize);
00297 
00298     // ptrGt: pointer to the beginning of GT record in the raw data
00299 
00300     unsigned char* ptrGt = gtRawData.data();
00301     unsigned char* ptrGtBegin = gtRawData.data();
00302 
00303     if (m_verbosity && m_isDebugEnabled) {
00304         LogDebug("L1GTEvmDigiToRaw") << "\n Size of raw data: " << gtRawData.size() << "\n"
00305                 << std::endl;
00306     }
00307 
00308     // ------- pack boards -------
00309 
00310     // pack header
00311     packHeader(ptrGt, iEvent);
00312     ptrGt += headerSize; // advance with header size
00313 
00314     // loop over other blocks in the raw record, if they are active
00315 
00316     for (CItBoardMaps
00317             itBoard = gtRecordMap.begin();
00318             itBoard != gtRecordMap.end(); ++itBoard) {
00319 
00320         if (itBoard->gtBoardType() == GTFE) {
00321 
00322             packGTFE(evSetup, ptrGt, gtfeBlock, activeBoardsGt);
00323 
00324             if (m_verbosity && m_isDebugEnabled) {
00325 
00326                 std::ostringstream myCoutStream;
00327                 gtfeBlock.print(myCoutStream);
00328                 LogTrace("L1GTEvmDigiToRaw")
00329                         << myCoutStream.str() << "\n"
00330                         << std::endl;
00331             }
00332 
00333             ptrGt += gtfeBlock.getSize(); // advance with GTFE block size
00334 
00335             continue;
00336         }
00337 
00338 
00339         // pack modules other than GTFE if they are active
00340 
00341         int iActiveBit = itBoard->gtBitEvmActiveBoards();
00342         bool activeBoardToPack = false;
00343 
00344         int altNrBxBoardVal = -1;
00345 
00346         if (iActiveBit >= 0) {
00347             activeBoardToPack = activeBoardsGt & (1 << iActiveBit);
00348 
00349             altNrBxBoardVal = (altNrBxBoardInitial & ( 1 << iActiveBit )) >> iActiveBit;
00350 
00351             if (altNrBxBoardVal == 1) {
00352                 m_totalBxInEvent = recordLength1;
00353             } else if (altNrBxBoardVal == 0) {
00354                 m_totalBxInEvent = recordLength0;
00355             } else {
00356                 if (m_verbosity) {
00357                     edm::LogWarning("L1GTEvmDigiToRaw")
00358                     << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal
00359                     << " for board " << std::hex << ( itBoard->gtBoardId() ) << std::dec
00360                     << "\n  iActiveBit =            " << iActiveBit
00361                     << "\n  altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial <<  std::dec
00362                     << "\n  activeBoardsGt =      0x" << std::hex << activeBoardsGt <<  std::dec
00363                     << "\n  activeBoardToPack =   " << activeBoardToPack
00364                     << "\n Set altNrBxBoardVal tentatively to "
00365                     << recordLength0 << "\n Job may crash or produce wrong results!\n\n"
00366                     << std::endl;
00367                 }
00368 
00369                 m_totalBxInEvent = recordLength0;
00370             }
00371 
00372             m_minBxInEvent = (m_totalBxInEvent + 1)/2 - m_totalBxInEvent;
00373             m_maxBxInEvent = (m_totalBxInEvent + 1)/2 - 1;
00374 
00375         } else {
00376             // board not in the ActiveBoards for the record
00377             continue;
00378         }
00379 
00380         if (activeBoardToPack) {
00381 
00382             if (m_verbosity && m_isDebugEnabled) {
00383                 LogDebug("L1GTEvmDigiToRaw")
00384                         << "\nBoard " << std::hex << "0x" << ( itBoard->gtBoardId() ) << std::dec
00385                         << "\n  Number of bunch crosses in the record: " << m_totalBxInEvent
00386                         << " = " << "[" << m_minBxInEvent << ", " << m_maxBxInEvent
00387                         << "] BX\n"
00388                         << std::endl;
00389             }
00390 
00391             // active board, pack it
00392             switch (itBoard->gtBoardType()) {
00393 
00394                 case TCS: {
00395 
00396                         L1TcsWord tcsBlock = gtReadoutRecord->tcsWord();
00397                         packTCS(evSetup, ptrGt, tcsBlock);
00398 
00399                         if (m_verbosity && m_isDebugEnabled) {
00400 
00401                             std::ostringstream myCoutStream;
00402                             tcsBlock.print(myCoutStream);
00403                             LogTrace("L1GTEvmDigiToRaw")
00404                                     << myCoutStream.str() << "\n"
00405                                     << std::endl;
00406                         }
00407 
00408                         ptrGt += tcsBlock.getSize(); // advance with TCS block size
00409 
00410                     }
00411                     break;
00412                 case FDL: {
00413 
00414                         for (int iBxInEvent = m_minBxInEvent; iBxInEvent <= m_maxBxInEvent;
00415                                 ++iBxInEvent) {
00416 
00417                             L1GtFdlWord fdlBlock = gtReadoutRecord->gtFdlWord(iBxInEvent);
00418                             packFDL(evSetup, ptrGt, fdlBlock);
00419 
00420                             if (m_verbosity && m_isDebugEnabled) {
00421 
00422                                 std::ostringstream myCoutStream;
00423                                 fdlBlock.print(myCoutStream);
00424                                 LogTrace("L1GTEvmDigiToRaw")
00425                                         << myCoutStream.str() << "\n"
00426                                         << std::endl;
00427                             }
00428 
00429                             ptrGt += fdlBlock.getSize(); // advance with FDL block size
00430                         }
00431 
00432                     }
00433                     break;
00434                 default: {
00435 
00436                         // do nothing, all blocks are given in GtBoardType enum
00437                         break;
00438                     }
00439             }
00440 
00441         }
00442     }
00443 
00444     // pack trailer
00445     packTrailer(ptrGt, ptrGtBegin, gtDataSize);
00446 
00447     // put the raw data in the event
00448 
00449     iEvent.put(allFedRawData);
00450 
00451 
00452 }
00453 
00454 
00455 // pack header
00456 void L1GTEvmDigiToRaw::packHeader(unsigned char* ptrGt, edm::Event& iEvent)
00457 {
00458     // TODO FIXME where from to get all numbers?
00459 
00460     // Event Trigger type identifier
00461     int triggerTypeVal = 0;
00462 
00463     // Level-1 event number generated by the TTC system
00464     int lvl1IdVal = iEvent.id().event();
00465 
00466     // The bunch crossing number
00467     int bxCross = iEvent.bunchCrossing();
00468     boost::uint16_t bxCrossHw = 0;
00469     if ((bxCross & 0xFFF) == bxCross) {
00470         bxCrossHw = static_cast<boost::uint16_t> (bxCross);
00471     }
00472     else {
00473         bxCrossHw = 0; // Bx number too large, set to 0!
00474         if (m_verbosity && m_isDebugEnabled) {
00475             LogDebug("L1GTEvmDigiToRaw")
00476                     << "\nBunch cross number [hex] = "
00477                     << std::hex << bxCross
00478                     << "\n  larger than 12 bits. Set to 0! \n"
00479                     << std::dec
00480                     << std::endl;
00481         }
00482     }
00483     int bxIdVal = bxCrossHw;
00484 
00485     // Identifier of the FED
00486     int sourceIdVal = m_evmGtFedId;
00487 
00488     // Version identifier of the FED data format
00489     int versionVal = 0;
00490 
00491     // 0 -> the current header word is the last one.
00492     // 1-> other header words can follow
00493     // (always 1 for ECAL)
00494     bool moreHeadersVal = false;
00495 
00496 
00497     FEDHeader gtFEDHeader(ptrGt);
00498 
00499     gtFEDHeader.set(ptrGt,
00500                     triggerTypeVal, lvl1IdVal, bxIdVal, sourceIdVal, versionVal,
00501                     moreHeadersVal);
00502 
00503 
00504 }
00505 
00506 // pack the GTFE block
00507 void L1GTEvmDigiToRaw::packGTFE(
00508     const edm::EventSetup& evSetup,
00509     unsigned char* ptrGt,
00510     L1GtfeExtWord& gtfeBlock,
00511     boost::uint16_t activeBoardsGtValue)
00512 {
00513 
00514     if (m_verbosity && m_isDebugEnabled) {
00515         LogDebug("L1GTEvmDigiToRaw") << "\nPacking GTFE \n" << std::endl;
00516     }
00517 
00518     int uLength = L1GlobalTriggerReadoutSetup::UnitLength;
00519 
00520     // initialize the required number of word64
00521     int nrWord64 = gtfeBlock.getSize()/uLength;
00522     std::vector<boost::uint64_t> tmpWord64;
00523     tmpWord64.resize(nrWord64);
00524 
00525     for (int iWord = 0; iWord < nrWord64; ++iWord) {
00526         tmpWord64[iWord] = 0x0000000000000000ULL;
00527     }
00528 
00529     // fill the values in the words
00530     for (int iWord = 0; iWord < nrWord64; ++iWord) {
00531 
00532         gtfeBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
00533         gtfeBlock.setRecordLength1Word64(tmpWord64[iWord], iWord);
00534         gtfeBlock.setRecordLengthWord64(tmpWord64[iWord], iWord);
00535         gtfeBlock.setBxNrWord64(tmpWord64[iWord], iWord);
00536         gtfeBlock.setSetupVersionWord64(tmpWord64[iWord], iWord);
00537         gtfeBlock.setActiveBoardsWord64(tmpWord64[iWord], iWord, activeBoardsGtValue);
00538         gtfeBlock.setAltNrBxBoardWord64(tmpWord64[iWord], iWord);
00539         gtfeBlock.setTotalTriggerNrWord64(tmpWord64[iWord], iWord);
00540 
00541         for (int iBst = 0; iBst < m_bstLengthBytes; ++iBst) {
00542             gtfeBlock.setBstWord64(tmpWord64[iWord], iBst, iWord);
00543         }
00544 
00545     }
00546 
00547     // put the words in the FED record
00548 
00549     boost::uint64_t* pw =
00550         reinterpret_cast<boost::uint64_t*>(const_cast<unsigned char*>(ptrGt));
00551 
00552     for (int iWord = 0; iWord < nrWord64; ++iWord) {
00553 
00554         *pw++ = tmpWord64[iWord];
00555 
00556         if (m_verbosity && m_isDebugEnabled) {
00557             LogTrace("L1GTEvmDigiToRaw")
00558                     << std::setw(4) << iWord << "  "
00559                     << std::hex << std::setfill('0')
00560                     << std::setw(16) << tmpWord64[iWord]
00561                     << std::dec << std::setfill(' ')
00562                     << std::endl;
00563         }
00564     }
00565 
00566 
00567 }
00568 
00569 // pack the TCS block
00570 void L1GTEvmDigiToRaw::packTCS(
00571     const edm::EventSetup& evSetup,
00572     unsigned char* ptrGt,
00573     L1TcsWord& tcsBlock)
00574 {
00575 
00576     if (m_verbosity && m_isDebugEnabled) {
00577         LogDebug("L1GTEvmDigiToRaw") << "\nPacking TCS \n" << std::endl;
00578     }
00579 
00580     int uLength = L1GlobalTriggerReadoutSetup::UnitLength;
00581 
00582     // initialize the required number of word64
00583     int nrWord64 = tcsBlock.getSize()/uLength;
00584     std::vector<boost::uint64_t> tmpWord64;
00585     tmpWord64.resize(nrWord64);
00586 
00587     for (int iWord = 0; iWord < nrWord64; ++iWord) {
00588         tmpWord64[iWord] = 0x0000000000000000ULL;
00589     }
00590 
00591     // fill the values in the words
00592     for (int iWord = 0; iWord < nrWord64; ++iWord) {
00593 
00594         tcsBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
00595         tcsBlock.setBxNrWord64(tmpWord64[iWord], iWord);
00596         tcsBlock.setDaqNrWord64(tmpWord64[iWord], iWord);
00597         tcsBlock.setTriggerTypeWord64(tmpWord64[iWord], iWord);
00598         tcsBlock.setStatusWord64(tmpWord64[iWord], iWord);
00599         tcsBlock.setLuminositySegmentNrWord64(tmpWord64[iWord], iWord);
00600 
00601         tcsBlock.setPartRunNrWord64(tmpWord64[iWord], iWord);
00602         tcsBlock.setAssignedPartitionsWord64(tmpWord64[iWord], iWord);
00603 
00604         tcsBlock.setPartTrigNrWord64(tmpWord64[iWord], iWord);
00605         tcsBlock.setEventNrWord64(tmpWord64[iWord], iWord);
00606 
00607         tcsBlock.setOrbitNrWord64(tmpWord64[iWord], iWord);
00608 
00609     }
00610 
00611     // put the words in the FED record
00612 
00613     boost::uint64_t* pw =
00614         reinterpret_cast<boost::uint64_t*>(const_cast<unsigned char*>(ptrGt));
00615 
00616     for (int iWord = 0; iWord < nrWord64; ++iWord) {
00617 
00618         *pw++ = tmpWord64[iWord];
00619 
00620         if (m_verbosity && m_isDebugEnabled) {
00621             LogTrace("L1GTEvmDigiToRaw")
00622                     << std::setw(4) << iWord << "  "
00623                     << std::hex << std::setfill('0')
00624                     << std::setw(16) << tmpWord64[iWord]
00625                     << std::dec << std::setfill(' ')
00626                     << std::endl;
00627         }
00628     }
00629 
00630 
00631 }
00632 
00633 // pack the FDL block
00634 void L1GTEvmDigiToRaw::packFDL(
00635     const edm::EventSetup& evSetup,
00636     unsigned char* ptrGt,
00637     L1GtFdlWord& fdlBlock)
00638 {
00639 
00640     if (m_verbosity && m_isDebugEnabled) {
00641         LogDebug("L1GTEvmDigiToRaw") << "\nPacking FDL \n" << std::endl;
00642     }
00643 
00644     int uLength = L1GlobalTriggerReadoutSetup::UnitLength;
00645 
00646     // initialize the required number of word64
00647     int nrWord64 = fdlBlock.getSize()/uLength;
00648     std::vector<boost::uint64_t> tmpWord64;
00649     tmpWord64.resize(nrWord64);
00650 
00651     for (int iWord = 0; iWord < nrWord64; ++iWord) {
00652         tmpWord64[iWord] = 0x0000000000000000ULL;
00653     }
00654 
00655     // fill the values in the words
00656     for (int iWord = 0; iWord < nrWord64; ++iWord) {
00657 
00658         fdlBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
00659         fdlBlock.setBxInEventWord64(tmpWord64[iWord], iWord);
00660         fdlBlock.setBxNrWord64(tmpWord64[iWord], iWord);
00661         fdlBlock.setEventNrWord64(tmpWord64[iWord], iWord);
00662 
00663         fdlBlock.setGtTechnicalTriggerWordWord64(tmpWord64[iWord], iWord);
00664 
00665         fdlBlock.setGtDecisionWordAWord64(tmpWord64[iWord], iWord);
00666         fdlBlock.setGtDecisionWordBWord64(tmpWord64[iWord], iWord);
00667 
00668         fdlBlock.setGtDecisionWordExtendedWord64(tmpWord64[iWord], iWord);
00669 
00670         fdlBlock.setPhysicsDeclaredWord64(tmpWord64[iWord], iWord);
00671         fdlBlock.setGtPrescaleFactorIndexTechWord64(tmpWord64[iWord], iWord);
00672         fdlBlock.setGtPrescaleFactorIndexAlgoWord64(tmpWord64[iWord], iWord);
00673         fdlBlock.setNoAlgoWord64(tmpWord64[iWord], iWord);
00674         fdlBlock.setFinalORWord64(tmpWord64[iWord], iWord);
00675 
00676         fdlBlock.setOrbitNrWord64(tmpWord64[iWord], iWord);
00677         fdlBlock.setLumiSegmentNrWord64(tmpWord64[iWord], iWord);
00678         fdlBlock.setLocalBxNrWord64(tmpWord64[iWord], iWord);
00679 
00680     }
00681 
00682     // put the words in the FED record
00683 
00684     boost::uint64_t* pw =
00685         reinterpret_cast<boost::uint64_t*>(const_cast<unsigned char*>(ptrGt));
00686 
00687     for (int iWord = 0; iWord < nrWord64; ++iWord) {
00688 
00689         *pw++ = tmpWord64[iWord];
00690 
00691         if (m_verbosity && m_isDebugEnabled) {
00692             LogTrace("L1GTEvmDigiToRaw")
00693             << std::setw(4) << iWord << "  "
00694             << std::hex << std::setfill('0')
00695             << std::setw(16) << tmpWord64[iWord]
00696             << std::dec << std::setfill(' ')
00697             << std::endl;
00698         }
00699     }
00700 
00701 }
00702 
00703 
00704 // pack trailer
00705 void L1GTEvmDigiToRaw::packTrailer(unsigned char* ptrGt,
00706                                    unsigned char* ptrGtBegin, int dataSize)
00707 {
00708 
00709     // TODO FIXME where from to get all numbers?
00710 
00711     // The length of the event fragment counted in 64-bit words including header and trailer
00712     int lengthVal = dataSize/8;
00713 
00714     // Cyclic Redundancy Code of the event fragment including header and trailer
00715     int crcVal = evf::compute_crc(ptrGtBegin, dataSize);
00716 
00717     // Event fragment status information
00718     int evtStatusVal = 0;
00719 
00720     // Current value of the Trigger Throttling System bits.
00721     int ttsBitsVal = 0;
00722 
00723     // 0 -> the current trailer word is the last one.
00724     // 1-> other trailer words can follow
00725     // (always 0 for ECAL)
00726     bool moreTrailersVal = false;
00727 
00728     FEDTrailer gtFEDTrailer(ptrGt);
00729     gtFEDTrailer.set(ptrGt,
00730                      lengthVal, crcVal, evtStatusVal, ttsBitsVal,
00731                      moreTrailersVal);
00732 
00733 }
00734 
00735 //
00736 void L1GTEvmDigiToRaw::endJob()
00737 {
00738 
00739     // empty now
00740 }
00741 
00742 
00743 // static class members