CMS 3D CMS Logo

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