CMS 3D CMS Logo

CSCDCCEventData.cc
Go to the documentation of this file.
1 
11 #include <iostream>
12 #include <cstdio>
14 
15 #ifdef LOCAL_UNPACK
16 bool CSCDCCEventData::debug = false;
17 #else
18 #include <atomic>
19 std::atomic<bool> CSCDCCEventData::debug{false};
20 #endif
21 
22 CSCDCCEventData::CSCDCCEventData(int sourceId, int nDDUs, int bx, int l1a) : theDCCHeader(bx, l1a, sourceId) {
23  theDDUData.reserve(nDDUs);
24 }
25 
26 CSCDCCEventData::CSCDCCEventData(const uint16_t* buf, CSCDCCExaminer* examiner) { unpack_data(buf, examiner); }
27 
29 
30 void CSCDCCEventData::unpack_data(const uint16_t* buf, CSCDCCExaminer* examiner) {
31  /*
32  for (int i=0;i<20;i++) {
33  printf("%04x %04x %04x %04x\n",buf[i+3],buf[i+2],buf[i+1],buf[i]);
34  i+=3;
35  }
36 */
37 
38  theDDUData.clear();
39  if (debug)
40  LogTrace("CSCDCCEventData|CSCRawToDigi") << "CSCDCCEventData::unpack_data() is called";
41 
42  // decode DCC header (128 bits)
43  if (debug)
44  LogTrace("CSCDCCEventData|CSCRawToDigi") << "unpacking dcc header...";
46  //theDCCHeader = CSCDCCHeader(buf); // direct unpacking instead of bitfields
47  buf += theDCCHeader.sizeInWords();
48 
49  //std::cout <<"Sandrik DCC Id = " << theDCCHeader.getCDFSourceId() << std::endl;
50 
52  while ((buf[7] == 0x8000) && (buf[6] == 0x0001) && (buf[5] == 0x8000)) {
53  CSCDDUEventData dduEventData(buf, examiner);
54  // CSCDDUEventData dduEventData(buf);
55 
56  if (debug)
57  LogTrace("CSCDCCEventData|CSCRawToDigi") << " checking ddu data integrity ";
58  if (dduEventData.check()) {
59  theDDUData.push_back(dduEventData);
60  buf += dduEventData.sizeInWords();
61  } else {
62  if (debug)
63  LogTrace("CSCDCCEventData|CSCRawToDigi") << "DDU Data Check failed! ";
64  break;
65  }
66  }
67 
68  if (debug) {
69  LogTrace("CSCDCCEventData|CSCRawToDigi") << "unpacking dcc trailer ";
70  LogTrace("CSCDCCEventData|CSCRawToDigi") << std::hex << buf[3] << " " << buf[2] << " " << buf[1] << " " << buf[0];
71  }
72 
73  //decode dcc trailer (128 bits)
74  if (debug)
75  LogTrace("CSCDCCEventData|CSCRawToDigi") << "decoding DCC trailer";
77  if (debug)
78  LogTrace("CSCDCCEventData|CSCRawToDigi") << "checking DDU Trailer" << theDCCTrailer.check();
79 
80  // buf += theDCCTrailer.sizeInWords(); /* =VB= Commented out to please static analyzer */
81 
82  //std::cout << " DCC Size: " << std::dec << theSizeInWords << std::endl;
83  //std::cout << "LastBuf: " << std::hex << inputBuf[theSizeInWords-4] << std::endl;
84 }
85 
86 bool CSCDCCEventData::check() const {
87  // the trailer counts in 64-bit words
88  if (debug) {
89  LogTrace("CSCDCCEventData|CSCRawToDigi") << "size in Words () = " << std::dec << sizeInWords();
90  }
91 
92  return theDCCHeader.check() && theDCCTrailer.check();
93 }
94 
96  CSCEventData& chamber, int dduID, int dduSlot, int dduInput, int dmbID, uint16_t format_version) {
97  // first, find this DDU
98  int dduIndex = -1;
99  int nDDUs = theDDUData.size();
100  for (int i = 0; dduIndex == -1 && i < nDDUs; ++i) {
101  if (theDDUData[i].header().source_id() == dduID)
102  dduIndex = i;
103  }
104 
106  unsigned ddu_fmt_version = 0x6; // 2005 Format
107  if (format_version == 2013)
108  ddu_fmt_version = 0x7;
109 
110  if (dduIndex == -1) {
111  // make a new one
112  CSCDDUHeader newDDUHeader(
113  dccHeader().getCDFBunchCounter(), dccHeader().getCDFEventNumber(), dduID, ddu_fmt_version);
114  theDDUData.push_back(CSCDDUEventData(newDDUHeader));
115  dduIndex = nDDUs;
116  dccHeader().setDAV(dduSlot);
117  }
118  theDDUData[dduIndex].add(chamber, dmbID, dduInput, format_version);
119 }
120 
121 boost::dynamic_bitset<> CSCDCCEventData::pack() {
122  boost::dynamic_bitset<> result(theDCCHeader.sizeInWords() * 16);
124  //std::cout <<"SANDRIK DCC size of header in words"<< theDCCHeader.sizeInWords()*16 <<std::endl;
125  //std::cout <<"SANDRIK DCC size of header in bits"<< result.size()<<std::endl;
126  //for(size_t i = 0; i < result.size(); ++i) {
127  // std::cout<<result[i];
128  // if (((i+1)%32)==0) std::cout<<std::endl;
129  //}
130 
131  for (size_t i = 0; i < theDDUData.size(); ++i) {
132  result = bitset_utilities::append(result, theDDUData[i].pack());
133  //std::cout <<"SANDRIK here is ddu data check ";
134  //theDDUData[i].header().check();
135  //std::cout <<std::endl;
136  //bitset_utilities::printWords(result);
137  }
138 
139  //std::cout <<"SANDRIK packed dcc size is "<<result.size()<<std::endl;
140  //for(size_t i = 0; i < result.size(); ++i) {
141  // std::cout<<result[i];
142  // if (((i+1)%32)==0) std::cout<<std::endl;
143  //}
144 
145  boost::dynamic_bitset<> dccTrailer =
147  result = bitset_utilities::append(result, dccTrailer);
148  // bitset_utilities::printWords(result);
149  return result;
150 }
bool check() const
for making events. Sets the bxnum and lvl1num inside the chamber event
bool check() const
Definition: CSCDCCTrailer.h:48
CSCDCCHeader theDCCHeader
int sizeInWords() const
void setDAV(int dduSlot)
Definition: CSCDCCHeader.cc:28
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 short * data()
Definition: CSCDCCTrailer.h:49
void setFromBuffer(uint16_t const *buf)
Definition: CSCDCCHeader.h:19
CSCDCCTrailer theDCCTrailer
CSCDCCTrailer dccTrailer() const
boost::dynamic_bitset pack()
packs data into bits
static std::atomic< bool > debug
CSCDCCHeader dccHeader() const
std::vector< CSCDDUEventData > theDDUData
bool check() const
Definition: CSCDCCHeader.h:27
#define LogTrace(id)
void addChamber(CSCEventData &chamber, int dduID, int dduSlot, int dduInput, int dmbID, uint16_t format_version=2005)
CSCDCCEventData(int sourceId, int nDDUs, int bx, int l1a)
static unsigned sizeInWords()
Definition: CSCDCCHeader.h:29
void setFromBuffer(uint16_t const *buf)
Definition: CSCDCCTrailer.h:24
static unsigned sizeInWords()
Definition: CSCDCCTrailer.h:46
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...
void unpack_data(const uint16_t *buf, CSCDCCExaminer *examiner=0)
bool check() const
unsigned short * data()
Definition: CSCDCCHeader.h:28
int sizeInWords() const