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