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
|
#include "EventFilter/HcalRawToDigi/interface/HcalUHTRData.h"
#include <cstring>
static const int HEADER_LENGTH_16BIT = 2 * sizeof(uint64_t) / sizeof(uint16_t);
HcalUHTRData::const_iterator::const_iterator(const uint16_t* ptr, const uint16_t* limit)
: m_ptr(ptr), m_limit(limit), m_stepclass(0), m_technicalDataType(0) {
if (isHeader())
determineMode();
}
HcalUHTRData::const_iterator& HcalUHTRData::const_iterator::operator++() {
if (m_ptr == m_limit)
return *this;
if (m_stepclass == 0)
m_ptr++;
else if (m_stepclass == 1) {
if (m_microstep == 0) {
m_ptr++;
m_microstep++;
} else {
m_microstep--;
}
} else if (m_stepclass == 2) {
if (isHeader()) {
m_ptr++;
} else {
m_ptr += 2;
}
}
if (isHeader()) {
determineMode();
m_header_ptr = m_ptr;
m_0th_data_ptr = m_header_ptr + 1;
}
return *this;
}
void HcalUHTRData::const_iterator::determineMode() {
if (!isHeader())
return;
m_flavor = flavor();
m_stepclass = 0;
if (m_flavor == 5) {
m_stepclass = 1;
m_microstep = 0;
} else if (m_flavor == 2) {
m_stepclass = 2;
}
if (m_flavor == 7) {
m_technicalDataType = technicalDataType();
}
}
int HcalUHTRData::const_iterator::errFlags() const {
if ((m_flavor == 7 && m_technicalDataType == 15) && !isHeader())
return ((*m_ptr) >> 11) & 0x1;
else
return ((*m_ptr) >> 10) & 0x3;
}
bool HcalUHTRData::const_iterator::dataValid() const {
if ((m_flavor == 7 && m_technicalDataType == 15) && !isHeader())
return ((*m_ptr) >> 10) & 0x1;
else
return !(errFlags() & 0x2);
}
int HcalUHTRData::const_iterator::technicalDataType() const {
if (m_flavor == 7)
return ((*m_ptr) >> 8) & 0xF;
else
return 0;
}
uint8_t HcalUHTRData::const_iterator::adc() const {
if (m_flavor == 5 && m_microstep == 0)
return ((*m_ptr) >> 8) & 0x7F;
else if (m_flavor == 7 && m_technicalDataType == 15)
return (*m_ptr) & 0x7F;
else
return (*m_ptr) & 0xFF;
}
uint8_t HcalUHTRData::const_iterator::le_tdc() const {
if (m_flavor == 5 || (m_flavor == 7 && m_technicalDataType == 15))
return 0x80;
else if (m_flavor == 2)
return (m_ptr[1] & 0x3F);
else
return (((*m_ptr) & 0x3F00) >> 8);
}
bool HcalUHTRData::const_iterator::soi() const {
if (m_flavor == 5 || (m_flavor == 7 && m_technicalDataType == 15))
return false;
else if (m_flavor == 2)
return (m_ptr[0] & 0x2000);
else
return (((*m_ptr) & 0x4000));
}
uint8_t HcalUHTRData::const_iterator::te_tdc() const {
if (m_flavor == 2)
return (m_ptr[1] >> 6) & 0x1F;
else
return 0x80;
}
uint8_t HcalUHTRData::const_iterator::capid() const {
if (m_flavor == 2)
return (m_ptr[1] >> 12) & 0x3;
else if (m_flavor == 7 && m_technicalDataType == 15) {
return ((*m_ptr) >> 8) & 0x3;
} else if (m_flavor == 1 || m_flavor == 0) {
// For flavor 0,1 we only get the first capid in the header, and so we need
// to count the number of data rows and figure out which cap we want,
// knowing that they go 0->1->2->3->0
return 0;
} else {
return 0;
}
}
bool HcalUHTRData::const_iterator::ok() const {
if (m_flavor == 2) {
return (m_ptr[0] >> 12) & 0x1;
} else if (m_flavor == 4) {
return (m_ptr[0] >> 13) & 0x1;
} else {
return false;
}
}
HcalUHTRData::const_iterator HcalUHTRData::begin() const {
return HcalUHTRData::const_iterator(m_raw16 + HEADER_LENGTH_16BIT,
m_raw16 + (m_rawLength64 - 1) * sizeof(uint64_t) / sizeof(uint16_t));
}
HcalUHTRData::const_iterator HcalUHTRData::end() const {
return HcalUHTRData::const_iterator(m_raw16 + (m_rawLength64 - 1) * sizeof(uint64_t) / sizeof(uint16_t),
m_raw16 + (m_rawLength64 - 1) * sizeof(uint64_t) / sizeof(uint16_t));
}
HcalUHTRData::HcalUHTRData()
: m_formatVersion(-2), m_rawLength64(0), m_raw64(nullptr), m_raw16(nullptr), m_ownData(nullptr) {}
HcalUHTRData::HcalUHTRData(const uint64_t* data, int length)
: m_rawLength64(length), m_raw64(data), m_raw16((const uint16_t*)(data)), m_ownData(nullptr) {
m_formatVersion = (m_raw16[6] >> 12) & 0xF;
}
HcalUHTRData::HcalUHTRData(const HcalUHTRData& hd)
: m_formatVersion(hd.m_formatVersion),
m_rawLength64(hd.m_rawLength64),
m_raw64(hd.m_raw64),
m_raw16(hd.m_raw16),
m_ownData(nullptr) {}
HcalUHTRData::HcalUHTRData(int version_to_create) : m_formatVersion(version_to_create) {
// the needed space is for the biggest possible event...
// fibers*maxsamples/fiber
const int needed = (0x20 + FIBERS_PER_UHTR * CHANNELS_PER_FIBER_MAX * (10 + 1)) * sizeof(uint16_t) / sizeof(uint64_t);
m_ownData = new uint64_t[needed];
memset(m_ownData, 0, sizeof(uint64_t) * needed);
m_rawLength64 = 0;
m_raw64 = m_ownData;
m_raw16 = (const uint16_t*)m_raw64;
}
HcalUHTRData& HcalUHTRData::operator=(const HcalUHTRData& hd) {
if (m_ownData == nullptr) {
m_formatVersion = hd.m_formatVersion;
m_rawLength64 = hd.m_rawLength64;
m_raw64 = hd.m_raw64;
m_raw16 = hd.m_raw16;
}
return (*this);
}
|