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