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