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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 8; -*-
#ifndef MATACQTBRAWEVENT_H
#define MATACQTBRAWEVENT_H
#include <cinttypes>
#include <ctime>
#include <vector>
//replace 1 by 0 to remove XDAQ dependency. In this case it is assumed the machine is little endian.
#if 0
#include "i2o/utils/endian.h" //from XDAQ
#define UINT32_FROM_LE i2odecodel
#define UINT16_FROM_LE i2odecodes
#define INT16_FROM_LE i2odecodes
#else //assuming little endianness of the machine
#define UINT32_FROM_LE
#define UINT16_FROM_LE
#define INT16_FROM_LE
#endif
/** Wrapper for matacq raw event fragments. This class provides the
* method to interpret the data.
*/
class MatacqTBRawEvent {
//typedefs, enums and static constants
public:
enum matacqError_t {
/** Event length is specified both in the data header and the trailer. This
* flags indicates an inconsitency between the two indications.
*/
errorLengthConsistency = 1 << 0,
/** Error in data length.
*/
errorLength = 1 << 1,
/** Wrong Begin of eevent flag
*/
errorWrongBoe = 1 << 2
};
/* The following types are little-endian encoded types. Use of these types
* for the I20 data block should offer portability to big-endian platforms.
*/
//@{
struct uint32le_t {
uint32_t littleEndianInt;
operator uint32_t() const { return UINT32_FROM_LE(littleEndianInt); }
};
struct uint16le_t {
uint16_t littleEndianInt;
operator uint16_t() const { return UINT16_FROM_LE(littleEndianInt); }
};
struct int16le_t {
int16_t littleEndianInt;
operator int16_t() const { return INT16_FROM_LE(littleEndianInt); }
};
//@}
struct ChannelData {
/** Matacq channel number. From 0 to 3.
*/
int chId;
/** Number of samples in following array
*/
int nSamples;
/** ADC count of time samples. Array of size nSamples
*/
const int16le_t* samples;
};
private:
/** Matacq header data structure
*/
struct matacqHeader_t {
uint16le_t version;
unsigned char freqGHz;
unsigned char channelCount;
uint32_t timeStamp;
};
/** Specification of DAQ header field.
*/
struct field32spec_t {
int offset;
unsigned int mask;
};
/** DAQ header field specifications.
*/
static const field32spec_t fov32;
static const field32spec_t fedId32;
static const field32spec_t bxId32;
static const field32spec_t lv132;
static const field32spec_t triggerType32;
static const field32spec_t boeType32;
static const field32spec_t dccLen32;
static const field32spec_t dccErrors32;
static const field32spec_t runNum32;
static const field32spec_t h1Marker32;
//constructors
public:
/** Constuctor.
* @param dataBuffer pointer to the raw data. Beware the data are not copied,
* therefore the data must be kept valid during the lifetime of the
* constructed object. pData must be aligned at least on 32-bit words.
* @param bufferSize size of the buffer pointed by dataBuffer and containing
* the data. The data themselves are allowed to be smaller than the buffer.
* @throw std::exception if the data cannot be decoded due to data corruption
* or truncation.
*/
MatacqTBRawEvent(const unsigned char* dataBuffer, std::size_t bufferSize) { setRawData(dataBuffer, bufferSize); }
//methods
public:
/** Gets the Fed event fragment data format (FOV) field content.
* Currently the FOV is not used for MATACQ.
* Note that matacq data format has its own internal version. See
* #getMatacqDataFormatVersion()
* @return FOV
*/
int getFov() const { return read32(daqHeader, fov32); }
/** Gets the FED ID field contents. Should be 43.
* @return FED ID
*/
int getFedId() const { return read32(daqHeader, fedId32); }
/** Gets the bunch crossing id field contents.
* @return BX id
*/
int getBxId() const { return read32(daqHeader, bxId32); }
/** Gets the LV1 field contents.
* @return LV1 id
*/
unsigned getEventId() const { return read32(daqHeader, lv132); }
/** Gets the trigger type field contents.
* @return trigger type
*/
int getTriggerType() const { return read32(daqHeader, triggerType32); }
/** Gets the beging of event field contents (BOE). Must be 0x5.
* @return BOE
*/
int getBoe() const { return read32(daqHeader, boeType32); }
/** Gets the event length specifies in the "a la DCC" header.
* @return event length
*/
unsigned getDccLen() const { return read32(daqHeader, dccLen32); }
/** Gets the event length specifies in the DAQ trailer
* @return event length
*/
unsigned getDaqLen() const { return fragLen; }
/** Gets the contents of the DCC error field. Currently Not used for Matacq.
* @return dcc error
*/
int getDccErrors() const { return read32(daqHeader, dccErrors32); }
/** Gets the run number field contents.
* @return run number
*/
unsigned getRunNum() const { return read32(daqHeader, runNum32); }
/** Gets the header marker field contents. Must be 1
* @return H1 header marker
*/
int getH1Marker() const { return read32(daqHeader, h1Marker32); }
/** Gets the matcq data format version
* @return data version
*/
int getMatacqDataFormatVersion() const { return matacqHeader->version; }
/** Gets the raw data status. Bitwise OR of the error flags
* defined by matcqError_t
* @return status
*/
int32_t getStatus() const { return error; }
/** Gets the matacq sampling frequency field contents.
* @return sampling frequency in GHz: 1 or 2
*/
int getFreqGHz() const { return matacqHeader->freqGHz; }
/** Gets the matacq channel count field contents.
* @return number of channels
*/
int getChannelCount() const { return matacqHeader->channelCount; }
/** Gets the matacq channel data. Beware that no copy is done and that
* the returned data will be invalidated if the data contains in the buffer
* is modified (see constructor and #setRawData().
* @return matacq channel data.
*/
const std::vector<ChannelData>& getChannelData() const { return channelData; }
/** Gets the data length in number of 64-bit words computed by the data
* parser.
* @return event length
*/
int getParsedLen() { return parsedLen; }
/** Gets the matacq data timestamp field contents:
* @return acquisition date of the data expressed in number of "elapsed"
* second since the EPOCH as defined in POSIX.1. See time() standard c
* function.
*/
time_t getTimeStamp() const { return matacqHeader->timeStamp; }
/** Gets the Matacq trigger time.
* @return (t_trig-t_0) in ps, with t_0 the time of the first sample and
* t_trig the trigger time.
*/
int getTTrigPs() const { return tTrigPs; }
private:
/** Help function to decode header content.
* @param data pointer
* @param spec specification of the data field to read
* @return content of data field specified by 'spec'
*/
int read32(const uint32le_t* pData, field32spec_t spec) const;
/** Changes the raw data pointer and updates accordingly this object.
* @param buffer new pointer to the data buffer. Must be aligned at least
* on 32-bit words.
* @param size of the data buffer.
* @throw std::exception if the data cannot be decoded due to data corruption
* or truncation.
*/
void setRawData(const unsigned char* buffer, std::size_t bufferSize);
//fields
private:
/** Begin Of Event marker
*/
int boe;
/** Bunch crossing Id
*/
int bxId;
/** Number of matacq channels in the data.
*/
int channelCount;
/** Channel samples
*/
std::vector<ChannelData> channelData;
/** Pointer to the standard CMS DAQ header
*/
const uint32le_t* daqHeader;
/** DCC error field content.
*/
int dccErrors;
/** Event length specified in 'DCC' header
*/
unsigned dccLen;
/** Event id. Actually LV1 ID.
*/
unsigned eventId;
/** Error code or 0 if no error.
*/
int32_t error;
/** FED ID
*/
int fedId;
/** FED data format version
*/
int fov;
/** event fragment length as read in the std DAQ trailer. In 64-bit words
*/
int fragLen;
/** MATACQ sampling frequency in GHz
*/
int freqGHz;
/** header marker
*/
int h1Marker;
/**Matacq header:
*/
const matacqHeader_t* matacqHeader;
/** MATACQ data format internal version
*/
int matacqDataFormatVersion;
/** event lenght computed by the raw data parser
*/
int parsedLen;
/** Pointer to MATACQ samples block
*/
uint16le_t* pSamples;
/** Run number
*/
unsigned runNum;
/** Matacq acquisition time stamp
*/
time_t timeStamp;
/** MATACQ trigger time position in ps
*/
int tTrigPs;
/** Trigger type
*/
int triggerType;
};
#endif //MATACQRAWEVENT_H not defined
|