CMS 3D CMS Logo

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