CMS 3D CMS Logo

CSCEventData.cc
Go to the documentation of this file.
9 #include <iostream>
10 #include <iterator>
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(nullptr),
21  theAnodeData(nullptr),
22  theALCTTrailer(nullptr),
23  theTMBData(nullptr),
24  theDMBTrailer(format_version),
25  theChamberType(chamberType),
26  alctZSErecovered(nullptr),
27  zseEnable(0),
28  theFormatVersion(format_version) {
29  for (unsigned i = 0; i < CSCConstants::MAX_CFEBS_RUN2; ++i) {
30  theCFEBData[i] = nullptr;
31  }
32 }
33 
34 CSCEventData::CSCEventData(const uint16_t* buf, uint16_t format_version) : theFormatVersion(format_version) {
35  theFormatVersion = format_version;
37 }
38 
39 void CSCEventData::unpack_data(const uint16_t* buf) {
40  // zero everything
41  init();
42  const uint16_t* pos = buf;
43  if (debug) {
44  LogTrace("CSCEventData|CSCRawToDigi") << "The event data ";
45  for (int i = 0; i < 16; ++i) {
46  LogTrace("CSCEventData|CSCRawToDigi") << std::hex << pos[i] << " ";
47  }
48  }
49 
51  if (!(theDMBHeader.check())) {
52  LogTrace("CSCEventData|CSCRawToDigi") << "Bad DMB Header??? "
53  << " first four words: ";
54  for (int i = 0; i < 4; ++i) {
55  LogTrace("CSCEventData|CSCRawToDigi") << std::hex << pos[i] << " ";
56  }
57  }
58 
59  if (debug) {
60  LogTrace("CSCEventData|CSCRawToDigi") << "nalct = " << nalct();
61  LogTrace("CSCEventData|CSCRawToDigi") << "nclct = " << nclct();
62  }
63 
64  if (debug) {
65  LogTrace("CSCEventData|CSCRawToDigi") << "size in words of DMBHeader" << theDMBHeader.sizeInWords();
66  LogTrace("CSCEventData|CSCRawToDigi") << "sizeof(DMBHeader)" << sizeof(theDMBHeader);
67  }
68 
70 
71  if (nalct() == 1) {
72  if (isALCT(pos)) //checking for ALCTData
73  {
75  if (!theALCTHeader->check()) {
76  LogTrace("CSCEventData|CSCRawToDigi") << "+++WARNING: Corrupt ALCT data - won't attempt to decode";
77  } else {
78  //dataPresent|=0x40;
79  pos += theALCTHeader->sizeInWords(); //size of the header
80  //fill ALCT Digis
82 
83  //theAnodeData = new CSCAnodeData(*theALCTHeader, pos);
84 
86  /*
87  std::cout << " ****The ALCT information from CSCEventData.cc (begin)**** " << std::endl; ///to_rm
88  std::cout << " alctHeader2007().size: " << theALCTHeader->alctHeader2007().sizeInWords() << std::endl; ///to_rm
89  std::cout << " ALCT Header Content: " << std::endl; ///to_rm
91  for(int k=0; k<theALCTHeader->sizeInWords(); k+=4){
92  std::cout << std::hex << theALCTHeader->data()[k+3]
93  << " " << theALCTHeader->data()[k+2]
94  << " " << theALCTHeader->data()[k+1]
95  << " " << theALCTHeader->data()[k] << std::dec << std::endl;
96  }
97  */
98  //std::cout << " ALCT Size: " << theAnodeData->sizeInWords() << std::endl;
100  // int zseEnable = 0;
101  zseEnable = (theALCTHeader->data()[5] & 0x1000) >> 12;
102  //std::cout << " ZSE Bit: " << zseEnable << std::endl; /// to_rm
103  int sizeInWord_ZSE = 0;
104 
105  //alctZSErecovered = new unsigned short [theAnodeData->sizeInWords()];
106 
107  if (zseEnable) {
110  int nWGs_per_layer = ((theALCTHeader->data()[6] & 0x0007) + 1) * 16;
112  int nWG_round_up = int(nWGs_per_layer / 12) + (nWGs_per_layer % 3 ? 1 : 0);
113  //std::cout << " Words per layer: " << nWG_round_up << std::endl; ///to_rm
114  const uint16_t* posZSE = pos;
115  std::vector<unsigned short> alctZSErecoveredVector;
116  alctZSErecoveredVector.clear();
117 
118  //alctZSErecovered = new unsigned short [theAnodeData->sizeInWords()];
119  //delete [] alctZSErecovered;
120  //std::cout << " ALCT Buffer with ZSE: " << std::endl; ///to_rm
124  //unsigned short * posZSEdebug = pos; ///to_rm
125 
127  /*
128  while (*posZSEdebug != 0xDE0D){
129  unsigned short d = *posZSEdebug;
130  unsigned short c = *(posZSEdebug+1);
131  unsigned short b = *(posZSEdebug+2);
132  unsigned short a = *(posZSEdebug+3);
133  posZSEdebug+=4;
134  std::cout << std::hex << a << " " << b << " " << c << " " << d << std::dec << std::endl;
135  }
136  */
138 
140  while (*posZSE != 0xDE0D) {
141  if ((*posZSE == 0x1000) && (*posZSE != 0x3000)) {
142  for (int j = 0; j < nWG_round_up; j++) {
143  alctZSErecoveredVector.push_back(0x0000);
144  }
145  } else {
146  alctZSErecoveredVector.push_back(*posZSE);
147  }
148  posZSE++;
149  sizeInWord_ZSE++;
150  }
151 
152  alctZSErecovered = new unsigned short[alctZSErecoveredVector.size()];
153 
155  for (int l = 0; l < (int)alctZSErecoveredVector.size(); l++) {
156  alctZSErecovered[l] = alctZSErecoveredVector[l];
157  }
158 
159  unsigned short* posRecovered = alctZSErecovered;
160  theAnodeData = new CSCAnodeData(*theALCTHeader, posRecovered);
161 
164  /*
165  std::cout << " The ALCT payload recovered: " << std::endl;
166  for(int k=0; k<theAnodeData->sizeInWords(); k+=4){
167  std::cout << std::hex << alctZSErecovered[k+3] << " "
168  << alctZSErecovered[k+2] << " "
169  << alctZSErecovered[k+1] << " "
170  << alctZSErecovered[k] << std::dec << std::endl;
171  }
172  */
173  //delete [] alctZSErecovered;
174  //std::cout << " ALCT SizeZSE : " << sizeInWord_ZSE << std::endl; ///to_rm
175  //std::cout << " ALCT Size Expected: " << theAnodeData->sizeInWords() << std::endl; ///to_rm
176  pos += sizeInWord_ZSE;
177  } else {
178  //pos +=sizeInWord_ZSE;
180  pos += theAnodeData->sizeInWords(); // size of the data is determined during unpacking
181  }
182  //std::cout << " ****The ALCT information from CSCEventData.cc (end)**** " << std::endl; ///to_rm
185  }
186  } else {
187  LogTrace("CSCEventData|CSCRawToDigi") << "Error:nalct reported but no ALCT data found!!!";
188  }
189  }
190 
191  if (nclct() == 1) {
192  if (isTMB(pos)) {
193  //dataPresent|=0x20;
194  theTMBData = new CSCTMBData(pos); //fill all TMB data
195  pos += theTMBData->size();
196  } else {
197  LogTrace("CSCEventData|CSCRawToDigi") << "Error:nclct reported but no TMB data found!!!";
198  }
199  }
200 
201  //now let's try to find and unpack the DMBTrailer
202  bool dmbTrailerReached = false;
203  for (int i = 0; i < 12000; ++i) //8000 max for cfeb + 1980ALCT + 287 TMB
204  {
205  dmbTrailerReached = (*(i + pos) & 0xF000) == 0xF000 && (*(i + pos + 1) & 0xF000) == 0xF000 &&
206  (*(i + pos + 2) & 0xF000) == 0xF000 && (*(i + pos + 3) & 0xF000) == 0xF000 &&
207  (*(i + pos + 4) & 0xF000) == 0xE000 && (*(i + pos + 5) & 0xF000) == 0xE000 &&
208  (*(i + pos + 6) & 0xF000) == 0xE000 && (*(i + pos + 7) & 0xF000) == 0xE000;
209  if (dmbTrailerReached) {
210  // theDMBTrailer = *( (CSCDMBTrailer *) (pos+i) );
212  break;
213  }
214  }
215  if (dmbTrailerReached) {
216  for (int icfeb = 0; icfeb < CSCConstants::MAX_CFEBS_RUN2; ++icfeb) {
217  theCFEBData[icfeb] = nullptr;
218  int cfeb_available = theDMBHeader.cfebAvailable(icfeb);
219  unsigned int cfebTimeout = theDMBTrailer.cfeb_starttimeout() | theDMBTrailer.cfeb_endtimeout();
220  //cfeb_available cannot be trusted - need additional verification!
221  if (cfeb_available == 1) {
222  if ((cfebTimeout >> icfeb) & 1) {
223  if (debug)
224  LogTrace("CSCEventData|CSCRawToDigi") << "CFEB Timed out! ";
225  } else {
226  //dataPresent|=(0x1>>icfeb);
227  // Fill CFEB data and convert it into cathode digis
228 
229  // Check if we have here DCFEB using DMB format version field (new ME11 with DCFEBs - 0x2, other chamber types 0x1)
230  bool isDCFEB = false;
231  if (theDMBHeader.format_version() == 2)
232  isDCFEB = true;
233 
234  theCFEBData[icfeb] = new CSCCFEBData(icfeb, pos, theFormatVersion, isDCFEB);
235  pos += theCFEBData[icfeb]->sizeInWords();
236  }
237  }
238  }
240  size_ = pos - buf;
241  } else {
242  LogTrace("CSCEventData|CSCRawToDigi") << "Critical Error: DMB Trailer was not found!!! ";
243  }
244 
245  // std::cout << "CSC format: " << theFormatVersion << " " << getFormatVersion() << std::endl;
246 }
247 
248 bool CSCEventData::isALCT(const short unsigned int* buf) {
249  return (((buf[0] & 0xFFFF) == 0xDB0A) || (((buf[0] & 0xF800) == 0x6000) && ((buf[1] & 0xF800) == 0)));
250 }
251 
252 bool CSCEventData::isTMB(const short unsigned int* buf) { return ((buf[0] & 0xFFF) == 0xB0C); }
253 
255 
257 
259  // check for self-assignment before destructing
260  if (&data != this)
261  destroy();
262  copy(data);
263  return *this;
264 }
265 
267  //dataPresent = 0;
268  theALCTHeader = nullptr;
269  theAnodeData = nullptr;
270  theALCTTrailer = nullptr;
271  theTMBData = nullptr;
272  for (int icfeb = 0; icfeb < CSCConstants::MAX_CFEBS_RUN2; ++icfeb) {
273  theCFEBData[icfeb] = nullptr;
274  }
275  alctZSErecovered = nullptr;
276  zseEnable = 0;
277 }
278 
280  init();
281  theFormatVersion = data.theFormatVersion;
282  theDMBHeader = data.theDMBHeader;
283  theDMBTrailer = data.theDMBTrailer;
284  if (data.theALCTHeader != nullptr)
285  theALCTHeader = new CSCALCTHeader(*(data.theALCTHeader));
286  if (data.theAnodeData != nullptr)
287  theAnodeData = new CSCAnodeData(*(data.theAnodeData));
288  if (data.theALCTTrailer != nullptr)
289  theALCTTrailer = new CSCALCTTrailer(*(data.theALCTTrailer));
290  if (data.theTMBData != nullptr)
291  theTMBData = new CSCTMBData(*(data.theTMBData));
292  for (int icfeb = 0; icfeb < CSCConstants::MAX_CFEBS_RUN2; ++icfeb) {
293  theCFEBData[icfeb] = nullptr;
294  if (data.theCFEBData[icfeb] != nullptr)
295  theCFEBData[icfeb] = new CSCCFEBData(*(data.theCFEBData[icfeb]));
296  }
297  size_ = data.size_;
298  theChamberType = data.theChamberType;
299 }
300 
302  if (zseEnable) {
303  delete[] alctZSErecovered;
304  }
305  delete theALCTHeader;
306  delete theAnodeData;
307  delete theALCTTrailer;
308  delete theTMBData;
309  for (int icfeb = 0; icfeb < CSCConstants::MAX_CFEBS_RUN2; ++icfeb) {
310  delete theCFEBData[icfeb];
311  }
312  /*
313  std::cout << "Before delete alctZSErecovered " << std::endl;
314  delete [] alctZSErecovered;
315  std::cout << "After delete alctZSErecovered " << std::endl;
316  */
317 }
318 
319 std::vector<CSCStripDigi> CSCEventData::stripDigis(const CSCDetId& idlayer) const {
320  std::vector<CSCStripDigi> result;
321  for (unsigned icfeb = 0; icfeb < CSCConstants::MAX_CFEBS_RUN2; ++icfeb) {
322  std::vector<CSCStripDigi> newDigis = stripDigis(idlayer, icfeb);
323  result.insert(result.end(), newDigis.begin(), newDigis.end());
324  }
325  return result;
326 }
327 
328 std::vector<CSCStripDigi> CSCEventData::stripDigis(unsigned idlayer, unsigned icfeb) const {
329  std::vector<CSCStripDigi> result;
330  if (theCFEBData[icfeb] != nullptr) {
331  std::vector<CSCStripDigi> newDigis = theCFEBData[icfeb]->digis(idlayer);
332  result.insert(result.end(), newDigis.begin(), newDigis.end());
333  }
334 
335  return result;
336 }
337 
338 std::vector<CSCWireDigi> CSCEventData::wireDigis(unsigned ilayer) const {
339  if (theAnodeData == nullptr) {
340  return std::vector<CSCWireDigi>();
341  } else {
342  return theAnodeData->wireDigis(ilayer);
343  }
344 }
345 
346 std::vector<std::vector<CSCStripDigi> > CSCEventData::stripDigis() const {
347  std::vector<std::vector<CSCStripDigi> > result;
349  std::vector<CSCStripDigi> digis = stripDigis(layer);
350  result.push_back(digis);
351  }
352  return result;
353 }
354 
355 std::vector<std::vector<CSCWireDigi> > CSCEventData::wireDigis() const {
356  std::vector<std::vector<CSCWireDigi> > result;
358  result.push_back(wireDigis(layer));
359  }
360  return result;
361 }
362 
363 const CSCCFEBData* CSCEventData::cfebData(unsigned icfeb) const { return theCFEBData[icfeb]; }
364 
366  if (nalct() == 0)
367  throw cms::Exception("No ALCT for this chamber");
368  return theALCTHeader;
369 }
370 
372  if (nalct() == 0)
373  throw cms::Exception("No ALCT for this chamber");
374  return theALCTTrailer;
375 }
376 
378  if (nalct() == 0)
379  throw cms::Exception("No ALCT for this chamber");
380  return theAnodeData;
381 }
382 
384  if (nclct() == 0)
385  throw cms::Exception("No CLCT for this chamber");
386  return theTMBData;
387 }
388 
390  if ((nclct() == 0) || (tmbData() == nullptr))
391  throw cms::Exception("No CLCT header for this chamber");
392  return tmbData()->tmbHeader();
393 }
394 
396  if ((nclct() == 0) || (tmbData() == nullptr))
397  throw cms::Exception("No CLCT data for this chamber");
398  return tmbData()->comparatorData();
399 }
400 
401 void CSCEventData::setEventInformation(int bxnum, int lvl1num) {
402  theDMBHeader.setBXN(bxnum);
403  theDMBHeader.setL1A(lvl1num);
404  theDMBHeader.setL1A24(lvl1num);
405  if (theALCTHeader) {
407  }
408  if (theTMBData) {
410 
411  assert(theChamberType > 0);
412 
414 
415  // Set number of CFEBs to 7 for Post-LS1 ME11
416  if ((theFormatVersion >= 2013) && ((theChamberType == 1) || (theChamberType == 2))) {
418  }
419  }
420  for (unsigned cfeb = 0; cfeb < CSCConstants::MAX_CFEBS_RUN2; cfeb++) {
421  if (theCFEBData[cfeb])
422  theCFEBData[cfeb]->setL1A(lvl1num);
423  }
424 }
425 
427  if (theAnodeData == nullptr) {
428  assert(theChamberType > 0);
434  // set data available flag
436  }
437 }
438 
440  int nCFEBs = CSCConstants::MAX_CFEBS_RUN1;
441  if ((theFormatVersion >= 2013) && ((theChamberType == 1) || (theChamberType == 2))) {
443  }
444  if (theTMBData == nullptr) {
445  if (theFormatVersion == 2013) { // Set to TMB format for Post-LS1/Run2 data
446  theTMBData = new CSCTMBData(2013, 0x7a76, nCFEBs);
447  } else if (theFormatVersion == 2020) { // Set to TMB format for Run3 data
448  if ((theChamberType == 1) || (theChamberType == 2)) {
449  theTMBData = new CSCTMBData(2020, 0x602, nCFEBs); // ME11 GEM fw
450  } else {
451  theTMBData = new CSCTMBData(2020, 0x403); // MEx1 CCLUT fw
452  }
453  } else {
454  theTMBData = new CSCTMBData(2007, 0x50c3);
455  }
458  }
459  theTMBData->tmbHeader()->setNCFEBs(nCFEBs);
460 }
461 
462 void CSCEventData::add(const CSCStripDigi& digi, int layer) {
463  //@@ need special logic here for ME11
464  unsigned cfeb = digi.getCFEB();
465  bool sixteenSamples = false;
466  if (digi.getADCCounts().size() == 16)
467  sixteenSamples = true;
468  if (theCFEBData[cfeb] == nullptr) {
469  bool isDCFEB = false;
470  if (theDMBHeader.format_version() == 2)
471  isDCFEB = true;
472  theCFEBData[cfeb] = new CSCCFEBData(cfeb, sixteenSamples, theFormatVersion, isDCFEB);
473  theDMBHeader.addCFEB(cfeb);
474  }
475  theCFEBData[cfeb]->add(digi, layer);
476 }
477 
478 void CSCEventData::add(const CSCWireDigi& digi, int layer) {
480  theAnodeData->add(digi, layer);
483 }
484 
485 void CSCEventData::add(const CSCComparatorDigi& digi, int layer) {
486  checkTMBClasses();
487  theTMBData->comparatorData()->add(digi, layer);
488 }
489 
490 void CSCEventData::add(const CSCComparatorDigi& digi, const CSCDetId& cid) {
491  checkTMBClasses();
492  theTMBData->comparatorData()->add(digi, cid);
493 }
494 
495 void CSCEventData::add(const std::vector<CSCALCTDigi>& digis) {
497  theALCTHeader->add(digis);
498 }
499 
500 void CSCEventData::add(const std::vector<CSCCLCTDigi>& digis) {
501  checkTMBClasses();
502  theTMBData->tmbHeader()->add(digis);
503 }
504 
505 void CSCEventData::add(const std::vector<CSCCorrelatedLCTDigi>& digis) {
506  checkTMBClasses();
507  theTMBData->tmbHeader()->add(digis);
508 }
509 
511 void CSCEventData::addShower(const std::vector<CSCShowerDigi>& digis) {
512  checkTMBClasses();
513  for (auto it : digis) {
515  }
516 }
517 
519 void CSCEventData::addAnodeShower(const std::vector<CSCShowerDigi>& digis) {
520  checkTMBClasses();
521  for (auto it : digis) {
523  }
524 }
525 
527 void CSCEventData::addCathodeShower(const std::vector<CSCShowerDigi>& digis) {
528  checkTMBClasses();
529  for (auto it : digis) {
531  }
532 }
533 
535 void CSCEventData::addAnodeALCTShower(const std::vector<CSCShowerDigi>& digis) {
537  theALCTHeader->addShower(digis);
538 }
539 
541 void CSCEventData::add(const std::vector<GEMPadDigiCluster>& clusters, const GEMDetId& gemdetid) {
542  checkTMBClasses();
543  if (theTMBData->hasGEM()) {
544  int gem_layer = gemdetid.layer();
545  int eta_roll = gemdetid.roll();
546  for (const auto& it : clusters) {
547  if (it.isValid())
548  theTMBData->tmbHeader()->setALCTMatchTime(it.alctMatchTime());
549  theTMBData->gemData()->addEtaPadCluster(it, gem_layer - 1, 8 - eta_roll);
550  }
551  }
552 }
553 
554 std::ostream& operator<<(std::ostream& os, const CSCEventData& evt) {
555  for (int ilayer = CSCDetId::minLayerId(); ilayer <= CSCDetId::maxLayerId(); ++ilayer) {
556  std::vector<CSCStripDigi> stripDigis = evt.stripDigis(ilayer);
557  //copy(stripDigis.begin(), stripDigis.end(), std::ostream_iterator<CSCStripDigi>(os, "\n"));
558  //print your scas here
559  std::vector<CSCWireDigi> wireDigis = evt.wireDigis(ilayer);
560  //copy(wireDigis.begin(), wireDigis.end(), std::ostream_iterator<CSCWireDigi>(os, "\n"));
561  }
562  return os;
563 }
564 
565 boost::dynamic_bitset<> CSCEventData::pack() {
566  boost::dynamic_bitset<> result =
568 
569  // Container for CRC calculations
570  std::vector<std::pair<unsigned int, unsigned short*> > crcvec;
571 
572  if (theALCTHeader != nullptr) {
573  boost::dynamic_bitset<> alctHeader = theALCTHeader->pack();
575  crcvec.push_back(std::make_pair(theALCTHeader->sizeInWords(), theALCTHeader->data()));
576  }
577  if (theAnodeData != nullptr) {
578  boost::dynamic_bitset<> anodeData =
580  result = bitset_utilities::append(result, anodeData);
581  crcvec.push_back(std::make_pair(theAnodeData->sizeInWords(), theAnodeData->data()));
582  }
583  if (theALCTTrailer != nullptr) {
584  unsigned int crc = calcALCTcrc(crcvec);
585  theALCTTrailer->setCRC(crc);
586  boost::dynamic_bitset<> alctTrailer =
589  }
590  if (theTMBData != nullptr) {
592  }
593 
594  for (int icfeb = 0; icfeb < CSCConstants::MAX_CFEBS_RUN2; ++icfeb) {
595  if (theCFEBData[icfeb] != nullptr) {
596  boost::dynamic_bitset<> cfebData =
597  bitset_utilities::ushortToBitset(theCFEBData[icfeb]->sizeInWords() * 16, theCFEBData[icfeb]->data());
599  }
600  }
601 
602  boost::dynamic_bitset<> dmbTrailer =
605  return result;
606 }
607 
608 unsigned int CSCEventData::calcALCTcrc(std::vector<std::pair<unsigned int, unsigned short*> >& vec) {
609  int CRC = 0;
610 
611  for (unsigned int n = 0; n < vec.size(); n++) {
612  for (uint16_t j = 0, w = 0; j < vec[n].first; j++) {
613  if (vec[n].second != nullptr) {
614  w = vec[n].second[j] & 0xffff;
615  for (uint32_t i = 15, t = 0, ncrc = 0; i < 16; i--) {
616  t = ((w >> i) & 1) ^ ((CRC >> 21) & 1);
617  ncrc = (CRC << 1) & 0x3ffffc;
618  ncrc |= (t ^ (CRC & 1)) << 1;
619  ncrc |= t;
620  CRC = ncrc;
621  }
622  }
623  }
624  }
625 
626  return CRC;
627 }
628 
630  CSCEventData chamberData(5);
631  CSCDetId detId(1, 3, 2, 1, 3);
632  std::vector<CSCCLCTDigi> clctDigis;
633  // Both CLCTs are read-out at the same (pre-trigger) bx, so the last-but-one
634  // arguments in both digis must be the same.
635  clctDigis.push_back(CSCCLCTDigi(1, 1, 4, 1, 0, 30, 3, 2, 1)); // valid for 2007
636  clctDigis.push_back(CSCCLCTDigi(1, 1, 2, 1, 1, 31, 1, 2, 2));
637 
638  // BX of LCT (8th argument) is 1-bit word (the least-significant bit
639  // of ALCT's bx).
640  std::vector<CSCCorrelatedLCTDigi> corrDigis;
641  corrDigis.push_back(CSCCorrelatedLCTDigi(1, 1, 2, 10, 98, 5, 0, 1, 0, 0, 0, 0));
642  corrDigis.push_back(CSCCorrelatedLCTDigi(2, 1, 2, 20, 15, 9, 1, 0, 0, 0, 0, 0));
643 
644  chamberData.add(clctDigis);
645  chamberData.add(corrDigis);
646 
647  CSCWireDigi wireDigi(10, 6);
648  CSCComparatorDigi comparatorDigi(30, 1, 6);
649  chamberData.add(wireDigi, 3);
650  chamberData.add(comparatorDigi, 3);
651 
652  CSCEventData newData = cscPackAndUnpack(chamberData);
653 
654  std::vector<CSCCLCTDigi> clcts = newData.tmbHeader()->CLCTDigis(detId.rawId());
655  assert(cscPackerCompare(clcts[0], clctDigis[0]));
656  assert(cscPackerCompare(clcts[1], clctDigis[1]));
657 
658  std::vector<CSCCorrelatedLCTDigi> lcts = newData.tmbHeader()->CorrelatedLCTDigis(detId.rawId());
659  assert(cscPackerCompare(lcts[0], corrDigis[0]));
660  assert(cscPackerCompare(lcts[1], corrDigis[1]));
661 
662  // test strip digis
663  CSCDetId me1adet1(1, 1, 1, 4, 1);
664  CSCDetId me1bdet1(1, 1, 4, 4, 6);
665  CSCDetId me1adet2(2, 1, 1, 4, 2);
666  CSCDetId me1bdet2(2, 1, 4, 4, 5);
667 
668  std::vector<int> sca(16, 600);
669  std::vector<unsigned short> overflow(16, 0), overlap(16, 0), errorfl(16, 0);
670  CSCStripDigi me1a(5, sca, overflow, overlap, errorfl);
671  CSCStripDigi me1b(8, sca, overflow, overlap, errorfl);
672 
673  CSCEventData forward(1);
674  CSCEventData backward(1);
675 
676  forward.add(me1a, me1adet1.layer());
677  forward.add(me1b, me1bdet1.layer());
678  backward.add(me1a, me1adet2.layer());
679  backward.add(me1b, me1adet2.layer());
680  std::vector<CSCStripDigi> me1afs = forward.stripDigis(me1adet1);
681  std::vector<CSCStripDigi> me1bfs = forward.stripDigis(me1bdet1);
682  std::vector<CSCStripDigi> me1abs = backward.stripDigis(me1adet2);
683  std::vector<CSCStripDigi> me1bbs = backward.stripDigis(me1bdet2);
684  //FIXME The current code works under the assumption that ME11 and ME1A
685  // go into separate EventData. They need to be combined.
686  assert(me1afs.size() == 16);
687  assert(me1bfs.size() == 16);
688  assert(me1abs.size() == 16);
689  assert(me1bbs.size() == 16);
690 
691  assert(me1afs[4].getStrip() == 5);
692  assert(me1bfs[7].getStrip() == 8);
693  assert(me1abs[4].getStrip() == 5);
694  assert(me1bbs[7].getStrip() == 8);
695  assert(me1afs[4].pedestal() == 600);
696  assert(me1bfs[7].pedestal() == 600);
697  assert(me1abs[4].pedestal() == 600);
698  assert(me1bbs[7].pedestal() == 600);
699 }
void unpack_data(const uint16_t *buf)
Definition: CSCEventData.cc:39
void setEventInformation(const CSCDMBHeader &dmbHeader)
fills fields like bxn and l1a
Definition: CSCTMBHeader.h:38
void setEventInformation(int bxnum, int lvl1num)
unsigned short * alctZSErecovered
Auxiliary bufer to recove the ALCT raw payload from zero suppression.
Definition: CSCEventData.h:175
CSCGEMData * gemData()
Definition: CSCTMBData.cc:409
uint16_t theFormatVersion
Output Format Version (2005, 2013)
Definition: CSCEventData.h:179
void addEtaPadCluster(const GEMPadDigiCluster &digi, int gem_chamber, int eta_roll)
Add and pack GEMPadDigiCluster digis.
Definition: CSCGEMData.cc:191
void checkALCTClasses()
makes new ALCT classes, if needed
CSCCFEBData * theCFEBData[CSCConstants::MAX_CFEBS_RUN2]
for up to MAX_CFEB CFEB boards
Definition: CSCEventData.h:165
boost::dynamic_bitset pack()
not const because it sets size int TMBTrailer
Definition: CSCTMBData.cc:444
void addNCLCT()
Definition: CSCDMBHeader.h:24
unsigned sizeInWords() const
Definition: CSCCFEBData.h:46
T w() const
bool check() const
unsigned cfeb_starttimeout() const
Definition: CSCDMBTrailer.h:37
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 ...
unsigned sizeInWords() const
Definition: CSCDMBTrailer.h:61
void checkTMBClasses()
makes new TMB classes, if needed
void add(const CSCStripDigi &, int layer)
Definition: CSCCFEBData.cc:82
void setL1A(unsigned l1a)
Definition: CSCCFEBData.cc:159
CSCAnodeData * alctData() const
user must check if nalct > 0
unsigned short size() const
size of the data buffer used, in bytes
Definition: CSCEventData.h:39
const CSCCFEBData * cfebData(unsigned icfeb) const
unpacked in long mode: has overflow and error bits decoded
void setBXNCount(unsigned int bxn)
Definition: CSCALCTHeader.h:79
void setL1A(int l1a)
Definition: CSCDMBHeader.h:28
int layer() const
Definition: CSCDetId.h:56
void add(const std::vector< CSCCLCTDigi > &digis)
these methods need more brains to figure which one goes first
unsigned short int sizeInWords() const
the amount of the input binary buffer read, in 16-bit words
Definition: CSCAnodeData.h:18
constexpr int layer() const
Definition: GEMDetId.h:190
std::vector< CSCStripDigi > stripDigis(const CSCDetId &idlayer) const
returns all the strip digis in the chamber, with the comparator information.
assert(be >=bs)
void setEventInformation(const CSCDMBHeader &)
int getWireGroupBX() const
return BX assigned for the wire group (16 upper bits from the wire group number)
Definition: CSCWireDigi.h:24
void setBXN(int bxn)
Definition: CSCDMBHeader.h:27
#define LogTrace(id)
void addAnodeShower(const std::vector< CSCShowerDigi > &)
Add/pack anode CSCShower object (from OTMB header)
const unsigned short size() const
Definition: CSCTMBData.h:38
static int sizeInWords()
in 16-bit frames
CSCComparatorData * comparatorData() const
user must check if nclct > 0
void addAnodeALCTShower(const std::vector< CSCShowerDigi > &)
Add/pack anode CSCShower objects (from ALCT board data)
bool isALCT(const uint16_t *buf)
if dealing with ALCT data
U second(std::pair< T, U > const &p)
unsigned cfeb_endtimeout() const
Definition: CSCDMBTrailer.h:33
CSCDMBHeader theDMBHeader
Definition: CSCEventData.h:154
void setNCFEBs(uint16_t ncfebs)
Definition: CSCTMBHeader.h:76
unsigned short * data()
Definition: CSCDMBTrailer.h:58
CSCTMBData * theTMBData
Definition: CSCEventData.h:162
int nalct() const
the flag for existence of ALCT data
Definition: CSCEventData.h:67
void addShower(const std::vector< CSCShowerDigi > &)
Run3 CSC Shower HMT objects.
CSCALCTHeader * theALCTHeader
Definition: CSCEventData.h:159
std::ostream & operator<<(std::ostream &os, const CSCEventData &evt)
void addCathodeShower(const CSCShowerDigi &digi)
Definition: CSCTMBHeader.h:134
std::vector< CSCWireDigi > wireDigis(int layer) const
input layer is from 1 to 6
Definition: CSCAnodeData.h:21
void add(const CSCWireDigi &wireDigi, int layer)
Definition: CSCAnodeData.h:24
const CSCDMBTrailer * dmbTrailer() const
DMB trailer.
Definition: CSCEventData.h:95
void add(const std::vector< CSCALCTDigi > &digis)
boost::dynamic_bitset pack()
void addCFEB(int icfeb)
Definition: CSCDMBHeader.h:23
CSCDMBTrailer theDMBTrailer
Definition: CSCEventData.h:167
void addShower(const CSCShowerDigi &digi)
Definition: CSCTMBHeader.h:130
unsigned short * data()
unsigned format_version() const
Definition: CSCDMBHeader.h:49
CSCEventData operator=(const CSCEventData &data)
int sizeInWords()
in 16-bit words
void addAnodeShower(const CSCShowerDigi &digi)
Definition: CSCTMBHeader.h:132
CSCALCTTrailer * theALCTTrailer
Definition: CSCEventData.h:161
std::vector< CSCCLCTDigi > CLCTDigis(uint32_t idlayer)
returns CLCT digis
Definition: CSCTMBHeader.h:102
unsigned short * data()
Definition: CSCDMBHeader.h:53
static int minLayerId()
Definition: CSCDetId.h:242
unsigned sizeInWords() const
Definition: CSCDMBHeader.h:48
unsigned short int alctFirmwareVersion() const
CSCComparatorData * comparatorData()
Definition: CSCTMBData.h:41
void copy(const CSCEventData &)
void setL1A24(int l1a)
Definition: CSCDMBHeader.h:29
void add(const CSCComparatorDigi &digi, int layer)
TODO for packing. Doesn&#39;t do flipping yet.
bool isTMB(const uint16_t *buf)
if dealing with TMB data
void digis(uint32_t idlayer, std::vector< CSCStripDigi > &result) const
faster way to get to digis
Definition: CSCCFEBData.cc:202
std::vector< std::vector< CSCStripDigi > > stripDigis() const
deprecated. Use the above methods instead
bool cscPackerCompare(const T &t1, const T &t2)
CSCALCTTrailer * alctTrailer() const
user must check if nalct > 0
void add(const CSCStripDigi &, int layer)
routines to add digis to the data
CSCTMBHeader * tmbHeader()
Definition: CSCTMBData.h:40
int getCFEB() const
Get the CFEB number. Counts from 0.
Definition: CSCStripDigi.cc:25
int nclct() const
the number of CLCTs
Definition: CSCEventData.h:70
T cscPackAndUnpack(T &t)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
constexpr int roll() const
Definition: GEMDetId.h:194
std::vector< CSCALCTDigi > ALCTDigis() const
bool check() const
Definition: CSCDMBHeader.h:51
bool hasGEM() const
Definition: CSCTMBData.h:55
static std::atomic< bool > debug
Definition: CSCEventData.h:133
CSCALCTHeader * alctHeader() const
user must check if nalct > 0
CSCTMBData * tmbData() const
user must check in nclct > 0
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.
std::vector< CSCWireDigi > wireDigis(unsigned ilayer) const
std::vector< std::vector< CSCWireDigi > > wireDigis() const
deprecated. Use the above method instead.
void addShower(const std::vector< CSCShowerDigi > &digis)
Add Run3 ALCT HMT shower bits.
void addNALCT()
Definition: CSCDMBHeader.h:26
void setALCTMatchTime(uint16_t alctmatchtime)
Definition: CSCTMBHeader.h:45
void setDAVForChannel(int wireGroup)
std::vector< CSCCorrelatedLCTDigi > CorrelatedLCTDigis(uint32_t idlayer) const
returns CorrelatedLCT digis
Definition: CSCTMBHeader.h:105
void addCathodeShower(const std::vector< CSCShowerDigi > &)
Add/pack cathode CSCShower object (from OTMB header)
static int maxLayerId()
Definition: CSCDetId.h:243
unsigned short * data()
Definition: CSCAnodeData.h:16
bool cfebAvailable(unsigned icfeb)
Definition: CSCDMBHeader.h:21
unsigned int calcALCTcrc(std::vector< std::pair< unsigned int, unsigned short *> > &vec)
CSCTMBHeader * tmbHeader() const
user must check if nclct > 0
void setCRC(unsigned int crc)
std::vector< int > const & getADCCounts() const
Get ADC readings.
Definition: CSCStripDigi.h:47
int getWireGroup() const
default
Definition: CSCWireDigi.h:22
CSCAnodeData * theAnodeData
Definition: CSCEventData.h:160
unsigned short int * data()
static void selfTest()