CMS 3D CMS Logo

L1GTDigiToRaw.cc
Go to the documentation of this file.
1 
16 // this class header
18 
19 // system include files
20 #include <vector>
21 #include <iostream>
22 #include <iomanip>
23 
24 // user include files
27 
31 
34 
39 
43 
46 
49 
52 
53 // constructor(s)
55  :
56 
57  m_daqGtFedId(pSet.getUntrackedParameter<int>("DaqGtFedId", FEDNumbering::MAXTriggerGTPFEDID)),
58  m_daqGtInputToken(consumes<L1GlobalTriggerReadoutRecord>(pSet.getParameter<edm::InputTag>("DaqGtInputTag"))),
59  m_muGmtInputToken(consumes<L1MuGMTReadoutCollection>(pSet.getParameter<edm::InputTag>("MuGmtInputTag"))),
60  m_daqGtInputTag(pSet.getParameter<edm::InputTag>("DaqGtInputTag")),
61  m_muGmtInputTag(pSet.getParameter<edm::InputTag>("MuGmtInputTag")),
62  m_l1GtBMToken(esConsumes<L1GtBoardMaps, L1GtBoardMapsRcd>()),
63  m_activeBoardsMaskGt(pSet.getParameter<unsigned int>("ActiveBoardsMask")),
64  m_totalBxInEvent(0),
65  m_minBxInEvent(0),
66  m_maxBxInEvent(),
67  m_verbosity(pSet.getUntrackedParameter<int>("Verbosity", 0)),
68  m_isDebugEnabled(edm::isDebugEnabled())
69 
70 {
72  LogDebug("L1GTDigiToRaw") << "\nFED Id for DAQ GT record: " << m_daqGtFedId << " \n"
73  << "\nInput tag for DAQ GT record: " << m_daqGtInputTag << " \n"
74  << "\nInput tag for GMT record: " << m_muGmtInputTag << " \n"
75  << "\nMask for active boards (hex format): " << std::hex
76  << std::setw(sizeof(m_activeBoardsMaskGt) * 2) << std::setfill('0')
77  << m_activeBoardsMaskGt << std::dec << std::setfill(' ') << " \n"
78  << std::endl;
79  }
80 
81  //
82  produces<FEDRawDataCollection>();
83 }
84 
85 // member functions
86 
87 // method called to produce the data
89  // define new FEDRawDataCollection
90  // it contains ALL FEDs in an event
91  std::unique_ptr<FEDRawDataCollection> allFedRawData(new FEDRawDataCollection);
92 
93  FEDRawData& gtRawData = allFedRawData->FEDData(m_daqGtFedId);
94 
95  // get records from EventSetup
96 
97  // board maps
99 
100  const std::vector<L1GtBoard> boardMaps = l1GtBM->gtBoardMaps();
101  int boardMapsSize = boardMaps.size();
102 
103  typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
104 
105  // create an ordered vector for the GT DAQ record
106  // header (pos 0 in record) and trailer (last position in record)
107  // not included, as they are not in board list
108  std::vector<L1GtBoard> gtRecordMap;
109  gtRecordMap.reserve(boardMapsSize);
110 
111  for (int iPos = 0; iPos < boardMapsSize; ++iPos) {
112  for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
113  if (itBoard->gtPositionDaqRecord() == iPos) {
114  gtRecordMap.push_back(*itBoard);
115  break;
116  }
117  }
118  }
119 
120  // get L1GlobalTriggerReadoutRecord
122  iEvent.getByToken(m_daqGtInputToken, gtReadoutRecord);
123 
124  if (!gtReadoutRecord.isValid()) {
125  if (m_verbosity) {
126  edm::LogWarning("L1GTDigiToRaw") << "\nWarning: L1GlobalTriggerReadoutRecord with input tag " << m_daqGtInputTag
127  << "\nrequested in configuration, but not found in the event."
128  << "\nQuit packing this event" << std::endl;
129  }
130 
131  // put the raw data in the event
132  iEvent.put(std::move(allFedRawData));
133 
134  return;
135  }
136 
137  if (m_verbosity && m_isDebugEnabled) {
138  std::ostringstream myCoutStream;
139  gtReadoutRecord->print(myCoutStream);
140  LogTrace("L1GTDigiToRaw") << "\n The following L1 GT DAQ readout record will be packed.\n"
141  << " Some boards could be disabled before packing,"
142  << " see detailed board packing.\n"
143  << myCoutStream.str() << "\n"
144  << std::endl;
145  }
146 
147  // get GTFE block
148  L1GtfeWord gtfeBlock = gtReadoutRecord->gtfeWord();
149 
150  // get the number of Bx in the event for alternative 0 and alternative 1
151  cms_uint16_t recordLength0 = gtfeBlock.recordLength();
152  cms_uint16_t recordLength1 = gtfeBlock.recordLength1();
153 
154  // get list of active boards from the GTFE payload
155  // and mask some boards, if required
156  // boards not active are not written to the record
157 
158  cms_uint16_t activeBoardsGtInitial = gtfeBlock.activeBoards();
159  cms_uint16_t altNrBxBoardInitial = gtfeBlock.altNrBxBoard();
160 
161  // mask some boards, if needed
162 
163  cms_uint16_t activeBoardsGt = activeBoardsGtInitial & m_activeBoardsMaskGt;
164 
165  if (m_verbosity && m_isDebugEnabled) {
166  LogDebug("L1GTDigiToRaw") << "\nActive boards before masking(hex format): " << std::hex
167  << std::setw(sizeof(activeBoardsGtInitial) * 2) << std::setfill('0')
168  << activeBoardsGtInitial << std::dec << std::setfill(' ')
169  << "Active boards after masking(hex format): " << std::hex
170  << std::setw(sizeof(activeBoardsGt) * 2) << std::setfill('0') << activeBoardsGt
171  << std::dec << std::setfill(' ') << " \n"
172  << std::endl;
173  }
174 
175  // get the size of the record
176 
177  unsigned int gtDataSize = 0;
178 
179  unsigned int headerSize = 8;
180  gtDataSize += headerSize;
181 
182  for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
183  if (itBoard->gtBoardType() == GTFE) {
184  gtDataSize += gtfeBlock.getSize();
185  continue;
186  }
187 
188  int iActiveBit = itBoard->gtBitDaqActiveBoards();
189  bool activeBoardToPack = false;
190 
191  int altNrBxBoardVal = -1;
192 
193  if (iActiveBit >= 0) {
194  activeBoardToPack = activeBoardsGt & (1 << iActiveBit);
195 
196  altNrBxBoardVal = (altNrBxBoardInitial & (1 << iActiveBit)) >> iActiveBit;
197 
198  if (altNrBxBoardVal == 1) {
199  m_totalBxInEvent = recordLength1;
200  } else if (altNrBxBoardVal == 0) {
201  m_totalBxInEvent = recordLength0;
202  } else {
203  if (m_verbosity) {
204  edm::LogWarning("L1GTDigiToRaw")
205  << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal << " for board " << std::hex
206  << (itBoard->gtBoardId()) << std::dec << "\n iActiveBit = " << iActiveBit
207  << "\n altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial << std::dec
208  << "\n activeBoardsGt = 0x" << std::hex << activeBoardsGt << std::dec
209  << "\n activeBoardToPack = " << activeBoardToPack << "\n Set altNrBxBoardVal tentatively to "
210  << recordLength0 << "\n Job may crash or produce wrong results!\n\n"
211  << std::endl;
212  }
213 
214  m_totalBxInEvent = recordLength0;
215  }
216 
217  } else {
218  // board not in the ActiveBoards for the record
219  continue;
220  }
221 
222  if (activeBoardToPack) {
223  switch (itBoard->gtBoardType()) {
224  case GTFE: {
225  // size already added;
226  }
227 
228  break;
229  case FDL: {
230  L1GtFdlWord fdlBlock;
231  gtDataSize += m_totalBxInEvent * fdlBlock.getSize();
232  }
233 
234  break;
235  case PSB: {
236  L1GtPsbWord psbBlock;
237  gtDataSize += m_totalBxInEvent * psbBlock.getSize();
238  }
239 
240  break;
241  case GMT: {
242  // 17*64/8 TODO FIXME ask Ivan for a getSize() function for GMT record
243  unsigned int gmtRecordSize = 136;
244  unsigned int gmtCollSize = m_totalBxInEvent * gmtRecordSize;
245  gtDataSize += gmtCollSize;
246  }
247 
248  break;
249  case TCS: {
250  L1TcsWord tcsBlock;
251  gtDataSize += tcsBlock.getSize();
252  }
253 
254  break;
255  case TIM: {
256  // not considered
257  }
258 
259  break;
260  default: {
261  // do nothing, all blocks are given in GtBoardType enum
262  }
263 
264  break;
265  }
266  }
267  }
268 
269  unsigned int trailerSize = 8;
270  gtDataSize += trailerSize;
271 
272  // resize, GT raw data record has variable length,
273  // depending on active boards (read in GTFE)
274  gtRawData.resize(gtDataSize);
275 
276  // ptrGt: pointer to the beginning of GT record in the raw data
277 
278  unsigned char* ptrGt = gtRawData.data();
279  unsigned char* ptrGtBegin = gtRawData.data();
280 
281  if (m_verbosity && m_isDebugEnabled) {
282  LogDebug("L1GTDigiToRaw") << "\n Size of raw data: " << gtRawData.size() << "\n" << std::endl;
283  }
284 
285  // ------- pack boards -------
286 
287  // pack header
288  packHeader(ptrGt, iEvent);
289  ptrGt += headerSize; // advance with header size
290 
291  // loop over other blocks in the raw record, if they are active
292 
293  for (CItBoardMaps itBoard = gtRecordMap.begin(); itBoard != gtRecordMap.end(); ++itBoard) {
294  if (itBoard->gtBoardType() == GTFE) {
295  packGTFE(evSetup, ptrGt, gtfeBlock, activeBoardsGt);
296 
297  if (m_verbosity && m_isDebugEnabled) {
298  std::ostringstream myCoutStream;
299  gtfeBlock.print(myCoutStream);
300  LogTrace("L1GTDigiToRaw") << myCoutStream.str() << "\n" << std::endl;
301  }
302 
303  ptrGt += gtfeBlock.getSize(); // advance with GTFE block size
304 
305  continue;
306  }
307 
308  // pack modules other than GTFE if they are active
309 
310  int iActiveBit = itBoard->gtBitDaqActiveBoards();
311  bool activeBoardToPack = false;
312 
313  int altNrBxBoardVal = -1;
314 
315  if (iActiveBit >= 0) {
316  activeBoardToPack = activeBoardsGt & (1 << iActiveBit);
317 
318  altNrBxBoardVal = (altNrBxBoardInitial & (1 << iActiveBit)) >> iActiveBit;
319 
320  if (altNrBxBoardVal == 1) {
321  m_totalBxInEvent = recordLength1;
322  } else if (altNrBxBoardVal == 0) {
323  m_totalBxInEvent = recordLength0;
324  } else {
325  if (m_verbosity) {
326  edm::LogWarning("L1GTDigiToRaw")
327  << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal << " for board " << std::hex
328  << (itBoard->gtBoardId()) << std::dec << "\n iActiveBit = " << iActiveBit
329  << "\n altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial << std::dec
330  << "\n activeBoardsGt = 0x" << std::hex << activeBoardsGt << std::dec
331  << "\n activeBoardToPack = " << activeBoardToPack << "\n Set altNrBxBoardVal tentatively to "
332  << recordLength0 << "\n Job may crash or produce wrong results!\n\n"
333  << std::endl;
334  }
335 
336  m_totalBxInEvent = recordLength0;
337  }
338 
340  m_maxBxInEvent = (m_totalBxInEvent + 1) / 2 - 1;
341 
342  } else {
343  // board not in the ActiveBoards for the record
344  continue;
345  }
346 
347  if (activeBoardToPack) {
348  if (m_verbosity && m_isDebugEnabled) {
349  LogDebug("L1GTDigiToRaw") << "\nBoard " << std::hex << "0x" << (itBoard->gtBoardId()) << std::dec
350  << "\n Number of bunch crosses in the record: " << m_totalBxInEvent << " = "
351  << "[" << m_minBxInEvent << ", " << m_maxBxInEvent << "] BX\n"
352  << std::endl;
353  }
354 
355  // active board, pack it
356  switch (itBoard->gtBoardType()) {
357  case FDL: {
358  for (int iBxInEvent = m_minBxInEvent; iBxInEvent <= m_maxBxInEvent; ++iBxInEvent) {
359  L1GtFdlWord fdlBlock = gtReadoutRecord->gtFdlWord(iBxInEvent);
360  packFDL(evSetup, ptrGt, fdlBlock);
361 
362  if (m_verbosity && m_isDebugEnabled) {
363  std::ostringstream myCoutStream;
364  fdlBlock.print(myCoutStream);
365  LogTrace("L1GTDigiToRaw") << myCoutStream.str() << "\n" << std::endl;
366  }
367 
368  ptrGt += fdlBlock.getSize(); // advance with FDL block size
369  }
370 
371  } break;
372  case PSB: {
373  if (m_verbosity && m_isDebugEnabled) {
374  LogDebug("L1GTDigiToRaw") << "\nBoard of type " << itBoard->gtBoardName() << " with index "
375  << itBoard->gtBoardIndex() << " and boardId " << std::hex << itBoard->gtBoardId()
376  << std::dec << "\n"
377  << std::endl;
378  }
379 
380  for (int iBxInEvent = m_minBxInEvent; iBxInEvent <= m_maxBxInEvent; ++iBxInEvent) {
381  L1GtPsbWord psbBlock = gtReadoutRecord->gtPsbWord(itBoard->gtBoardId(), iBxInEvent);
382 
383  packPSB(evSetup, ptrGt, psbBlock);
384 
385  if (m_verbosity && m_isDebugEnabled) {
386  std::ostringstream myCoutStream;
387  psbBlock.print(myCoutStream);
388  LogTrace("L1GTDigiToRaw") << myCoutStream.str() << "\n" << std::endl;
389  }
390 
391  ptrGt += psbBlock.getSize(); // advance with PSB block size
392  }
393 
394  } break;
395  case GMT: {
396  // get GMT record TODO separate GMT record or via RefProd from GT record
398  iEvent.getByToken(m_muGmtInputToken, gmtrc_handle);
399  if (!gmtrc_handle.isValid()) {
400  if (m_verbosity) {
401  edm::LogWarning("L1GTDigiToRaw")
402  << "\nWarning: L1MuGMTReadoutCollection with input tag " << m_muGmtInputTag
403  << "\nrequested in configuration, but not found in the event."
404  << "\nQuit packing this event" << std::endl;
405  }
406 
407  std::unique_ptr<FEDRawDataCollection> allFedRawData(new FEDRawDataCollection);
408 
409  // put the raw data in the event
410  iEvent.put(std::move(allFedRawData));
411 
412  return;
413  }
414 
415  L1MuGMTReadoutCollection const* gmtrc = gmtrc_handle.product();
416 
417  // pack the GMT record
418 
419  unsigned int gmtCollSize = 0;
420  gmtCollSize = packGmtCollection(ptrGt, gmtrc);
421  ptrGt += gmtCollSize; // advance with GMT collection size
422 
423  } break;
424  default: {
425  // do nothing, all blocks are given in GtBoardType enum
426  break;
427  }
428  }
429  }
430  }
431 
432  // pack trailer
433  packTrailer(ptrGt, ptrGtBegin, gtDataSize);
434 
435  // put the raw data in the event
436  iEvent.put(std::move(allFedRawData));
437 }
438 
439 // pack header
440 void L1GTDigiToRaw::packHeader(unsigned char* ptrGt, edm::Event& iEvent) {
441  // TODO FIXME where from to get all numbers?
442 
443  // Event Trigger type identifier
444  int triggerTypeVal = 0;
445 
446  // Level-1 event number generated by the TTC system
447  int lvl1IdVal = iEvent.id().event();
448 
449  // The bunch crossing number
450  int bxCross = iEvent.bunchCrossing();
451  cms_uint16_t bxCrossHw = 0;
452  if ((bxCross & 0xFFF) == bxCross) {
453  bxCrossHw = static_cast<cms_uint16_t>(bxCross);
454  } else {
455  bxCrossHw = 0; // Bx number too large, set to 0!
456  if (m_verbosity && m_isDebugEnabled) {
457  LogDebug("L1GTDigiToRaw") << "\nBunch cross number [hex] = " << std::hex << bxCross
458  << "\n larger than 12 bits. Set to 0! \n"
459  << std::dec << std::endl;
460  }
461  }
462  int bxIdVal = bxCrossHw;
463 
464  // Identifier of the FED
465  int sourceIdVal = m_daqGtFedId;
466 
467  // Version identifier of the FED data format
468  int versionVal = 0;
469 
470  // 0 -> the current header word is the last one.
471  // 1-> other header words can follow
472  // (always 1 for ECAL)
473  bool moreHeadersVal = false;
474 
475  FEDHeader gtFEDHeader(ptrGt);
476 
477  gtFEDHeader.set(ptrGt, triggerTypeVal, lvl1IdVal, bxIdVal, sourceIdVal, versionVal, moreHeadersVal);
478 }
479 
480 // pack the GTFE block
482  unsigned char* ptrGt,
483  L1GtfeWord& gtfeBlock,
484  cms_uint16_t activeBoardsGtValue) {
485  if (m_verbosity && m_isDebugEnabled) {
486  LogDebug("L1GTDigiToRaw") << "\nPacking GTFE \n" << std::endl;
487  }
488 
490 
491  // initialize the required number of word64
492  int nrWord64 = gtfeBlock.getSize() / uLength;
493  std::vector<cms_uint64_t> tmpWord64;
494  tmpWord64.resize(nrWord64);
495 
496  for (int iWord = 0; iWord < nrWord64; ++iWord) {
497  tmpWord64[iWord] = 0x0000000000000000ULL;
498  }
499 
500  // fill the values in the words
501  for (int iWord = 0; iWord < nrWord64; ++iWord) {
502  gtfeBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
503  gtfeBlock.setRecordLength1Word64(tmpWord64[iWord], iWord);
504  gtfeBlock.setRecordLengthWord64(tmpWord64[iWord], iWord);
505  gtfeBlock.setBxNrWord64(tmpWord64[iWord], iWord);
506  gtfeBlock.setSetupVersionWord64(tmpWord64[iWord], iWord);
507  gtfeBlock.setActiveBoardsWord64(tmpWord64[iWord], iWord, activeBoardsGtValue);
508  gtfeBlock.setAltNrBxBoardWord64(tmpWord64[iWord], iWord);
509  gtfeBlock.setTotalTriggerNrWord64(tmpWord64[iWord], iWord);
510  }
511 
512  // put the words in the FED record
513 
514  cms_uint64_t* pw = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(ptrGt));
515 
516  for (int iWord = 0; iWord < nrWord64; ++iWord) {
517  *pw++ = tmpWord64[iWord];
518 
519  if (m_verbosity && m_isDebugEnabled) {
520  LogTrace("L1GTDigiToRaw") << std::setw(4) << iWord << " " << std::hex << std::setfill('0') << std::setw(16)
521  << tmpWord64[iWord] << std::dec << std::setfill(' ') << std::endl;
522  }
523  }
524 }
525 
526 // pack the FDL block
527 void L1GTDigiToRaw::packFDL(const edm::EventSetup& evSetup, unsigned char* ptrGt, L1GtFdlWord& fdlBlock) {
528  if (m_verbosity && m_isDebugEnabled) {
529  LogDebug("L1GTDigiToRaw") << "\nPacking FDL \n" << std::endl;
530  }
531 
533 
534  // initialize the required number of word64
535  int nrWord64 = fdlBlock.getSize() / uLength;
536  std::vector<cms_uint64_t> tmpWord64;
537  tmpWord64.resize(nrWord64);
538 
539  for (int iWord = 0; iWord < nrWord64; ++iWord) {
540  tmpWord64[iWord] = 0x0000000000000000ULL;
541  }
542 
543  // fill the values in the words
544  for (int iWord = 0; iWord < nrWord64; ++iWord) {
545  fdlBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
546  fdlBlock.setBxInEventWord64(tmpWord64[iWord], iWord);
547  fdlBlock.setBxNrWord64(tmpWord64[iWord], iWord);
548  fdlBlock.setEventNrWord64(tmpWord64[iWord], iWord);
549 
550  fdlBlock.setGtTechnicalTriggerWordWord64(tmpWord64[iWord], iWord);
551 
552  fdlBlock.setGtDecisionWordAWord64(tmpWord64[iWord], iWord);
553  fdlBlock.setGtDecisionWordBWord64(tmpWord64[iWord], iWord);
554 
555  fdlBlock.setGtDecisionWordExtendedWord64(tmpWord64[iWord], iWord);
556 
557  fdlBlock.setPhysicsDeclaredWord64(tmpWord64[iWord], iWord);
558  fdlBlock.setGtPrescaleFactorIndexTechWord64(tmpWord64[iWord], iWord);
559  fdlBlock.setGtPrescaleFactorIndexAlgoWord64(tmpWord64[iWord], iWord);
560  fdlBlock.setNoAlgoWord64(tmpWord64[iWord], iWord);
561  fdlBlock.setFinalORWord64(tmpWord64[iWord], iWord);
562 
563  fdlBlock.setOrbitNrWord64(tmpWord64[iWord], iWord);
564  fdlBlock.setLumiSegmentNrWord64(tmpWord64[iWord], iWord);
565  fdlBlock.setLocalBxNrWord64(tmpWord64[iWord], iWord);
566  }
567 
568  // put the words in the FED record
569 
570  cms_uint64_t* pw = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(ptrGt));
571 
572  for (int iWord = 0; iWord < nrWord64; ++iWord) {
573  *pw++ = tmpWord64[iWord];
574 
575  if (m_verbosity && m_isDebugEnabled) {
576  LogTrace("L1GTDigiToRaw") << std::setw(4) << iWord << " " << std::hex << std::setfill('0') << std::setw(16)
577  << tmpWord64[iWord] << std::dec << std::setfill(' ') << std::endl;
578  }
579  }
580 }
581 
582 // pack the PSB block
583 void L1GTDigiToRaw::packPSB(const edm::EventSetup& evSetup, unsigned char* ptrGt, L1GtPsbWord& psbBlock) {
584  if (m_verbosity && m_isDebugEnabled) {
585  LogDebug("L1GTDigiToRaw") << "\nPacking PSB \n" << std::endl;
586  }
587 
589 
590  // initialize the required number of word64
591  int nrWord64 = psbBlock.getSize() / uLength;
592  std::vector<cms_uint64_t> tmpWord64;
593  tmpWord64.resize(nrWord64);
594 
595  for (int iWord = 0; iWord < nrWord64; ++iWord) {
596  tmpWord64[iWord] = 0x0000000000000000ULL;
597  }
598 
599  // fill the values in the words
600  for (int iWord = 0; iWord < nrWord64; ++iWord) {
601  psbBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
602  psbBlock.setBxInEventWord64(tmpWord64[iWord], iWord);
603  psbBlock.setBxNrWord64(tmpWord64[iWord], iWord);
604  psbBlock.setEventNrWord64(tmpWord64[iWord], iWord);
605 
606  psbBlock.setADataWord64(tmpWord64[iWord], iWord);
607  psbBlock.setBDataWord64(tmpWord64[iWord], iWord);
608 
609  psbBlock.setLocalBxNrWord64(tmpWord64[iWord], iWord);
610  }
611 
612  // put the words in the FED record
613 
614  cms_uint64_t* pw = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(ptrGt));
615 
616  for (int iWord = 0; iWord < nrWord64; ++iWord) {
617  *pw++ = tmpWord64[iWord];
618 
619  if (m_verbosity && m_isDebugEnabled) {
620  LogTrace("L1GTDigiToRaw") << std::setw(4) << iWord << " " << std::hex << std::setfill('0') << std::setw(16)
621  << tmpWord64[iWord] << std::dec << std::setfill(' ') << std::endl;
622  }
623  }
624 }
625 
626 // pack the GMT collection using packGMT (GMT record packing)
627 unsigned int L1GTDigiToRaw::packGmtCollection(unsigned char* ptrGt, L1MuGMTReadoutCollection const* digis) {
628  if (m_verbosity && m_isDebugEnabled) {
629  LogDebug("L1GTDigiToRaw") << "\nPacking GMT collection \n" << std::endl;
630  }
631 
632  unsigned gmtsize = 0;
633 
634  // loop range: int m_totalBxInEvent is normally even (L1A-1, L1A, L1A+1, with L1A = 0)
635  for (int iBxInEvent = m_minBxInEvent; iBxInEvent <= m_maxBxInEvent; ++iBxInEvent) {
636  L1MuGMTReadoutRecord const& gmtrr = digis->getRecord(iBxInEvent);
637  gmtsize = packGMT(gmtrr, ptrGt);
638  ptrGt += gmtsize;
639  }
640 
641  return m_totalBxInEvent * gmtsize;
642 }
643 
644 // pack a GMT record
645 unsigned L1GTDigiToRaw::packGMT(L1MuGMTReadoutRecord const& gmtrr, unsigned char* chp) {
646  const unsigned SIZE = 136;
647  const unsigned boardId = 0xdd12;
648  memset(chp, 0, SIZE);
649 
650  unsigned* p = (unsigned*)chp;
651 
652  // event number + bcerr
653  *p++ = (gmtrr.getEvNr() & 0xffffff) | ((gmtrr.getBCERR() & 0xff) << 24);
654  // bx number, bx in event, length(?), board-id(?)
655  *p++ = (gmtrr.getBxNr() & 0xfff) | ((gmtrr.getBxInEvent() & 0xf) << 12) | (boardId << 16);
656 
657  std::vector<L1MuRegionalCand> vrc;
658  std::vector<L1MuRegionalCand>::const_iterator irc;
659  unsigned* pp = p;
660 
661  vrc = gmtrr.getDTBXCands();
662  pp = p;
663  for (irc = vrc.begin(); irc != vrc.end(); irc++) {
664  *pp++ = (*irc).getDataWord();
665  }
666  p += 4;
667 
668  vrc = gmtrr.getBrlRPCCands();
669  pp = p;
670  for (irc = vrc.begin(); irc != vrc.end(); irc++) {
671  *pp++ = (*irc).getDataWord();
672  }
673  p += 4;
674 
675  vrc = gmtrr.getCSCCands();
676  pp = p;
677  for (irc = vrc.begin(); irc != vrc.end(); irc++) {
678  *pp++ = (*irc).getDataWord();
679  }
680  p += 4;
681 
682  vrc = gmtrr.getFwdRPCCands();
683  pp = p;
684  for (irc = vrc.begin(); irc != vrc.end(); irc++) {
685  *pp++ = (*irc).getDataWord();
686  }
687  p += 4;
688 
689  // the regional candidates are written to the record with inverted Pt and qual bits
690  pp = p - 16;
691  for (int i = 0; i < 16; i++) {
692  unsigned w = *pp;
693  *pp++ = (w & 0xffff00ff) | ((~w) & 0x0000ff00);
694  }
695 
696  std::vector<L1MuGMTExtendedCand> vgc;
697  std::vector<L1MuGMTExtendedCand>::const_iterator igc;
698 
699  vgc = gmtrr.getGMTBrlCands();
700  pp = p;
701  for (igc = vgc.begin(); igc != vgc.end(); igc++) {
702  *pp++ = (*igc).getDataWord();
703  }
704  p += 4;
705 
706  vgc = gmtrr.getGMTFwdCands();
707  pp = p;
708  for (igc = vgc.begin(); igc != vgc.end(); igc++) {
709  *pp++ = (*igc).getDataWord();
710  }
711  p += 4;
712 
713  vgc = gmtrr.getGMTCands();
714  pp = p;
715  for (igc = vgc.begin(); igc != vgc.end(); igc++) {
716  *pp++ = (*igc).getDataWord();
717  }
718  p += 4;
719 
720  unsigned char* chpp;
721 
722  vgc = gmtrr.getGMTBrlCands();
723  chpp = (unsigned char*)p;
724  for (igc = vgc.begin(); igc != vgc.end(); igc++) {
725  *chpp++ = (*igc).rank();
726  }
727  p++;
728 
729  vgc = gmtrr.getGMTFwdCands();
730  chpp = (unsigned char*)p;
731  for (igc = vgc.begin(); igc != vgc.end(); igc++) {
732  *chpp++ = (*igc).rank();
733  }
734  p++;
735 
736  return SIZE;
737 }
738 
739 unsigned int L1GTDigiToRaw::flipPtQ(unsigned int w) { return ((w & 0xffff00ff) | ((~w) & 0x0000ff00)); }
740 
741 // pack trailer
742 void L1GTDigiToRaw::packTrailer(unsigned char* ptrGt, unsigned char* ptrGtBegin, int dataSize) {
743  // TODO FIXME where from to get all numbers?
744 
745  // The length of the event fragment counted in 64-bit words including header and trailer
746  int lengthVal = dataSize / 8;
747 
748  // Cyclic Redundancy Code of the event fragment including header and trailer
749  int crcVal = evf::compute_crc(ptrGtBegin, dataSize);
750 
751  // Event fragment status information
752  int evtStatusVal = 0;
753 
754  // Current value of the Trigger Throttling System bits.
755  int ttsBitsVal = 0;
756 
757  // 0 -> the current trailer word is the last one.
758  // 1-> other trailer words can follow
759  // (always 0 for ECAL)
760  bool moreTrailersVal = false;
761 
762  FEDTrailer gtFEDTrailer(ptrGt);
763  gtFEDTrailer.set(ptrGt, lengthVal, crcVal, evtStatusVal, ttsBitsVal, moreTrailersVal);
764 }
765 
766 // static class members
bool isDebugEnabled()
const cms_uint16_t altNrBxBoard() const
get/set alternative for number of BX per board
Definition: L1GtfeWord.h:134
virtual void print(std::ostream &myCout) const
pretty print the content of a L1GtfeWord
Definition: L1GtfeWord.cc:253
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void packFDL(const edm::EventSetup &, unsigned char *, L1GtFdlWord &)
pack FDL blocks for various bunch crosses
void setEventNrWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtPsbWord.cc:173
void setRecordLength1Word64(cms_uint64_t &word64, int iWord)
Definition: L1GtfeWord.cc:129
void setNoAlgoWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:514
void setGtDecisionWordBWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:388
const cms_uint16_t recordLength1() const
get/set record length for alternative 1
Definition: L1GtfeWord.h:71
const unsigned int getSize() const
get the size of the PSB block in GT DAQ record (in multiple of 8 bits)
Definition: L1GtPsbWord.h:147
const unsigned int getSize() const
get the size of the GTFE block in GT DAQ record (in multiple of 8 bits)
Definition: L1GtfeWord.h:160
T w() const
const edm::EDGetTokenT< L1MuGMTReadoutCollection > m_muGmtInputToken
input tag for GMT record
Definition: L1GTDigiToRaw.h:93
void print(std::ostream &myCout) const
pretty print the content of a L1GlobalTriggerReadoutRecord
static const int UnitLength
one unit in the word is UnitLength bits
void packHeader(unsigned char *, edm::Event &)
block packers -------——
T const * product() const
Definition: Handle.h:70
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
void setBoardIdWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:179
void setLumiSegmentNrWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:549
const L1GtfeWord gtfeWord() const
get / set GTFE word (record) in the GT readout record
void setActiveBoardsWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtfeWord.cc:191
void setBxNrWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtPsbWord.cc:158
void setSetupVersionWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtfeWord.cc:166
const L1GtFdlWord gtFdlWord(int bxInEventValue) const
get / set FDL word (record) in the GT readout record
void setOrbitNrWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:536
cms_uint16_t m_activeBoardsMaskGt
mask for active boards
void setGtTechnicalTriggerWordWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:259
#define LogTrace(id)
const cms_uint16_t recordLength() const
get/set record length for alternative 0
Definition: L1GtfeWord.h:82
void setBxInEventWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtPsbWord.cc:141
int iEvent
Definition: GenABIO.cc:224
std::vector< L1MuGMTExtendedCand > getGMTBrlCands() const
get GMT barrel candidates vector
void setADataWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtPsbWord.cc:233
void print(std::ostream &myCout) const
pretty print
Definition: L1GtPsbWord.cc:348
void setGtPrescaleFactorIndexTechWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:490
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:31
std::vector< L1MuRegionalCand > getDTBXCands() const
get DT candidates vector
void packPSB(const edm::EventSetup &, unsigned char *, L1GtPsbWord &)
void resize(size_t newsize)
Definition: FEDRawData.cc:28
void setBxInEventWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:194
void setLocalBxNrWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtPsbWord.cc:323
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
void setPhysicsDeclaredWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:477
unsigned int packGMT(L1MuGMTReadoutRecord const &, unsigned char *)
pack a GMT record
const edm::InputTag m_muGmtInputTag
Definition: L1GTDigiToRaw.h:95
void setEventNrWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:218
void packTrailer(unsigned char *, unsigned char *, int)
pack trailer word
unsigned short cms_uint16_t
Definition: typedefs.h:13
int getBxNr() const
get counters
const unsigned int getSize() const
get the size of the TCS block in GT EVM record (in multiple of 8 bits)
Definition: L1TcsWord.h:197
const edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > m_daqGtInputToken
input tag for GT DAQ record
Definition: L1GTDigiToRaw.h:90
void setBxNrWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:207
const std::vector< L1GtBoard > & gtBoardMaps() const
get / set / print the L1 GT board map
Definition: L1GtBoardMaps.h:43
void setBoardIdWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtfeWord.cc:116
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
void setBDataWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtPsbWord.cc:295
std::vector< L1MuGMTExtendedCand > getGMTFwdCands() const
get GMT forward candidates vector
std::vector< L1MuRegionalCand > getBrlRPCCands() const
get barrel RPC candidates vector
std::vector< L1MuRegionalCand > getCSCCands() const
get CSC candidates vector
const edm::InputTag m_daqGtInputTag
Definition: L1GTDigiToRaw.h:94
void setAltNrBxBoardWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtfeWord.cc:212
unsigned int packGmtCollection(unsigned char *ptrGt, L1MuGMTReadoutCollection const *digis)
pack the GMT collection using packGMT (GMT record packing)
const L1GtPsbWord gtPsbWord(cms_uint16_t boardIdValue, int bxInEventValue) const
get / set PSB word (record) in the GT readout record
void packGTFE(const edm::EventSetup &, unsigned char *, L1GtfeWord &, cms_uint16_t activeBoardsGtValue)
unsigned int flipPtQ(unsigned int)
void setGtDecisionWordExtendedWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:446
const unsigned int getSize() const
get the size of the FDL block in GT DAQ record (in multiple of 8 bits)
Definition: L1GtFdlWord.h:271
bool isValid() const
Definition: HandleBase.h:70
void setLocalBxNrWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:560
void setGtDecisionWordAWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:361
const edm::ESGetToken< L1GtBoardMaps, L1GtBoardMapsRcd > m_l1GtBMToken
EventSetup Token for L1GtBoardMaps.
Definition: L1GTDigiToRaw.h:98
HLT enums.
void setBxNrWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtfeWord.cc:153
void produce(edm::Event &, const edm::EventSetup &) override
loop over events
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
L1MuGMTReadoutRecord const & getRecord(int bx=0) const
int m_verbosity
verbosity level
void print(std::ostream &myCout) const
pretty print the content of a L1GtFdlWord
Definition: L1GtFdlWord.cc:595
static void set(unsigned char *header, uint8_t triggerType, uint32_t lvl1ID, uint16_t bxID, uint16_t sourceID, uint8_t version=0, bool moreHeaders=false)
Set all fields in the header.
Definition: FEDHeader.cc:25
void setFinalORWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:525
std::vector< L1MuRegionalCand > getFwdRPCCands() const
get forward RPC candidates vector
unsigned long long cms_uint64_t
Definition: typedefs.h:17
const cms_uint16_t activeBoards() const
get/set boards contributing to EVM respectively DAQ record
Definition: L1GtfeWord.h:119
Log< level::Warning, false > LogWarning
void setTotalTriggerNrWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtfeWord.cc:233
void setGtPrescaleFactorIndexAlgoWord64(cms_uint64_t &word64, const int iWord)
Definition: L1GtFdlWord.cc:503
std::vector< L1MuGMTExtendedCand > getGMTCands() const
get GMT candidates vector
int m_totalBxInEvent
total Bx&#39;s in the event, obtained from GTFE block
L1GTDigiToRaw(const edm::ParameterSet &)
constructor(s)
void setBoardIdWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtPsbWord.cc:123
void setRecordLengthWord64(cms_uint64_t &word64, int iWord)
Definition: L1GtfeWord.cc:142
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)