00001
00018
00019 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerFDL.h"
00020
00021
00022 #include <iostream>
00023
00024
00025 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00026 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00027 #include "DataFormats/L1GlobalTrigger/interface/L1GtFdlWord.h"
00028
00029 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00030 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00031
00032 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerGTL.h"
00033 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerPSB.h"
00034
00035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00036 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00037
00038 #include "FWCore/Framework/interface/Event.h"
00039
00040 #include "CondFormats/L1TObjects/interface/L1GtFwd.h"
00041 #include "CondFormats/L1TObjects/interface/L1GtBoard.h"
00042
00043
00044
00045
00046
00047
00048 L1GlobalTriggerFDL::L1GlobalTriggerFDL()
00049 {
00050
00051
00052 m_gtFdlWord = new L1GtFdlWord();
00053
00054
00055 m_firstEv = true;
00056 m_firstEvLumiSegment = true;
00057 m_firstEvRun = true;
00058
00059
00060
00061 }
00062
00063
00064 L1GlobalTriggerFDL::~L1GlobalTriggerFDL()
00065 {
00066
00067 reset();
00068 delete m_gtFdlWord;
00069
00070 }
00071
00072
00073
00074
00075 void L1GlobalTriggerFDL::run(
00076 edm::Event& iEvent,
00077 const std::vector<int>& prescaleFactorsAlgoTrig,
00078 const std::vector<int>& prescaleFactorsTechTrig,
00079 const std::vector<unsigned int>& triggerMaskAlgoTrig,
00080 const std::vector<unsigned int>& triggerMaskTechTrig,
00081 const std::vector<unsigned int>& triggerMaskVetoAlgoTrig,
00082 const std::vector<unsigned int>& triggerMaskVetoTechTrig,
00083 const std::vector<L1GtBoard>& boardMaps,
00084 const int totalBxInEvent,
00085 const int iBxInEvent,
00086 const unsigned int numberPhysTriggers, const unsigned int numberTechnicalTriggers,
00087 const unsigned int numberDaqPartitions,
00088 const L1GlobalTriggerGTL* ptrGTL,
00089 const L1GlobalTriggerPSB* ptrPSB,
00090 const int pfAlgoSetIndex,
00091 const int pfTechSetIndex)
00092 {
00093
00094
00095 const unsigned int numberPhysTriggersSet =
00096 L1GlobalTriggerReadoutSetup::NumberPhysTriggers;
00097
00098
00099 std::bitset<numberPhysTriggersSet> gtlDecisionWord = ptrGTL->getAlgorithmOR();
00100
00101
00102 DecisionWord algoDecisionWord(numberPhysTriggers);
00103
00104 for (unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
00105
00106 bool bitValue = gtlDecisionWord.test( iBit );
00107 algoDecisionWord[ iBit ] = bitValue;
00108 }
00109
00110
00111
00112 if (m_firstEv) {
00113
00114
00115 m_prescaleCounterAlgoTrig.reserve(numberPhysTriggers*totalBxInEvent);
00116
00117 for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
00118
00119 m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
00120 }
00121
00122
00123 m_prescaleCounterTechTrig.reserve(numberTechnicalTriggers*totalBxInEvent);
00124
00125 for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
00126
00127 m_prescaleCounterTechTrig.push_back(prescaleFactorsTechTrig);
00128 }
00129
00130 m_firstEv = false;
00131 }
00132
00133
00134 if (m_firstEvLumiSegment) {
00135
00136 m_prescaleCounterAlgoTrig.clear();
00137 for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
00138 m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
00139 }
00140
00141 m_prescaleCounterTechTrig.clear();
00142 for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
00143 m_prescaleCounterTechTrig.push_back(prescaleFactorsTechTrig);
00144 }
00145
00146 m_firstEvLumiSegment = false;
00147
00148 }
00149
00150
00151
00152
00153
00154 int inBxInEvent = totalBxInEvent/2 + iBxInEvent;
00155
00156 for (unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
00157
00158 if (prescaleFactorsAlgoTrig.at(iBit) != 1) {
00159
00160 bool bitValue = algoDecisionWord.at( iBit );
00161 if (bitValue) {
00162
00163 (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit))--;
00164 if (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) == 0) {
00165
00166
00167 m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) =
00168 prescaleFactorsAlgoTrig.at(iBit);
00169
00170
00171
00172
00173
00174
00175 } else {
00176
00177
00178 algoDecisionWord[iBit] = false;;
00179
00180
00181
00182
00183
00184 }
00185 }
00186 }
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196 std::vector<bool> techDecisionWord = *(ptrPSB->getGtTechnicalTriggers());
00197
00198
00199
00200 for (unsigned int iBit = 0; iBit < numberTechnicalTriggers; ++iBit) {
00201
00202 if (prescaleFactorsTechTrig.at(iBit) != 1) {
00203
00204 bool bitValue = techDecisionWord.at( iBit );
00205 if (bitValue) {
00206
00207 (m_prescaleCounterTechTrig.at(inBxInEvent).at(iBit))--;
00208 if (m_prescaleCounterTechTrig.at(inBxInEvent).at(iBit) == 0) {
00209
00210
00211 m_prescaleCounterTechTrig.at(inBxInEvent).at(iBit) =
00212 prescaleFactorsTechTrig.at(iBit);
00213
00214
00215
00216
00217
00218
00219 } else {
00220
00221
00222 techDecisionWord[iBit] = false;
00223
00224
00225
00226
00227
00228 }
00229 }
00230 }
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240 boost::uint16_t finalOrValue = 0;
00241
00242 for (unsigned int iDaq = 0; iDaq < numberDaqPartitions; ++iDaq) {
00243
00244 bool daqPartitionFinalOR = false;
00245
00246
00247
00248
00249 bool vetoTechTrig = false;
00250
00251 for (unsigned int iBit = 0; iBit < numberTechnicalTriggers; ++iBit) {
00252
00253 int triggerMaskVetoTechTrigBit =
00254 triggerMaskVetoTechTrig[iBit] & (1 << iDaq);
00255
00256
00257
00258
00259
00260
00261 if (triggerMaskVetoTechTrigBit && techDecisionWord[iBit]) {
00262
00263 daqPartitionFinalOR = false;
00264 vetoTechTrig = true;
00265
00266
00267
00268
00269
00270
00271 break;
00272 }
00273
00274 }
00275
00276
00277 if (!vetoTechTrig) {
00278
00279
00280 bool algoFinalOr = false;
00281
00282 for (unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
00283
00284 bool iBitDecision = false;
00285
00286 int triggerMaskAlgoTrigBit = triggerMaskAlgoTrig[iBit] & (1 << iDaq);
00287
00288
00289
00290
00291
00292
00293 if (triggerMaskAlgoTrigBit) {
00294 iBitDecision = false;
00295
00296
00297
00298
00299 } else {
00300 iBitDecision = algoDecisionWord[iBit];
00301 }
00302
00303 algoFinalOr = algoFinalOr || iBitDecision;
00304
00305 }
00306
00307
00308
00309 bool techFinalOr = false;
00310
00311 for (unsigned int iBit = 0; iBit < numberTechnicalTriggers; ++iBit) {
00312
00313 bool iBitDecision = false;
00314
00315 int triggerMaskTechTrigBit = triggerMaskTechTrig[iBit] & (1 << iDaq);
00316
00317
00318
00319
00320
00321 if (triggerMaskTechTrigBit) {
00322
00323 iBitDecision = false;
00324
00325
00326
00327
00328 } else {
00329 iBitDecision = techDecisionWord[iBit];
00330 }
00331
00332 techFinalOr = techFinalOr || iBitDecision;
00333 }
00334
00335 daqPartitionFinalOR = algoFinalOr || techFinalOr;
00336
00337 } else {
00338
00339 daqPartitionFinalOR = false;
00340
00341 }
00342
00343
00344 boost::uint16_t daqPartitionFinalORValue =
00345 static_cast<boost::uint16_t>(daqPartitionFinalOR);
00346
00347 finalOrValue = finalOrValue | (daqPartitionFinalORValue << iDaq);
00348
00349 }
00350
00351
00352
00353
00354 typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
00355 for (CItBoardMaps
00356 itBoard = boardMaps.begin();
00357 itBoard != boardMaps.end(); ++itBoard) {
00358
00359
00360 if ((itBoard->gtBoardType() == FDL)) {
00361
00362 m_gtFdlWord->setBoardId( itBoard->gtBoardId() );
00363
00364
00365 m_gtFdlWord->setBxInEvent(iBxInEvent);
00366
00367
00368
00369
00370
00371 int bxCross = iEvent.bunchCrossing();
00372 boost::uint16_t bxCrossHw = 0;
00373 if ((bxCross & 0xFFF) == bxCross) {
00374 bxCrossHw = static_cast<boost::uint16_t> (bxCross);
00375 }
00376 else {
00377 bxCrossHw = 0;
00378 LogDebug("L1GlobalTrigger")
00379 << "\nBunch cross number [hex] = "
00380 << std::hex << bxCross
00381 << "\n larger than 12 bits. Set to 0! \n"
00382 << std::dec << std::endl;
00383 }
00384
00385 m_gtFdlWord->setBxNr(bxCrossHw);
00386
00387
00388 m_gtFdlWord->setEventNr(
00389 static_cast<boost::uint32_t>(iEvent.id().event()) );
00390
00391
00392 m_gtFdlWord->setGtTechnicalTriggerWord(techDecisionWord);
00393
00394
00395 m_gtFdlWord->setGtDecisionWord(algoDecisionWord);
00396
00397
00398 m_gtFdlWord->setGtPrescaleFactorIndexTech(static_cast<boost::uint16_t>(pfTechSetIndex));
00399 m_gtFdlWord->setGtPrescaleFactorIndexAlgo(static_cast<boost::uint16_t>(pfAlgoSetIndex));
00400
00401
00402
00403
00404 m_gtFdlWord->setFinalOR(finalOrValue);
00405
00406
00407 m_gtFdlWord->setOrbitNr(static_cast<boost::uint32_t>(iEvent.orbitNumber()) );
00408
00409
00410 m_gtFdlWord->setLumiSegmentNr(static_cast<boost::uint16_t>(iEvent.luminosityBlock()));
00411
00412
00413 m_gtFdlWord->setLocalBxNr(bxCrossHw);
00414
00415
00416 }
00417
00418 }
00419
00420 }
00421
00422
00423 void L1GlobalTriggerFDL::fillDaqFdlBlock(
00424 const boost::uint16_t& activeBoardsGtDaq,
00425 const std::vector<L1GtBoard>& boardMaps,
00426 std::auto_ptr<L1GlobalTriggerReadoutRecord>& gtDaqReadoutRecord)
00427 {
00428
00429 typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
00430 for (CItBoardMaps
00431 itBoard = boardMaps.begin();
00432 itBoard != boardMaps.end(); ++itBoard) {
00433
00434 int iPosition = itBoard->gtPositionDaqRecord();
00435 if (iPosition > 0) {
00436
00437 int iActiveBit = itBoard->gtBitDaqActiveBoards();
00438 bool activeBoard = false;
00439
00440 if (iActiveBit >= 0) {
00441 activeBoard = activeBoardsGtDaq & (1 << iActiveBit);
00442 }
00443
00444 if (activeBoard && (itBoard->gtBoardType() == FDL)) {
00445
00446 gtDaqReadoutRecord->setGtFdlWord(*m_gtFdlWord);
00447
00448
00449 }
00450
00451 }
00452
00453 }
00454
00455
00456 }
00457
00458
00459 void L1GlobalTriggerFDL::fillEvmFdlBlock(
00460 const boost::uint16_t& activeBoardsGtEvm,
00461 const std::vector<L1GtBoard>& boardMaps,
00462 std::auto_ptr<L1GlobalTriggerEvmReadoutRecord>& gtEvmReadoutRecord)
00463 {
00464
00465 typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
00466 for (CItBoardMaps
00467 itBoard = boardMaps.begin();
00468 itBoard != boardMaps.end(); ++itBoard) {
00469
00470 int iPosition = itBoard->gtPositionEvmRecord();
00471 if (iPosition > 0) {
00472
00473 int iActiveBit = itBoard->gtBitEvmActiveBoards();
00474 bool activeBoard = false;
00475
00476 if (iActiveBit >= 0) {
00477 activeBoard = activeBoardsGtEvm & (1 << iActiveBit);
00478 }
00479
00480 if (activeBoard && (itBoard->gtBoardType() == FDL)) {
00481
00482 gtEvmReadoutRecord->setGtFdlWord(*m_gtFdlWord);
00483
00484
00485 }
00486
00487 }
00488
00489 }
00490
00491 }
00492
00493
00494
00495 void L1GlobalTriggerFDL::reset()
00496 {
00497
00498 m_gtFdlWord->reset();
00499
00500
00501
00502 }