CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GlobaTriggerRawToDigi.cc
Go to the documentation of this file.
1 
18 // this class header
20 
21 // system include files
22 #include <iostream>
23 #include <iomanip>
24 #include <algorithm>
25 
26 // user include files
29 
34 
38 
42 
45 
48 
51 
56 
59 
62 
63 // constructor(s)
65 
66  // input tag for DAQ GT record
67  m_daqGtInputTag(pSet.getParameter<edm::InputTag> ("DaqGtInputTag")),
68 
69  // FED Id for GT DAQ record
70  // default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc
71  // default value: assume the DAQ record is the last GT record
72  m_daqGtFedId(pSet.getUntrackedParameter<int> (
73  "DaqGtFedId", FEDNumbering::MAXTriggerGTPFEDID)),
74 
75  // mask for active boards
76  m_activeBoardsMaskGt(pSet.getParameter<unsigned int> ("ActiveBoardsMask")),
77 
78  // number of bunch crossing to be unpacked
79  m_unpackBxInEvent(pSet.getParameter<int> ("UnpackBxInEvent")),
80 
81  // create GTFE, FDL, PSB cards once per producer
82  // content will be reset whenever needed
83 
84  m_lowSkipBxInEvent(0), m_uppSkipBxInEvent(0),
85 
86  m_recordLength0(0), m_recordLength1(0),
87 
88  m_totalBxInEvent(0), m_verbosity(pSet.getUntrackedParameter<int> ("Verbosity", 0)),
89 
90  m_isDebugEnabled(edm::isDebugEnabled())
91 
92 {
93 
94  produces<L1GlobalTriggerReadoutRecord> ();
95  produces<L1MuGMTReadoutCollection> ();
96 
97  produces<std::vector<L1MuRegionalCand> > ("DT");
98  produces<std::vector<L1MuRegionalCand> > ("CSC");
99  produces<std::vector<L1MuRegionalCand> > ("RPCb");
100  produces<std::vector<L1MuRegionalCand> > ("RPCf");
101  produces<std::vector<L1MuGMTCand> > ();
102 
103  // create GTFE, FDL, PSB cards once per producer
104  // content will be reset whenever needed
105  m_gtfeWord = new L1GtfeWord();
106  m_gtFdlWord = new L1GtFdlWord();
107  m_gtPsbWord = new L1GtPsbWord();
108 
109  if (m_verbosity && m_isDebugEnabled) {
110 
111  LogDebug("L1GlobalTriggerRawToDigi")
112  << "\nInput tag for DAQ GT record: " << m_daqGtInputTag
113  << "\nFED Id for DAQ GT record: " << m_daqGtFedId
114  << "\nMask for active boards (hex format): " << std::hex
115  << std::setw(sizeof(m_activeBoardsMaskGt) * 2) << std::setfill('0')
117  << std::dec << std::setfill(' ')
118  << "\nNumber of bunch crossing to be unpacked: "
119  << m_unpackBxInEvent << "\n"
120  << std::endl;
121  }
122 
123  if ( ( m_unpackBxInEvent > 0 ) && ( ( m_unpackBxInEvent % 2 ) == 0 )) {
125 
126  if (m_verbosity) {
127  edm::LogInfo("L1GlobalTriggerRawToDigi")
128  << "\nWARNING: Number of bunch crossing to be unpacked rounded to: "
129  << m_unpackBxInEvent << "\n The number must be an odd number!\n"
130  << std::endl;
131  }
132  }
133 
134 }
135 
136 // destructor
138 
139  delete m_gtfeWord;
140  delete m_gtFdlWord;
141  delete m_gtPsbWord;
142 
143 }
144 
145 // member functions
146 
148  // empty
149 }
150 
151 // method called to produce the data
153 
154  // get records from EventSetup
155 
156  // muon trigger scales
158  evSetup.get<L1MuTriggerScalesRcd> ().get(trigscales_h);
159  m_TriggerScales = trigscales_h.product();
160 
161  edm::ESHandle<L1MuTriggerPtScale> trigptscale_h;
162  evSetup.get<L1MuTriggerPtScaleRcd> ().get(trigptscale_h);
163  m_TriggerPtScale = trigptscale_h.product();
164 
165  // board maps
167  evSetup.get<L1GtBoardMapsRcd> ().get(l1GtBM);
168 
169  const std::vector<L1GtBoard> boardMaps = l1GtBM->gtBoardMaps();
170  int boardMapsSize = boardMaps.size();
171 
172  typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
173 
174  // create an ordered vector for the GT DAQ record
175  // header (pos 0 in record) and trailer (last position in record)
176  // not included, as they are not in board list
177  std::vector<L1GtBoard> gtRecordMap;
178  gtRecordMap.reserve(boardMapsSize);
179 
180  for (int iPos = 0; iPos < boardMapsSize; ++iPos) {
181  for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
182 
183  if (itBoard->gtPositionDaqRecord() == iPos) {
184  gtRecordMap.push_back(*itBoard);
185  break;
186  }
187 
188  }
189  }
190 
191  // raw collection
192 
194  iEvent.getByLabel(m_daqGtInputTag, fedHandle);
195 
196  if (!fedHandle.isValid()) {
197  if (m_verbosity) {
198  edm::LogWarning("L1GlobalTriggerRawToDigi")
199  << "\nWarning: FEDRawDataCollection with input tag " << m_daqGtInputTag
200  << "\nrequested in configuration, but not found in the event."
201  << "\nQuit unpacking this event" << std::endl;
202  }
203 
204  produceEmptyProducts(iEvent);
205 
206  return;
207  }
208 
209  // retrieve data for Global Trigger FED (GT + GMT)
210  const FEDRawData& raw = ( fedHandle.product() )->FEDData(m_daqGtFedId);
211 
212  int gtSize = raw.size();
213 
214  // get a const pointer to the beginning of the data buffer
215  const unsigned char* ptrGt = raw.data();
216 
217  // get a const pointer to the end of the data buffer
218  const unsigned char* endPtrGt = ptrGt + gtSize;
219 
220  //
221  if (m_verbosity && m_isDebugEnabled) {
222 
223  LogTrace("L1GlobalTriggerRawToDigi") << "\n Size of raw data: "
224  << gtSize << "\n" << std::endl;
225 
226  std::ostringstream myCoutStream;
227  dumpFedRawData(ptrGt, gtSize, myCoutStream);
228 
229  LogTrace("L1GlobalTriggerRawToDigi") << "\n Dump FEDRawData\n"
230  << myCoutStream.str() << "\n" << std::endl;
231 
232  }
233 
234  // unpack header (we have one header only)
235  int headerSize = 8;
236 
237  if ((ptrGt + headerSize) > endPtrGt) {
238  edm::LogError("L1GlobalTriggerRawToDigi")
239  << "\nError: Pointer after header greater than end pointer."
240  << "\n Put empty products in the event!"
241  << "\n Quit unpacking this event." << std::endl;
242 
243  produceEmptyProducts(iEvent);
244 
245  return;
246  }
247 
248 
249  FEDHeader cmsHeader(ptrGt);
250  FEDTrailer cmsTrailer(ptrGt + gtSize - headerSize);
251 
252  unpackHeader(ptrGt, cmsHeader);
253  ptrGt += headerSize; // advance with header size
254 
255  // unpack first GTFE to find the length of the record and the active boards
256  // here GTFE assumed immediately after the header
257 
258  // if pointer after GTFE payload is greater than pointer at
259  // the end of GT payload, produce empty products and quit unpacking
260  if ((ptrGt + m_gtfeWord->getSize()) > endPtrGt) {
261  edm::LogError("L1GlobalTriggerRawToDigi")
262  << "\nError: Pointer after GTFE greater than end pointer."
263  << "\n Put empty products in the event!"
264  << "\n Quit unpacking this event." << std::endl;
265 
266  produceEmptyProducts(iEvent);
267 
268  return;
269  }
270 
271  bool gtfeUnpacked = false;
272 
273  for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
274 
275  if (itBoard->gtBoardType() == GTFE) {
276 
277  // unpack GTFE
278  if (itBoard->gtPositionDaqRecord() == 1) {
279 
280  m_gtfeWord->unpack(ptrGt);
281  ptrGt += m_gtfeWord->getSize(); // advance with GTFE block size
282  gtfeUnpacked = true;
283 
284  if (m_verbosity && m_isDebugEnabled) {
285 
286  std::ostringstream myCoutStream;
287  m_gtfeWord->print(myCoutStream);
288  LogTrace("L1GlobalTriggerRawToDigi") << myCoutStream.str() << "\n" << std::endl;
289  }
290 
291  // break the loop - GTFE was found
292  break;
293 
294  } else {
295 
296  if (m_verbosity) {
297  edm::LogWarning("L1GlobalTriggerRawToDigi")
298  << "\nWarning: GTFE block found in raw data does not follow header."
299  << "\nAssumed start position of the block is wrong!"
300  << "\nQuit unpacking this event" << std::endl;
301  }
302 
303  produceEmptyProducts(iEvent);
304 
305  return;
306  }
307 
308  }
309  }
310 
311  // quit if no GTFE found
312  if (!gtfeUnpacked) {
313 
314  if (m_verbosity) {
315  edm::LogWarning("L1GlobalTriggerRawToDigi")
316  << "\nWarning: no GTFE block found in raw data."
317  << "\nCan not find the record length (BxInEvent) and the active boards!"
318  << "\nQuit unpacking this event" << std::endl;
319  }
320 
321  produceEmptyProducts(iEvent);
322 
323  return;
324  }
325 
326  // life normal here, GTFE found
327 
328  // get list of active blocks
329  // blocks not active are not written to the record
330  cms_uint16_t activeBoardsGtInitial = m_gtfeWord->activeBoards();
331  cms_uint16_t altNrBxBoardInitial = m_gtfeWord->altNrBxBoard();
332 
333  // mask some boards, if needed
334  cms_uint16_t activeBoardsGt = activeBoardsGtInitial & m_activeBoardsMaskGt;
335  m_gtfeWord->setActiveBoards(activeBoardsGt);
336 
337  if (m_verbosity) {
338  LogDebug("L1GlobalTriggerRawToDigi") << "\nActive boards before masking: 0x" << std::hex
339  << std::setw(sizeof ( activeBoardsGtInitial ) * 2) << std::setfill('0')
340  << activeBoardsGtInitial << std::dec << std::setfill(' ')
341  << "\nActive boards after masking: 0x" << std::hex << std::setw(
342  sizeof ( activeBoardsGt ) * 2) << std::setfill('0') << activeBoardsGt << std::dec
343  << std::setfill(' ') << " \n" << std::endl;
344  }
345 
346  // loop over other blocks in the raw record, count them if they are active
347 
348  int numberGtfeBoards = 0;
349  int numberFdlBoards = 0;
350  int numberPsbBoards = 0;
351  int numberGmtBoards = 0;
352  int numberTcsBoards = 0;
353  int numberTimBoards = 0;
354 
355  for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
356 
357  int iActiveBit = itBoard->gtBitDaqActiveBoards();
358  bool activeBoardToUnpack = false;
359 
360  if (iActiveBit >= 0) {
361  activeBoardToUnpack = activeBoardsGt & ( 1 << iActiveBit );
362  } else {
363  // board not in the ActiveBoards for the record
364  continue;
365  }
366 
367  if (activeBoardToUnpack) {
368 
369  switch (itBoard->gtBoardType()) {
370  case GTFE: {
371  numberGtfeBoards++;
372  }
373 
374  break;
375  case FDL: {
376  numberFdlBoards++;
377  }
378 
379  break;
380  case PSB: {
381  numberPsbBoards++;
382  }
383 
384  break;
385  case GMT: {
386  numberGmtBoards++;
387  }
388 
389  break;
390  case TCS: {
391  numberTcsBoards++;
392  }
393 
394  break;
395  case TIM: {
396  numberTimBoards++;
397  }
398 
399  break;
400  default: {
401  // do nothing, all blocks are given in GtBoardType enum
402  if (m_verbosity) {
403  LogDebug("L1GlobalTriggerRawToDigi") << "\nBoard of type "
404  << itBoard->gtBoardType() << " not expected in record.\n"
405  << std::endl;
406  }
407  }
408 
409  break;
410  }
411  }
412 
413  }
414 
415  // produce the L1GlobalTriggerReadoutRecord now, after we found the maximum number of
416  // BxInEvent the record has and how many boards are active (it is just reserving space
417  // for vectors)
418  //LogDebug("L1GlobalTriggerRawToDigi")
419  //<< "\nL1GlobalTriggerRawToDigi: producing L1GlobalTriggerReadoutRecord\n"
420  //<< "\nL1GlobalTriggerRawToDigi: producing L1MuGMTReadoutCollection;\n"
421  //<< std::endl;
422 
423  // get number of Bx in the event from GTFE block corresponding to alternative 0 and 1 in
426 
427  int maxBxInEvent = std::max(m_recordLength0, m_recordLength1);
428 
429 
430  std::auto_ptr<L1GlobalTriggerReadoutRecord> gtReadoutRecord(new L1GlobalTriggerReadoutRecord(
431  maxBxInEvent, numberFdlBoards, numberPsbBoards));
432 
433  // produce also the GMT readout collection and set the reference in GT record
434  std::auto_ptr<L1MuGMTReadoutCollection> gmtrc(new L1MuGMTReadoutCollection(maxBxInEvent));
435 
436  //edm::RefProd<L1MuGMTReadoutCollection> refProdMuGMT = iEvent.getRefBeforePut<
437  // L1MuGMTReadoutCollection> ();
438 
439  //if (m_verbosity) {
440  // LogDebug("L1GlobalTriggerRawToDigi")
441  // << "\nL1GlobalTriggerRawToDigi: set L1MuGMTReadoutCollection RefProd"
442  // << " in L1GlobalTriggerReadoutRecord.\n" << std::endl;
443  //}
444  //gtReadoutRecord->setMuCollectionRefProd(refProdMuGMT);
445 
446 
447  // ... then unpack modules other than GTFE, if requested
448 
449  for (CItBoardMaps itBoard = gtRecordMap.begin(); itBoard != gtRecordMap.end(); ++itBoard) {
450 
451  int iActiveBit = itBoard->gtBitDaqActiveBoards();
452 
453  bool activeBoardToUnpack = false;
454  bool activeBoardInitial = false;
455 
456  int altNrBxBoardVal = -1;
457 
458  if (iActiveBit >= 0) {
459  activeBoardInitial = activeBoardsGtInitial & ( 1 << iActiveBit );
460  activeBoardToUnpack = activeBoardsGt & ( 1 << iActiveBit );
461 
462  altNrBxBoardVal = (altNrBxBoardInitial & ( 1 << iActiveBit )) >> iActiveBit;
463 
464  if (altNrBxBoardVal == 1) {
466  } else if (altNrBxBoardVal == 0) {
468  } else {
469  if (m_verbosity) {
470  edm::LogWarning("L1GlobalTriggerRawToDigi")
471  << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal
472  << " for board " << std::hex << ( itBoard->gtBoardId() ) << std::dec
473  << "\n iActiveBit = " << iActiveBit
474  << "\n altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial << std::dec
475  << "\n activeBoardsGt = 0x" << std::hex << activeBoardsGt << std::dec
476  << "\n activeBoardInitial = " << activeBoardInitial
477  << "\n activeBoardToUnpack = " << activeBoardToUnpack
478  << "\n Set altNrBxBoardVal tentatively to "
479  << m_recordLength0 << "\n Job may crash or produce wrong results!\n\n"
480  << std::endl;
481  }
482 
484  }
485 
486  // number of BX required to be unpacked
487 
489  if (m_verbosity) {
490  LogDebug("L1GlobalTriggerRawToDigi")
491  << "\nWARNING: Number of available bunch crosses for board"
492  << ( itBoard->gtBoardId() ) << " in the record ( " << m_totalBxInEvent
493  << " ) \n is smaller than the number of bunch crosses requested to be unpacked ("
494  << m_unpackBxInEvent << " )!!! \n Unpacking only "
495  << m_totalBxInEvent << " bunch crosses.\n" << std::endl;
496  }
497 
498  m_lowSkipBxInEvent = 0;
500 
501  } else if (m_unpackBxInEvent < 0) {
502 
503  m_lowSkipBxInEvent = 0;
505 
506  if (m_verbosity) {
507  LogDebug("L1GlobalTriggerRawToDigi") << "\nUnpacking all " << m_totalBxInEvent
508  << " bunch crosses available." << "\n" << std::endl;
509  }
510 
511 
512  } else if (m_unpackBxInEvent == 0) {
513 
516 
517  if (m_verbosity) {
518  LogDebug("L1GlobalTriggerRawToDigi")
519  << "\nNo bxInEvent required to be unpacked from " << m_totalBxInEvent
520  << " bunch crosses available." << "\n" << std::endl;
521  }
522 
523  // change RecordLength
524  // cast int to cms_uint16_t (there are normally 3 or 5 BxInEvent)
525  m_gtfeWord->setRecordLength(static_cast<cms_uint16_t> (m_unpackBxInEvent));
526  m_gtfeWord->setRecordLength1(static_cast<cms_uint16_t> (m_unpackBxInEvent));
527 
528  } else {
529 
532 
533  if (m_verbosity) {
534  LogDebug("L1GlobalTriggerRawToDigi") << "\nUnpacking " << m_unpackBxInEvent
535  << " bunch crosses from " << m_totalBxInEvent
536  << " bunch crosses available." << "\n" << std::endl;
537  }
538 
539  // change RecordLength
540  // cast int to cms_uint16_t (there are normally 3 or 5 BxInEvent)
541  m_gtfeWord->setRecordLength(static_cast<cms_uint16_t> (m_unpackBxInEvent));
542  m_gtfeWord->setRecordLength1(static_cast<cms_uint16_t> (m_unpackBxInEvent));
543 
544  }
545 
546  } else {
547  // board not in the ActiveBoards for the record
548  continue;
549  }
550 
551  if (!activeBoardInitial) {
552  if (m_verbosity) {
553  LogDebug("L1GlobalTriggerRawToDigi") << "\nBoard of type "
554  << itBoard->gtBoardName() << " with index " << itBoard->gtBoardIndex()
555  << " not active initially in raw data.\n" << std::endl;
556  }
557  continue;
558  }
559 
560  // active board initially, could unpack it
561  switch (itBoard->gtBoardType()) {
562 
563  case FDL: {
564  for (int iFdl = 0; iFdl < m_totalBxInEvent; ++iFdl) {
565 
566  // if pointer after FDL payload is greater than pointer at
567  // the end of GT payload, produce empty products and quit unpacking
568  if ((ptrGt + m_gtFdlWord->getSize()) > endPtrGt) {
569  edm::LogError("L1GlobalTriggerRawToDigi")
570  << "\nError: Pointer after FDL " << iFdl
571  << " greater than end pointer."
572  << "\n Put empty products in the event!"
573  << "\n Quit unpacking this event." << std::endl;
574 
575  produceEmptyProducts(iEvent);
576 
577  return;
578  }
579 
580  // unpack only if requested, otherwise skip it
581  if (activeBoardToUnpack) {
582 
583  // unpack only bxInEvent requested, otherwise skip it
584  if ( ( iFdl >= m_lowSkipBxInEvent ) && ( iFdl < m_uppSkipBxInEvent )) {
585 
586  m_gtFdlWord->unpack(ptrGt);
587 
588  // add 1 to the GT luminosity number to use the same convention as
589  // offline, where LS number starts with 1;
590  // in GT hardware, LS starts with 0
591  cms_uint16_t lsNr = m_gtFdlWord->lumiSegmentNr() + 1;
593 
594  // add FDL block to GT readout record
595  gtReadoutRecord->setGtFdlWord(*m_gtFdlWord);
596 
597  if (m_verbosity && m_isDebugEnabled) {
598 
599  std::ostringstream myCoutStream;
600  m_gtFdlWord->print(myCoutStream);
601  LogTrace("L1GlobalTriggerRawToDigi") << myCoutStream.str() << "\n"
602  << std::endl;
603  }
604 
605  // ... and reset it
606  m_gtFdlWord->reset();
607  }
608 
609  }
610 
611  ptrGt += m_gtFdlWord->getSize(); // advance with FDL block size
612 
613  }
614  }
615 
616  break;
617  case PSB: {
618  for (int iPsb = 0; iPsb < m_totalBxInEvent; ++iPsb) {
619 
620  // if pointer after PSB payload is greater than pointer at
621  // the end of GT payload, produce empty products and quit unpacking
622  if ((ptrGt + m_gtPsbWord->getSize()) > endPtrGt) {
623  edm::LogError("L1GlobalTriggerRawToDigi")
624  << "\nError: Pointer after PSB " << iPsb
625  << " greater than end pointer."
626  << "\n Put empty products in the event!"
627  << "\n Quit unpacking this event." << std::endl;
628 
629  produceEmptyProducts(iEvent);
630 
631  return;
632  }
633 
634  // unpack only if requested, otherwise skip it
635  if (activeBoardToUnpack) {
636 
637  // unpack only bxInEvent requested, otherwise skip it
638  if ( ( iPsb >= m_lowSkipBxInEvent ) && ( iPsb < m_uppSkipBxInEvent )) {
639 
640  unpackPSB(evSetup, ptrGt, *m_gtPsbWord);
641 
642  // add PSB block to GT readout record
643  gtReadoutRecord->setGtPsbWord(*m_gtPsbWord);
644 
645  if (m_verbosity && m_isDebugEnabled) {
646 
647  std::ostringstream myCoutStream;
648  m_gtPsbWord->print(myCoutStream);
649  LogTrace("L1GlobalTriggerRawToDigi") << myCoutStream.str() << "\n"
650  << std::endl;
651  }
652 
653  // ... and reset it
654  m_gtPsbWord->reset();
655  }
656 
657  }
658 
659  ptrGt += m_gtPsbWord->getSize(); // advance with PSB block size
660 
661  }
662  }
663  break;
664  case GMT: {
665 
666  // 17*64/8 TODO FIXME ask Ivan for a getSize() function for GMT record
667  unsigned int gmtRecordSize = 136;
668  unsigned int gmtCollSize = m_totalBxInEvent * gmtRecordSize;
669 
670  // if pointer after GMT payload is greater than pointer at
671  // the end of GT payload, produce empty products and quit unpacking
672  if ((ptrGt + gmtCollSize) > endPtrGt) {
673  edm::LogError("L1GlobalTriggerRawToDigi")
674  << "\nError: Pointer after GMT "
675  << " greater than end pointer."
676  << "\n Put empty products in the event!"
677  << "\n Quit unpacking this event." << std::endl;
678 
679  produceEmptyProducts(iEvent);
680 
681  return;
682  }
683 
684  // unpack only if requested, otherwise skip it
685  if (activeBoardToUnpack) {
686  unpackGMT(ptrGt, gmtrc, iEvent);
687  }
688 
689 
690  ptrGt += gmtCollSize; // advance with GMT block size
691  }
692  break;
693  default: {
694  // do nothing, all blocks are given in GtBoardType enum
695  if (m_verbosity) {
696 
697  LogDebug("L1GlobalTriggerRawToDigi") << "\nBoard of type "
698  << itBoard->gtBoardType() << " not expected in record.\n" << std::endl;
699  }
700  }
701  break;
702 
703  }
704 
705  }
706 
707  // add GTFE block to GT readout record, after updating active boards and record length
708 
709  gtReadoutRecord->setGtfeWord(*m_gtfeWord);
710 
711  // ... and reset it
712  m_gtfeWord->reset();
713 
714 
715 
716  // unpack trailer
717 
718  int trailerSize = 8;
719 
720  // if pointer after trailer is greater than pointer at
721  // the end of GT payload, produce empty products and quit unpacking
722  if ((ptrGt + trailerSize) > endPtrGt) {
723  edm::LogError("L1GlobalTriggerRawToDigi")
724  << "\nError: Pointer after trailer "
725  << " greater than end pointer."
726  << "\n Put empty products in the event!"
727  << "\n Quit unpacking this event." << std::endl;
728 
729  produceEmptyProducts(iEvent);
730 
731  return;
732  }
733 
734  unpackTrailer(ptrGt, cmsTrailer);
735 
736  //
737  if (m_verbosity && m_isDebugEnabled) {
738  std::ostringstream myCoutStream;
739  gtReadoutRecord->print(myCoutStream);
740  LogTrace("L1GlobalTriggerRawToDigi")
741  << "\n The following L1 GT DAQ readout record was unpacked.\n"
742  << myCoutStream.str() << "\n" << std::endl;
743  }
744 
745  // put records into event
746 
747  iEvent.put(gmtrc);
748  iEvent.put(gtReadoutRecord);
749 
750 }
751 
752 // unpack header
753 void L1GlobalTriggerRawToDigi::unpackHeader(const unsigned char* gtPtr, FEDHeader& cmsHeader) {
754 
755  // TODO if needed in another format
756 
757  // print the header info
758  if (m_verbosity && m_isDebugEnabled) {
759 
760  const cms_uint64_t* payload =
761  reinterpret_cast<cms_uint64_t*> (const_cast<unsigned char*> (gtPtr));
762 
763  std::ostringstream myCoutStream;
764 
765  // one word only
766  int iWord = 0;
767 
768  myCoutStream << std::setw(4) << iWord << " " << std::hex << std::setfill('0')
769  << std::setw(16) << payload[iWord] << std::dec << std::setfill(' ') << "\n"
770  << std::endl;
771 
772  myCoutStream << " Event_type: " << std::hex << " hex: " << " " << std::setw(1)
773  << std::setfill('0') << cmsHeader.triggerType() << std::setfill(' ') << std::dec
774  << " dec: " << cmsHeader.triggerType() << std::endl;
775 
776  myCoutStream << " LVL1_Id: " << std::hex << " hex: " << "" << std::setw(6)
777  << std::setfill('0') << cmsHeader.lvl1ID() << std::setfill(' ') << std::dec
778  << " dec: " << cmsHeader.lvl1ID() << std::endl;
779 
780  myCoutStream << " BX_Id: " << std::hex << " hex: " << " " << std::setw(3)
781  << std::setfill('0') << cmsHeader.bxID() << std::setfill(' ') << std::dec
782  << " dec: " << cmsHeader.bxID() << std::endl;
783 
784  myCoutStream << " Source_Id: " << std::hex << " hex: " << " " << std::setw(3)
785  << std::setfill('0') << cmsHeader.sourceID() << std::setfill(' ') << std::dec
786  << " dec: " << cmsHeader.sourceID() << std::endl;
787 
788  myCoutStream << " FOV: " << std::hex << " hex: " << " " << std::setw(1)
789  << std::setfill('0') << cmsHeader.version() << std::setfill(' ') << std::dec
790  << " dec: " << cmsHeader.version() << std::endl;
791 
792  myCoutStream << " H: " << std::hex << " hex: " << " " << std::setw(1)
793  << std::setfill('0') << cmsHeader.moreHeaders() << std::setfill(' ') << std::dec
794  << " dec: " << cmsHeader.moreHeaders() << std::endl;
795 
796  LogDebug("L1GlobalTriggerRawToDigi") << "\n CMS Header \n" << myCoutStream.str() << "\n"
797  << std::endl;
798 
799  }
800 
801 }
802 
803 // unpack PSB records
804 // psbPtr pointer to the beginning of the each PSB block obtained from gtPtr
806  const edm::EventSetup& evSetup, const unsigned char* psbPtr, L1GtPsbWord& psbWord) {
807 
808  //LogDebug("L1GlobalTriggerRawToDigi")
809  //<< "\nUnpacking PSB block.\n"
810  //<< std::endl;
811 
813 
814  int psbSize = psbWord.getSize();
815  int psbWords = psbSize / uLength;
816 
817  const cms_uint64_t* payload =
818  reinterpret_cast<cms_uint64_t*> (const_cast<unsigned char*> (psbPtr));
819 
820  for (int iWord = 0; iWord < psbWords; ++iWord) {
821 
822  // fill PSB
823  // the second argument must match the word index defined in L1GtPsbWord class
824 
825  psbWord.setBoardId(payload[iWord], iWord);
826  psbWord.setBxInEvent(payload[iWord], iWord);
827  psbWord.setBxNr(payload[iWord], iWord);
828  psbWord.setEventNr(payload[iWord], iWord);
829 
830  psbWord.setAData(payload[iWord], iWord);
831  psbWord.setBData(payload[iWord], iWord);
832 
833  psbWord.setLocalBxNr(payload[iWord], iWord);
834 
835  LogTrace("L1GlobalTriggerRawToDigi") << std::setw(4) << iWord << " " << std::hex
836  << std::setfill('0') << std::setw(16) << payload[iWord] << std::dec
837  << std::setfill(' ') << std::endl;
838 
839  }
840 
841 }
842 
843 // unpack the GMT record
844 void L1GlobalTriggerRawToDigi::unpackGMT(const unsigned char* chp, std::auto_ptr<
846 
847  //LogDebug("L1GlobalTriggerRawToDigi")
848  //<< "\nUnpacking GMT collection.\n"
849  //<< std::endl;
850 
851  // 17*64/2 TODO FIXME ask Ivan for a getSize() function for GMT record
852  const unsigned int gmtRecordSize32 = 34;
853 
854  std::auto_ptr<std::vector<L1MuRegionalCand> > DTCands(new std::vector<L1MuRegionalCand>);
855  std::auto_ptr<std::vector<L1MuRegionalCand> > CSCCands(new std::vector<L1MuRegionalCand>);
856  std::auto_ptr<std::vector<L1MuRegionalCand> > RPCbCands(new std::vector<L1MuRegionalCand>);
857  std::auto_ptr<std::vector<L1MuRegionalCand> > RPCfCands(new std::vector<L1MuRegionalCand>);
858  std::auto_ptr<std::vector<L1MuGMTCand> > GMTCands(new std::vector<L1MuGMTCand>);
859 
860  const unsigned* p = (const unsigned*) chp;
861 
862  // min Bx's in the event, computed after m_totalBxInEvent is obtained from GTFE block
863  // assume symmetrical number of BX around L1Accept
864  int iBxInEvent = ( m_totalBxInEvent + 1 ) / 2 - m_totalBxInEvent;
865 
866  for (int iGmtRec = 0; iGmtRec < m_totalBxInEvent; ++iGmtRec) {
867 
868  // unpack only bxInEvent requested, otherwise skip it
869  if ( ( iGmtRec >= m_lowSkipBxInEvent ) && ( iGmtRec < m_uppSkipBxInEvent )) {
870 
871  // Dump the block
872  const cms_uint64_t* bp =
873  reinterpret_cast<cms_uint64_t*> (const_cast<unsigned*> (p));
874  for (int iWord = 0; iWord < 17; iWord++) {
875  LogTrace("L1GlobalTriggerRawToDigi") << std::setw(4) << iWord << " " << std::hex
876  << std::setfill('0') << std::setw(16) << *bp++ << std::dec << std::setfill(
877  ' ') << std::endl;
878  }
879 
880  L1MuGMTReadoutRecord gmtrr(iBxInEvent);
881 
882  gmtrr.setEvNr( ( *p ) & 0xffffff);
883  gmtrr.setBCERR( ( ( *p ) >> 24 ) & 0xff);
884  p++;
885 
886  gmtrr.setBxNr( ( *p ) & 0xfff);
887  if ( ( ( *p ) >> 15 ) & 1) {
888  gmtrr.setBxInEvent( ( ( ( *p ) >> 12 ) & 7 ) - 8);
889  } else {
890  gmtrr.setBxInEvent( ( ( ( *p ) >> 12 ) & 7 ));
891  }
892  // to do: check here the block length and the board id
893  p++;
894 
895  for (int im = 0; im < 16; im++) {
896  // flip the pt and quality bits -- this should better be done by GMT input chips
897  unsigned waux = *p++;
898  waux = ( waux & 0xffff00ff ) | ( ( ~waux ) & 0x0000ff00 );
899  L1MuRegionalCand cand(waux, iBxInEvent);
900  // fix the type assignment (csc=2, rpcb=1) -- should be done by GMT input chips
901  if (im >= 4 && im < 8) cand.setType(1);
902  if (im >= 8 && im < 12) cand.setType(2);
904  cand.setEtaValue(m_TriggerScales->getRegionalEtaScale(cand.type_idx())->getCenter(
905  cand.eta_packed()));
907  gmtrr.setInputCand(im, cand);
908  if (!cand.empty()) {
909  if (im < 4) DTCands->push_back(cand);
910  if (im >= 4 && im < 8) RPCbCands->push_back(cand);
911  if (im >= 8 && im < 12) CSCCands->push_back(cand);
912  if (im >= 12) RPCfCands->push_back(cand);
913  }
914  }
915 
916  unsigned char* prank = (unsigned char*) ( p + 12 );
917 
918  for (int im = 0; im < 12; im++) {
919  unsigned waux = *p++;
920  unsigned raux = im < 8 ? *prank++ : 0; // only fwd and brl cands have valid rank
921  L1MuGMTExtendedCand cand(waux, raux, iBxInEvent);
925  if (im < 4)
926  gmtrr.setGMTBrlCand(im, cand);
927  else if (im < 8)
928  gmtrr.setGMTFwdCand(im - 4, cand);
929  else {
930  gmtrr.setGMTCand(im - 8, cand);
931  if (!cand.empty()) GMTCands->push_back(cand);
932  }
933  }
934 
935  // skip the two sort rank words and two chip BX words
936  p += 4;
937 
938  gmtrc->addRecord(gmtrr);
939 
940  } else {
941  // increase the pointer with the GMT record size
942  p += gmtRecordSize32;
943  }
944 
945  // increase the BxInEvent number
946  iBxInEvent++;
947 
948  }
949 
950  iEvent.put(DTCands, "DT");
951  iEvent.put(CSCCands, "CSC");
952  iEvent.put(RPCbCands, "RPCb");
953  iEvent.put(RPCfCands, "RPCf");
954  iEvent.put(GMTCands);
955 
956 }
957 
958 // unpack trailer word
959 // trPtr pointer to the beginning of trailer obtained from gtPtr
960 void L1GlobalTriggerRawToDigi::unpackTrailer(const unsigned char* trlPtr, FEDTrailer& cmsTrailer) {
961 
962  // TODO if needed in another format
963 
964  // print the trailer info
965  if (m_verbosity && m_isDebugEnabled) {
966 
967  const cms_uint64_t* payload =
968  reinterpret_cast<cms_uint64_t*> (const_cast<unsigned char*> (trlPtr));
969 
970  std::ostringstream myCoutStream;
971 
972  // one word only
973  int iWord = 0;
974 
975  myCoutStream << std::setw(4) << iWord << " " << std::hex << std::setfill('0')
976  << std::setw(16) << payload[iWord] << std::dec << std::setfill(' ') << "\n"
977  << std::endl;
978 
979  myCoutStream << " Event_length: " << std::hex << " hex: " << "" << std::setw(6)
980  << std::setfill('0') << cmsTrailer.lenght() << std::setfill(' ') << std::dec
981  << " dec: " << cmsTrailer.lenght() << std::endl;
982 
983  myCoutStream << " CRC: " << std::hex << " hex: " << " " << std::setw(4)
984  << std::setfill('0') << cmsTrailer.crc() << std::setfill(' ') << std::dec
985  << " dec: " << cmsTrailer.crc() << std::endl;
986 
987  myCoutStream << " Event_status: " << std::hex << " hex: " << " " << std::setw(2)
988  << std::setfill('0') << cmsTrailer.evtStatus() << std::setfill(' ') << std::dec
989  << " dec: " << cmsTrailer.evtStatus() << std::endl;
990 
991  myCoutStream << " TTS_bits: " << std::hex << " hex: " << " " << std::setw(1)
992  << std::setfill('0') << cmsTrailer.ttsBits() << std::setfill(' ') << std::dec
993  << " dec: " << cmsTrailer.ttsBits() << std::endl;
994 
995  myCoutStream << " More trailers: " << std::hex << " hex: " << " " << std::setw(1)
996  << std::setfill('0') << cmsTrailer.moreTrailers() << std::setfill(' ') << std::dec
997  << " dec: " << cmsTrailer.moreTrailers() << std::endl;
998 
999  LogDebug("L1GlobalTriggerRawToDigi") << "\n CMS Trailer \n" << myCoutStream.str() << "\n"
1000  << std::endl;
1001 
1002  }
1003 
1004 }
1005 
1006 // produce empty products in case of problems
1008 
1009  std::auto_ptr<L1GlobalTriggerReadoutRecord> gtReadoutRecord(
1011 
1012  std::auto_ptr<L1MuGMTReadoutCollection> gmtrc(new L1MuGMTReadoutCollection());
1013 
1014  std::auto_ptr<std::vector<L1MuRegionalCand> > DTCands(new std::vector<L1MuRegionalCand>);
1015  std::auto_ptr<std::vector<L1MuRegionalCand> > CSCCands(new std::vector<L1MuRegionalCand>);
1016  std::auto_ptr<std::vector<L1MuRegionalCand> > RPCbCands(new std::vector<L1MuRegionalCand>);
1017  std::auto_ptr<std::vector<L1MuRegionalCand> > RPCfCands(new std::vector<L1MuRegionalCand>);
1018  std::auto_ptr<std::vector<L1MuGMTCand> > GMTCands(new std::vector<L1MuGMTCand>);
1019 
1020  // put empty records into event
1021 
1022  iEvent.put(gmtrc);
1023  iEvent.put(gtReadoutRecord);
1024 
1025  iEvent.put(DTCands, "DT");
1026  iEvent.put(CSCCands, "CSC");
1027  iEvent.put(RPCbCands, "RPCb");
1028  iEvent.put(RPCfCands, "RPCf");
1029  iEvent.put(GMTCands);
1030 
1031 }
1032 
1033 
1034 
1035 // dump FED raw data
1037  const unsigned char* gtPtr, int gtSize, std::ostream& myCout) {
1038 
1039  LogDebug("L1GlobalTriggerRawToDigi") << "\nDump FED raw data.\n" << std::endl;
1040 
1043 
1044  int gtWords = gtSize / uLength;
1045  LogTrace("L1GlobalTriggerRawToDigi") << "\nFED GT words (" << wLength << " bits):" << gtWords
1046  << "\n" << std::endl;
1047 
1048  const cms_uint64_t* payload =
1049  reinterpret_cast<cms_uint64_t*> (const_cast<unsigned char*> (gtPtr));
1050 
1051  for (unsigned int i = 0; i < gtSize / sizeof(cms_uint64_t); i++) {
1052  myCout << std::setw(4) << i << " " << std::hex << std::setfill('0') << std::setw(16)
1053  << payload[i] << std::dec << std::setfill(' ') << std::endl;
1054  }
1055 
1056 }
1057 
1058 //
1060 
1061  // empty now
1062 }
1063 
1064 // static class members
1065 
#define LogDebug(id)
const L1MuTriggerScales * m_TriggerScales
muon trigger scales to convert unpacked data into physical quantities
bool isDebugEnabled()
int i
Definition: DBlmapReader.cc:9
void reset()
reset the content of a L1GtPsbWord
Definition: L1GtPsbWord.cc:434
const unsigned int getSize() const
get the size of the GTFE block in GT DAQ record (in multiple of 8 bits)
Definition: L1GtfeWord.h:231
int version()
Version identifier of the FED data format.
Definition: FEDHeader.cc:34
virtual void print(std::ostream &myCout) const
pretty print the content of a L1GtfeWord
Definition: L1GtfeWord.cc:323
const L1MuScale * getPtScale() const
get the Pt scale
unsigned int phiIndex() const
get phi-code
Definition: L1MuGMTCand.h:75
void unpackHeader(const unsigned char *, FEDHeader &)
block unpackers
cms_uint16_t m_activeBoardsMaskGt
mask for active boards
static const int UnitLength
one unit in the word is UnitLength bits
virtual bool empty() const
return empty flag
virtual void produce(edm::Event &, const edm::EventSetup &)
void setGMTBrlCand(int nr, L1MuGMTExtendedCand const &cand)
set GMT barrel candidate
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
int evtStatus()
Event fragment status information.
Definition: FEDTrailer.cc:29
bool moreTrailers()
Definition: FEDTrailer.cc:39
int m_recordLength0
total Bx&#39;s in the event, obtained from GTFE block
void setBData(cms_uint16_t bDataVal, int iB)
Definition: L1GtPsbWord.cc:339
unsigned int etaIndex() const
get eta-code
Definition: L1MuGMTCand.h:110
void setGMTFwdCand(int nr, L1MuGMTExtendedCand const &cand)
set GMT forward candidate
void unpack(const unsigned char *fdlPtr)
Definition: L1GtFdlWord.cc:893
void setInputCand(int nr, unsigned data)
set Input muon
void unpackPSB(const edm::EventSetup &, const unsigned char *, L1GtPsbWord &)
void setRecordLength(cms_uint16_t recordLengthValue)
Definition: L1GtfeWord.h:111
virtual float getCenter(unsigned packed) const =0
get the center of bin represented by packed
void setPtValue(float ptVal)
Set Pt Value.
const unsigned int getSize() const
get the size of the FDL block in GT DAQ record (in multiple of 8 bits)
Definition: L1GtFdlWord.h:394
const cms_uint16_t altNrBxBoard() const
get/set alternative for number of BX per board
Definition: L1GtfeWord.h:189
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
static const int WordLength
GT DAQ record organized in words of WordLength bits.
const cms_uint16_t recordLength() const
get/set record length for alternative 0
Definition: L1GtfeWord.h:106
void setEventNr(cms_uint32_t eventNrValue)
Definition: L1GtPsbWord.h:136
int sourceID()
Identifier of the FED.
Definition: FEDHeader.cc:30
void setBxNr(cms_uint16_t bxNrValue)
Definition: L1GtPsbWord.h:115
bool empty() const
is it an empty muon candidate?
Definition: L1MuGMTCand.h:66
virtual void reset()
reset the content of a L1GtfeWord
Definition: L1GtfeWord.cc:308
int iEvent
Definition: GenABIO.cc:243
const L1MuTriggerPtScale * m_TriggerPtScale
void setPhiValue(float phiVal)
Set Phi Value.
bool moreHeaders()
Definition: FEDHeader.cc:38
void setBoardId(cms_uint16_t boardIdValue)
Definition: L1GtPsbWord.h:73
int m_recordLength1
corresponding to alternative 1 in altNrBxBoard()
void setPhiValue(float phiVal)
Setters for physical values.
Definition: L1MuGMTCand.h:179
const T & max(const T &a, const T &b)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
void setLumiSegmentNr(const cms_uint16_t &lumiSegmentNrValue)
Definition: L1GtFdlWord.h:359
edm::InputTag m_daqGtInputTag
input tags for GT DAQ record
void setBxInEvent(int bxInEventValue)
Definition: L1GtPsbWord.h:94
const L1MuScale * getPhiScale() const
get the phi scale
void reset()
reset the content of a L1GtFdlWord
Definition: L1GtFdlWord.cc:734
void setEtaValue(float etaVal)
Set Eta Value (need to set type, first)
unsigned eta_packed() const
return eta packed as in hardware
unsigned short cms_uint16_t
Definition: typedefs.h:13
void setType(unsigned type)
Set Type: 0 DT, 1 bRPC, 2 CSC, 3 fRPC.
void setRecordLength1(cms_uint16_t recordLengthValue)
Definition: L1GtfeWord.h:92
bool isValid() const
Definition: HandleBase.h:76
L1GlobalTriggerRawToDigi(const edm::ParameterSet &)
constructor(s)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
const cms_uint16_t activeBoards() const
get/set boards contributing to EVM respectively DAQ record
Definition: L1GtfeWord.h:165
#define LogTrace(id)
void unpackGMT(const unsigned char *, std::auto_ptr< L1MuGMTReadoutCollection > &, edm::Event &)
unpack the GMT record
void print(std::ostream &myCout) const
pretty print the content of a L1GtFdlWord
Definition: L1GtFdlWord.cc:768
void print(std::ostream &myCout) const
pretty print
Definition: L1GtPsbWord.cc:455
int ttsBits()
Current value of the Trigger Throttling System bitsAQ).
Definition: FEDTrailer.cc:34
const cms_uint16_t lumiSegmentNr() const
get/set luminosity segment number of the actual bx
Definition: L1GtFdlWord.h:354
int m_totalBxInEvent
number of Bx for a board, obtained from GTFE block (record length &amp; alternative)
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:19
void setActiveBoards(cms_uint16_t activeBoardsValue)
Definition: L1GtfeWord.h:170
const T & get() const
Definition: EventSetup.h:55
void setEtaValue(float etaVal)
Set Eta Value (need to set type, first)
Definition: L1MuGMTCand.h:185
int bxID()
The bunch crossing number.
Definition: FEDHeader.cc:26
T const * product() const
Definition: ESHandle.h:62
void setBxNr(int bxnr)
set counters
void unpackTrailer(const unsigned char *, FEDTrailer &)
unpack trailer word
T const * product() const
Definition: Handle.h:74
const L1MuScale * getRegionalEtaScale(int isys) const
get the regioanl muon trigger eta scale, isys = 0(DT), 1(bRPC), 2(CSC), 3(fwdRPC) ...
virtual ~L1GlobalTriggerRawToDigi()
destructor
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
void setLocalBxNr(cms_uint16_t localBxNrValue)
Definition: L1GtPsbWord.h:185
int crc()
Cyclic Redundancy Code of the event fragment including header and trailer.
Definition: FEDTrailer.cc:24
const L1MuScale * getGMTEtaScale() const
get the GMT eta scale
void setGMTCand(int nr, L1MuGMTExtendedCand const &cand)
set GMT candidate (does not store rank)
int lvl1ID()
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:22
unsigned long long cms_uint64_t
Definition: typedefs.h:17
void produceEmptyProducts(edm::Event &)
produce empty products in case of problems
void setPtValue(float ptVal)
Set Pt Value.
Definition: L1MuGMTCand.h:182
unsigned pt_packed() const
return pt packed as in hardware
const cms_uint16_t recordLength1() const
get/set record length for alternative 1
Definition: L1GtfeWord.h:87
unsigned int ptIndex() const
get pt-code
Definition: L1MuGMTCand.h:78
int triggerType()
Event Trigger type identifier.
Definition: FEDHeader.cc:18
void setAData(cms_uint16_t aDataVal, int iA)
Definition: L1GtPsbWord.cc:244
virtual void unpack(const unsigned char *gtfePtr)
Definition: L1GtfeWord.cc:382
unsigned type_idx() const
return type: 0 DT, 1 bRPC, 2 CSC, 3 fRPC
unsigned phi_packed() const
return phi packed as in hardware
const unsigned int getSize() const
get the size of the PSB block in GT DAQ record (in multiple of 8 bits)
Definition: L1GtPsbWord.h:200
void dumpFedRawData(const unsigned char *, int, std::ostream &)
dump FED raw data