CMS 3D CMS Logo

CSCRPCData.cc
Go to the documentation of this file.
4 
5 #include <string>
6 #include <cstdio>
7 #include <strings.h> // for bzero
8 #include <cstring>
9 
19 #ifdef LOCAL_UNPACK
20 bool CSCRPCData::debug = false;
21 #else
22 std::atomic<bool> CSCRPCData::debug{false};
23 #endif
24 
25 CSCRPCData::CSCRPCData(int ntbins) : ntbins_(ntbins), size_(0) {
26  theData[0] = 0x6b04;
27  for (int i = 1; i < 257; ++i) {
28  // data format is bits 12-14 are RPC number, 0 to 3
29  int rpc = (i - 1) / 14;
30  theData[i] = rpc << 12;
31 
32  // bits 8-11 of the first word of the pair is time bin
33  int tbin = ((i - 1) % 14) / 2;
34  theData[i] |= tbin << 8;
35  }
36  theData[257] = 0x6e04;
37 }
38 
39 CSCRPCData::CSCRPCData(const unsigned short* buf, int length) : size_(length) {
40  //size_ = ntbins_*2*4+2;
41  // header & trailer word, + 4 RPCs per time bin, 2 lines per RPC
42  ntbins_ = (size_ - 2) / 8;
43  memcpy(theData, buf, size_ * 2);
44 }
45 
46 void CSCRPCData::Print() const {
47  LogTrace("CSCRPCData|CSCRawToDigi") << "CSCRPCData.Print";
48  for (int line = 0; line < ((size_)); ++line) {
49  LogTrace("CSCRPCData|CSCRawToDigi") << std::hex << theData[line];
50  }
51 
52  for (int linePair = 0; linePair < ((size_ - 2) / 2); ++linePair) {
53  // skip header word
54  int pos = linePair * 2 + 1;
55  // make the two pad words into one and see if it's empty
56  //int pad = theData[pos] & 0xff + ((theData[pos+1] & 0x3f) << 8);
57 
58  int bxnnew = ((theData[pos + 1] >> 8) & 0x7);
59 
60  int rpc = (theData[pos] >> 12) & 0x7;
61  int tbin = (theData[pos] >> 8) & 0xf;
62  int bxn = bxnnew;
63 
64  LogTrace("CSCRPCData|CSCRawToDigi") << " RPC=" << rpc << " Tbin=" << tbin << " BXN=" << bxn;
65  }
66 }
67 
68 std::vector<int> CSCRPCData::BXN() const {
69  std::vector<int> result;
70  for (int linePair = 0; linePair < ((size_ - 2) / 2); ++linePair) {
71  // skip header word
72  int pos = linePair * 2 + 1;
74  //int pad = theData[pos] & 0xff + ((theData[pos+1] & 0x3f) << 8);
75 
76  int bxnnew = ((theData[pos + 1] >> 8) & 0x7);
77  //int bxnnew = (((theData[pos+1] >> 8) & 0x3 )<<2) | ((theData[pos+1]>>6)&0x3) ;
78 
79  int rpc = (theData[pos] >> 12) & 0x7;
80  //int tbin = (theData[pos] >> 8) & 0xf;
81  //int bxn = bxnnew;
82  result.push_back(bxnnew);
83  result.push_back(rpc);
84  }
85  return result;
86 }
87 
88 std::vector<CSCRPCDigi> CSCRPCData::digis() const {
89  std::vector<CSCRPCDigi> result;
90  int bxnold = 0;
91  int bxnnew = 0;
92  //int bxnewGreg;
93  for (int linePair = 0; linePair < ((size_ - 2) / 2); ++linePair) {
94  // skip header word
95  int pos = linePair * 2 + 1;
96  // LogTrace("RPC") << "+++ CSCRPCData " << std::hex << theData[pos]
97  // << " " << theData[pos+1];
98  if (debug)
99  LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData " << std::hex << theData[pos] << " " << theData[pos + 1];
100  // make the two pad words into one and see if it's empty
101  int pad = (theData[pos] & 0xff) + ((theData[pos + 1] & 0xff) << 8);
102 
103  //bxnnew = (((theData[pos+1] >> 8) & 0x3 )<<2) | ((theData[pos+1]>>6)&0x3) ;
104  bxnnew = ((theData[pos + 1] >> 8) & 0x7);
105  //LogTrace("RPC") << " " << "bxnnew" << " " << bxnnew;
106  //LogTrace("RPC") << " " << "bxnnewGreg" << " " << bxnewGreg;
107  if (linePair == 0)
108  bxnold = bxnnew;
109  if (bxnnew - bxnold > 1)
110  LogTrace("CSCRPCData|CSCRawToDigi")
111  << "+++ CSCRPCData warning: RPC BXN is incrementing by more than 1 clock cycle";
112  bxnold = bxnnew;
113 
114  if (pad != 0) {
115  if (debug)
116  LogTrace("CSCRPCData|CSCRawToDigi")
117  << "+++ CSCRPCData Found a PAD =" << std::hex << pad << " " << theData[pos] << " + " << theData[pos + 1];
118  int rpc = (theData[pos] >> 12) & 0x7;
119  int tbin = (theData[pos] >> 8) & 0xf;
120  int bxn = bxnnew;
121  //LogTrace("RPC") << " rpc: " << rpc << " bxn: " << bxn << " tbin: " << tbin;
122  for (int i = 0; i < 16; ++i) {
123  // if the bit is set, make a digi
124  if ((pad >> i) & 1) {
125  result.push_back(CSCRPCDigi(rpc, i, bxn, tbin));
126  //LogTrace("RPC") << "digi-->" << " rpc: " << rpc << " i: " << i << " bxn: " << bxn << " tbin: " << tbin;
127  }
128  }
129  }
130  }
131  return result;
132 }
CSCRPCData::digis
std::vector< CSCRPCDigi > digis() const
Definition: CSCRPCData.cc:88
CSCRPCData::CSCRPCData
CSCRPCData(int ntbins=7)
default constructor
Definition: CSCRPCData.cc:25
mps_fire.i
i
Definition: mps_fire.py:428
CSCRPCData::debug
static std::atomic< bool > debug
Definition: CSCRPCData.h:32
MessageLogger.h
pos
Definition: PixelAliasList.h:18
CSCRPCData.h
CSCRPCData::BXN
std::vector< int > BXN() const
Definition: CSCRPCData.cc:68
CSCRPCDigi.h
CSCRPCData::Print
void Print() const
Definition: CSCRPCData.cc:46
CSCRPCDigi
Definition: CSCRPCDigi.h:15
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
CSCRPCData::theData
unsigned short theData[2 *4 *32+2]
Definition: CSCRPCData.h:36
CSCRPCData::ntbins_
int ntbins_
Definition: CSCRPCData.h:34
mps_fire.result
result
Definition: mps_fire.py:311
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
mps_splice.line
line
Definition: mps_splice.py:76
omtf::DataWord64::rpc
Definition: OmtfDataWord64.h:16
CSCRPCData::size_
int size_
Definition: CSCRPCData.h:35