CMS 3D CMS Logo

CSCALCTTrailer.h
Go to the documentation of this file.
1 #ifndef CSCALCTTrailer_h
2 #define CSCALCTTrailer_h
3 
8 #include <cstring> // memcpy
9 #ifndef LOCAL_UNPACK
10 #include <atomic>
11 #endif
14 
17 
18  void setFromBuffer(unsigned short const* buf) {
19  memcpy(this, buf, sizeInWords()*2);
20  }
21 
22  void setSize(int size) {frameCount = size;}
23  void setCRC(unsigned int crc) {crc0 = crc&0x7FF; crc1 = (crc >> 11) & 0x7FF;}
24  short unsigned int sizeInWords() const {
25  return 4;
26  }
27  unsigned crc0:11, zero_0:1, d_0:4;
28  unsigned crc1:11, zero_1:1, d_1:4;
29  unsigned e0dLine:16;
30  unsigned frameCount:11, reserved_3:1, d_3:4;
31 };
32 
35 
36  void setFromBuffer(unsigned short const* buf) {
37  memcpy(this, buf, sizeInWords()*2);
38  }
39 
40  void setSize(int size) {frameCount = size;}
41  void setCRC(unsigned int crc) {crc0 = crc&0x7FF; crc1 = (crc >> 11) & 0x7FF;}
42  short unsigned int sizeInWords() const {
43  return 4;
44  }
45  unsigned e0dLine:16;
46  unsigned crc0:11, zero_0:1, reserved_0:4;
47  unsigned crc1:11, zero_1:1, reserved_1:4;
48  unsigned frameCount:11, reserved_3:1, reserved_4:4;
49 };
50 
51 
52 
54 {
55 public:
57  CSCALCTTrailer(int size, int firmVersion);
58  CSCALCTTrailer(const unsigned short * buf);
60  CSCALCTTrailer(digi.trailer());
61  }
62 
63  static void setDebug(bool debugValue) {debug = debugValue;}
64 
65  unsigned short * data() {
66 #ifdef LOCAL_UNPACK
67  switch (firmwareVersion) {
68 #else
69  switch (firmwareVersion.load()) {
70 #endif
71  case 2006:
72  memcpy(theOriginalBuffer, &trailer2006, trailer2006.sizeInWords()*2);
73  break;
74  case 2007:
75  memcpy(theOriginalBuffer, &trailer2007, trailer2007.sizeInWords()*2);
76  break;
77  default:
78  edm::LogError("CSCALCTTrailer|CSCRawToDigi")
79  <<"couldn't access data: ALCT firmware version is bad/not defined!";
80  break;
81  }
82  return theOriginalBuffer;
83  }
84 
86  static int sizeInWords() {return 4;}
87 
88  void setCRC(unsigned int crc){
89 #ifdef LOCAL_UNPACK
90  switch (firmwareVersion) {
91 #else
92  switch (firmwareVersion.load()) {
93 #endif
94  case 2006:
95  trailer2006.setCRC(crc);
96  break;
97  case 2007:
98  trailer2007.setCRC(crc);
99  break;
100  default:
101  edm::LogError("CSCALCTTrailer|CSCRawToDigi")
102  <<"couldn't setCRC: ALCT firmware version is bad/not defined!";
103  break;
104  }
105  }
106 
107 
108  int getCRC() {
109 #ifdef LOCAL_UNPACK
110  switch (firmwareVersion) {
111 #else
112  switch (firmwareVersion.load()) {
113 #endif
114  case 2006:
115  return ((trailer2006.crc1&0x7ff)<<11) | (trailer2006.crc0&0x7ff);
116  case 2007:
117  return ((trailer2007.crc1&0x7ff)<<11) | (trailer2007.crc0&0x7ff);
118  default:
119  edm::LogError("CSCALCTTrailer|CSCRawToDigi")
120  <<"couldn't getCRC: ALCT firmware version is bad/not defined!";
121  return 0;
122  }
123  }
124 
125  bool check() const {
126 #ifdef LOCAL_UNPACK
127  switch (firmwareVersion) {
128 #else
129  switch (firmwareVersion.load()) {
130 #endif
131  case 2006:
132  return (trailer2006.e0dLine & 0xfff) == 0xe0d;
133  case 2007:
134  return (trailer2007.e0dLine & 0xffff) == 0xde0d;
135  default:
136  edm::LogError("CSCALCTTrailer|CSCRawToDigi")
137  <<"couldn't check: ALCT firmware version is bad/not defined!";
138  return false;
139  }
140  }
141 
142  int wordCount() const {
143 #ifdef LOCAL_UNPACK
144  switch (firmwareVersion) {
145 #else
146  switch (firmwareVersion.load()) {
147 #endif
148  case 2006:
149  return trailer2006.frameCount;
150  case 2007:
151  return trailer2007.frameCount;
152  default:
153  edm::LogError("CSCALCTTrailer|CSCRawToDigi")
154  <<"couldn't wordCount: ALCT firmware version is bad/not defined!";
155  return 0;
156  }
157  }
158 
159  unsigned alctCRCCheck() const {
160 #ifdef LOCAL_UNPACK
161  switch (firmwareVersion) {
162 #else
163  switch (firmwareVersion.load()) {
164 #endif
165  case 2006:
166  return trailer2006.reserved_3;
167  case 2007:
168  return trailer2007.reserved_3;
169  default:
170  edm::LogError("CSCALCTTrailer|CSCRawToDigi")
171  <<"couldn't CRCcheck: ALCT firmware version is bad/not defined!";
172  return 0;
173  }
174  }
175 
176  unsigned FrameCount() const { return wordCount(); }
177 
178  CSCALCTTrailer2006 alctTrailer2006() {return trailer2006;}
179  CSCALCTTrailer2007 alctTrailer2007() {return trailer2007;}
180 
181 private:
182 
183 #ifdef LOCAL_UNPACK
184  static bool debug;
185  static unsigned short int firmwareVersion;
186 #else
187  static std::atomic<bool> debug;
188  static std::atomic<unsigned short int> firmwareVersion;
189 #endif
190 
193  unsigned short int theOriginalBuffer[4];
194 
195 };
196 
197 #endif
198 
size
Write out results.
CSCALCTTrailer(const CSCALCTStatusDigi &digi)
const uint16_t * trailer() const
unsigned FrameCount() const
void setFromBuffer(unsigned short const *buf)
void setCRC(unsigned int crc)
void setFromBuffer(unsigned short const *buf)
short unsigned int sizeInWords() const
CSCALCTTrailer2006 alctTrailer2006()
static std::atomic< bool > debug
unsigned alctCRCCheck() const
static std::atomic< unsigned short int > firmwareVersion
CSCALCTTrailer2007 trailer2007
int wordCount() const
static int sizeInWords()
in 16-bit frames
CSCALCTTrailer2006 trailer2006
short unsigned int sizeInWords() const
unsigned short * data()
void setCRC(unsigned int crc)
CSCALCTTrailer2007 alctTrailer2007()
#define debug
Definition: HDRShower.cc:19
void setSize(int size)
static void setDebug(bool debugValue)
void setSize(int size)
bool check() const
void setCRC(unsigned int crc)