CMS 3D CMS Logo

CSCDDUEventData.cc

Go to the documentation of this file.
00001 /* CSCDDUEventData.cc
00002  * Modified 4/21/03 to get rid of arrays and store all CSC data 
00003  * in vectors. 
00004  * A.Tumanov
00005  */
00006 
00007 #include "EventFilter/CSCRawToDigi/interface/CSCDDUEventData.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 
00010 #include <iostream>
00011 #include <cstdio>
00012 
00013 #include "EventFilter/CSCRawToDigi/src/bitset_append.h"
00014 
00015 bool CSCDDUEventData::debug = false;
00016 unsigned int CSCDDUEventData::errMask = 0xFFFFFFFF;
00017 
00018 
00019 CSCDDUEventData::CSCDDUEventData(const CSCDDUHeader & header) 
00020 {
00021   theDDUHeader = header;
00022 }
00023 
00024   
00025 CSCDDUEventData::CSCDDUEventData(unsigned short *buf, CSCDCCExaminer* examiner) 
00026 {
00027   unpack_data(buf, examiner);
00028 }
00029 
00030 CSCDDUEventData::~CSCDDUEventData() 
00031 {
00032 }
00033 
00034 
00035 void CSCDDUEventData::add(CSCEventData & cscData, int dmbId) 
00036 {
00037   theDDUHeader.setDMBDAV(dmbId);
00038   theDDUTrailer.setDMBDAV(dmbId);
00039   cscData.dmbHeader()->setdmbID(dmbId);
00040   cscData.setEventInformation(theDDUHeader.bxnum(), theDDUHeader.lvl1num());
00041   theData.push_back(cscData);
00042 }
00043 
00044 void CSCDDUEventData::decodeStatus() const 
00045 {
00046   this->decodeStatus(theDDUTrailer.errorstat());
00047 }
00048 
00049 void CSCDDUEventData::decodeStatus(int code) const 
00050 {
00051   // JRG is Jason Gilmore
00052   // JRG, low-order 16-bit status (most serious errors):
00053   if((code&errMask)>0)
00054     {
00055       // JRG, low-order 16-bit status (most serious errors):
00056       if((code&0x0000F000)>0)
00057         {
00058           if((0x00008000&code)>0)
00059             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Critical Error, ** needs reset **";
00060           if((0x00004000&code)>0)
00061             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Single Error, bad event";
00062           if((0x00002000&code)>0)
00063             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Single Warning";
00064           if((0x00001000&code)>0)
00065             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Near Full Warning";
00066         }
00067       if((code&0x00000F00)>0)
00068         {
00069           if((0x00000800&code)>0) 
00070             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU 64-bit Alignment Error";
00071           if((0x00000400&code)>0)
00072             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Control DLL Error occured";
00073           if((0x00000200&code)>0)
00074             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU DMB Error occurred";
00075           if((0x00000100&code)>0)
00076             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Lost In Event Error";
00077         }
00078       if((code&0x000000F0)>0)
00079         {
00080           if((0x00000080&code)>0)
00081             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Lost In Data Error occurred";
00082           if((0x00000040&code)>0)
00083             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Timeout Error";
00084           if((0x00000020&code)>0)
00085             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   TMB or ALCT CRC Error";
00086           if((0x00000010&code)>0)
00087             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Multiple Transmit Errors";
00088         }
00089       if((code&0x0000000F)>0)
00090         {
00091           if((0x00000008&code)>0)
00092             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Sync Lost or FIFO Full Error";
00093           if((0x00000004&code)>0)
00094             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Fiber/FIFO Connection Error";
00095           if((0x00000002&code)>0)
00096             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU L1A Match Error";
00097           if((0x00000001&code)>0)
00098             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU DMB or CFEB CRC Error";
00099         }
00100       if((code&0xF0000000)>0)
00101         {
00102           // JRG, high-order 16-bit status (not-so-serious errors):
00103           if((0x80000000&code)>0)
00104             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU DMB LCT/DAV/Movlp Mismatch";
00105           if((0x40000000&code)>0)
00106             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU-CFEB L1 Mismatch";
00107           if((0x20000000&code)>0)
00108             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU saw no good DMB CRCs";
00109           if((0x10000000&code)>0)
00110             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU CFEB Count Error";
00111         }
00112       if((code&0x0F000000)>0)
00113         {
00114           if((0x08000000&code)>0)
00115             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU FirstDat Error";
00116           if((0x04000000&code)>0)
00117             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU L1A-FIFO Full Error";
00118           if((0x02000000&code)>0)
00119             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Data Stuck in FIFO";
00120           if((0x01000000&code)>0)
00121             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU NoLiveFibers Error";
00122         }
00123       if((code&0x00F00000)>0)
00124         {
00125           if((0x00800000&code)>0)
00126             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Spwd single-bit Warning";
00127           if((0x00400000&code)>0)
00128             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Input FPGA Error";
00129           if((0x00200000&code)>0)
00130             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU DAQ Stop bit set";
00131           if((0x00100000&code)>0)
00132             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU DAQ says Not Ready";
00133           if((0x00300000&code)==0x00200000)
00134             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU DAQ Applied Backpressure";
00135         }
00136       if((code&0x000F0000)>0)
00137         {
00138           if((0x00080000&code)>0)
00139             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU TMB Error";
00140           if((0x00040000&code)>0)
00141             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU ALCT Error";
00142           if((0x00020000&code)>0)
00143             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Trigger Readout Wordcount Error";
00144           if((0x00010000&code)>0)
00145             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "   DDU Trigger L1A Match Error";
00146         }
00147     }
00148 }
00149 
00150 void CSCDDUEventData::unpack_data(unsigned short *buf, CSCDCCExaminer* examiner) 
00151 {
00152   // just to calculate length
00153   unsigned short * inputBuf = buf;
00154   theData.clear();
00155   if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << "CSCDDUEventData::unpack_data() is called";
00156   if (debug) for (int i=0;i<4;++i) 
00157     {
00158       LogTrace ("CSCDDUEventData|CSCRawToDigi") << i << std::hex << buf[4*i+3] << buf[4*i+2] 
00159                                                 << buf[4*i+1] << buf[4*i];
00160     }
00161 
00162   memcpy(&theDDUHeader, buf, theDDUHeader.sizeInWords()*2);
00163   
00164   if (debug) {
00165     LogTrace ("CSCDDUEventData|CSCRawToDigi") << "size of ddu header in words = " << theDDUHeader.sizeInWords();
00166     LogTrace ("CSCDDUEventData|CSCRawToDigi") << "sizeof(DDUHeader) = " << sizeof(theDDUHeader);
00167   }
00168   buf += theDDUHeader.sizeInWords();
00169 
00170 
00171 
00172 
00173   //std::cout << "sandrik dduID =" << theDDUHeader.source_id() << std::endl; 
00174   //int i=-1;
00175 
00176  
00177   // we really don't want to copy CSCEventData's while filling the vec
00178   theData.clear();
00179   theData.reserve(theDDUHeader.ncsc());
00180 
00181   if (examiner!= NULL) { // Use selective unpacking mode
00182 
00183     if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << "selective unpacking starting";
00184 
00185     // Find this DDU in examiner's DDUs list
00186     int dduID = theDDUHeader.source_id();       
00187         
00188     std::map<short,std::map<short,const unsigned short*> > ddus = examiner->DMB_block();
00189     std::map<short,std::map<short,const unsigned short*> >::iterator ddu_itr = ddus.find(dduID);
00190     unsigned short* dduBlock = (unsigned short*)((examiner->DDU_block())[dduID]);
00191     unsigned long dduBufSize = (examiner->DDU_size())[dduID];
00192                 
00193     if (ddu_itr != ddus.end() && dduBufSize!=0 && dduBlock==inputBuf) {
00194       std::map<short,const unsigned short*> &cscs = ddu_itr->second;
00195       std::map<short,const unsigned short*>::iterator csc_itr;
00196 
00197       for (csc_itr=cscs.begin(); csc_itr != cscs.end(); ++csc_itr) {
00198         short cscid = csc_itr->first;
00199 
00200         if(cscid != -1)
00201         {
00202           unsigned short* pos = (unsigned short*)csc_itr->second;
00203         
00204         
00205           long errors = examiner->errorsForChamber(cscid);
00206           if ((errors & examiner->getMask()) > 0 ) {    
00207                 if (debug) 
00208                 LogTrace ("CSCDDUEventData|CSCRawToDigi" )
00209                        << "skip unpacking of CSC " << cscid << " due format errors: 0x" << std::hex << errors << std::dec;
00210             continue;
00211           } 
00212         
00213           theData.push_back(CSCEventData(pos));
00214         }
00215       }
00216 
00217       if (debug)
00218         {
00219           LogTrace ("CSCDDUEventData|CSCRawToDigi") << "size of vector of cscData = " << theData.size();
00220         }
00221 
00222       // decode ddu tail
00223       memcpy(&theDDUTrailer, inputBuf+dduBufSize, theDDUTrailer.sizeInWords()*2);
00224       // memcpy(&theDDUTrailer, dduBlock+(dduBufSize-theDDUTrailer.sizeInWords())*2, theDDUTrailer.sizeInWords()*2);
00225       if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << theDDUTrailer.check();
00226       errorstat=theDDUTrailer.errorstat();
00227       if ((errorstat&errMask) != 0)
00228         {
00229           if (theDDUTrailer.check())
00230             {
00231               if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi")
00232                 << "+++ CSCDDUEventData warning: DDU Trailer errors = " << std::hex << errorstat << " +++ ";
00233               if (debug) decodeStatus(errorstat);
00234             }
00235           else
00236             {
00237               if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi" )
00238                 << " Unpacking lost DDU trailer - check() failed and 8 8 ffff 8 was not found ";
00239             }
00240         }
00241 
00242       if (debug) {
00243         LogTrace ("CSCDDUEventData|CSCRawToDigi")  << " Final errorstat " << std::hex << errorstat << std::dec ;
00244       }
00245       // the trailer counts in 64-bit words
00246 
00247       // theSizeInWords = dduBufSize;
00248       // buf=inputBuf+dduBufSize;
00249 
00250     }
00251     theSizeInWords = dduBufSize+12;
00252     buf=inputBuf+dduBufSize;
00253         
00254   } else {
00255 
00256 
00257     while( (((buf[0]&0xf000) == 0x9000)||((buf[0]&0xf000) == 0xa000)) 
00258            && (buf[3] != 0x8000)) {
00259         // ++i;
00260         if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << "unpack csc data loop started";
00261         theData.push_back(CSCEventData(buf));
00262         buf += (theData.back()).size();
00263         if (debug) {
00264             LogTrace ("CSCDDUEventData|CSCRawToDigi") << "size of vector of cscData = " << theData.size();
00265         }
00266     }
00267  
00268     if (debug) {
00269         LogTrace ("CSCDDUEventData|CSCRawToDigi") << "unpacking ddu trailer ";
00270         LogTrace ("CSCDDUEventData|CSCRawToDigi") << std::hex << buf[3]<<" " << buf[2] 
00271                                          <<" " << buf[1]<<" " << buf[0];
00272     }
00273 
00274     // decode ddu tail
00275     memcpy(&theDDUTrailer, buf, theDDUTrailer.sizeInWords()*2);
00276     if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") << theDDUTrailer.check();
00277     errorstat=theDDUTrailer.errorstat();
00278     if ((errorstat&errMask) != 0)  
00279       {
00280         if (theDDUTrailer.check())
00281           {
00282             if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi") 
00283               << "+++ CSCDDUEventData warning: DDU Trailer errors = " << std::hex << errorstat << " +++ ";
00284             if (debug) decodeStatus(errorstat);
00285           } 
00286         else 
00287           {
00288             if (debug) LogTrace ("CSCDDUEventData|CSCRawToDigi" ) 
00289               << " Unpacking lost DDU trailer - check() failed and 8 8 ffff 8 was not found ";
00290           }
00291       }
00292    
00293     if (debug) 
00294       LogTrace ("CSCDDUEventData|CSCRawToDigi")  << " Final errorstat " << std::hex << errorstat << std::dec ;
00295     // the trailer counts in 64-bit words
00296     buf += theDDUTrailer.sizeInWords();
00297   
00298     theSizeInWords = buf - inputBuf;
00299   }
00300 }
00301 
00302 
00303 bool CSCDDUEventData::check() const 
00304 {
00305   // the trailer counts in 64-bit words
00306   if (debug)
00307     {
00308       LogTrace ("CSCDDUEventData|CSCRawToDigi") << sizeInWords();
00309       LogTrace ("CSCDDUEventData|CSCRawToDigi") << "wordcount = " << theDDUTrailer.wordcount()*4;
00310     }
00311 
00312   return theDDUHeader.check() && theDDUTrailer.check();
00313 }
00314 
00315 boost::dynamic_bitset<> CSCDDUEventData::pack() 
00316 {
00317   boost::dynamic_bitset<> result = bitset_utilities::ushortToBitset( theDDUHeader.sizeInWords()*16,
00318                                                                      theDDUHeader.data());
00319   //std::cout <<"SANDRIK inside DDUEvdata check = ";
00320   //theDDUHeader.check();
00321   //std::cout <<std::endl;
00322   //std::cout <<"printing out ddu header words"<<std::endl;
00323   //for (unsigned int i=0;i<theDDUHeader.sizeInWords();i++) {
00324   //  unsigned short * buf = theDDUHeader.data();
00325   //  printf("%04x %04x %04x %04x\n",buf[i+3],buf[i+2],buf[i+1],buf[i]);
00326   //  i+=3;
00327   //}
00328   //std::cout <<"printing out ddu header words via bitset"<<std::endl;
00329   //bitset_utilities::printWords(result);
00330  
00331   for(unsigned int i = 0; i < theData.size(); ++i) 
00332     {
00333       result = bitset_utilities::append(result,theData[i].pack());
00334     }
00335   theSizeInWords = result.size()/16 + theDDUTrailer.sizeInWords();
00336   // 64-bit word count
00337   theDDUTrailer.setWordCount(theSizeInWords/4); 
00338   boost::dynamic_bitset<> dduTrailer = bitset_utilities::ushortToBitset ( theDDUTrailer.sizeInWords()*16, 
00339                                                                           theDDUTrailer.data());
00340   result =  bitset_utilities::append(result,dduTrailer);
00341 
00342   return result;
00343 }
00344 

Generated on Tue Jun 9 17:34:24 2009 for CMSSW by  doxygen 1.5.4