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 bool CSCRPCData::debug = false;
20 
22  : ntbins_(ntbins), size_( 0 )
23 {
24  theData[0] = 0x6b04;
25  for(int i = 1; i < 257; ++i) {
26  // data format is bits 12-14 are RPC number, 0 to 3
27  int rpc = (i-1)/14;
28  theData[i] = rpc << 12;
29 
30  // bits 8-11 of the first word of the pair is time bin
31  int tbin = ((i-1)%14)/2;
32  theData[i] |= tbin << 8;
33  }
34  theData[257] = 0x6e04;
35 }
36 
37 CSCRPCData::CSCRPCData(const unsigned short * buf, int length)
38  : size_(length)
39 {
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 
69 std::vector<int> CSCRPCData::BXN() const {
70  std::vector<int> result;
71  for(int linePair = 0; linePair < ((size_-2)/2); ++linePair) {
72  // skip header word
73  int pos = linePair*2 + 1;
75  //int pad = theData[pos] & 0xff + ((theData[pos+1] & 0x3f) << 8);
76 
77  int bxnnew = ((theData[pos+1] >> 8) & 0x7 ) ;
78  //int bxnnew = (((theData[pos+1] >> 8) & 0x3 )<<2) | ((theData[pos+1]>>6)&0x3) ;
79 
80  int rpc = (theData[pos] >> 12) & 0x7;
81  //int tbin = (theData[pos] >> 8) & 0xf;
82  //int bxn = bxnnew;
83  result.push_back(bxnnew);
84  result.push_back(rpc);
85 
86 
87  }
88  return result;
89 }
90 
91 std::vector<CSCRPCDigi> CSCRPCData::digis() const {
92  std::vector<CSCRPCDigi> result;
93  int bxnold =0 ;
94  int bxnnew =0 ;
95  //int bxnewGreg;
96  for(int linePair = 0; linePair < ((size_-2)/2); ++linePair) {
97  // skip header word
98  int pos = linePair*2 + 1;
99  // LogTrace("RPC") << "+++ CSCRPCData " << std::hex << theData[pos]
100  // << " " << theData[pos+1];
101  if (debug)
102  LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData " << std::hex << theData[pos]
103  << " " << theData[pos+1];
104  // make the two pad words into one and see if it's empty
105  int pad = (theData[pos] & 0xff) + ((theData[pos+1] & 0xff) << 8);
106 
107  //bxnnew = (((theData[pos+1] >> 8) & 0x3 )<<2) | ((theData[pos+1]>>6)&0x3) ;
108  bxnnew = ((theData[pos+1] >> 8) & 0x7 ) ;
109  //LogTrace("RPC") << " " << "bxnnew" << " " << bxnnew;
110  //LogTrace("RPC") << " " << "bxnnewGreg" << " " << bxnewGreg;
111  if ( linePair == 0 ) bxnold = bxnnew;
112  if ( bxnnew - bxnold > 1 )
113  LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData warning: RPC BXN is incrementing by more than 1 clock cycle";
114  bxnold = bxnnew;
115 
116  if(pad != 0) {
117  if (debug) LogTrace("CSCRPCData|CSCRawToDigi") << "+++ CSCRPCData Found a PAD ="
118  << std::hex << pad << " " << theData[pos]
119  << " + " << theData[pos+1];
120  int rpc = (theData[pos] >> 12) & 0x7;
121  int tbin = (theData[pos] >> 8) & 0xf;
122  int bxn = bxnnew;
123  //LogTrace("RPC") << " rpc: " << rpc << " bxn: " << bxn << " tbin: " << tbin;
124  for(int i = 0; i < 16; ++i) {
125  // if the bit is set, make a digi
126  if((pad>>i)&1) {
127  result.push_back(CSCRPCDigi(rpc, i, bxn, tbin));
128  //LogTrace("RPC") << "digi-->" << " rpc: " << rpc << " i: " << i << " bxn: " << bxn << " tbin: " << tbin;
129  }
130  }
131  }
132  }
133  return result;
134 }
135 
int i
Definition: DBlmapReader.cc:9
std::vector< CSCRPCDigi > digis() const
Definition: CSCRPCData.cc:91
tuple result
Definition: query.py:137
std::vector< int > BXN() const
Definition: CSCRPCData.cc:69
#define LogTrace(id)
static bool debug
Definition: CSCRPCData.h:27
CSCRPCData(int ntbins=7)
default constructor
Definition: CSCRPCData.cc:21
size_(0)
Definition: OwnArray.h:181
unsigned short theData[2 *4 *32+2]
Definition: CSCRPCData.h:30
void Print() const
Definition: CSCRPCData.cc:46
int ntbins_
Definition: CSCRPCData.h:28