CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/EventFilter/CSCRawToDigi/src/CSCRPCData.cc

Go to the documentation of this file.
00001 #include "EventFilter/CSCRawToDigi/interface/CSCRPCData.h"
00002 #include "DataFormats/CSCDigi/interface/CSCRPCDigi.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include <string>
00006 #include <cstdio>
00007 #include <strings.h> // for bzero
00008 #include <cstring>
00009 
00019 bool CSCRPCData::debug = false;
00020 
00021 CSCRPCData::CSCRPCData(int ntbins) 
00022   : ntbins_(ntbins), size_( 0 )
00023 {
00024   theData[0] = 0x6b04;
00025   for(int i = 1; i < 257; ++i) {
00026     // data format is bits 12-14 are RPC number, 0 to 3
00027     int rpc = (i-1)/14;
00028     theData[i] = rpc << 12;
00029 
00030     // bits 8-11 of the first word of the pair is time bin
00031     int tbin = ((i-1)%14)/2;
00032     theData[i] |= tbin << 8;
00033   }
00034   theData[257] = 0x6e04;  
00035 }
00036 
00037 CSCRPCData::CSCRPCData(const unsigned short * buf, int length) 
00038   : size_(length)
00039 {
00040   //size_ = ntbins_*2*4+2;
00041   // header & trailer word, + 4 RPCs per time bin, 2 lines per RPC
00042   ntbins_ = (size_-2)/8;
00043   memcpy(theData, buf, size_*2);
00044 }
00045 
00046 void CSCRPCData::Print() const {
00047   LogTrace ("CSCRPCData|CSCRawToDigi") << "CSCRPCData.Print";
00048   for(int line = 0; line < ((size_)); ++line) {
00049     LogTrace("CSCRPCData|CSCRawToDigi") <<std::hex << theData[line];
00050   }
00051   
00052   for(int linePair = 0; linePair < ((size_-2)/2); ++linePair) {
00053     // skip header word
00054     int pos = linePair*2 + 1;
00055     // make the two pad words into one and see if it's empty
00056     //int pad = theData[pos] & 0xff + ((theData[pos+1] & 0x3f) << 8);
00057   
00058     int bxnnew = ((theData[pos+1] >> 8)  & 0x7 );
00059   
00060     int rpc  = (theData[pos]   >> 12) & 0x7;
00061     int tbin = (theData[pos]   >> 8)  & 0xf;
00062     int bxn  = bxnnew;
00063   
00064     LogTrace ("CSCRPCData|CSCRawToDigi") << " RPC=" << rpc << " Tbin=" <<tbin <<" BXN=" << bxn;
00065   
00066   }
00067 }
00068 
00069 std::vector<int> CSCRPCData::BXN() const {
00070   std::vector<int> result;
00071   for(int linePair = 0; linePair < ((size_-2)/2); ++linePair) {
00072     // skip header word
00073     int pos = linePair*2 + 1;
00075     //int pad = theData[pos] & 0xff + ((theData[pos+1] & 0x3f) << 8);
00076    
00077     int bxnnew = ((theData[pos+1] >> 8)  & 0x7 ) ;
00078     //int bxnnew = (((theData[pos+1] >> 8)  & 0x3 )<<2) | ((theData[pos+1]>>6)&0x3) ;
00079    
00080     int rpc  = (theData[pos]   >> 12) & 0x7;
00081     //int tbin = (theData[pos]   >> 8)  & 0xf;
00082     //int bxn  = bxnnew;
00083     result.push_back(bxnnew);
00084     result.push_back(rpc);
00085 
00086    
00087   }
00088   return result;
00089 }
00090 
00091 std::vector<CSCRPCDigi> CSCRPCData::digis() const {
00092   std::vector<CSCRPCDigi> result;
00093   int bxnold =0 ;
00094   int bxnnew =0 ;
00095   //int bxnewGreg;
00096   for(int linePair = 0; linePair < ((size_-2)/2); ++linePair) {
00097     // skip header word
00098     int pos = linePair*2 + 1;
00099     //  LogTrace("RPC") << "+++ CSCRPCData " << std::hex << theData[pos] 
00100         //                       << " " << theData[pos+1];
00101     if (debug) 
00102       LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData " << std::hex << theData[pos] 
00103                                  << " " << theData[pos+1];
00104     // make the two pad words into one and see if it's empty
00105     int pad = (theData[pos] & 0xff) + ((theData[pos+1] & 0xff) << 8);
00106 
00107     //bxnnew = (((theData[pos+1] >> 8)  & 0x3 )<<2) | ((theData[pos+1]>>6)&0x3) ;
00108     bxnnew = ((theData[pos+1] >> 8)  & 0x7 ) ;
00109     //LogTrace("RPC") << "               " << "bxnnew" << " " << bxnnew;
00110     //LogTrace("RPC") << "               " << "bxnnewGreg" << " " << bxnewGreg;
00111     if ( linePair == 0 ) bxnold = bxnnew;
00112     if ( bxnnew - bxnold > 1 ) 
00113       LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData warning: RPC BXN is incrementing by more than 1 clock cycle";
00114     bxnold = bxnnew;
00115 
00116     if(pad != 0) {
00117       if (debug) LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData Found a PAD =" 
00118                                             << std::hex << pad << " " << theData[pos] 
00119                                             << " + " << theData[pos+1];
00120       int rpc  = (theData[pos]   >> 12) & 0x7;
00121       int tbin = (theData[pos]   >> 8)  & 0xf;
00122       int bxn  = bxnnew;
00123       //LogTrace("RPC") << " rpc: " << rpc << " bxn: " << bxn << " tbin: " << tbin;
00124       for(int i = 0; i < 16; ++i) {
00125         // if the bit is set, make a digi
00126         if((pad>>i)&1) {
00127           result.push_back(CSCRPCDigi(rpc, i, bxn, tbin));
00128           //LogTrace("RPC") << "digi-->" << " rpc: " << rpc << " i: " << i << " bxn: " << bxn << " tbin: " << tbin;
00129         }
00130       }
00131     } 
00132   }
00133   return result;
00134 }
00135