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