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>
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
00027 int rpc = (i-1)/14;
00028 theData[i] = rpc << 12;
00029
00030
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
00041
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
00054 int pos = linePair*2 + 1;
00055
00056
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
00073 int pos = linePair*2 + 1;
00075
00076
00077 int bxnnew = ((theData[pos+1] >> 8) & 0x7 ) ;
00078
00079
00080 int rpc = (theData[pos] >> 12) & 0x7;
00081
00082
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
00096 for(int linePair = 0; linePair < ((size_-2)/2); ++linePair) {
00097
00098 int pos = linePair*2 + 1;
00099
00100
00101 if (debug)
00102 LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData " << std::hex << theData[pos]
00103 << " " << theData[pos+1];
00104
00105 int pad = (theData[pos] & 0xff) + ((theData[pos+1] & 0xff) << 8);
00106
00107
00108 bxnnew = ((theData[pos+1] >> 8) & 0x7 ) ;
00109
00110
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
00124 for(int i = 0; i < 16; ++i) {
00125
00126 if((pad>>i)&1) {
00127 result.push_back(CSCRPCDigi(rpc, i, bxn, tbin));
00128
00129 }
00130 }
00131 }
00132 }
00133 return result;
00134 }
00135