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