CMS 3D CMS Logo

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