CMS 3D CMS Logo

L1GlobalTriggerFDL.cc
Go to the documentation of this file.
1 
16 // this class header
18 
19 // system include files
20 #include <iostream>
21 
22 // user include files
26 
29 
32 
35 
37 
40 
41 
42 // forward declarations
43 
44 
45 // constructor
47  // logical switches
48  m_firstEv(true),
49  m_firstEvLumiSegment(true),
50  m_firstEvRun(true),
51  m_isDebugEnabled(edm::isDebugEnabled())
52 {
53 
54  // create empty FDL word
55  m_gtFdlWord = new L1GtFdlWord();
56 
57 
58  // can not reserve memory here for prescale counters - no access to EventSetup
59 
60 }
61 
62 // destructor
64 {
65 
66  reset();
67  delete m_gtFdlWord;
68 
69 }
70 
71 // Operations
72 
73 // run FDL
76  const std::vector<int>& prescaleFactorsAlgoTrig,
77  const std::vector<int>& prescaleFactorsTechTrig,
78  const std::vector<unsigned int>& triggerMaskAlgoTrig,
79  const std::vector<unsigned int>& triggerMaskTechTrig,
80  const std::vector<unsigned int>& triggerMaskVetoAlgoTrig,
81  const std::vector<unsigned int>& triggerMaskVetoTechTrig,
82  const std::vector<L1GtBoard>& boardMaps,
83  const int totalBxInEvent,
84  const int iBxInEvent,
85  const unsigned int numberPhysTriggers, const unsigned int numberTechnicalTriggers,
86  const unsigned int numberDaqPartitions,
87  const L1GlobalTriggerGTL* ptrGTL,
88  const L1GlobalTriggerPSB* ptrPSB,
89  const int pfAlgoSetIndex,
90  const int pfTechSetIndex,
91  const bool algorithmTriggersUnprescaled,
92  const bool algorithmTriggersUnmasked,
93  const bool technicalTriggersUnprescaled,
94  const bool technicalTriggersUnmasked,
95  const bool technicalTriggersVetoUnmasked
96  )
97 {
98 
99  // FIXME get rid of bitset in GTL in order to use only EventSetup
100  const unsigned int numberPhysTriggersSet =
102 
103  // get gtlDecisionWord from GTL
104  std::bitset<numberPhysTriggersSet> gtlDecisionWord = ptrGTL->getAlgorithmOR();
105 
106  // convert decision word from std::bitset to std::vector<bool>
107  DecisionWord algoDecisionWord(numberPhysTriggers);
108 
109  for (unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
110 
111  bool bitValue = gtlDecisionWord.test( iBit );
112  algoDecisionWord[ iBit ] = bitValue;
113  }
114 
115  // prescale counters are reset at the beginning of the luminosity segment
116 
117  if (m_firstEv) {
118 
119  // prescale counters: numberPhysTriggers counters per bunch cross
120  m_prescaleCounterAlgoTrig.reserve(numberPhysTriggers*totalBxInEvent);
121 
122  for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
123 
124  m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
125  }
126 
127  // prescale counters: numberTechnicalTriggers counters per bunch cross
128  m_prescaleCounterTechTrig.reserve(numberTechnicalTriggers*totalBxInEvent);
129 
130  for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
131 
132  m_prescaleCounterTechTrig.push_back(prescaleFactorsTechTrig);
133  }
134 
135  m_firstEv = false;
136  }
137 
138  // TODO FIXME find the beginning of the luminosity segment
139  if (m_firstEvLumiSegment) {
140 
142  for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
143  m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
144  }
145 
147  for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
148  m_prescaleCounterTechTrig.push_back(prescaleFactorsTechTrig);
149  }
150 
151  m_firstEvLumiSegment = false;
152 
153  }
154 
155 
156  // prescale the algorithm, if necessary
157 
158  // iBxInEvent is ... -2 -1 0 1 2 ... while counters are 0 1 2 3 4 ...
159  int inBxInEvent = totalBxInEvent/2 + iBxInEvent;
160 
161  for (unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
162 
163  if ((!algorithmTriggersUnprescaled) && (prescaleFactorsAlgoTrig.at(iBit) != 1)) {
164 
165  bool bitValue = algoDecisionWord.at( iBit );
166  if (bitValue) {
167 
168  (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit))--;
169  if (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) == 0) {
170 
171  // bit already true in algoDecisionWord, just reset counter
172  m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) =
173  prescaleFactorsAlgoTrig.at(iBit);
174 
175  //LogTrace("L1GlobalTrigger")
176  //<< "\nPrescaled algorithm: " << iBit << ". Reset counter to "
177  //<< prescaleFactorsAlgoTrig.at(iBit) << "\n"
178  //<< std::endl;
179 
180  } else {
181 
182  // change bit to false
183  algoDecisionWord[iBit] = false;;
184 
185  //LogTrace("L1GlobalTrigger")
186  //<< "\nPrescaled algorithm: " << iBit << ". Result set to false"
187  //<< std::endl;
188 
189  }
190  }
191  }
192  }
193 
194  // algo decision word written in the FDL readout before the trigger mask
195  // in order to allow multiple DAQ partitions
196 
197  //
198  // technical triggers
199  //
200 
201  std::vector<bool> techDecisionWord = *(ptrPSB->getGtTechnicalTriggers());
202 
203  // prescale the technical trigger, if necessary
204 
205  for (unsigned int iBit = 0; iBit < numberTechnicalTriggers; ++iBit) {
206 
207  if ((!technicalTriggersUnprescaled) && (prescaleFactorsTechTrig.at(iBit) != 1)) {
208 
209  bool bitValue = techDecisionWord.at( iBit );
210  if (bitValue) {
211 
212  (m_prescaleCounterTechTrig.at(inBxInEvent).at(iBit))--;
213  if (m_prescaleCounterTechTrig.at(inBxInEvent).at(iBit) == 0) {
214 
215  // bit already true in techDecisionWord, just reset counter
216  m_prescaleCounterTechTrig.at(inBxInEvent).at(iBit) =
217  prescaleFactorsTechTrig.at(iBit);
218 
219  //LogTrace("L1GlobalTrigger")
220  //<< "\nPrescaled algorithm: " << iBit << ". Reset counter to "
221  //<< prescaleFactorsTechTrig.at(iBit) << "\n"
222  //<< std::endl;
223 
224  } else {
225 
226  // change bit to false
227  techDecisionWord[iBit] = false;
228 
229  //LogTrace("L1GlobalTrigger")
230  //<< "\nPrescaled technical trigger: " << iBit << ". Result set to false"
231  //<< std::endl;
232 
233  }
234  }
235  }
236  }
237 
238  // technical trigger decision word written in the FDL readout before the trigger mask
239  // in order to allow multiple DAQ partitions
240 
241  //
242  // compute the final decision word per DAQ partition
243  //
244 
245  boost::uint16_t finalOrValue = 0;
246 
247  for (unsigned int iDaq = 0; iDaq < numberDaqPartitions; ++iDaq) {
248 
249  bool daqPartitionFinalOR = false;
250 
251  // starts with technical trigger veto mask to minimize computation
252  // no algorithm trigger veto mask is implemented up to now in hardware,
253  // therefore do not implement it here
254  bool vetoTechTrig = false;
255 
256  // vetoTechTrig can change only when using trigger veto masks
257  if (!technicalTriggersVetoUnmasked) {
258 
259  for (unsigned int iBit = 0; iBit < numberTechnicalTriggers; ++iBit) {
260 
261  int triggerMaskVetoTechTrigBit = triggerMaskVetoTechTrig[iBit]
262  & (1 << iDaq);
263  //LogTrace("L1GlobalTrigger")
264  //<< "\nTechnical trigger bit: " << iBit
265  //<< " mask = " << triggerMaskVetoTechTrigBit
266  //<< " DAQ partition " << iDaq
267  //<< std::endl;
268 
269  if (triggerMaskVetoTechTrigBit && techDecisionWord[iBit]) {
270 
271  daqPartitionFinalOR = false;
272  vetoTechTrig = true;
273 
274  //LogTrace("L1GlobalTrigger")
275  //<< "\nVeto mask technical trigger: " << iBit
276  // << ". FinalOR for DAQ partition " << iDaq << " set to false"
277  //<< std::endl;
278 
279  break;
280  }
281 
282  }
283  }
284 
285  // apply algorithm and technical trigger masks only if no veto from technical trigger
286  if (!vetoTechTrig) {
287 
288  // algorithm trigger mask
289  bool algoFinalOr = false;
290 
291  for (unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
292 
293  bool iBitDecision = false;
294 
295  int triggerMaskAlgoTrigBit = -1;
296 
297  if (algorithmTriggersUnmasked) {
298  triggerMaskAlgoTrigBit = 0;
299  } else {
300  triggerMaskAlgoTrigBit = triggerMaskAlgoTrig[iBit] & (1
301  << iDaq);
302 
303  }
304  //LogTrace("L1GlobalTrigger")
305  //<< "\nAlgorithm trigger bit: " << iBit
306  //<< " mask = " << triggerMaskAlgoTrigBit
307  //<< " DAQ partition " << iDaq
308  //<< std::endl;
309 
310  if (triggerMaskAlgoTrigBit) {
311  iBitDecision = false;
312 
313  //LogTrace("L1GlobalTrigger")
314  //<< "\nMasked algorithm trigger: " << iBit << ". Result set to false"
315  //<< std::endl;
316  } else {
317  iBitDecision = algoDecisionWord[iBit];
318  }
319 
320  algoFinalOr = algoFinalOr || iBitDecision;
321 
322  }
323 
324  // set the technical trigger mask: block the corresponding algorithm if bit value is 1
325 
326  bool techFinalOr = false;
327 
328  for (unsigned int iBit = 0; iBit < numberTechnicalTriggers; ++iBit) {
329 
330  bool iBitDecision = false;
331 
332  int triggerMaskTechTrigBit = -1;
333 
334  if (technicalTriggersUnmasked) {
335  triggerMaskTechTrigBit = 0;
336  } else {
337  triggerMaskTechTrigBit = triggerMaskTechTrig[iBit] & (1
338  << iDaq);
339  }
340  //LogTrace("L1GlobalTrigger")
341  //<< "\nTechnical trigger bit: " << iBit
342  //<< " mask = " << triggerMaskTechTrigBit
343  //<< std::endl;
344 
345  if (triggerMaskTechTrigBit) {
346 
347  iBitDecision = false;
348 
349  //LogTrace("L1GlobalTrigger")
350  //<< "\nMasked technical trigger: " << iBit << ". Result set to false"
351  //<< std::endl;
352  } else {
353  iBitDecision = techDecisionWord[iBit];
354  }
355 
356  techFinalOr = techFinalOr || iBitDecision;
357  }
358 
359  daqPartitionFinalOR = algoFinalOr || techFinalOr;
360 
361  } else {
362 
363  daqPartitionFinalOR = false; // vetoTechTrig
364 
365  }
366 
367  // push it in finalOrValue
368  boost::uint16_t daqPartitionFinalORValue =
369  static_cast<boost::uint16_t>(daqPartitionFinalOR);
370 
371  finalOrValue = finalOrValue | (daqPartitionFinalORValue << iDaq);
372 
373  }
374 
375 
376  // fill everything we know in the L1GtFdlWord
377 
378  typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
379  for (CItBoardMaps
380  itBoard = boardMaps.begin();
381  itBoard != boardMaps.end(); ++itBoard) {
382 
383 
384  if ((itBoard->gtBoardType() == FDL)) {
385 
386  m_gtFdlWord->setBoardId( itBoard->gtBoardId() );
387 
388  // BxInEvent
389  m_gtFdlWord->setBxInEvent(iBxInEvent);
390 
391  // bunch crossing
392 
393  // fill in emulator the same bunch crossing (12 bits - hardwired number of bits...)
394  // and the same local bunch crossing for all boards
395  int bxCross = iEvent.bunchCrossing();
396  boost::uint16_t bxCrossHw = 0;
397  if ((bxCross & 0xFFF) == bxCross) {
398  bxCrossHw = static_cast<boost::uint16_t> (bxCross);
399  }
400  else {
401  bxCrossHw = 0; // Bx number too large, set to 0!
402  if (m_verbosity) {
403  LogDebug("L1GlobalTrigger")
404  << "\nBunch cross number [hex] = "
405  << std::hex << bxCross
406  << "\n larger than 12 bits. Set to 0! \n"
407  << std::dec << std::endl;
408  }
409  }
410 
411  m_gtFdlWord->setBxNr(bxCrossHw);
412 
413  // set event number since last L1 reset generated in FDL
415  static_cast<boost::uint32_t>(iEvent.id().event()) );
416 
417  // technical trigger decision word
418  m_gtFdlWord->setGtTechnicalTriggerWord(techDecisionWord);
419 
420  // algorithm trigger decision word
421  m_gtFdlWord->setGtDecisionWord(algoDecisionWord);
422 
423  // index of prescale factor set - technical triggers and algo
424  m_gtFdlWord->setGtPrescaleFactorIndexTech(static_cast<boost::uint16_t>(pfTechSetIndex));
425  m_gtFdlWord->setGtPrescaleFactorIndexAlgo(static_cast<boost::uint16_t>(pfAlgoSetIndex));
426 
427  // NoAlgo bit FIXME
428 
429  // finalOR
430  m_gtFdlWord->setFinalOR(finalOrValue);
431 
432  // orbit number
433  m_gtFdlWord->setOrbitNr(static_cast<boost::uint32_t>(iEvent.orbitNumber()) );
434 
435  // luminosity segment number
436  m_gtFdlWord->setLumiSegmentNr(static_cast<boost::uint16_t>(iEvent.luminosityBlock()));
437 
438  // local bunch crossing - set identical with absolute BxNr
439  m_gtFdlWord->setLocalBxNr(bxCrossHw);
440 
441 
442  }
443 
444  }
445 
446 }
447 
448 // fill the FDL block in the L1 GT DAQ record for iBxInEvent
449 void L1GlobalTriggerFDL::fillDaqFdlBlock(const int iBxInEvent,
450  const boost::uint16_t& activeBoardsGtDaq, const int recordLength0,
451  const int recordLength1, const unsigned int altNrBxBoardDaq,
452  const std::vector<L1GtBoard>& boardMaps,
453  L1GlobalTriggerReadoutRecord* gtDaqReadoutRecord)
454 {
455 
456  typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
457  for (CItBoardMaps
458  itBoard = boardMaps.begin();
459  itBoard != boardMaps.end(); ++itBoard) {
460 
461  int iPosition = itBoard->gtPositionDaqRecord();
462  if (iPosition > 0) {
463 
464  int iActiveBit = itBoard->gtBitDaqActiveBoards();
465  bool activeBoard = false;
466  bool writeBoard = false;
467 
468  int recLength = -1;
469 
470  if (iActiveBit >= 0) {
471  activeBoard = activeBoardsGtDaq & ( 1 << iActiveBit );
472 
473  int altNrBxBoard = (altNrBxBoardDaq & ( 1 << iActiveBit )) >> iActiveBit;
474 
475  if (altNrBxBoard == 1) {
476  recLength = recordLength1;
477  } else {
478  recLength = recordLength0;
479  }
480 
481  int lowBxInEvent = (recLength + 1)/2 - recLength;
482  int uppBxInEvent = (recLength + 1)/2 - 1;
483 
484  if ((iBxInEvent >= lowBxInEvent) && (iBxInEvent <= uppBxInEvent)) {
485  writeBoard = true;
486  }
487 
488  }
489 
490  if (activeBoard && writeBoard && (itBoard->gtBoardType() == FDL)) {
491 
492  gtDaqReadoutRecord->setGtFdlWord(*m_gtFdlWord);
493 
494 
495  }
496 
497  }
498 
499  }
500 
501 
502 }
503 
504 // fill the FDL block in the L1 GT EVM record for iBxInEvent
505 void L1GlobalTriggerFDL::fillEvmFdlBlock(const int iBxInEvent,
506  const boost::uint16_t& activeBoardsGtEvm, const int recordLength0,
507  const int recordLength1, const unsigned int altNrBxBoardEvm,
508  const std::vector<L1GtBoard>& boardMaps,
509  L1GlobalTriggerEvmReadoutRecord* gtEvmReadoutRecord)
510 {
511 
512  typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
513  for (CItBoardMaps
514  itBoard = boardMaps.begin();
515  itBoard != boardMaps.end(); ++itBoard) {
516 
517  int iPosition = itBoard->gtPositionEvmRecord();
518  if (iPosition > 0) {
519 
520  int iActiveBit = itBoard->gtBitEvmActiveBoards();
521  bool activeBoard = false;
522 
523  if (iActiveBit >= 0) {
524  activeBoard = activeBoardsGtEvm & (1 << iActiveBit);
525  }
526 
527  if (activeBoard && (itBoard->gtBoardType() == FDL)) {
528 
529  gtEvmReadoutRecord->setGtFdlWord(*m_gtFdlWord);
530 
531 
532  }
533 
534  }
535 
536  }
537 
538 }
539 
540 
541 // clear FDL
543 {
544 
545  m_gtFdlWord->reset();
546 
547  // do NOT reset the prescale counters
548 
549 }
#define LogDebug(id)
EventNumber_t event() const
Definition: EventID.h:41
bool isDebugEnabled()
void setBoardId(const cms_uint16_t &boardIdValue)
set BoardId from a BoardId value
Definition: L1GtFdlWord.h:75
void setFinalOR(const cms_uint16_t &finalORValue)
Definition: L1GtFdlWord.h:311
L1GtFdlWord * m_gtFdlWord
int bunchCrossing() const
Definition: EventBase.h:64
void setEventNr(const cms_uint32_t &eventNrValue)
Definition: L1GtFdlWord.h:135
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
void setGtDecisionWord(const DecisionWord &gtDecisionWordValue)
Definition: L1GtFdlWord.h:176
void setLocalBxNr(const cms_uint16_t &localBxNrValue)
Definition: L1GtFdlWord.h:377
void fillEvmFdlBlock(const int iBxInEvent, const boost::uint16_t &activeBoardsGtEvm, const int recordLength0, const int recordLength1, const unsigned int altNrBxBoardEvm, const std::vector< L1GtBoard > &boardMaps, L1GlobalTriggerEvmReadoutRecord *gtEvmReadoutRecord)
fill the FDL block in the L1 GT EVM record for iBxInEvent
void setGtFdlWord(const L1GtFdlWord &, int bxInEventValue)
int iEvent
Definition: GenABIO.cc:230
void setGtTechnicalTriggerWord(const TechnicalTriggerWord &gtTechnicalTriggerWordValue)
Definition: L1GtFdlWord.h:154
const std::vector< bool > * getGtTechnicalTriggers() const
pointer to technical trigger bits
void setLumiSegmentNr(const cms_uint16_t &lumiSegmentNrValue)
Definition: L1GtFdlWord.h:357
std::vector< std::vector< int > > m_prescaleCounterAlgoTrig
prescale counters: NumberPhysTriggers counters per bunch cross in event
std::vector< bool > DecisionWord
typedefs
int m_verbosity
verbosity level
void reset()
reset the content of a L1GtFdlWord
Definition: L1GtFdlWord.cc:732
static const unsigned int NumberPhysTriggers
L1GlobalTriggerFDL()
constructor
int orbitNumber() const
Definition: EventBase.h:65
void setGtPrescaleFactorIndexAlgo(const cms_uint16_t &gtPrescaleFactorIndexAlgoValue)
Definition: L1GtFdlWord.h:272
void setGtPrescaleFactorIndexTech(const cms_uint16_t &gtPrescaleFactorIndexTechValue)
Definition: L1GtFdlWord.h:253
void reset()
clear FDL
void setGtFdlWord(const L1GtFdlWord &, int bxInEvent)
virtual ~L1GlobalTriggerFDL()
destructor
const std::bitset< L1GlobalTriggerReadoutSetup::NumberPhysTriggers > & getAlgorithmOR() const
return algorithm OR decision
edm::EventID id() const
Definition: EventBase.h:58
HLT enums.
void run(edm::Event &iEvent, const std::vector< int > &prescaleFactorsAlgoTrig, const std::vector< int > &prescaleFactorsTechTrig, const std::vector< unsigned int > &triggerMaskAlgoTrig, const std::vector< unsigned int > &triggerMaskTechTrig, const std::vector< unsigned int > &triggerMaskVetoAlgoTrig, const std::vector< unsigned int > &triggerMaskVetoTechTrig, const std::vector< L1GtBoard > &boardMaps, const int totalBxInEvent, const int iBxInEvent, const unsigned int numberPhysTriggers, const unsigned int numberTechnicalTriggers, const unsigned int numberDaqPartitions, const L1GlobalTriggerGTL *ptrGTL, const L1GlobalTriggerPSB *ptrPSB, const int pfAlgoSetIndex, const int pfTechSetIndex, const bool algorithmTriggersUnprescaled, const bool algorithmTriggersUnmasked, const bool technicalTriggersUnprescaled, const bool technicalTriggersUnmasked, const bool technicalTriggersVetoUnmasked)
run the FDL
void setOrbitNr(const cms_uint32_t &orbitNrValue)
Definition: L1GtFdlWord.h:337
void setBxInEvent(const int bxInEventValue)
Definition: L1GtFdlWord.h:95
std::vector< std::vector< int > > m_prescaleCounterTechTrig
prescale counters: technical trigger counters per bunch cross in event
void setBxNr(const cms_uint16_t &bxNrValue)
Definition: L1GtFdlWord.h:115
void fillDaqFdlBlock(const int iBxInEvent, const boost::uint16_t &activeBoardsGtDaq, const int recordLength0, const int recordLength1, const unsigned int altNrBxBoardDaq, const std::vector< L1GtBoard > &boardMaps, L1GlobalTriggerReadoutRecord *gtDaqReadoutRecord)
fill the FDL block in the L1 GT DAQ record for iBxInEvent