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