File indexing completed on 2024-04-06 12:10:26
0001 #include "EventFilter/CSCRawToDigi/interface/CSCRPCData.h"
0002 #include "DataFormats/CSCDigi/interface/CSCRPCDigi.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004
0005 #include <string>
0006 #include <cstdio>
0007 #include <strings.h> // for bzero
0008 #include <cstring>
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifdef LOCAL_UNPACK
0020 bool CSCRPCData::debug = false;
0021 #else
0022 std::atomic<bool> CSCRPCData::debug{false};
0023 #endif
0024
0025 CSCRPCData::CSCRPCData(int ntbins) : ntbins_(ntbins), size_(0) {
0026 theData[0] = 0x6b04;
0027 for (int i = 1; i < 257; ++i) {
0028
0029 int rpc = (i - 1) / 14;
0030 theData[i] = rpc << 12;
0031
0032
0033 int tbin = ((i - 1) % 14) / 2;
0034 theData[i] |= tbin << 8;
0035 }
0036 theData[257] = 0x6e04;
0037 }
0038
0039 CSCRPCData::CSCRPCData(const unsigned short* buf, int length) : size_(length) {
0040
0041
0042 ntbins_ = (size_ - 2) / 8;
0043 memcpy(theData, buf, size_ * 2);
0044 }
0045
0046 void CSCRPCData::Print() const {
0047 LogTrace("CSCRPCData|CSCRawToDigi") << "CSCRPCData.Print";
0048 for (int line = 0; line < ((size_)); ++line) {
0049 LogTrace("CSCRPCData|CSCRawToDigi") << std::hex << theData[line];
0050 }
0051
0052 for (int linePair = 0; linePair < ((size_ - 2) / 2); ++linePair) {
0053
0054 int pos = linePair * 2 + 1;
0055
0056
0057
0058 int bxnnew = ((theData[pos + 1] >> 8) & 0x7);
0059
0060 int rpc = (theData[pos] >> 12) & 0x7;
0061 int tbin = (theData[pos] >> 8) & 0xf;
0062 int bxn = bxnnew;
0063
0064 LogTrace("CSCRPCData|CSCRawToDigi") << " RPC=" << rpc << " Tbin=" << tbin << " BXN=" << bxn;
0065 }
0066 }
0067
0068 std::vector<int> CSCRPCData::BXN() const {
0069 std::vector<int> result;
0070 for (int linePair = 0; linePair < ((size_ - 2) / 2); ++linePair) {
0071
0072 int pos = linePair * 2 + 1;
0073
0074
0075
0076 int bxnnew = ((theData[pos + 1] >> 8) & 0x7);
0077
0078
0079 int rpc = (theData[pos] >> 12) & 0x7;
0080
0081
0082 result.push_back(bxnnew);
0083 result.push_back(rpc);
0084 }
0085 return result;
0086 }
0087
0088 std::vector<CSCRPCDigi> CSCRPCData::digis() const {
0089 std::vector<CSCRPCDigi> result;
0090 int bxnold = 0;
0091 int bxnnew = 0;
0092
0093 for (int linePair = 0; linePair < ((size_ - 2) / 2); ++linePair) {
0094
0095 int pos = linePair * 2 + 1;
0096
0097
0098 if (debug)
0099 LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData " << std::hex << theData[pos] << " " << theData[pos + 1];
0100
0101 int pad = (theData[pos] & 0xff) + ((theData[pos + 1] & 0xff) << 8);
0102
0103
0104 bxnnew = ((theData[pos + 1] >> 8) & 0x7);
0105
0106
0107 if (linePair == 0)
0108 bxnold = bxnnew;
0109 if (bxnnew - bxnold > 1)
0110 LogTrace("CSCRPCData|CSCRawToDigi")
0111 << "+++ CSCRPCData warning: RPC BXN is incrementing by more than 1 clock cycle";
0112 bxnold = bxnnew;
0113
0114 if (pad != 0) {
0115 if (debug)
0116 LogTrace("CSCRPCData|CSCRawToDigi")
0117 << "+++ CSCRPCData Found a PAD =" << std::hex << pad << " " << theData[pos] << " + " << theData[pos + 1];
0118 int rpc = (theData[pos] >> 12) & 0x7;
0119 int tbin = (theData[pos] >> 8) & 0xf;
0120 int bxn = bxnnew;
0121
0122 for (int i = 0; i < 16; ++i) {
0123
0124 if ((pad >> i) & 1) {
0125 result.push_back(CSCRPCDigi(rpc, i, bxn, tbin));
0126
0127 }
0128 }
0129 }
0130 }
0131 return result;
0132 }