CMS 3D CMS Logo

L1GlobaTriggerEvmRawToDigi.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "EventFilter/L1GlobalTriggerRawToDigi/interface/L1GlobalTriggerEvmRawToDigi.h"
00019 
00020 // system include files
00021 #include <boost/cstdint.hpp>
00022 #include <iostream>
00023 #include <iomanip>
00024 #include <algorithm>
00025 
00026 // user include files
00027 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00028 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00029 
00030 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00031 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
00032 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00033 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00034 
00035 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeWord.h"
00036 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeExtWord.h"
00037 #include "DataFormats/L1GlobalTrigger/interface/L1TcsWord.h"
00038 #include "DataFormats/L1GlobalTrigger/interface/L1GtFdlWord.h"
00039 
00040 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00041 #include "FWCore/ParameterSet/interface/InputTag.h"
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 #include "CondFormats/L1TObjects/interface/L1GtParameters.h"
00056 #include "CondFormats/DataRecord/interface/L1GtParametersRcd.h"
00057 
00058 // constructor(s)
00059 L1GlobalTriggerEvmRawToDigi::L1GlobalTriggerEvmRawToDigi(const edm::ParameterSet& pSet) :
00060 
00061     // input tag for EVM GT record
00062             m_evmGtInputTag(pSet.getParameter<edm::InputTag> ("EvmGtInputTag")),
00063 
00064             // FED Id for GT EVM record
00065             // default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc
00066             // default value: assume the EVM record is the first GT record
00067             m_evmGtFedId(pSet.getUntrackedParameter<int> (
00068                     "EvmGtFedId", FEDNumbering::getTriggerGTPFEDIds().first)),
00069 
00070             // mask for active boards
00071             m_activeBoardsMaskGt(pSet.getParameter<unsigned int> ("ActiveBoardsMask")),
00072 
00073             // number of bunch crossing to be unpacked
00074             m_unpackBxInEvent(pSet.getParameter<int> ("UnpackBxInEvent")),
00075 
00076             m_lowSkipBxInEvent(0), m_uppSkipBxInEvent(0),
00077 
00078             m_recordLength0(0), m_recordLength1(0),
00079 
00080             m_totalBxInEvent(0),
00081 
00082             // length of BST record (in bytes)
00083             m_bstLengthBytes(pSet.getParameter<int> ("BstLengthBytes")),
00084 
00085             m_verbosity(pSet.getUntrackedParameter<int> ("Verbosity", 0)),
00086 
00087             m_isDebugEnabled(edm::isDebugEnabled())
00088 
00089 {
00090 
00091     produces<L1GlobalTriggerEvmReadoutRecord> ();
00092 
00093     if (m_verbosity && m_isDebugEnabled) {
00094 
00095         LogDebug("L1GlobalTriggerEvmRawToDigi")
00096                 << "\nInput tag for EVM GT record:             " << m_evmGtInputTag
00097                 << "\nFED Id for EVM GT record:                " << m_evmGtFedId
00098                 << "\nMask for active boards (hex format):     " << std::hex
00099                 << std::setw(sizeof(m_activeBoardsMaskGt) * 2) << std::setfill('0')
00100                 << m_activeBoardsMaskGt
00101                 << std::dec << std::setfill(' ')
00102                 << "\nNumber of bunch crossing to be unpacked: " << m_unpackBxInEvent
00103                 << "\nLength of BST message [bytes]:           " << m_bstLengthBytes << "\n"
00104                 << std::endl;
00105     }
00106 
00107     if ( ( m_unpackBxInEvent > 0 ) && ( ( m_unpackBxInEvent % 2 ) == 0 )) {
00108         m_unpackBxInEvent = m_unpackBxInEvent - 1;
00109 
00110         if (m_verbosity) {
00111             edm::LogInfo("L1GlobalTriggerEvmRawToDigi")
00112                     << "\nWARNING: Number of bunch crossing to be unpacked rounded to: "
00113                     << m_unpackBxInEvent << "\n         The number must be an odd number!\n"
00114                     << std::endl;
00115         }
00116     }
00117 
00118     // create GTFE, TCS, FDL cards once per analyzer
00119     // content will be reset whenever needed
00120 
00121     m_gtfeWord = new L1GtfeExtWord();
00122     m_tcsWord = new L1TcsWord();
00123     m_gtFdlWord = new L1GtFdlWord();
00124 
00125 }
00126 
00127 // destructor
00128 L1GlobalTriggerEvmRawToDigi::~L1GlobalTriggerEvmRawToDigi() {
00129 
00130     delete m_gtfeWord;
00131     delete m_tcsWord;
00132     delete m_gtFdlWord;
00133 
00134 }
00135 
00136 // member functions
00137 
00138 void L1GlobalTriggerEvmRawToDigi::beginJob() {
00139 
00140     // empty now
00141 
00142 }
00143 
00144 // method called to produce the data
00145 void L1GlobalTriggerEvmRawToDigi::produce(edm::Event& iEvent, const edm::EventSetup& evSetup) {
00146 
00147     // get records from EventSetup
00148 
00149     //  board maps
00150     edm::ESHandle<L1GtBoardMaps> l1GtBM;
00151     evSetup.get<L1GtBoardMapsRcd> ().get(l1GtBM);
00152 
00153     const std::vector<L1GtBoard> boardMaps = l1GtBM->gtBoardMaps();
00154     int boardMapsSize = boardMaps.size();
00155 
00156     typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
00157 
00158     // create an ordered vector for the GT EVM record
00159     // header (pos 0 in record) and trailer (last position in record)
00160     // not included, as they are not in board list
00161     std::vector<L1GtBoard> gtRecordMap;
00162     gtRecordMap.reserve(boardMapsSize);
00163 
00164     for (int iPos = 0; iPos < boardMapsSize; ++iPos) {
00165         for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
00166 
00167             if (itBoard->gtPositionEvmRecord() == iPos) {
00168                 gtRecordMap.push_back(*itBoard);
00169                 break;
00170             }
00171 
00172         }
00173     }
00174 
00175     // raw collection
00176 
00177     edm::Handle<FEDRawDataCollection> fedHandle;
00178     iEvent.getByLabel(m_evmGtInputTag, fedHandle);
00179 
00180     if (!fedHandle.isValid()) {
00181         if (m_verbosity) {
00182             edm::LogWarning("L1GlobalTriggerEvmRawToDigi")
00183                     << "\nWarning: FEDRawDataCollection with input tag " << m_evmGtInputTag
00184                     << "\nrequested in configuration, but not found in the event."
00185                     << "\nQuit unpacking this event" << std::endl;
00186         }
00187 
00188         std::auto_ptr<L1GlobalTriggerEvmReadoutRecord> gtReadoutRecord(
00189                 new L1GlobalTriggerEvmReadoutRecord());
00190 
00191         // put empty records into event
00192         iEvent.put(gtReadoutRecord);
00193 
00194         return;
00195     }
00196 
00197     // retrieve data for Global Trigger EVM FED
00198     const FEDRawData& raw = ( fedHandle.product() )->FEDData(m_evmGtFedId);
00199 
00200     int gtSize = raw.size();
00201 
00202     // get a const pointer to the beginning of the data buffer
00203     const unsigned char* ptrGt = raw.data();
00204 
00205     //
00206     if (m_verbosity && m_isDebugEnabled) {
00207 
00208         std::ostringstream myCoutStream;
00209         dumpFedRawData(ptrGt, gtSize, myCoutStream);
00210         LogTrace("L1GlobalTriggerEvmRawToDigi") << "\n Size of raw data: " << gtSize << "\n"
00211                 << "\n Dump FEDRawData\n" << myCoutStream.str() << "\n" << std::endl;
00212 
00213     }
00214 
00215     // unpack header
00216     int headerSize = 8;
00217 
00218     FEDHeader cmsHeader(ptrGt);
00219     FEDTrailer cmsTrailer(ptrGt + gtSize - headerSize);
00220 
00221     unpackHeader(ptrGt, cmsHeader);
00222     ptrGt += headerSize; // advance with header size
00223 
00224     // unpack first GTFE to find the length of the record and the active boards
00225     // here GTFE assumed immediately after the header
00226 
00227     bool gtfeUnpacked = false;
00228 
00229     // get the length of the BST message from parameter set or from event setup
00230 
00231     int bstLengthBytes = 0;
00232 
00233     if (m_bstLengthBytes < 0) {
00234         // length from event setup // TODO cache it, if too slow
00235 
00236         edm::ESHandle<L1GtParameters> l1GtPar;
00237         evSetup.get<L1GtParametersRcd> ().get(l1GtPar);
00238         const L1GtParameters* m_l1GtPar = l1GtPar.product();
00239 
00240         bstLengthBytes = static_cast<int> (m_l1GtPar->gtBstLengthBytes());
00241 
00242     } else {
00243         // length from parameter set
00244         bstLengthBytes = m_bstLengthBytes;
00245     }
00246 
00247     if (m_verbosity) {
00248         LogTrace("L1GlobalTriggerEvmRawToDigi") << "\n Length of BST message (in bytes): "
00249                 << bstLengthBytes << "\n" << std::endl;
00250     }
00251 
00252     for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
00253 
00254         if (itBoard->gtBoardType() == GTFE) {
00255 
00256             // unpack GTFE
00257             if (itBoard->gtPositionEvmRecord() == 1) {
00258 
00259                 // resize to the right size before unapacking
00260                 m_gtfeWord->resize(bstLengthBytes);
00261 
00262                 m_gtfeWord->unpack(ptrGt);
00263                 ptrGt += m_gtfeWord->getSize(); // advance with GTFE block size
00264                 gtfeUnpacked = true;
00265 
00266                 if (m_verbosity && m_isDebugEnabled) {
00267 
00268                     std::ostringstream myCoutStream;
00269                     m_gtfeWord->print(myCoutStream);
00270                     LogTrace("L1GlobalTriggerEvmRawToDigi") << myCoutStream.str() << "\n"
00271                             << std::endl;
00272                 }
00273 
00274                 // break the loop - GTFE was found
00275                 break;
00276 
00277             } else {
00278 
00279                 if (m_verbosity) {
00280                     edm::LogWarning("L1GlobalTriggerEvmRawToDigi")
00281                             << "\nWarning: GTFE block found in raw data does not follow header."
00282                             << "\nAssumed start position of the block is wrong!"
00283                             << "\nQuit unpacking this event" << std::endl;
00284                 }
00285 
00286                 std::auto_ptr<L1GlobalTriggerEvmReadoutRecord> gtReadoutRecord(
00287                         new L1GlobalTriggerEvmReadoutRecord());
00288 
00289                 // put empty records into event
00290                 iEvent.put(gtReadoutRecord);
00291 
00292                 return;
00293 
00294             }
00295 
00296         }
00297     }
00298 
00299     // quit if no GTFE found
00300     if (!gtfeUnpacked) {
00301 
00302         if (m_verbosity) {
00303             edm::LogWarning("L1GlobalTriggerEvmRawToDigi")
00304                     << "\nWarning: no GTFE block found in raw data."
00305                     << "\nCan not find the record length (BxInEvent) and the active boards!"
00306                     << "\nQuit unpacking this event" << std::endl;
00307         }
00308 
00309         std::auto_ptr<L1GlobalTriggerEvmReadoutRecord> gtReadoutRecord(
00310                 new L1GlobalTriggerEvmReadoutRecord());
00311 
00312         // put empty records into event
00313         iEvent.put(gtReadoutRecord);
00314 
00315         return;
00316     }
00317 
00318     // life normal here, GTFE found
00319 
00320     // get list of active blocks
00321     // blocks not active are not written to the record
00322     boost::uint16_t activeBoardsGtInitial = m_gtfeWord->activeBoards();
00323     boost::uint16_t altNrBxBoardInitial = m_gtfeWord->altNrBxBoard();
00324 
00325     // mask some boards, if needed
00326     boost::uint16_t activeBoardsGt = activeBoardsGtInitial & m_activeBoardsMaskGt;
00327     m_gtfeWord->setActiveBoards(activeBoardsGt);
00328 
00329     if (m_verbosity) {
00330         LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nActive boards before masking(hex format): "
00331                 << std::hex << std::setw(sizeof ( activeBoardsGtInitial ) * 2) << std::setfill('0')
00332                 << activeBoardsGtInitial << std::dec << std::setfill(' ')
00333                 << "\nActive boards after masking(hex format):  " << std::hex << std::setw(
00334                 sizeof ( activeBoardsGt ) * 2) << std::setfill('0') << activeBoardsGt << std::dec
00335                 << std::setfill(' ') << " \n" << std::endl;
00336     }
00337 
00338     // loop over other blocks in the raw record, count them if they are active
00339 
00340     int numberGtfeBoards = 0;
00341     int numberFdlBoards = 0;
00342     int numberPsbBoards = 0;
00343     int numberGmtBoards = 0;
00344     int numberTcsBoards = 0;
00345     int numberTimBoards = 0;
00346 
00347     for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
00348 
00349         int iActiveBit = itBoard->gtBitEvmActiveBoards();
00350         bool activeBoardToUnpack = false;
00351 
00352         if (iActiveBit >= 0) {
00353             activeBoardToUnpack = activeBoardsGt & ( 1 << iActiveBit );
00354         } else {
00355             // board not in the ActiveBoards for the record
00356             continue;
00357         }
00358 
00359         if (activeBoardToUnpack) {
00360 
00361             switch (itBoard->gtBoardType()) {
00362                 case GTFE: {
00363                     numberGtfeBoards++;
00364                 }
00365 
00366                     break;
00367                 case FDL: {
00368                     numberFdlBoards++;
00369                 }
00370 
00371                     break;
00372                 case PSB: {
00373                     numberPsbBoards++;
00374                 }
00375 
00376                     break;
00377                 case GMT: {
00378                     numberGmtBoards++;
00379                 }
00380 
00381                     break;
00382                 case TCS: {
00383                     numberTcsBoards++;
00384                 }
00385 
00386                     break;
00387                 case TIM: {
00388                     numberTimBoards++;
00389                 }
00390 
00391                     break;
00392                 default: {
00393                     // do nothing, all blocks are given in GtBoardType enum
00394                     if (m_verbosity) {
00395                         LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nBoard of type "
00396                                 << itBoard->gtBoardType() << " not expected  in record.\n"
00397                                 << std::endl;
00398                     }
00399 
00400                 }
00401 
00402                     break;
00403             }
00404         }
00405 
00406     }
00407 
00408     // produce the L1GlobalTriggerEvmReadoutRecord now, after we found how many
00409     // BxInEvent the record has and how many boards are active
00410     //LogDebug("L1GlobalTriggerEvmRawToDigi")
00411     //<< "\nL1GlobalTriggerEvmRawToDigi: producing L1GlobalTriggerEvmReadoutRecord\n"
00412     //<< std::endl;
00413 
00414     // get number of Bx in the event from GTFE block corresponding to alternative 0 and 1 in
00415     m_recordLength0 = m_gtfeWord->recordLength();
00416     m_recordLength1 = m_gtfeWord->recordLength1();
00417 
00418     int maxBxInEvent = std::max(m_recordLength0, m_recordLength1);
00419 
00420     std::auto_ptr<L1GlobalTriggerEvmReadoutRecord> gtReadoutRecord(
00421             new L1GlobalTriggerEvmReadoutRecord(maxBxInEvent, numberFdlBoards));
00422 
00423     // ... then unpack modules other than GTFE, if requested
00424 
00425     for (CItBoardMaps itBoard = gtRecordMap.begin(); itBoard != gtRecordMap.end(); ++itBoard) {
00426 
00427         int iActiveBit = itBoard->gtBitEvmActiveBoards();
00428 
00429         bool activeBoardToUnpack = false;
00430         bool activeBoardInitial = false;
00431 
00432         int altNrBxBoardVal = -1;
00433 
00434         if (iActiveBit >= 0) {
00435             activeBoardInitial = activeBoardsGtInitial & ( 1 << iActiveBit );
00436             activeBoardToUnpack = activeBoardsGt & ( 1 << iActiveBit );
00437 
00438             altNrBxBoardVal = (altNrBxBoardInitial & ( 1 << iActiveBit )) >> iActiveBit;
00439 
00440             if (altNrBxBoardVal == 1) {
00441                 m_totalBxInEvent = m_recordLength1;
00442             } else if (altNrBxBoardVal == 0) {
00443                 m_totalBxInEvent = m_recordLength0;
00444             } else {
00445                 if (m_verbosity) {
00446                     edm::LogWarning("L1GlobalTriggerEvmRawToDigi")
00447                             << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal
00448                             << " for board " << std::hex << ( itBoard->gtBoardId() ) << std::dec
00449                             << "\n  iActiveBit =            " << iActiveBit
00450                             << "\n  altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial <<  std::dec
00451                             << "\n  activeBoardsGt =      0x" << std::hex << activeBoardsGt <<  std::dec
00452                             << "\n  activeBoardInitial =    " << activeBoardInitial
00453                             << "\n  activeBoardToUnpack =   " << activeBoardToUnpack
00454                             << "\n Set altNrBxBoardVal tentatively to "
00455                             << m_recordLength0 << "\n Job may crash or produce wrong results!\n\n"
00456                             << std::endl;
00457                 }
00458 
00459                 m_totalBxInEvent = m_recordLength0;
00460             }
00461 
00462             // number of BX required to be unpacked
00463 
00464             if (m_unpackBxInEvent > m_totalBxInEvent) {
00465                 if (m_verbosity) {
00466                     LogDebug("L1GlobalTriggerEvmRawToDigi")
00467                             << "\nWARNING: Number of available bunch crosses for board"
00468                             << ( itBoard->gtBoardId() ) << " in the record ( " << m_totalBxInEvent
00469                             << " ) \n is smaller than the number of bunch crosses requested to be unpacked ("
00470                             << m_unpackBxInEvent << " )!!! \n         Unpacking only "
00471                             << m_totalBxInEvent << " bunch crosses.\n" << std::endl;
00472                 }
00473 
00474                 m_lowSkipBxInEvent = 0;
00475                 m_uppSkipBxInEvent = m_totalBxInEvent;
00476 
00477             } else if (m_unpackBxInEvent < 0) {
00478 
00479                 m_lowSkipBxInEvent = 0;
00480                 m_uppSkipBxInEvent = m_totalBxInEvent;
00481 
00482                 if (m_verbosity) {
00483                     LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nUnpacking all " << m_totalBxInEvent
00484                             << " bunch crosses available." << "\n" << std::endl;
00485                 }
00486 
00487             } else if (m_unpackBxInEvent == 0) {
00488 
00489                 m_lowSkipBxInEvent = m_totalBxInEvent;
00490                 m_uppSkipBxInEvent = m_totalBxInEvent;
00491 
00492                 if (m_verbosity) {
00493                     LogDebug("L1GlobalTriggerEvmRawToDigi")
00494                             << "\nNo bxInEvent required to be unpacked from " << m_totalBxInEvent
00495                             << " bunch crosses available." << "\n" << std::endl;
00496                 }
00497 
00498                 // change RecordLength
00499                 // cast int to boost::uint16_t (there are normally 3 or 5 BxInEvent)
00500                 m_gtfeWord->setRecordLength(static_cast<boost::uint16_t> (m_unpackBxInEvent));
00501                 m_gtfeWord->setRecordLength1(static_cast<boost::uint16_t> (m_unpackBxInEvent));
00502 
00503             } else {
00504 
00505                 m_lowSkipBxInEvent = ( m_totalBxInEvent - m_unpackBxInEvent ) / 2;
00506                 m_uppSkipBxInEvent = m_totalBxInEvent - m_lowSkipBxInEvent;
00507 
00508                 if (m_verbosity) {
00509                     LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nUnpacking " << m_unpackBxInEvent
00510                             << " bunch crosses from " << m_totalBxInEvent
00511                             << " bunch crosses available." << "\n" << std::endl;
00512                 }
00513 
00514                 // change RecordLength
00515                 // cast int to boost::uint16_t (there are normally 3 or 5 BxInEvent)
00516                 m_gtfeWord->setRecordLength(static_cast<boost::uint16_t> (m_unpackBxInEvent));
00517                 m_gtfeWord->setRecordLength1(static_cast<boost::uint16_t> (m_unpackBxInEvent));
00518 
00519             }
00520 
00521         } else {
00522             // board not in the ActiveBoards for the record
00523             continue;
00524         }
00525 
00526         if (!activeBoardInitial) {
00527             if (m_verbosity) {
00528                 LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nBoard of type "
00529                         << itBoard->gtBoardName() << " with index " << itBoard->gtBoardIndex()
00530                         << " not active initially in raw data.\n" << std::endl;
00531             }
00532             continue;
00533         }
00534 
00535         // active board initially, could unpack it
00536         switch (itBoard->gtBoardType()) {
00537 
00538             case TCS: {
00539                 // unpack only if requested, otherwise skip it
00540                 if (activeBoardToUnpack) {
00541 
00542                     m_tcsWord->unpack(ptrGt);
00543 
00544                     // add TCS block to GT EVM readout record
00545                     gtReadoutRecord->setTcsWord(*m_tcsWord);
00546 
00547                     if (m_verbosity && m_isDebugEnabled) {
00548 
00549                         std::ostringstream myCoutStream;
00550                         m_tcsWord->print(myCoutStream);
00551                         LogTrace("L1GlobalTriggerEvmRawToDigi") << myCoutStream.str() << "\n"
00552                                 << std::endl;
00553                     }
00554 
00555                     // ... and reset it
00556                     m_tcsWord->reset();
00557                 }
00558 
00559                 ptrGt += m_tcsWord->getSize(); // advance with TCS block size
00560 
00561             }
00562                 break;
00563             case FDL: {
00564                 for (int iFdl = 0; iFdl < m_totalBxInEvent; ++iFdl) {
00565 
00566                     // unpack only if requested, otherwise skip it
00567                     if (activeBoardToUnpack) {
00568 
00569                         // unpack only bxInEvent requested, otherwise skip it
00570                         if ( ( iFdl >= m_lowSkipBxInEvent ) && ( iFdl < m_uppSkipBxInEvent )) {
00571 
00572                             m_gtFdlWord->unpack(ptrGt);
00573 
00574                             // add FDL block to GT readout record
00575                             gtReadoutRecord->setGtFdlWord(*m_gtFdlWord);
00576 
00577                             if (m_verbosity && m_isDebugEnabled) {
00578 
00579                                 std::ostringstream myCoutStream;
00580                                 m_gtFdlWord->print(myCoutStream);
00581                                 LogTrace("L1GlobalTriggerEvmRawToDigi") << myCoutStream.str()
00582                                         << "\n" << std::endl;
00583                             }
00584 
00585                             // ... and reset it
00586                             m_gtFdlWord->reset();
00587                         }
00588 
00589                     }
00590 
00591                     ptrGt += m_gtFdlWord->getSize(); // advance with FDL block size
00592 
00593                 }
00594             }
00595 
00596                 break;
00597             default: {
00598                 // do nothing, all blocks are given in GtBoardType enum
00599                 if (m_verbosity) {
00600                     LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nBoard of type "
00601                             << itBoard->gtBoardType() << " not expected  in record.\n" << std::endl;
00602                 }
00603             }
00604                 break;
00605 
00606         }
00607 
00608     }
00609 
00610     // add GTFE block to GT readout record, after updating active boards and record length
00611 
00612     gtReadoutRecord->setGtfeWord(*m_gtfeWord);
00613 
00614     // ... and reset it
00615     m_gtfeWord->reset();
00616 
00617     // unpack trailer
00618     unpackTrailer(ptrGt, cmsTrailer);
00619 
00620     if (m_verbosity && m_isDebugEnabled) {
00621         std::ostringstream myCoutStream;
00622         gtReadoutRecord->print(myCoutStream);
00623         LogTrace("L1GlobalTriggerEvmRawToDigi")
00624                 << "\n The following L1 GT EVM readout record was unpacked.\n"
00625                 << myCoutStream.str() << "\n" << std::endl;
00626     }
00627 
00628     // put records into event
00629     iEvent.put(gtReadoutRecord);
00630 
00631 }
00632 
00633 // unpack header
00634 void L1GlobalTriggerEvmRawToDigi::unpackHeader(const unsigned char* gtPtr, FEDHeader& cmsHeader) {
00635 
00636     // TODO  if needed in another format
00637 
00638     // print the header info
00639     if (edm::isDebugEnabled()) {
00640 
00641         const boost::uint64_t* payload =
00642                 reinterpret_cast<boost::uint64_t*> (const_cast<unsigned char*> (gtPtr));
00643 
00644         std::ostringstream myCoutStream;
00645 
00646         // one word only
00647         int iWord = 0;
00648 
00649         myCoutStream << std::setw(4) << iWord << "  " << std::hex << std::setfill('0')
00650                 << std::setw(16) << payload[iWord] << std::dec << std::setfill(' ') << "\n"
00651                 << std::endl;
00652 
00653         myCoutStream << "  Event_type:  " << std::hex << " hex: " << "     " << std::setw(1)
00654                 << std::setfill('0') << cmsHeader.triggerType() << std::setfill(' ') << std::dec
00655                 << " dec: " << cmsHeader.triggerType() << std::endl;
00656 
00657         myCoutStream << "  LVL1_Id:     " << std::hex << " hex: " << "" << std::setw(6)
00658                 << std::setfill('0') << cmsHeader.lvl1ID() << std::setfill(' ') << std::dec
00659                 << " dec: " << cmsHeader.lvl1ID() << std::endl;
00660 
00661         myCoutStream << "  BX_Id:       " << std::hex << " hex: " << "   " << std::setw(3)
00662                 << std::setfill('0') << cmsHeader.bxID() << std::setfill(' ') << std::dec
00663                 << " dec: " << cmsHeader.bxID() << std::endl;
00664 
00665         myCoutStream << "  Source_Id:   " << std::hex << " hex: " << "   " << std::setw(3)
00666                 << std::setfill('0') << cmsHeader.sourceID() << std::setfill(' ') << std::dec
00667                 << " dec: " << cmsHeader.sourceID() << std::endl;
00668 
00669         myCoutStream << "  FOV:         " << std::hex << " hex: " << "     " << std::setw(1)
00670                 << std::setfill('0') << cmsHeader.version() << std::setfill(' ') << std::dec
00671                 << " dec: " << cmsHeader.version() << std::endl;
00672 
00673         myCoutStream << "  H:           " << std::hex << " hex: " << "     " << std::setw(1)
00674                 << std::setfill('0') << cmsHeader.moreHeaders() << std::setfill(' ') << std::dec
00675                 << " dec: " << cmsHeader.moreHeaders() << std::endl;
00676 
00677         LogDebug("L1GlobalTriggerEvmRawToDigi") << "\n CMS Header \n" << myCoutStream.str() << "\n"
00678                 << std::endl;
00679 
00680     }
00681 
00682 }
00683 
00684 // unpack trailer word
00685 // trPtr pointer to the beginning of trailer obtained from gtPtr
00686 void L1GlobalTriggerEvmRawToDigi::unpackTrailer(const unsigned char* trlPtr, FEDTrailer& cmsTrailer) {
00687 
00688     // TODO  if needed in another format
00689 
00690     // print the trailer info
00691     if (m_verbosity && m_isDebugEnabled) {
00692 
00693         const boost::uint64_t* payload =
00694                 reinterpret_cast<boost::uint64_t*> (const_cast<unsigned char*> (trlPtr));
00695 
00696         std::ostringstream myCoutStream;
00697 
00698         // one word only
00699         int iWord = 0;
00700 
00701         myCoutStream << std::setw(4) << iWord << "  " << std::hex << std::setfill('0')
00702                 << std::setw(16) << payload[iWord] << std::dec << std::setfill(' ') << "\n"
00703                 << std::endl;
00704 
00705         myCoutStream << "  Event_length:  " << std::hex << " hex: " << "" << std::setw(6)
00706                 << std::setfill('0') << cmsTrailer.lenght() << std::setfill(' ') << std::dec
00707                 << " dec: " << cmsTrailer.lenght() << std::endl;
00708 
00709         myCoutStream << "  CRC:           " << std::hex << " hex: " << "  " << std::setw(4)
00710                 << std::setfill('0') << cmsTrailer.crc() << std::setfill(' ') << std::dec
00711                 << " dec: " << cmsTrailer.crc() << std::endl;
00712 
00713         myCoutStream << "  Event_status:  " << std::hex << " hex: " << "    " << std::setw(2)
00714                 << std::setfill('0') << cmsTrailer.evtStatus() << std::setfill(' ') << std::dec
00715                 << " dec: " << cmsTrailer.evtStatus() << std::endl;
00716 
00717         myCoutStream << "  TTS_bits:      " << std::hex << " hex: " << "     " << std::setw(1)
00718                 << std::setfill('0') << cmsTrailer.ttsBits() << std::setfill(' ') << std::dec
00719                 << " dec: " << cmsTrailer.ttsBits() << std::endl;
00720 
00721         myCoutStream << "  More trailers: " << std::hex << " hex: " << "     " << std::setw(1)
00722                 << std::setfill('0') << cmsTrailer.moreTrailers() << std::setfill(' ') << std::dec
00723                 << " dec: " << cmsTrailer.moreTrailers() << std::endl;
00724 
00725         LogDebug("L1GlobalTriggerEvmRawToDigi") << "\n CMS Trailer \n" << myCoutStream.str()
00726                 << "\n" << std::endl;
00727 
00728     }
00729 
00730 }
00731 
00732 // dump FED raw data
00733 void L1GlobalTriggerEvmRawToDigi::dumpFedRawData(
00734         const unsigned char* gtPtr, int gtSize, std::ostream& myCout) {
00735 
00736     LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nDump FED raw data.\n" << std::endl;
00737 
00738     int wLength = L1GlobalTriggerReadoutSetup::WordLength;
00739     int uLength = L1GlobalTriggerReadoutSetup::UnitLength;
00740 
00741     int gtWords = gtSize / uLength;
00742     LogTrace("L1GlobalTriggerEvmRawToDigi") << "\nFED GT words (" << wLength << " bits):"
00743             << gtWords << "\n" << std::endl;
00744 
00745     const boost::uint64_t* payload =
00746             reinterpret_cast<boost::uint64_t*> (const_cast<unsigned char*> (gtPtr));
00747 
00748     for (unsigned int i = 0; i < gtSize / sizeof(boost::uint64_t); i++) {
00749         myCout << std::setw(4) << i << "  " << std::hex << std::setfill('0') << std::setw(16)
00750                 << payload[i] << std::dec << std::setfill(' ') << std::endl;
00751     }
00752 
00753 }
00754 
00755 //
00756 void L1GlobalTriggerEvmRawToDigi::endJob() {
00757 
00758     // empty now
00759 }
00760 
00761 // static class members
00762 

Generated on Tue Jun 9 17:34:42 2009 for CMSSW by  doxygen 1.5.4