CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCDDUEventData.cc
Go to the documentation of this file.
1 /* CSCDDUEventData.cc
2  * Modified 4/21/03 to get rid of arrays and store all CSC data
3  * in vectors.
4  * A.Tumanov
5  */
6 
9 
10 #include <iostream>
11 #include <cstdio>
12 
14 
15 bool CSCDDUEventData::debug = false;
16 uint32_t CSCDDUEventData::errMask = 0xFFFFFFFF;
17 
18 
20 {
22 }
23 
24 
25 CSCDDUEventData::CSCDDUEventData(uint16_t *buf, CSCDCCExaminer* examiner)
26 {
27  unpack_data(buf, examiner);
28 }
29 
31 {
32 }
33 
34 
35 void CSCDDUEventData::add(CSCEventData & cscData, int dmbId, int dduInput)
36 {
37  theDDUHeader.setDMBDAV(dduInput);
38  //@@ Tim: The following sets the word which is supposed to be CSCs in error, with bit 15 set for DMB Full
39  //@@ so I think sim should not set it at all
40  //@@ theDDUTrailer.setDMBDAV(dmbId);
41  cscData.dmbHeader()->setdmbID(dmbId);
43  theData.push_back(cscData);
44 }
45 
47 {
49 }
50 
51 void CSCDDUEventData::decodeStatus(int code) const
52 {
53  // JRG is Jason Gilmore
54  // JRG, low-order 16-bit status (most serious errors):
55  if((code&errMask)>0)
56  {
57  // JRG, low-order 16-bit status (most serious errors):
58  if((code&0x0000F000)>0)
59  {
60  if((0x00008000&code)>0)
61  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Critical Error, ** needs reset **";
62  if((0x00004000&code)>0)
63  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Single Error, bad event";
64  if((0x00002000&code)>0)
65  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Single Warning";
66  if((0x00001000&code)>0)
67  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Near Full Warning";
68  }
69  if((code&0x00000F00)>0)
70  {
71  if((0x00000800&code)>0)
72  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU 64-bit Alignment Error";
73  if((0x00000400&code)>0)
74  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Control DLL Error occured";
75  if((0x00000200&code)>0)
76  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU DMB Error occurred";
77  if((0x00000100&code)>0)
78  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Lost In Event Error";
79  }
80  if((code&0x000000F0)>0)
81  {
82  if((0x00000080&code)>0)
83  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Lost In Data Error occurred";
84  if((0x00000040&code)>0)
85  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Timeout Error";
86  if((0x00000020&code)>0)
87  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " TMB or ALCT CRC Error";
88  if((0x00000010&code)>0)
89  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Multiple Transmit Errors";
90  }
91  if((code&0x0000000F)>0)
92  {
93  if((0x00000008&code)>0)
94  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Sync Lost or FIFO Full Error";
95  if((0x00000004&code)>0)
96  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Fiber/FIFO Connection Error";
97  if((0x00000002&code)>0)
98  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU L1A Match Error";
99  if((0x00000001&code)>0)
100  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU DMB or CFEB CRC Error";
101  }
102  if((code&0xF0000000)>0)
103  {
104  // JRG, high-order 16-bit status (not-so-serious errors):
105  if((0x80000000&code)>0)
106  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU DMB LCT/DAV/Movlp Mismatch";
107  if((0x40000000&code)>0)
108  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU-CFEB L1 Mismatch";
109  if((0x20000000&code)>0)
110  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU saw no good DMB CRCs";
111  if((0x10000000&code)>0)
112  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU CFEB Count Error";
113  }
114  if((code&0x0F000000)>0)
115  {
116  if((0x08000000&code)>0)
117  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU FirstDat Error";
118  if((0x04000000&code)>0)
119  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU L1A-FIFO Full Error";
120  if((0x02000000&code)>0)
121  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Data Stuck in FIFO";
122  if((0x01000000&code)>0)
123  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU NoLiveFibers Error";
124  }
125  if((code&0x00F00000)>0)
126  {
127  if((0x00800000&code)>0)
128  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Spwd single-bit Warning";
129  if((0x00400000&code)>0)
130  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Input FPGA Error";
131  if((0x00200000&code)>0)
132  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU DAQ Stop bit set";
133  if((0x00100000&code)>0)
134  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU DAQ says Not Ready";
135  if((0x00300000&code)==0x00200000)
136  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU DAQ Applied Backpressure";
137  }
138  if((code&0x000F0000)>0)
139  {
140  if((0x00080000&code)>0)
141  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU TMB Error";
142  if((0x00040000&code)>0)
143  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU ALCT Error";
144  if((0x00020000&code)>0)
145  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Trigger Readout Wordcount Error";
146  if((0x00010000&code)>0)
147  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " DDU Trigger L1A Match Error";
148  }
149  }
150 }
151 
152 void CSCDDUEventData::unpack_data(uint16_t *buf, CSCDCCExaminer* examiner)
153 {
154  // just to calculate length
155  uint16_t * inputBuf = buf;
156  uint16_t * inputBuf0 = buf;
157  theData.clear();
158  if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << "CSCDDUEventData::unpack_data() is called";
159  if (debug)
160  for (int i=0;i<6;++i)
161  {
162  LogTrace ("CSCDDUEventData|CSCRawToDigi") << i << std::hex << buf[4*i+3] << buf[4*i+2]
163  << buf[4*i+1] << buf[4*i];
164  std::cout << i << " " << std::hex << buf[4*i+3] << " " << buf[4*i+2] << " "
165  << buf[4*i+1] << " " << buf[4*i] << std::endl;
166  }
167  //std::cout << "DDU Size: " << std::dec << theDDUHeader.sizeInWords() << std::endl;
168 
169  memcpy(&theDDUHeader, buf, theDDUHeader.sizeInWords()*2);
170 
171  if (debug) {
172  LogTrace ("CSCDDUEventData|CSCRawToDigi") << "size of ddu header in words = " << theDDUHeader.sizeInWords();
173  LogTrace ("CSCDDUEventData|CSCRawToDigi") << "sizeof(DDUHeader) = " << sizeof(theDDUHeader);
174  }
175  buf += theDDUHeader.sizeInWords();
176 
177 
178 
179 
180  //std::cout << "sandrik dduID =" << theDDUHeader.source_id() << std::endl;
181  //int i=-1;
182 
183 
184  // we really don't want to copy CSCEventData's while filling the vec
185  theData.clear();
186  theData.reserve(theDDUHeader.ncsc());
187 
188  if (examiner!= NULL) { // Use selective unpacking mode
189 
190  if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << "selective unpacking starting";
191 
192  // Find this DDU in examiner's DDUs list
193  DDUIdType dduID = theDDUHeader.source_id();
194 
195  std::map<DDUIdType,std::map<CSCIdType,const uint16_t*> > ddus = examiner->DMB_block();
196  std::map<DDUIdType,std::map<CSCIdType,const uint16_t*> >::iterator ddu_itr = ddus.find(dduID);
197  uint16_t* dduBlock = (uint16_t*)((examiner->DDU_block())[dduID]);
198  uint32_t dduBufSize = (examiner->DDU_size())[dduID];
199 
200  if (ddu_itr != ddus.end() && dduBufSize!=0 && dduBlock==inputBuf) {
201  std::map<CSCIdType,const uint16_t*> &cscs = ddu_itr->second;
202  std::map<CSCIdType,const uint16_t*>::iterator csc_itr;
203 
204  for (csc_itr=cscs.begin(); csc_itr != cscs.end(); ++csc_itr) {
205  short cscid = csc_itr->first;
206 
207  if(cscid != -1)
208  {
209  uint16_t* pos = (uint16_t*)csc_itr->second;
210 
211 
212  ExaminerStatusType errors = examiner->errorsForChamber(cscid);
213  if ((errors & examiner->getMask()) > 0 ) {
214  if (debug)
215  LogTrace ("CSCDDUEventData|CSCRawToDigi" )
216  << "skip unpacking of CSC " << cscid << " due format errors: 0x" << std::hex << errors << std::dec;
217  continue;
218  }
219 
220  theData.push_back(CSCEventData(pos));
221  }
222  }
223 
224  if (debug)
225  {
226  LogTrace ("CSCDDUEventData|CSCRawToDigi") << "size of vector of cscData = " << theData.size();
227  }
228  // std::cout << std::dec << theDDUTrailer.sizeInWords() << std::endl;
229  // decode ddu tail
230  memcpy(&theDDUTrailer, inputBuf+dduBufSize, theDDUTrailer.sizeInWords()*2);
231  // memcpy(&theDDUTrailer, dduBlock+(dduBufSize-theDDUTrailer.sizeInWords())*2, theDDUTrailer.sizeInWords()*2);
232  if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << theDDUTrailer.check();
234  if ((errorstat&errMask) != 0)
235  {
236  if (theDDUTrailer.check())
237  {
238  if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi")
239  << "+++ CSCDDUEventData warning: DDU Trailer errors = " << std::hex << errorstat << " +++ ";
240  if (debug) decodeStatus(errorstat);
241  }
242  else
243  {
244  if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi" )
245  << " Unpacking lost DDU trailer - check() failed and 8 8 ffff 8 was not found ";
246  }
247  }
248 
249  if (debug) {
250  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " Final errorstat " << std::hex << errorstat << std::dec ;
251  }
252  // the trailer counts in 64-bit words
253 
254  // theSizeInWords = dduBufSize;
255  // buf=inputBuf+dduBufSize;
256 
257  }
258  theSizeInWords = dduBufSize+12;
259  buf=inputBuf+dduBufSize;
260 
261  } else {
262 
263 
264  while( (((buf[0]&0xf000) == 0x9000)||((buf[0]&0xf000) == 0xa000))
265  && (buf[3] != 0x8000)) {
266  // ++i;
267  if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << "unpack csc data loop started";
268  theData.push_back(CSCEventData(buf));
269  buf += (theData.back()).size();
270  if (debug) {
271  LogTrace ("CSCDDUEventData|CSCRawToDigi") << "size of vector of cscData = " << theData.size();
272  }
273  }
274 
275  if (debug) {
276  LogTrace ("CSCDDUEventData|CSCRawToDigi") << "unpacking ddu trailer ";
277  LogTrace ("CSCDDUEventData|CSCRawToDigi") << std::hex << buf[3]<<" " << buf[2]
278  <<" " << buf[1]<<" " << buf[0];
279  }
280 
281  // decode ddu tail
282  memcpy(&theDDUTrailer, buf, theDDUTrailer.sizeInWords()*2);
283  if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << theDDUTrailer.check();
285  if ((errorstat&errMask) != 0)
286  {
287  if (theDDUTrailer.check())
288  {
289  if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi")
290  << "+++ CSCDDUEventData warning: DDU Trailer errors = " << std::hex << errorstat << " +++ ";
291  if (debug) decodeStatus(errorstat);
292  }
293  else
294  {
295  if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi" )
296  << " Unpacking lost DDU trailer - check() failed and 8 8 ffff 8 was not found ";
297  }
298  }
299 
300  if (debug)
301  LogTrace ("CSCDDUEventData|CSCRawToDigi") << " Final errorstat " << std::hex << errorstat << std::dec ;
302  // the trailer counts in 64-bit words
303  buf += theDDUTrailer.sizeInWords();
304 
305  theSizeInWords = buf - inputBuf;
306  }
307 
308 //std::cout << "DDUevData Size: " << theSizeInWords << " BUFlast: " << std::hex << inputBuf0[theSizeInWords-4] << //std::endl;
310 theDDUTrailer0 = inputBuf0[theSizeInWords-4];
311 }
312 
313 
315 {
316  // the trailer counts in 64-bit words
317  if (debug)
318  {
319  LogTrace ("CSCDDUEventData|CSCRawToDigi") << sizeInWords();
320  LogTrace ("CSCDDUEventData|CSCRawToDigi") << "wordcount = " << theDDUTrailer.wordcount()*4;
321  }
322 
323  return theDDUHeader.check() && theDDUTrailer.check();
324 }
325 
326 boost::dynamic_bitset<> CSCDDUEventData::pack()
327 {
328  boost::dynamic_bitset<> result = bitset_utilities::ushortToBitset( theDDUHeader.sizeInWords()*16,
329  theDDUHeader.data());
330  //std::cout <<"SANDRIK inside DDUEvdata check = ";
331  //theDDUHeader.check();
332  //std::cout <<std::endl;
333  //std::cout <<"printing out ddu header words"<<std::endl;
334  //for (unsigned int i=0;i<theDDUHeader.sizeInWords();i++) {
335  // unsigned short * buf = theDDUHeader.data();
336  // printf("%04x %04x %04x %04x\n",buf[i+3],buf[i+2],buf[i+1],buf[i]);
337  // i+=3;
338  //}
339  //std::cout <<"printing out ddu header words via bitset"<<std::endl;
340  //bitset_utilities::printWords(result);
341 
342  for(unsigned int i = 0; i < theData.size(); ++i)
343  {
344  result = bitset_utilities::append(result,theData[i].pack());
345  }
346  theSizeInWords = result.size()/16 + theDDUTrailer.sizeInWords();
347  // 64-bit word count
349  boost::dynamic_bitset<> dduTrailer = bitset_utilities::ushortToBitset ( theDDUTrailer.sizeInWords()*16,
350  theDDUTrailer.data());
351  result = bitset_utilities::append(result,dduTrailer);
352 
353  return result;
354 }
355 
void setEventInformation(int bxnum, int lvl1num)
CSCDDUEventData(const CSCDDUHeader &)
void unpack_data(unsigned short *buf, CSCDCCExaminer *examiner=NULL)
a good test routine would be to unpack data, then pack it again.
int i
Definition: DBlmapReader.cc:9
CSCDDUHeader header() const
bool check() const
Definition: CSCDDUHeader.cc:48
void setDMBDAV(int dduInput)
Definition: CSCDDUHeader.cc:31
static unsigned sizeInWords()
Definition: CSCDDUTrailer.h:28
CSCDDUHeader theDDUHeader
int lvl1num() const
Definition: CSCDDUHeader.h:23
void setWordCount(unsigned wordcount)
Definition: CSCDDUTrailer.h:43
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 errorstat() const
Definition: CSCDDUTrailer.h:41
ExaminerStatusType errorsForChamber(CSCIdType chamber) const
#define NULL
Definition: scimark2.h:8
int bxnum() const
Definition: CSCDDUHeader.h:22
std::map< DDUIdType, std::map< CSCIdType, const uint16_t * > > DMB_block(void) const
unsigned short * data()
Definition: CSCDDUTrailer.h:37
static bool debug
tuple result
Definition: query.py:137
void add(CSCEventData &, int dmbId, int dduInput)
for making events. Sets the bxnum and lvl1num inside the chamber event
bool check() const
Definition: CSCDDUTrailer.h:30
static unsigned int errMask
std::map< DDUIdType, uint32_t > DDU_size(void) const
#define LogTrace(id)
std::map< DDUIdType, const uint16_t * > DDU_block(void) const
ExaminerMaskType getMask() const
uint16_t theDDUTrailer0
uint32_t ExaminerStatusType
int size() const
static unsigned sizeInWords()
Definition: CSCDDUHeader.h:31
int16_t DDUIdType
std::vector< CSCEventData > theData
unsigned wordcount() const
Definition: CSCDDUTrailer.h:42
tuple cout
Definition: gather_cfg.py:121
int ncsc() const
Definition: CSCDDUHeader.h:25
int source_id() const
Definition: CSCDDUHeader.h:21
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
void decodeStatus() const
CSCDDUTrailer theDDUTrailer
unsigned short * data()
Definition: CSCDDUHeader.h:33
const CSCDMBHeader * dmbHeader() const
the DAQ motherboard header. A good place for event and chamber info
Definition: CSCEventData.h:90
void setdmbID(int newDMBID)
Definition: CSCDMBHeader.h:29
long unsigned int errorstat
trailer info
boost::dynamic_bitset pack()
Alex check this 16 or 64.
int sizeInWords() const