CMS 3D CMS Logo

CSCEventData.cc
Go to the documentation of this file.
6 #include <iostream>
7 #include <iterator>
10 
11 
12 #ifdef LOCAL_UNPACK
13 bool CSCEventData::debug = false;
14 #else
15 std::atomic<bool> CSCEventData::debug{false};
16 #endif
17 
18 CSCEventData::CSCEventData(int chamberType, uint16_t format_version) :
19  theDMBHeader(format_version),
20  theALCTHeader(0),
21  theAnodeData(0),
22  theALCTTrailer(0),
23  theTMBData(0),
24  theDMBTrailer(format_version),
25  theChamberType(chamberType),
26  alctZSErecovered(0),
27  zseEnable(0),
28  theFormatVersion(format_version)
29 {
30 
31  for (unsigned i = 0; i < MAX_CFEB; ++i)
32  {
33  theCFEBData[i] = 0;
34  }
35 }
36 
37 
38 CSCEventData::CSCEventData(unsigned short * buf, uint16_t format_version): theFormatVersion(format_version)
39 {
40  theFormatVersion = format_version;
41  unpack_data(buf);
42 }
43 
44 
45 void CSCEventData::unpack_data(unsigned short * buf)
46 {
47  // zero everything
48  init();
49  unsigned short * pos = buf;
50  if (debug)
51  {
52  LogTrace ("CSCEventData|CSCRawToDigi") << "The event data ";
53  for (int i = 0; i < 16; ++i)
54  {
55  LogTrace ("CSCEventData|CSCRawToDigi") << std::hex << pos[i ] << " ";
56  }
57  }
58 
60  if (!(theDMBHeader.check()))
61  {
62  LogTrace ("CSCEventData|CSCRawToDigi") << "Bad DMB Header??? " << " first four words: ";
63  for (int i = 0; i < 4; ++i)
64  {
65  LogTrace ("CSCEventData|CSCRawToDigi") << std::hex << pos[i ] << " ";
66  }
67  }
68 
69 
70  if (debug)
71  {
72  LogTrace ("CSCEventData|CSCRawToDigi") << "nalct = " << nalct();
73  LogTrace ("CSCEventData|CSCRawToDigi") << "nclct = " << nclct();
74  }
75 
76  if (debug)
77  {
78  LogTrace ("CSCEventData|CSCRawToDigi") << "size in words of DMBHeader" << theDMBHeader.sizeInWords();
79  LogTrace ("CSCEventData|CSCRawToDigi") << "sizeof(DMBHeader)" << sizeof(theDMBHeader);
80  }
81 
82  pos += theDMBHeader.sizeInWords();
83 
84  if (nalct() ==1)
85  {
86  if (isALCT(pos)) //checking for ALCTData
87  {
88  theALCTHeader = new CSCALCTHeader( pos );
89  if (!theALCTHeader->check())
90  {
91  LogTrace ("CSCEventData|CSCRawToDigi") <<"+++WARNING: Corrupt ALCT data - won't attempt to decode";
92  }
93  else
94  {
95  //dataPresent|=0x40;
96  pos += theALCTHeader->sizeInWords(); //size of the header
97  //fill ALCT Digis
99 
100  //theAnodeData = new CSCAnodeData(*theALCTHeader, pos);
101 
102 
104  /*
105  std::cout << " ****The ALCT information from CSCEventData.cc (begin)**** " << std::endl; ///to_rm
106  std::cout << " alctHeader2007().size: " << theALCTHeader->alctHeader2007().sizeInWords() << std::endl; ///to_rm
107  std::cout << " ALCT Header Content: " << std::endl; ///to_rm
109  for(int k=0; k<theALCTHeader->sizeInWords(); k+=4){
110  std::cout << std::hex << theALCTHeader->data()[k+3]
111  << " " << theALCTHeader->data()[k+2]
112  << " " << theALCTHeader->data()[k+1]
113  << " " << theALCTHeader->data()[k] << std::dec << std::endl;
114  }
115  */
116  //std::cout << " ALCT Size: " << theAnodeData->sizeInWords() << std::endl;
118  // int zseEnable = 0;
119  zseEnable = (theALCTHeader->data()[5] & 0x1000) >> 12;
120  //std::cout << " ZSE Bit: " << zseEnable << std::endl; /// to_rm
121  int sizeInWord_ZSE =0;
122 
123  //alctZSErecovered = new unsigned short [theAnodeData->sizeInWords()];
124 
125  if (zseEnable)
126  {
129  int nWGs_per_layer = ( (theALCTHeader->data()[6]&0x0007) + 1 ) * 16 ;
131  int nWG_round_up = int(nWGs_per_layer/12)+(nWGs_per_layer%3?1:0);
132  //std::cout << " Words per layer: " << nWG_round_up << std::endl; ///to_rm
133  unsigned short * posZSE = pos;
134  std::vector<unsigned short> alctZSErecoveredVector;
135  alctZSErecoveredVector.clear();
136 
137  //alctZSErecovered = new unsigned short [theAnodeData->sizeInWords()];
138  //delete [] alctZSErecovered;
139  //std::cout << " ALCT Buffer with ZSE: " << std::endl; ///to_rm
143  //unsigned short * posZSEdebug = pos; ///to_rm
144 
146  /*
147  while (*posZSEdebug != 0xDE0D){
148  unsigned short d = *posZSEdebug;
149  unsigned short c = *(posZSEdebug+1);
150  unsigned short b = *(posZSEdebug+2);
151  unsigned short a = *(posZSEdebug+3);
152  posZSEdebug+=4;
153  std::cout << std::hex << a << " " << b << " " << c << " " << d << std::dec << std::endl;
154  }
155  */
157 
159  int alctZSErecoveredPos=0;
160  while (*posZSE != 0xDE0D)
161  {
162  if ( (*posZSE == 0x1000) && (*posZSE != 0x3000))
163  {
164  for (int j=0; j<nWG_round_up; j++)
165  {
166  alctZSErecoveredVector.push_back(0x0000);
167  }
168  alctZSErecoveredPos+=nWG_round_up;
169  }
170  else
171  {
172  alctZSErecoveredVector.push_back(*posZSE);
173  ++alctZSErecoveredPos;
174  }
175  posZSE++;
176  sizeInWord_ZSE++;
177  }
178 
179  alctZSErecovered = new unsigned short [alctZSErecoveredVector.size()];
180 
182  for (int l=0; l<(int)alctZSErecoveredVector.size(); l++)
183  {
184  alctZSErecovered[l]=alctZSErecoveredVector[l];
185  }
186 
187  unsigned short *posRecovered = alctZSErecovered;
188  theAnodeData = new CSCAnodeData(*theALCTHeader, posRecovered);
189 
192  /*
193  std::cout << " The ALCT payload recovered: " << std::endl;
194  for(int k=0; k<theAnodeData->sizeInWords(); k+=4){
195  std::cout << std::hex << alctZSErecovered[k+3] << " "
196  << alctZSErecovered[k+2] << " "
197  << alctZSErecovered[k+1] << " "
198  << alctZSErecovered[k] << std::dec << std::endl;
199  }
200  */
201  //delete [] alctZSErecovered;
202  //std::cout << " ALCT SizeZSE : " << sizeInWord_ZSE << std::endl; ///to_rm
203  //std::cout << " ALCT SizeZSE Recovered: " << alctZSErecoveredPos << std::endl; ///to_rm
204  //std::cout << " ALCT Size Expected: " << theAnodeData->sizeInWords() << std::endl; ///to_rm
205  pos +=sizeInWord_ZSE;
206  }
207  else
208  {
209  //pos +=sizeInWord_ZSE;
211  pos += theAnodeData->sizeInWords(); // size of the data is determined during unpacking
212  }
213  //std::cout << " ****The ALCT information from CSCEventData.cc (end)**** " << std::endl; ///to_rm
214  theALCTTrailer = new CSCALCTTrailer( pos );
215  pos += theALCTTrailer->sizeInWords();
216  }
217  }
218  else
219  {
220  LogTrace ("CSCEventData|CSCRawToDigi") << "Error:nalct reported but no ALCT data found!!!";
221  }
222  }
223 
224  if (nclct() ==1)
225  {
226  if (isTMB(pos))
227  {
228  //dataPresent|=0x20;
229  theTMBData = new CSCTMBData(pos); //fill all TMB data
230  pos += theTMBData->size();
231  }
232  else
233  {
234  LogTrace ("CSCEventData|CSCRawToDigi") << "Error:nclct reported but no TMB data found!!!";
235  }
236  }
237 
238  //now let's try to find and unpack the DMBTrailer
239  bool dmbTrailerReached= false;
240  for (int i=0; i<12000; ++i) //8000 max for cfeb + 1980ALCT + 287 TMB
241  {
242  dmbTrailerReached =
243  (*(i+pos) & 0xF000) == 0xF000 && (*(i+pos+1) & 0xF000) == 0xF000
244  && (*(i+pos+2) & 0xF000) == 0xF000 && (*(i+pos+3) & 0xF000) == 0xF000
245  && (*(i+pos+4) & 0xF000) == 0xE000 && (*(i+pos+5) & 0xF000) == 0xE000
246  && (*(i+pos+6) & 0xF000) == 0xE000 && (*(i+pos+7) & 0xF000) == 0xE000;
247  if (dmbTrailerReached)
248  {
249  // theDMBTrailer = *( (CSCDMBTrailer *) (pos+i) );
251  break;
252  }
253  }
254  if (dmbTrailerReached)
255  {
256  for (int icfeb = 0; icfeb < MAX_CFEB; ++icfeb)
257  {
258  theCFEBData[icfeb] = 0;
259  int cfeb_available = theDMBHeader.cfebAvailable(icfeb);
260  unsigned int cfebTimeout = theDMBTrailer.cfeb_starttimeout() | theDMBTrailer.cfeb_endtimeout();
261  //cfeb_available cannot be trusted - need additional verification!
262  if ( cfeb_available==1 )
263  {
264  if ((cfebTimeout >> icfeb) & 1)
265  {
266  if (debug) LogTrace ("CSCEventData|CSCRawToDigi") << "CFEB Timed out! ";
267  }
268  else
269  {
270  //dataPresent|=(0x1>>icfeb);
271  // Fill CFEB data and convert it into cathode digis
272 
273  // Check if we have here DCFEB using DMB format version field (new ME11 with DCFEBs - 0x2, other chamber types 0x1)
274  bool isDCFEB = false;
275  if (theDMBHeader.format_version() == 2) isDCFEB = true;
276 
277  theCFEBData[icfeb] = new CSCCFEBData(icfeb, pos, theFormatVersion, isDCFEB);
278  pos += theCFEBData[icfeb]->sizeInWords();
279  }
280  }
281  }
282  pos += theDMBTrailer.sizeInWords();
283  size_ = pos-buf;
284  }
285  else
286  {
287  LogTrace ("CSCEventData|CSCRawToDigi") << "Critical Error: DMB Trailer was not found!!! ";
288  }
289 
290  // std::cout << "CSC format: " << theFormatVersion << " " << getFormatVersion() << std::endl;
291 }
292 
293 bool CSCEventData::isALCT(const short unsigned int * buf)
294 {
295  return (((buf[0]&0xFFFF)==0xDB0A)||(((buf[0]&0xF800)==0x6000)&&((buf[1]&0xF800)==0)));
296 }
297 
298 bool CSCEventData::isTMB(const short unsigned int * buf)
299 {
300  return ((buf[0]&0xFFF)==0xB0C);
301 }
302 
303 
304 
306 {
307  copy(data);
308 }
309 
311 {
312  destroy();
313 }
314 
315 
317 {
318  // check for self-assignment before destructing
319  if (&data != this) destroy();
320  copy(data);
321  return *this;
322 }
323 
324 
326 {
327  //dataPresent = 0;
328  theALCTHeader = 0;
329  theAnodeData = 0;
330  theALCTTrailer = 0;
331  theTMBData = 0;
332  for (int icfeb = 0; icfeb < MAX_CFEB; ++icfeb)
333  {
334  theCFEBData[icfeb] = 0;
335  }
337  zseEnable=0;
338 }
339 
340 
342 {
343  init();
345  theDMBHeader = data.theDMBHeader;
347  if (data.theALCTHeader != NULL)
349  if (data.theAnodeData != NULL)
350  theAnodeData = new CSCAnodeData(*(data.theAnodeData));
351  if (data.theALCTTrailer != NULL)
353  if (data.theTMBData != NULL)
354  theTMBData = new CSCTMBData(*(data.theTMBData));
355  for (int icfeb = 0; icfeb < MAX_CFEB; ++icfeb)
356  {
357  theCFEBData[icfeb] = 0;
358  if (data.theCFEBData[icfeb] != NULL)
359  theCFEBData[icfeb] = new CSCCFEBData(*(data.theCFEBData[icfeb]));
360  }
361  size_ = data.size_;
363 
364 
365 }
366 
367 
369 {
370  if (zseEnable)
371  {
372  delete [] alctZSErecovered;
373  }
374  delete theALCTHeader;
375  delete theAnodeData;
376  delete theALCTTrailer;
377  delete theTMBData;
378  for (int icfeb = 0; icfeb < MAX_CFEB; ++icfeb)
379  {
380  delete theCFEBData[icfeb];
381  }
382  /*
383  std::cout << "Before delete alctZSErecovered " << std::endl;
384  delete [] alctZSErecovered;
385  std::cout << "After delete alctZSErecovered " << std::endl;
386  */
387 }
388 
389 
390 std::vector<CSCStripDigi> CSCEventData::stripDigis(const CSCDetId & idlayer) const
391 {
392  std::vector<CSCStripDigi> result;
393  for (unsigned icfeb = 0; icfeb < MAX_CFEB; ++icfeb)
394  {
395  std::vector<CSCStripDigi> newDigis = stripDigis(idlayer, icfeb);
396  result.insert(result.end(), newDigis.begin(), newDigis.end());
397  }
398  return result;
399 }
400 
401 
402 std::vector<CSCStripDigi> CSCEventData::stripDigis(unsigned idlayer, unsigned icfeb) const
403 {
404  // assert(ilayer > 0 && ilayer <= 6); // off because now idlayer is raw cscdetid
405  std::vector<CSCStripDigi> result;
406  if (theCFEBData[icfeb] != NULL)
407  {
408  std::vector<CSCStripDigi> newDigis = theCFEBData[icfeb]->digis(idlayer);
409  result.insert(result.end(), newDigis.begin(), newDigis.end());
410  }
411 
412  return result;
413 }
414 
415 
416 std::vector<CSCWireDigi> CSCEventData::wireDigis(unsigned ilayer) const
417 {
418  if (theAnodeData == 0)
419  {
420  return std::vector<CSCWireDigi>();
421  }
422  else
423  {
424  return theAnodeData->wireDigis(ilayer);
425  }
426 }
427 
428 
429 std::vector < std::vector<CSCStripDigi> > CSCEventData::stripDigis() const
430 {
431  std::vector < std::vector<CSCStripDigi> > result;
432  for (int layer = 1; layer <= 6; ++layer)
433  {
434  std::vector<CSCStripDigi> digis = stripDigis(layer);
435  result.push_back(digis);
436  }
437  return result;
438 }
439 
440 std::vector < std::vector<CSCWireDigi> > CSCEventData::wireDigis() const
441 {
442  std::vector < std::vector<CSCWireDigi> > result;
443  for (int layer = 1; layer <= 6; ++layer)
444  {
445  result.push_back(wireDigis(layer));
446  }
447  return result;
448 }
449 
450 
451 CSCCFEBData* CSCEventData::cfebData(unsigned icfeb) const
452 {
453  return theCFEBData[icfeb];
454 }
455 
456 
458 {
459  if (nalct() == 0) throw cms::Exception("No ALCT for this chamber");
460  return theALCTHeader;
461 }
462 
464 {
465  if (nalct() == 0) throw cms::Exception("No ALCT for this chamber");
466  return theALCTTrailer;
467 }
468 
469 
471 {
472  if (nalct() == 0) throw cms::Exception("No ALCT for this chamber");
473  return theAnodeData;
474 }
475 
477 {
478  if (nclct() == 0) throw cms::Exception("No CLCT for this chamber");
479  return theTMBData;
480 }
481 
482 
484 {
485  if ((nclct() == 0)||(tmbData()==NULL)) throw cms::Exception("No CLCT header for this chamber");
486  return tmbData()->tmbHeader();
487 }
488 
490 {
491  if ((nclct() == 0)||(tmbData()==NULL)) throw cms::Exception("No CLCT data for this chamber");
492  return tmbData()->clctData();
493 }
494 
495 
496 void CSCEventData::setEventInformation(int bxnum, int lvl1num)
497 {
498  theDMBHeader.setBXN(bxnum);
499  theDMBHeader.setL1A(lvl1num);
500  theDMBHeader.setL1A24(lvl1num);
501  if (theALCTHeader)
502  {
504  }
505  if (theTMBData)
506  {
508 
509  assert(theChamberType>0);
510 
512 
513  // Set number of CFEBs to 7 for Post-LS1 ME11
514  if ((theFormatVersion == 2013) && ((theChamberType == 1) || (theChamberType == 2)) ) {
516  }
517 /*
518  // Set number of CFEBs to 4 for ME13 chambers
519  if (theChamberType == 4) {
520  theTMBData->tmbHeader()->setNCFEBs(4);
521  }
522 */
523 
524  }
525  for (unsigned cfeb=0; cfeb< 7; cfeb++)
526  {
527  if (theCFEBData[cfeb]) theCFEBData[cfeb]->setL1A(lvl1num);
528  }
529 }
530 
531 
533 {
534  if (theAnodeData == NULL)
535  {
536  assert(theChamberType>0);
542  // set data available flag
544  }
545 }
546 
547 
549 {
550  int nCFEBs = 5;
551  if ((theFormatVersion == 2013) && ((theChamberType == 1) || (theChamberType == 2)) ) {
552  nCFEBs = 7;
553  }
554  if (theTMBData == NULL)
555  {
556  if (theFormatVersion == 2013) { // Set to TMB format for Post-LS1 data
557  theTMBData = new CSCTMBData(2013, 0x7a76, nCFEBs);
558  } else {
559  theTMBData = new CSCTMBData(2007, 0x50c3);
560  }
563  }
564  theTMBData->tmbHeader()->setNCFEBs(nCFEBs);
565  // std::cout << "nCFEBs: " << theTMBData->tmbHeader()->NCFEBs() << std::endl;
566 }
567 
568 
569 void CSCEventData::add(const CSCStripDigi & digi, int layer)
570 {
571  //@@ need special logic here for ME11
572  unsigned cfeb = (digi.getStrip()-1)/16;
573  bool sixteenSamples = false;
574  if (digi.getADCCounts().size()==16) sixteenSamples = true;
575  if (theCFEBData[cfeb] == 0)
576  {
577  bool isDCFEB = false;
578  if (theDMBHeader.format_version() == 2) isDCFEB = true;
579  theCFEBData[cfeb] = new CSCCFEBData(cfeb, sixteenSamples, theFormatVersion, isDCFEB);
580  theDMBHeader.addCFEB(cfeb);
581  }
582  theCFEBData[cfeb]->add(digi, layer);
583 
584 
585 }
586 
587 
588 void CSCEventData::add(const CSCWireDigi & digi, int layer)
589 {
591  theAnodeData->add(digi, layer);
594 
595 }
596 
597 void CSCEventData::add(const CSCComparatorDigi & digi, int layer)
598 {
599  checkTMBClasses();
600  theTMBData->clctData()->add(digi, layer);
601 
602 }
603 
604 void CSCEventData::add(const CSCComparatorDigi & digi, const CSCDetId & cid)
605 {
606  checkTMBClasses();
607  theTMBData->clctData()->add(digi, cid);
608 
609 }
610 
611 
612 
613 void CSCEventData::add(const std::vector<CSCALCTDigi> & digis)
614 {
616  theALCTHeader->add(digis);
617 }
618 
619 
620 void CSCEventData::add(const std::vector<CSCCLCTDigi> & digis)
621 {
622  checkTMBClasses();
623  theTMBData->tmbHeader()->add(digis);
624 }
625 
626 void CSCEventData::add(const std::vector<CSCCorrelatedLCTDigi> & digis)
627 {
628  checkTMBClasses();
629  theTMBData->tmbHeader()->add(digis);
630 }
631 
632 
633 
634 
635 std::ostream & operator<<(std::ostream & os, const CSCEventData & evt)
636 {
637  for (int ilayer = 1; ilayer <= 6; ++ilayer)
638  {
639  std::vector<CSCStripDigi> stripDigis = evt.stripDigis(ilayer);
640  //copy(stripDigis.begin(), stripDigis.end(), std::ostream_iterator<CSCStripDigi>(os, "\n"));
641  //print your scas here
642  std::vector<CSCWireDigi> wireDigis = evt.wireDigis(ilayer);
643  //copy(wireDigis.begin(), wireDigis.end(), std::ostream_iterator<CSCWireDigi>(os, "\n"));
644  }
645  return os;
646 }
647 
648 boost::dynamic_bitset<> CSCEventData::pack()
649 {
650  boost::dynamic_bitset<> result = bitset_utilities::ushortToBitset( theDMBHeader.sizeInWords()*16,
651  theDMBHeader.data());
652 
653  // Container for CRC calculations
654  std::vector<std::pair<unsigned int, unsigned short*> > crcvec;
655 
656  if (theALCTHeader != NULL)
657  {
658  boost::dynamic_bitset<> alctHeader = theALCTHeader->pack();
659  result = bitset_utilities::append(result, alctHeader);
660  crcvec.push_back(std::make_pair(theALCTHeader->sizeInWords(), theALCTHeader->data()));
661  }
662  if (theAnodeData != NULL)
663  {
664  boost::dynamic_bitset<> anodeData = bitset_utilities::ushortToBitset (theAnodeData->sizeInWords()*16,
665  theAnodeData->data());
666  result = bitset_utilities::append(result, anodeData);
667  crcvec.push_back(std::make_pair(theAnodeData->sizeInWords(), theAnodeData->data()));
668 
669  }
670  if (theALCTTrailer != NULL)
671  {
672  unsigned int crc = calcALCTcrc(crcvec);
673  theALCTTrailer->setCRC(crc);
675  theALCTTrailer->data());
676  result = bitset_utilities::append(result, alctTrailer);
677 
678  }
679  if (theTMBData != NULL)
680  {
681  result = bitset_utilities::append(result, theTMBData->pack());
682  }
683 
684  for (int icfeb = 0; icfeb < MAX_CFEB; ++icfeb)
685  {
686  if (theCFEBData[icfeb] != NULL)
687  {
688  boost::dynamic_bitset<> cfebData = bitset_utilities::ushortToBitset(theCFEBData[icfeb]->sizeInWords()*16,
689  theCFEBData[icfeb]->data());
690  result = bitset_utilities::append(result, cfebData);
691  }
692  }
693 
695  theDMBTrailer.data());
696  result = bitset_utilities::append(result, dmbTrailer);
697  return result;
698 }
699 
700 unsigned int CSCEventData::calcALCTcrc(std::vector< std::pair<unsigned int, unsigned short*> > &vec)
701 {
702  int CRC=0;
703 // int size=0;
704 
705  for (unsigned int n = 0; n < vec.size(); n++)
706  {
707 // size += vec[n].first;
708  for (uint16_t j=0, w=0; j<vec[n].first; j++ )
709  {
710 
711  if (vec[n].second != NULL) {
712  w = vec[n].second[j] & 0xffff;
713  for (uint32_t i=15, t=0, ncrc=0; i<16; i--)
714  {
715  t = ((w >> i) & 1) ^ ((CRC >> 21) & 1);
716  ncrc = (CRC << 1) & 0x3ffffc;
717  ncrc |= (t ^ (CRC & 1)) << 1;
718  ncrc |= t;
719  CRC = ncrc;
720  }
721 
722  }
723 
724  }
725  }
726 
727  // std::cout << "ALCT CRC vector size: " << size << ", crc: 0x" << std::hex << CRC<< std::endl;
728  return CRC;
729 }
730 
731 
732 
734 {
735  CSCEventData chamberData(5);
736  CSCDetId detId(1, 3, 2, 1, 3);
737  std::vector<CSCCLCTDigi> clctDigis;
738  // Both CLCTs are read-out at the same (pre-trigger) bx, so the last-but-one
739  // arguments in both digis must be the same.
740  clctDigis.push_back(CSCCLCTDigi(1, 1, 4, 1, 0, 30, 3, 2, 1)); // valid for 2007
741  clctDigis.push_back(CSCCLCTDigi(1, 1, 2, 1, 1, 31, 1, 2, 2));
742 
743  // BX of LCT (8th argument) is 1-bit word (the least-significant bit
744  // of ALCT's bx).
745  std::vector<CSCCorrelatedLCTDigi> corrDigis;
746  corrDigis.push_back(CSCCorrelatedLCTDigi(1, 1, 2, 10, 98, 5, 0, 1, 0, 0, 0, 0));
747  corrDigis.push_back(CSCCorrelatedLCTDigi(2, 1, 2, 20, 15, 9, 1, 0, 0, 0, 0, 0));
748 
749  chamberData.add(clctDigis);
750  chamberData.add(corrDigis);
751 
752  CSCWireDigi wireDigi(10, 6);
753  CSCComparatorDigi comparatorDigi(30, 1, 6);
754  chamberData.add(wireDigi, 3);
755  chamberData.add(comparatorDigi, 3);
756 
757  CSCEventData newData = cscPackAndUnpack(chamberData);
758 
759  std::vector<CSCCLCTDigi> clcts = newData.tmbHeader()->CLCTDigis(detId.rawId());
760  assert(cscPackerCompare(clcts[0],clctDigis[0]));
761  assert(cscPackerCompare(clcts[1],clctDigis[1]));
762 
763  std::vector<CSCCorrelatedLCTDigi> lcts = newData.tmbHeader()->CorrelatedLCTDigis(detId.rawId());
764  assert(cscPackerCompare(lcts[0], corrDigis[0]));
765  assert(cscPackerCompare(lcts[1], corrDigis[1]));
766 
767  // test strip digis
768  CSCDetId me1adet1(1, 1, 1, 4, 1);
769  CSCDetId me1bdet1(1, 1, 4, 4, 6);
770  CSCDetId me1adet2(2, 1, 1, 4, 2);
771  CSCDetId me1bdet2(2, 1, 4, 4, 5);
772 
773  std::vector<int> sca(16, 600);
774  std::vector<unsigned short> overflow(16, 0), overlap(16, 0), errorfl(16,0);
775  CSCStripDigi me1a(5, sca, overflow, overlap, errorfl);
776  CSCStripDigi me1b(8, sca, overflow, overlap, errorfl);
777 
778  CSCEventData forward(1);
779  CSCEventData backward(1);
780 
781  forward.add(me1a, me1adet1.layer());
782  forward.add(me1b, me1bdet1.layer());
783  backward.add(me1a, me1adet2.layer());
784  backward.add(me1b, me1adet2.layer());
785  std::vector<CSCStripDigi> me1afs = forward.stripDigis(me1adet1);
786  std::vector<CSCStripDigi> me1bfs = forward.stripDigis(me1bdet1);
787  std::vector<CSCStripDigi> me1abs = backward.stripDigis(me1adet2);
788  std::vector<CSCStripDigi> me1bbs = backward.stripDigis(me1bdet2);
789  //FIXME The current code works under the assumption that ME11 and ME1A
790  // go into separate EventData. They need to be combined.
791  assert(me1afs.size() == 16);
792  assert(me1bfs.size() == 16);
793  assert(me1abs.size() == 16);
794  assert(me1bbs.size() == 16);
795 
796  assert(me1afs[4].getStrip() == 5);
797  assert(me1bfs[7].getStrip() == 8);
798  assert(me1abs[4].getStrip() == 5);
799  assert(me1bbs[7].getStrip() == 8);
800  assert(me1afs[4].pedestal() == 600);
801  assert(me1bfs[7].pedestal() == 600);
802  assert(me1abs[4].pedestal() == 600);
803  assert(me1bbs[7].pedestal() == 600);
804 
805 
806 }
void setEventInformation(const CSCDMBHeader &dmbHeader)
fills fields like bxn and l1a
Definition: CSCTMBHeader.h:33
void setEventInformation(int bxnum, int lvl1num)
CSCCLCTData * clctData()
Definition: CSCTMBData.h:43
bool isALCT(const short unsigned int *buf)
if dealing with ALCT data
bool check() const
Definition: CSCDMBHeader.h:62
unsigned short int sizeInWords() const
the amount of the input binary buffer read, in 16-bit words
Definition: CSCAnodeData.h:21
unsigned int calcALCTcrc(std::vector< std::pair< unsigned int, unsigned short * > > &vec)
unsigned short * alctZSErecovered
Auxiliary bufer to recove the ALCT raw payload from zero suppression.
Definition: CSCEventData.h:193
int nclct() const
the number of CLCTs
Definition: CSCEventData.h:93
uint16_t theFormatVersion
Output Format Version (2005, 2013)
Definition: CSCEventData.h:197
std::vector< std::vector< CSCStripDigi > > stripDigis() const
deprecated. Use the above methods instead
#define MAX_CFEB
Maximum available CFEBs per chamber (for old system 5, for new ME11 should be 7)
Definition: CSCEventData.h:40
void checkALCTClasses()
makes new ALCT classes, if needed
std::vector< std::vector< CSCWireDigi > > wireDigis() const
deprecated. Use the above method instead.
const double w
Definition: UKUtility.cc:23
boost::dynamic_bitset pack()
not const because it sets size int TMBTrailer
Definition: CSCTMBData.cc:433
std::vector< int > const & getADCCounts() const
Get ADC readings.
Definition: CSCStripDigi.h:54
unsigned cfeb_endtimeout() const
Definition: CSCDMBTrailer.h:42
void addNCLCT()
Definition: CSCDMBHeader.h:35
const CSCDMBTrailer * dmbTrailer() const
DMB trailer.
Definition: CSCEventData.h:118
void digis(uint32_t idlayer, std::vector< CSCStripDigi > &result)
faster way to get to digis
Definition: CSCCFEBData.cc:223
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
const unsigned short size() const
Definition: CSCTMBData.h:40
std::vector< CSCCorrelatedLCTDigi > CorrelatedLCTDigis(uint32_t idlayer) const
returns CorrelatedLCT digis
Definition: CSCTMBHeader.h:104
void checkTMBClasses()
makes new TMB classes, if needed
void add(const CSCStripDigi &, int layer)
Definition: CSCCFEBData.cc:85
void setL1A(unsigned l1a)
Definition: CSCCFEBData.cc:170
unsigned sizeInWords() const
Definition: CSCDMBTrailer.h:70
#define NULL
Definition: scimark2.h:8
void setBXNCount(unsigned int bxn)
Definition: CSCALCTHeader.h:78
void setL1A(int l1a)
Definition: CSCDMBHeader.h:39
bool check() const
void add(const std::vector< CSCCLCTDigi > &digis)
these methods need more brains to figure which one goes first
int layer() const
Definition: CSCDetId.h:61
CSCAnodeData * alctData() const
user must check if nalct > 0
void setEventInformation(const CSCDMBHeader &)
std::vector< CSCWireDigi > wireDigis(unsigned ilayer) const
CSCALCTHeader * alctHeader() const
user must check if nalct > 0
void setBXN(int bxn)
Definition: CSCDMBHeader.h:38
int nalct() const
the flag for existence of ALCT data
Definition: CSCEventData.h:90
int getStrip() const
Definition: CSCStripDigi.h:51
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
static int sizeInWords()
in 16-bit frames
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
CSCDMBHeader theDMBHeader
Definition: CSCEventData.h:172
void setNCFEBs(uint16_t ncfebs)
Definition: CSCTMBHeader.h:92
CSCCLCTData * clctData() const
user must check if nclct > 0
unsigned short * data()
Definition: CSCDMBTrailer.h:67
CSCTMBData * theTMBData
Definition: CSCEventData.h:180
CSCALCTTrailer * alctTrailer() const
user must check if nalct > 0
CSCALCTHeader * theALCTHeader
Definition: CSCEventData.h:177
unsigned cfeb_starttimeout() const
Definition: CSCDMBTrailer.h:46
std::vector< CSCStripDigi > stripDigis(const CSCDetId &idlayer) const
returns all the strip digis in the chamber, with the comparator information.
std::ostream & operator<<(std::ostream &os, const CSCEventData &evt)
CSCTMBData * tmbData() const
user must check in nclct > 0
void add(const CSCWireDigi &wireDigi, int layer)
Definition: CSCAnodeData.h:27
void add(const std::vector< CSCALCTDigi > &digis)
unsigned sizeInWords() const
Definition: CSCDMBHeader.h:59
boost::dynamic_bitset pack()
void addCFEB(int icfeb)
Definition: CSCDMBHeader.h:34
CSCDMBTrailer theDMBTrailer
Definition: CSCEventData.h:185
unsigned short * data()
void unpack_data(unsigned short *buf)
Definition: CSCEventData.cc:45
#define LogTrace(id)
CSCEventData operator=(const CSCEventData &data)
int sizeInWords()
in 16-bit words
std::vector< CSCALCTDigi > ALCTDigis() const
CSCCFEBData * theCFEBData[7]
for up to MAX_CFEB CFEB boards
Definition: CSCEventData.h:183
CSCALCTTrailer * theALCTTrailer
Definition: CSCEventData.h:179
unsigned format_version() const
Definition: CSCDMBHeader.h:60
bool isTMB(const short unsigned int *buf)
if dealing with TMB data
std::vector< CSCCLCTDigi > CLCTDigis(uint32_t idlayer)
returns CLCT digis
Definition: CSCTMBHeader.h:98
unsigned short * data()
Definition: CSCDMBHeader.h:64
unsigned short int alctFirmwareVersion() const
int getWireGroup() const
default
Definition: CSCWireDigi.h:24
void copy(const CSCEventData &)
void setL1A24(int l1a)
Definition: CSCDMBHeader.h:40
int getWireGroupBX() const
return BX assigned for the wire group (16 upper bits from the wire group number)
Definition: CSCWireDigi.h:26
std::vector< CSCWireDigi > wireDigis(int layer) const
input layer is from 1 to 6
Definition: CSCAnodeData.h:24
void add(const CSCComparatorDigi &digi, int layer)
TODO for packing. Doesn&#39;t do flipping yet.
Definition: CSCCLCTData.cc:222
unsigned sizeInWords() const
Definition: CSCCFEBData.h:47
unsigned short size() const
size of the data buffer used, in bytes
Definition: CSCEventData.h:55
bool cscPackerCompare(const T &t1, const T &t2)
void add(const CSCStripDigi &, int layer)
routines to add digis to the data
CSCTMBHeader * tmbHeader()
Definition: CSCTMBData.h:42
CSCTMBHeader * tmbHeader() const
user must check if nclct > 0
T cscPackAndUnpack(T &t)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
CSCCFEBData * cfebData(unsigned icfeb) const
unpacked in long mode: has overflow and error bits decoded
static std::atomic< bool > debug
Definition: CSCEventData.h:151
boost::dynamic_bitset ushortToBitset(const unsigned int numberOfBits, unsigned short *buf)
this method takes numberOfBits bits from unsigned short * array and returns them in the bitset obj...
boost::dynamic_bitset pack()
returns the packed event data.
void addNALCT()
Definition: CSCDMBHeader.h:37
void setDAVForChannel(int wireGroup)
unsigned short * data()
Definition: CSCAnodeData.h:19
bool cfebAvailable(unsigned icfeb)
Definition: CSCDMBHeader.h:29
void setCRC(unsigned int crc)
CSCAnodeData * theAnodeData
Definition: CSCEventData.h:178
unsigned short int * data()
static void selfTest()