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