CMS 3D CMS Logo

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