test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
26  : ntbins_(ntbins), size_( 0 )
27 {
28  theData[0] = 0x6b04;
29  for(int i = 1; i < 257; ++i) {
30  // data format is bits 12-14 are RPC number, 0 to 3
31  int rpc = (i-1)/14;
32  theData[i] = rpc << 12;
33 
34  // bits 8-11 of the first word of the pair is time bin
35  int tbin = ((i-1)%14)/2;
36  theData[i] |= tbin << 8;
37  }
38  theData[257] = 0x6e04;
39 }
40 
41 CSCRPCData::CSCRPCData(const unsigned short * buf, int length)
42  : size_(length)
43 {
44  //size_ = ntbins_*2*4+2;
45  // header & trailer word, + 4 RPCs per time bin, 2 lines per RPC
46  ntbins_ = (size_-2)/8;
47  memcpy(theData, buf, size_*2);
48 }
49 
50 void CSCRPCData::Print() const {
51  LogTrace ("CSCRPCData|CSCRawToDigi") << "CSCRPCData.Print";
52  for(int line = 0; line < ((size_)); ++line) {
53  LogTrace("CSCRPCData|CSCRawToDigi") <<std::hex << theData[line];
54  }
55 
56  for(int linePair = 0; linePair < ((size_-2)/2); ++linePair) {
57  // skip header word
58  int pos = linePair*2 + 1;
59  // make the two pad words into one and see if it's empty
60  //int pad = theData[pos] & 0xff + ((theData[pos+1] & 0x3f) << 8);
61 
62  int bxnnew = ((theData[pos+1] >> 8) & 0x7 );
63 
64  int rpc = (theData[pos] >> 12) & 0x7;
65  int tbin = (theData[pos] >> 8) & 0xf;
66  int bxn = bxnnew;
67 
68  LogTrace ("CSCRPCData|CSCRawToDigi") << " RPC=" << rpc << " Tbin=" <<tbin <<" BXN=" << bxn;
69 
70  }
71 }
72 
73 std::vector<int> CSCRPCData::BXN() const {
74  std::vector<int> result;
75  for(int linePair = 0; linePair < ((size_-2)/2); ++linePair) {
76  // skip header word
77  int pos = linePair*2 + 1;
79  //int pad = theData[pos] & 0xff + ((theData[pos+1] & 0x3f) << 8);
80 
81  int bxnnew = ((theData[pos+1] >> 8) & 0x7 ) ;
82  //int bxnnew = (((theData[pos+1] >> 8) & 0x3 )<<2) | ((theData[pos+1]>>6)&0x3) ;
83 
84  int rpc = (theData[pos] >> 12) & 0x7;
85  //int tbin = (theData[pos] >> 8) & 0xf;
86  //int bxn = bxnnew;
87  result.push_back(bxnnew);
88  result.push_back(rpc);
89 
90 
91  }
92  return result;
93 }
94 
95 std::vector<CSCRPCDigi> CSCRPCData::digis() const {
96  std::vector<CSCRPCDigi> result;
97  int bxnold =0 ;
98  int bxnnew =0 ;
99  //int bxnewGreg;
100  for(int linePair = 0; linePair < ((size_-2)/2); ++linePair) {
101  // skip header word
102  int pos = linePair*2 + 1;
103  // LogTrace("RPC") << "+++ CSCRPCData " << std::hex << theData[pos]
104  // << " " << theData[pos+1];
105  if (debug)
106  LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData " << std::hex << theData[pos]
107  << " " << theData[pos+1];
108  // make the two pad words into one and see if it's empty
109  int pad = (theData[pos] & 0xff) + ((theData[pos+1] & 0xff) << 8);
110 
111  //bxnnew = (((theData[pos+1] >> 8) & 0x3 )<<2) | ((theData[pos+1]>>6)&0x3) ;
112  bxnnew = ((theData[pos+1] >> 8) & 0x7 ) ;
113  //LogTrace("RPC") << " " << "bxnnew" << " " << bxnnew;
114  //LogTrace("RPC") << " " << "bxnnewGreg" << " " << bxnewGreg;
115  if ( linePair == 0 ) bxnold = bxnnew;
116  if ( bxnnew - bxnold > 1 )
117  LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData warning: RPC BXN is incrementing by more than 1 clock cycle";
118  bxnold = bxnnew;
119 
120  if(pad != 0) {
121  if (debug) LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData Found a PAD ="
122  << std::hex << pad << " " << theData[pos]
123  << " + " << theData[pos+1];
124  int rpc = (theData[pos] >> 12) & 0x7;
125  int tbin = (theData[pos] >> 8) & 0xf;
126  int bxn = bxnnew;
127  //LogTrace("RPC") << " rpc: " << rpc << " bxn: " << bxn << " tbin: " << tbin;
128  for(int i = 0; i < 16; ++i) {
129  // if the bit is set, make a digi
130  if((pad>>i)&1) {
131  result.push_back(CSCRPCDigi(rpc, i, bxn, tbin));
132  //LogTrace("RPC") << "digi-->" << " rpc: " << rpc << " i: " << i << " bxn: " << bxn << " tbin: " << tbin;
133  }
134  }
135  }
136  }
137  return result;
138 }
139 
int i
Definition: DBlmapReader.cc:9
std::vector< CSCRPCDigi > digis() const
Definition: CSCRPCData.cc:95
static std::atomic< bool > debug
Definition: CSCRPCData.h:33
tuple result
Definition: mps_fire.py:84
std::vector< int > BXN() const
Definition: CSCRPCData.cc:73
#define LogTrace(id)
CSCRPCData(int ntbins=7)
default constructor
Definition: CSCRPCData.cc:25
size_(0)
Definition: OwnArray.h:181
unsigned short theData[2 *4 *32+2]
Definition: CSCRPCData.h:37
void Print() const
Definition: CSCRPCData.cc:50
int ntbins_
Definition: CSCRPCData.h:35