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