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