CMS 3D CMS Logo

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