CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1GlobaTriggerEvmRawToDigi.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <iostream>
20 #include <iomanip>
21 #include <algorithm>
22 
23 // user include files
26 
31 
36 
39 
42 
45 
48 
49 // constructor(s)
51  :
52 
53  // input tag for EVM GT record
54  m_evmGtInputTag(pSet.getParameter<edm::InputTag>("EvmGtInputTag")),
55 
56  // FED Id for GT EVM record
57  // default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc
58  // default value: assume the EVM record is the first GT record
59  m_evmGtFedId(pSet.getUntrackedParameter<int>("EvmGtFedId", FEDNumbering::MINTriggerGTPFEDID)),
60 
62  m_l1GtBMToken(esConsumes<L1GtBoardMaps, L1GtBoardMapsRcd>()),
63 
64  // mask for active boards
65  m_activeBoardsMaskGt(pSet.getParameter<unsigned int>("ActiveBoardsMask")),
66 
67  // number of bunch crossing to be unpacked
68  m_unpackBxInEvent(pSet.getParameter<int>("UnpackBxInEvent")),
69 
70  m_lowSkipBxInEvent(0),
71  m_uppSkipBxInEvent(0),
72 
73  m_recordLength0(0),
74  m_recordLength1(0),
75 
76  m_totalBxInEvent(0),
77 
78  // length of BST record (in bytes)
79  m_bstLengthBytes(pSet.getParameter<int>("BstLengthBytes")),
80 
81  m_verbosity(pSet.getUntrackedParameter<int>("Verbosity", 0)),
82 
83  m_isDebugEnabled(edm::isDebugEnabled())
84 
85 {
86  produces<L1GlobalTriggerEvmReadoutRecord>();
87 
89  LogDebug("L1GlobalTriggerEvmRawToDigi")
90  << "\nInput tag for EVM GT record: " << m_evmGtInputTag
91  << "\nFED Id for EVM GT record: " << m_evmGtFedId
92  << "\nMask for active boards (hex format): " << std::hex << std::setw(sizeof(m_activeBoardsMaskGt) * 2)
93  << std::setfill('0') << m_activeBoardsMaskGt << std::dec << std::setfill(' ')
94  << "\nNumber of bunch crossing to be unpacked: " << m_unpackBxInEvent
95  << "\nLength of BST message [bytes]: " << m_bstLengthBytes << "\n"
96  << std::endl;
97  }
98 
99  if ((m_unpackBxInEvent > 0) && ((m_unpackBxInEvent % 2) == 0)) {
101 
102  if (m_verbosity) {
103  edm::LogInfo("L1GlobalTriggerEvmRawToDigi")
104  << "\nWARNING: Number of bunch crossing to be unpacked rounded to: " << m_unpackBxInEvent
105  << "\n The number must be an odd number!\n"
106  << std::endl;
107  }
108  }
109 
110  // create GTFE, TCS, FDL cards once per analyzer
111  // content will be reset whenever needed
112 
113  m_gtfeWord = new L1GtfeExtWord();
114  m_tcsWord = new L1TcsWord();
115  m_gtFdlWord = new L1GtFdlWord();
116  consumes<FEDRawDataCollection>(m_evmGtInputTag);
117 
119  if (m_bstLengthBytes < 0) {
120  m_l1GtParamToken = esConsumes<L1GtParameters, L1GtParametersRcd>();
121  }
122 }
123 
124 // destructor
126  delete m_gtfeWord;
127  delete m_tcsWord;
128  delete m_gtFdlWord;
129 }
130 
131 // member functions
132 
133 // method called to produce the data
135  // get records from EventSetup
136 
137  // board maps
139 
140  const std::vector<L1GtBoard> boardMaps = l1GtBM->gtBoardMaps();
141  int boardMapsSize = boardMaps.size();
142 
143  typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
144 
145  // create an ordered vector for the GT EVM record
146  // header (pos 0 in record) and trailer (last position in record)
147  // not included, as they are not in board list
148  std::vector<L1GtBoard> gtRecordMap;
149  gtRecordMap.reserve(boardMapsSize);
150 
151  for (int iPos = 0; iPos < boardMapsSize; ++iPos) {
152  for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
153  if (itBoard->gtPositionEvmRecord() == iPos) {
154  gtRecordMap.push_back(*itBoard);
155  break;
156  }
157  }
158  }
159 
160  // raw collection
161 
163  iEvent.getByLabel(m_evmGtInputTag, fedHandle);
164 
165  if (!fedHandle.isValid()) {
166  if (m_verbosity) {
167  edm::LogWarning("L1GlobalTriggerEvmRawToDigi")
168  << "\nWarning: FEDRawDataCollection with input tag " << m_evmGtInputTag
169  << "\nrequested in configuration, but not found in the event."
170  << "\nQuit unpacking this event" << std::endl;
171  }
172 
173  produceEmptyProducts(iEvent);
174 
175  return;
176  }
177 
178  // retrieve data for Global Trigger EVM FED
179  const FEDRawData& raw = (fedHandle.product())->FEDData(m_evmGtFedId);
180 
181  int gtSize = raw.size();
182 
183  // get a const pointer to the beginning of the data buffer
184  const unsigned char* ptrGt = raw.data();
185 
186  // get a const pointer to the end of the data buffer
187  const unsigned char* endPtrGt = ptrGt + gtSize;
188 
189  //
190  if (m_verbosity && m_isDebugEnabled) {
191  LogTrace("L1GlobalTriggerEvmRawToDigi") << "\n Size of raw data: " << gtSize << "\n" << std::endl;
192 
193  std::ostringstream myCoutStream;
194  dumpFedRawData(ptrGt, gtSize, myCoutStream);
195 
196  LogTrace("L1GlobalTriggerEvmRawToDigi") << "\n Dump FEDRawData\n" << myCoutStream.str() << "\n" << std::endl;
197  }
198 
199  // unpack header
200  int headerSize = 8;
201 
202  if ((ptrGt + headerSize) > endPtrGt) {
203  edm::LogError("L1GlobalTriggerEvmRawToDigi") << "\nError: Pointer after header greater than end pointer."
204  << "\n Put empty products in the event!"
205  << "\n Quit unpacking this event." << std::endl;
206 
207  produceEmptyProducts(iEvent);
208 
209  return;
210  }
211 
212  FEDHeader cmsHeader(ptrGt);
213  FEDTrailer cmsTrailer(ptrGt + gtSize - headerSize);
214 
215  unpackHeader(ptrGt, cmsHeader);
216  ptrGt += headerSize; // advance with header size
217 
218  // unpack first GTFE to find the length of the record and the active boards
219  // here GTFE assumed immediately after the header
220 
221  bool gtfeUnpacked = false;
222 
223  // get the length of the BST message from parameter set or from event setup
224 
225  int bstLengthBytes = 0;
226 
227  if (m_bstLengthBytes < 0) {
228  // length from event setup // TODO cache it, if too slow
229 
231  const L1GtParameters* m_l1GtPar = l1GtPar.product();
232 
233  bstLengthBytes = static_cast<int>(m_l1GtPar->gtBstLengthBytes());
234 
235  } else {
236  // length from parameter set
237  bstLengthBytes = m_bstLengthBytes;
238  }
239 
240  if (m_verbosity) {
241  LogTrace("L1GlobalTriggerEvmRawToDigi") << "\n Length of BST message (in bytes): " << bstLengthBytes << "\n"
242  << std::endl;
243  }
244 
245  for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
246  if (itBoard->gtBoardType() == GTFE) {
247  // unpack GTFE
248  if (itBoard->gtPositionEvmRecord() == 1) {
249  // resize to the right size before unapacking
250  m_gtfeWord->resize(bstLengthBytes);
251 
252  m_gtfeWord->unpack(ptrGt);
253  ptrGt += m_gtfeWord->getSize(); // advance with GTFE block size
254  gtfeUnpacked = true;
255 
256  if (m_verbosity && m_isDebugEnabled) {
257  std::ostringstream myCoutStream;
258  m_gtfeWord->print(myCoutStream);
259  LogTrace("L1GlobalTriggerEvmRawToDigi") << myCoutStream.str() << "\n" << std::endl;
260  }
261 
262  // break the loop - GTFE was found
263  break;
264 
265  } else {
266  if (m_verbosity) {
267  edm::LogWarning("L1GlobalTriggerEvmRawToDigi")
268  << "\nWarning: GTFE block found in raw data does not follow header."
269  << "\nAssumed start position of the block is wrong!"
270  << "\nQuit unpacking this event" << std::endl;
271  }
272 
273  produceEmptyProducts(iEvent);
274 
275  return;
276  }
277  }
278  }
279 
280  // quit if no GTFE found
281  if (!gtfeUnpacked) {
282  if (m_verbosity) {
283  edm::LogWarning("L1GlobalTriggerEvmRawToDigi")
284  << "\nWarning: no GTFE block found in raw data."
285  << "\nCan not find the record length (BxInEvent) and the active boards!"
286  << "\nQuit unpacking this event" << std::endl;
287  }
288 
289  produceEmptyProducts(iEvent);
290 
291  return;
292  }
293 
294  // life normal here, GTFE found
295 
296  // get list of active blocks
297  // blocks not active are not written to the record
298  cms_uint16_t activeBoardsGtInitial = m_gtfeWord->activeBoards();
299  cms_uint16_t altNrBxBoardInitial = m_gtfeWord->altNrBxBoard();
300 
301  // mask some boards, if needed
302  cms_uint16_t activeBoardsGt = activeBoardsGtInitial & m_activeBoardsMaskGt;
303  m_gtfeWord->setActiveBoards(activeBoardsGt);
304 
305  if (m_verbosity) {
306  LogDebug("L1GlobalTriggerEvmRawToDigi")
307  << "\nActive boards before masking(hex format): " << std::hex << std::setw(sizeof(activeBoardsGtInitial) * 2)
308  << std::setfill('0') << activeBoardsGtInitial << std::dec << std::setfill(' ')
309  << "\nActive boards after masking(hex format): " << std::hex << std::setw(sizeof(activeBoardsGt) * 2)
310  << std::setfill('0') << activeBoardsGt << std::dec << std::setfill(' ') << " \n"
311  << std::endl;
312  }
313 
314  // loop over other blocks in the raw record, count them if they are active
315 
316  int numberGtfeBoards = 0;
317  int numberFdlBoards = 0;
318  int numberPsbBoards = 0;
319  int numberGmtBoards = 0;
320  int numberTcsBoards = 0;
321  int numberTimBoards = 0;
322 
323  for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
324  int iActiveBit = itBoard->gtBitEvmActiveBoards();
325  bool activeBoardToUnpack = false;
326 
327  if (iActiveBit >= 0) {
328  activeBoardToUnpack = activeBoardsGt & (1 << iActiveBit);
329  } else {
330  // board not in the ActiveBoards for the record
331  continue;
332  }
333 
334  if (activeBoardToUnpack) {
335  switch (itBoard->gtBoardType()) {
336  case GTFE: {
337  numberGtfeBoards++;
338  }
339 
340  break;
341  case FDL: {
342  numberFdlBoards++;
343  }
344 
345  break;
346  case PSB: {
347  numberPsbBoards++;
348  }
349 
350  break;
351  case GMT: {
352  numberGmtBoards++;
353  }
354 
355  break;
356  case TCS: {
357  numberTcsBoards++;
358  }
359 
360  break;
361  case TIM: {
362  numberTimBoards++;
363  }
364 
365  break;
366  default: {
367  // do nothing, all blocks are given in GtBoardType enum
368  if (m_verbosity) {
369  LogDebug("L1GlobalTriggerEvmRawToDigi")
370  << "\nBoard of type " << itBoard->gtBoardType() << " not expected in record.\n"
371  << std::endl;
372  }
373 
374  }
375 
376  break;
377  }
378  }
379  }
380 
381  // produce the L1GlobalTriggerEvmReadoutRecord now, after we found how many
382  // BxInEvent the record has and how many boards are active
383  //LogDebug("L1GlobalTriggerEvmRawToDigi")
384  //<< "\nL1GlobalTriggerEvmRawToDigi: producing L1GlobalTriggerEvmReadoutRecord\n"
385  //<< std::endl;
386 
387  // get number of Bx in the event from GTFE block corresponding to alternative 0 and 1 in
390 
391  int maxBxInEvent = std::max(m_recordLength0, m_recordLength1);
392 
393  std::unique_ptr<L1GlobalTriggerEvmReadoutRecord> gtReadoutRecord(
394  new L1GlobalTriggerEvmReadoutRecord(maxBxInEvent, numberFdlBoards));
395 
396  // ... then unpack modules other than GTFE, if requested
397 
398  for (CItBoardMaps itBoard = gtRecordMap.begin(); itBoard != gtRecordMap.end(); ++itBoard) {
399  int iActiveBit = itBoard->gtBitEvmActiveBoards();
400 
401  bool activeBoardToUnpack = false;
402  bool activeBoardInitial = false;
403 
404  int altNrBxBoardVal = -1;
405 
406  if (iActiveBit >= 0) {
407  activeBoardInitial = activeBoardsGtInitial & (1 << iActiveBit);
408  activeBoardToUnpack = activeBoardsGt & (1 << iActiveBit);
409 
410  altNrBxBoardVal = (altNrBxBoardInitial & (1 << iActiveBit)) >> iActiveBit;
411 
412  if (altNrBxBoardVal == 1) {
414  } else if (altNrBxBoardVal == 0) {
416  } else {
417  if (m_verbosity) {
418  edm::LogWarning("L1GlobalTriggerEvmRawToDigi")
419  << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal << " for board " << std::hex
420  << (itBoard->gtBoardId()) << std::dec << "\n iActiveBit = " << iActiveBit
421  << "\n altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial << std::dec
422  << "\n activeBoardsGt = 0x" << std::hex << activeBoardsGt << std::dec
423  << "\n activeBoardInitial = " << activeBoardInitial
424  << "\n activeBoardToUnpack = " << activeBoardToUnpack << "\n Set altNrBxBoardVal tentatively to "
425  << m_recordLength0 << "\n Job may crash or produce wrong results!\n\n"
426  << std::endl;
427  }
428 
430  }
431 
432  // number of BX required to be unpacked
433 
435  if (m_verbosity) {
436  LogDebug("L1GlobalTriggerEvmRawToDigi")
437  << "\nWARNING: Number of available bunch crosses for board" << (itBoard->gtBoardId())
438  << " in the record ( " << m_totalBxInEvent
439  << " ) \n is smaller than the number of bunch crosses requested to be unpacked (" << m_unpackBxInEvent
440  << " )!!! \n Unpacking only " << m_totalBxInEvent << " bunch crosses.\n"
441  << std::endl;
442  }
443 
444  m_lowSkipBxInEvent = 0;
446 
447  } else if (m_unpackBxInEvent < 0) {
448  m_lowSkipBxInEvent = 0;
450 
451  if (m_verbosity) {
452  LogDebug("L1GlobalTriggerEvmRawToDigi")
453  << "\nUnpacking all " << m_totalBxInEvent << " bunch crosses available."
454  << "\n"
455  << std::endl;
456  }
457 
458  } else if (m_unpackBxInEvent == 0) {
461 
462  if (m_verbosity) {
463  LogDebug("L1GlobalTriggerEvmRawToDigi")
464  << "\nNo bxInEvent required to be unpacked from " << m_totalBxInEvent << " bunch crosses available."
465  << "\n"
466  << std::endl;
467  }
468 
469  // change RecordLength
470  // cast int to cms_uint16_t (there are normally 3 or 5 BxInEvent)
471  m_gtfeWord->setRecordLength(static_cast<cms_uint16_t>(m_unpackBxInEvent));
472  m_gtfeWord->setRecordLength1(static_cast<cms_uint16_t>(m_unpackBxInEvent));
473 
474  } else {
477 
478  if (m_verbosity) {
479  LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nUnpacking " << m_unpackBxInEvent << " bunch crosses from "
480  << m_totalBxInEvent << " bunch crosses available."
481  << "\n"
482  << std::endl;
483  }
484 
485  // change RecordLength
486  // cast int to cms_uint16_t (there are normally 3 or 5 BxInEvent)
487  m_gtfeWord->setRecordLength(static_cast<cms_uint16_t>(m_unpackBxInEvent));
488  m_gtfeWord->setRecordLength1(static_cast<cms_uint16_t>(m_unpackBxInEvent));
489  }
490 
491  } else {
492  // board not in the ActiveBoards for the record
493  continue;
494  }
495 
496  if (!activeBoardInitial) {
497  if (m_verbosity) {
498  LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nBoard of type " << itBoard->gtBoardName() << " with index "
499  << itBoard->gtBoardIndex() << " not active initially in raw data.\n"
500  << std::endl;
501  }
502  continue;
503  }
504 
505  // active board initially, could unpack it
506  switch (itBoard->gtBoardType()) {
507  case TCS: {
508  // if pointer after TCS payload is greater than pointer at
509  // the end of GT payload, produce empty products and quit unpacking
510  if ((ptrGt + m_tcsWord->getSize()) > endPtrGt) {
511  edm::LogError("L1GlobalTriggerEvmRawToDigi") << "\nError: Pointer after TCS "
512  << " greater than end pointer."
513  << "\n Put empty products in the event!"
514  << "\n Quit unpacking this event." << std::endl;
515 
516  produceEmptyProducts(iEvent);
517 
518  return;
519  }
520 
521  // unpack only if requested, otherwise skip it
522  if (activeBoardToUnpack) {
523  m_tcsWord->unpack(ptrGt);
524 
525  // add 1 to the GT luminosity number to use the same convention as
526  // offline, where LS number starts with 1;
527  // in GT hardware, LS starts with 0
530 
531  // add TCS block to GT EVM readout record
532  gtReadoutRecord->setTcsWord(*m_tcsWord);
533 
534  if (m_verbosity && m_isDebugEnabled) {
535  std::ostringstream myCoutStream;
536  m_tcsWord->print(myCoutStream);
537  LogTrace("L1GlobalTriggerEvmRawToDigi") << myCoutStream.str() << "\n" << std::endl;
538  }
539 
540  // ... and reset it
541  m_tcsWord->reset();
542  }
543 
544  ptrGt += m_tcsWord->getSize(); // advance with TCS block size
545 
546  } break;
547  case FDL: {
548  for (int iFdl = 0; iFdl < m_totalBxInEvent; ++iFdl) {
549  // if pointer after FDL payload is greater than pointer at
550  // the end of GT payload, produce empty products and quit unpacking
551  if ((ptrGt + m_gtFdlWord->getSize()) > endPtrGt) {
552  edm::LogError("L1GlobalTriggerEvmRawToDigi")
553  << "\nError: Pointer after FDL " << iFdl << " greater than end pointer."
554  << "\n Put empty products in the event!"
555  << "\n Quit unpacking this event." << std::endl;
556 
557  produceEmptyProducts(iEvent);
558 
559  return;
560  }
561 
562  // unpack only if requested, otherwise skip it
563  if (activeBoardToUnpack) {
564  // unpack only bxInEvent requested, otherwise skip it
565  if ((iFdl >= m_lowSkipBxInEvent) && (iFdl < m_uppSkipBxInEvent)) {
566  m_gtFdlWord->unpack(ptrGt);
567 
568  // add 1 to the GT luminosity number to use the same convention as
569  // offline, where LS number starts with 1;
570  // in GT hardware, LS starts with 0
571  cms_uint16_t lsNr = m_gtFdlWord->lumiSegmentNr() + 1;
573 
574  // add FDL block to GT readout record
575  gtReadoutRecord->setGtFdlWord(*m_gtFdlWord);
576 
577  if (m_verbosity && m_isDebugEnabled) {
578  std::ostringstream myCoutStream;
579  m_gtFdlWord->print(myCoutStream);
580  LogTrace("L1GlobalTriggerEvmRawToDigi") << myCoutStream.str() << "\n" << std::endl;
581  }
582 
583  // ... and reset it
584  m_gtFdlWord->reset();
585  }
586  }
587 
588  ptrGt += m_gtFdlWord->getSize(); // advance with FDL block size
589  }
590  }
591 
592  break;
593  default: {
594  // do nothing, all blocks are given in GtBoardType enum
595  if (m_verbosity) {
596  LogDebug("L1GlobalTriggerEvmRawToDigi")
597  << "\nBoard of type " << itBoard->gtBoardType() << " not expected in record.\n"
598  << std::endl;
599  }
600  } break;
601  }
602  }
603 
604  // add GTFE block to GT readout record, after updating active boards and record length
605 
606  gtReadoutRecord->setGtfeWord(*m_gtfeWord);
607 
608  // ... and reset it
609  m_gtfeWord->reset();
610 
611  // unpack trailer
612 
613  int trailerSize = 8;
614 
615  // if pointer after trailer is greater than pointer at
616  // the end of GT payload, produce empty products and quit unpacking
617  if ((ptrGt + trailerSize) > endPtrGt) {
618  edm::LogError("L1GlobalTriggerEvmRawToDigi") << "\nError: Pointer after trailer "
619  << " greater than end pointer."
620  << "\n Put empty products in the event!"
621  << "\n Quit unpacking this event." << std::endl;
622 
623  produceEmptyProducts(iEvent);
624 
625  return;
626  }
627 
628  unpackTrailer(ptrGt, cmsTrailer);
629 
630  if (m_verbosity && m_isDebugEnabled) {
631  std::ostringstream myCoutStream;
632  gtReadoutRecord->print(myCoutStream);
633  LogTrace("L1GlobalTriggerEvmRawToDigi") << "\n The following L1 GT EVM readout record was unpacked.\n"
634  << myCoutStream.str() << "\n"
635  << std::endl;
636  }
637 
638  // put records into event
639  iEvent.put(std::move(gtReadoutRecord));
640 }
641 
642 // unpack header
643 void L1GlobalTriggerEvmRawToDigi::unpackHeader(const unsigned char* gtPtr, FEDHeader& cmsHeader) {
644  // TODO if needed in another format
645 
646  // print the header info
647  if (edm::isDebugEnabled()) {
648  const cms_uint64_t* payload = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(gtPtr));
649 
650  std::ostringstream myCoutStream;
651 
652  // one word only
653  int iWord = 0;
654 
655  myCoutStream << std::setw(4) << iWord << " " << std::hex << std::setfill('0') << std::setw(16) << payload[iWord]
656  << std::dec << std::setfill(' ') << "\n"
657  << std::endl;
658 
659  myCoutStream << " Event_type: " << std::hex << " hex: "
660  << " " << std::setw(1) << std::setfill('0') << cmsHeader.triggerType() << std::setfill(' ')
661  << std::dec << " dec: " << cmsHeader.triggerType() << std::endl;
662 
663  myCoutStream << " LVL1_Id: " << std::hex << " hex: "
664  << "" << std::setw(6) << std::setfill('0') << cmsHeader.lvl1ID() << std::setfill(' ') << std::dec
665  << " dec: " << cmsHeader.lvl1ID() << std::endl;
666 
667  myCoutStream << " BX_Id: " << std::hex << " hex: "
668  << " " << std::setw(3) << std::setfill('0') << cmsHeader.bxID() << std::setfill(' ') << std::dec
669  << " dec: " << cmsHeader.bxID() << std::endl;
670 
671  myCoutStream << " Source_Id: " << std::hex << " hex: "
672  << " " << std::setw(3) << std::setfill('0') << cmsHeader.sourceID() << std::setfill(' ') << std::dec
673  << " dec: " << cmsHeader.sourceID() << std::endl;
674 
675  myCoutStream << " FOV: " << std::hex << " hex: "
676  << " " << std::setw(1) << std::setfill('0') << cmsHeader.version() << std::setfill(' ') << std::dec
677  << " dec: " << cmsHeader.version() << std::endl;
678 
679  myCoutStream << " H: " << std::hex << " hex: "
680  << " " << std::setw(1) << std::setfill('0') << cmsHeader.moreHeaders() << std::setfill(' ')
681  << std::dec << " dec: " << cmsHeader.moreHeaders() << std::endl;
682 
683  LogDebug("L1GlobalTriggerEvmRawToDigi") << "\n CMS Header \n" << myCoutStream.str() << "\n" << std::endl;
684  }
685 }
686 
687 // unpack trailer word
688 // trPtr pointer to the beginning of trailer obtained from gtPtr
689 void L1GlobalTriggerEvmRawToDigi::unpackTrailer(const unsigned char* trlPtr, FEDTrailer& cmsTrailer) {
690  // TODO if needed in another format
691 
692  // print the trailer info
693  if (m_verbosity && m_isDebugEnabled) {
694  const cms_uint64_t* payload = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(trlPtr));
695 
696  std::ostringstream myCoutStream;
697 
698  // one word only
699  int iWord = 0;
700 
701  myCoutStream << std::setw(4) << iWord << " " << std::hex << std::setfill('0') << std::setw(16) << payload[iWord]
702  << std::dec << std::setfill(' ') << "\n"
703  << std::endl;
704 
705  myCoutStream << " Event_length: " << std::hex << " hex: "
706  << "" << std::setw(6) << std::setfill('0') << cmsTrailer.fragmentLength() << std::setfill(' ')
707  << std::dec << " dec: " << cmsTrailer.fragmentLength() << std::endl;
708 
709  myCoutStream << " CRC: " << std::hex << " hex: "
710  << " " << std::setw(4) << std::setfill('0') << cmsTrailer.crc() << std::setfill(' ') << std::dec
711  << " dec: " << cmsTrailer.crc() << std::endl;
712 
713  myCoutStream << " Event_status: " << std::hex << " hex: "
714  << " " << std::setw(2) << std::setfill('0') << cmsTrailer.evtStatus() << std::setfill(' ')
715  << std::dec << " dec: " << cmsTrailer.evtStatus() << std::endl;
716 
717  myCoutStream << " TTS_bits: " << std::hex << " hex: "
718  << " " << std::setw(1) << std::setfill('0') << cmsTrailer.ttsBits() << std::setfill(' ')
719  << std::dec << " dec: " << cmsTrailer.ttsBits() << std::endl;
720 
721  myCoutStream << " More trailers: " << std::hex << " hex: "
722  << " " << std::setw(1) << std::setfill('0') << cmsTrailer.moreTrailers() << std::setfill(' ')
723  << std::dec << " dec: " << cmsTrailer.moreTrailers() << std::endl;
724 
725  LogDebug("L1GlobalTriggerEvmRawToDigi") << "\n CMS Trailer \n" << myCoutStream.str() << "\n" << std::endl;
726  }
727 }
728 
729 // produce empty products in case of problems
731  std::unique_ptr<L1GlobalTriggerEvmReadoutRecord> gtReadoutRecord(new L1GlobalTriggerEvmReadoutRecord());
732 
733  // put empty records into event
734 
735  iEvent.put(std::move(gtReadoutRecord));
736 }
737 
738 // dump FED raw data
739 void L1GlobalTriggerEvmRawToDigi::dumpFedRawData(const unsigned char* gtPtr, int gtSize, std::ostream& myCout) {
740  LogDebug("L1GlobalTriggerEvmRawToDigi") << "\nDump FED raw data.\n" << std::endl;
741 
744 
745  int gtWords = gtSize / uLength;
746  LogTrace("L1GlobalTriggerEvmRawToDigi") << "\nFED GT words (" << wLength << " bits):" << gtWords << "\n" << std::endl;
747 
748  const cms_uint64_t* payload = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(gtPtr));
749 
750  for (unsigned int i = 0; i < gtSize / sizeof(cms_uint64_t); i++) {
751  myCout << std::setw(4) << i << " " << std::hex << std::setfill('0') << std::setw(16) << payload[i] << std::dec
752  << std::setfill(' ') << std::endl;
753  }
754 }
755 
756 // static class members
int m_bstLengthBytes
length of BST record (in bytes)
bool isDebugEnabled()
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void produce(edm::Event &, const edm::EventSetup &) override
uint8_t triggerType() const
Event Trigger type identifier.
Definition: FEDHeader.cc:13
int m_totalBxInEvent
number of Bx for a board, obtained from GTFE block (record length &amp; alternative)
void produceEmptyProducts(edm::Event &)
produce empty products in case of problems
void reset()
reset the content of a L1TcsWord
Definition: L1TcsWord.cc:259
static const int UnitLength
one unit in the word is UnitLength bits
bool moreHeaders() const
Definition: FEDHeader.cc:23
const unsigned int gtBstLengthBytes() const
get / set length of BST message (in bytes) for L1 GT EVM record
uint16_t sourceID() const
Identifier of the FED.
Definition: FEDHeader.cc:19
void unpack(const unsigned char *fdlPtr)
Definition: L1GtFdlWord.cc:689
uint16_t crc() const
Cyclic Redundancy Code of the event fragment including header and trailer.
Definition: FEDTrailer.cc:15
const cms_uint16_t luminositySegmentNr() const
get/set luminosity segment number
Definition: L1TcsWord.h:121
bool moreTrailers() const
Definition: FEDTrailer.cc:21
uint8_t version() const
Version identifier of the FED data format.
Definition: FEDHeader.cc:21
Log< level::Error, false > LogError
void dumpFedRawData(const unsigned char *, int, std::ostream &)
dump FED raw data
void setRecordLength(cms_uint16_t recordLengthValue)
Definition: L1GtfeWord.h:84
void setLuminositySegmentNr(const cms_uint16_t luminositySegmentNrValue)
Definition: L1TcsWord.h:123
const edm::ESGetToken< L1GtBoardMaps, L1GtBoardMapsRcd > m_l1GtBMToken
EventSetup Token for L1GtBoardMaps.
const unsigned int getSize() const
get the size of the FDL block in GT DAQ record (in multiple of 8 bits)
Definition: L1GtFdlWord.h:271
const cms_uint16_t altNrBxBoard() const
get/set alternative for number of BX per board
Definition: L1GtfeWord.h:134
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
static const int WordLength
GT DAQ record organized in words of WordLength bits.
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:13
#define LogTrace(id)
cms_uint16_t m_activeBoardsMaskGt
mask for active boards
const unsigned int getSize() const
get the size of the GTFE block in GT EVM record (in multiple of 8 bits)
const cms_uint16_t recordLength() const
get/set record length for alternative 0
Definition: L1GtfeWord.h:82
int iEvent
Definition: GenABIO.cc:224
edm::ESGetToken< L1GtParameters, L1GtParametersRcd > m_l1GtParamToken
EventSetup Token for L1GtParameters.
void print(std::ostream &myCout) const
pretty print the content of a L1TcsWord
Definition: L1TcsWord.cc:274
void setLumiSegmentNr(const cms_uint16_t &lumiSegmentNrValue)
Definition: L1GtFdlWord.h:249
def move
Definition: eostools.py:511
void reset()
reset the content of a L1GtFdlWord
Definition: L1GtFdlWord.cc:567
unsigned short cms_uint16_t
Definition: typedefs.h:13
void print(std::ostream &myCout) const override
pretty print the content of a L1GtfeExtWord
void setRecordLength1(cms_uint16_t recordLengthValue)
Definition: L1GtfeWord.h:73
void unpackHeader(const unsigned char *, FEDHeader &)
block unpackers
bool isValid() const
Definition: HandleBase.h:70
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
const cms_uint16_t activeBoards() const
get/set boards contributing to EVM respectively DAQ record
Definition: L1GtfeWord.h:119
int m_recordLength1
corresponding to alternative 1 in altNrBxBoard()
void print(std::ostream &myCout) const
pretty print the content of a L1GtFdlWord
Definition: L1GtFdlWord.cc:595
Log< level::Info, false > LogInfo
void resize(int bstSizeBytes)
resize the BST vector to get the right size of the block
int m_recordLength0
total Bx&#39;s in the event, obtained from GTFE block
const cms_uint16_t lumiSegmentNr() const
get/set luminosity segment number of the actual bx
Definition: L1GtFdlWord.h:247
uint8_t ttsBits() const
Current value of the Trigger Throttling System bits.
Definition: FEDTrailer.cc:19
T const * product() const
Definition: Handle.h:70
L1GlobalTriggerEvmRawToDigi(const edm::ParameterSet &)
constructor(s)
void setActiveBoards(cms_uint16_t activeBoardsValue)
Definition: L1GtfeWord.h:121
T const * product() const
Definition: ESHandle.h:86
uint8_t evtStatus() const
Event fragment status information.
Definition: FEDTrailer.cc:17
const unsigned int getSize() const
get the size of the TCS block in GT EVM record (in multiple of 8 bits)
Definition: L1TcsWord.h:197
uint16_t bxID() const
The bunch crossing number.
Definition: FEDHeader.cc:17
void unpack(const unsigned char *tcsPtr)
Definition: L1TcsWord.cc:339
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
uint32_t lvl1ID() const
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:15
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
unsigned long long cms_uint64_t
Definition: typedefs.h:17
Log< level::Warning, false > LogWarning
const cms_uint16_t recordLength1() const
get/set record length for alternative 1
Definition: L1GtfeWord.h:71
void reset() override
reset the content of a L1GtfeExtWord
void unpackTrailer(const unsigned char *, FEDTrailer &)
unpack trailer word
void unpack(const unsigned char *gtfePtr) override
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
~L1GlobalTriggerEvmRawToDigi() override
destructor
#define LogDebug(id)
edm::InputTag m_evmGtInputTag
input tags for GT EVM record