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