-
Notifications
You must be signed in to change notification settings - Fork 500
Expand file tree
/
Copy pathRawReaderZDC.cxx
More file actions
403 lines (386 loc) · 14.5 KB
/
RawReaderZDC.cxx
File metadata and controls
403 lines (386 loc) · 14.5 KB
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "ZDCRaw/RawReaderZDC.h"
#include <cstdlib>
namespace o2
{
namespace zdc
{
void RawReaderZDC::clear()
{
#ifndef O2_ZDC_DEBUG
LOG(info) << "RawReaderZDC::clear()";
#endif
for (int im = 0; im < NModules; im++) {
for (int ic = 0; ic < NChPerModule; ic++) {
mEvents[im][ic] = 0;
mDupOK[im][ic] = 0;
mDupKO[im][ic] = 0;
}
}
mDigitsBC.clear();
mDigitsCh.clear();
mOrbitData.clear();
}
int RawReaderZDC::processBinaryData(gsl::span<const uint8_t> payload, int linkID, uint8_t dataFormat)
{
if (0 <= linkID && linkID < 16) {
size_t payloadSize = payload.size();
if (dataFormat == 2) {
for (int32_t ip = 0; (ip + PayloadPerGBTW) <= payloadSize; ip += PayloadPerGBTW) {
#ifndef O2_ZDC_DEBUG
if (mVerbosity >= DbgExtra) {
o2::zdc::Digits2Raw::print_gbt_word((const uint32_t*)&payload[ip]);
}
#else
o2::zdc::Digits2Raw::print_gbt_word((const uint32_t*)&payload[ip]);
#endif
const uint32_t* gbtw = (const uint32_t*)&payload[ip];
if (gbtw[0] != 0xffffffff || gbtw[1] != 0xffffffff || (*((const uint16_t*)&gbtw[2])) != 0xffff) {
if (processWord(gbtw)) {
return 1;
}
}
}
} else if (dataFormat == 0) {
for (int32_t ip = 0; ip < payloadSize; ip += NBPerGBTW) {
#ifndef O2_ZDC_DEBUG
if (mVerbosity >= DbgExtra) {
o2::zdc::Digits2Raw::print_gbt_word((const uint32_t*)&payload[ip]);
}
#else
o2::zdc::Digits2Raw::print_gbt_word((const uint32_t*)&payload[ip]);
#endif
if (processWord((const uint32_t*)&payload[ip])) {
return 1;
}
}
} else {
LOG(fatal) << "RawReaderZDC::processBinaryData - Unsupported DataFormat " << dataFormat;
}
} else {
// put here code in case of bad rdh.linkID value
LOG(info) << "WARNING! WRONG LINK ID! " << linkID;
return 1;
}
return 0;
}
int RawReaderZDC::processWord(const uint32_t* word)
{
if (word == nullptr) {
LOG(error) << "NULL pointer";
return 1;
}
// LOGF(info, "GBT word %04x %08x %08x id=%u", *((uint16_t*)&word[2]), word[1], word[0], word[0] & 0x3);
if ((word[0] & 0x3) == Id_w0) {
mCh.w[0][NWPerGBTW - 1] = 0;
mCh.w[0][NWPerGBTW - 2] = 0;
memcpy((void*)&mCh.w[0][0], (const void*)word, PayloadPerGBTW);
} else if ((word[0] & 0x3) == Id_w1) {
if (mCh.f.fixed_0 == Id_w0) {
mCh.w[1][NWPerGBTW - 1] = 0;
mCh.w[1][NWPerGBTW - 2] = 0;
memcpy((void*)&mCh.w[1][0], (const void*)word, PayloadPerGBTW);
} else {
LOGF(error, "Wrong word sequence: %04x %08x %08x id=%u *%u*", *((uint16_t*)&word[2]), word[1], word[0], mCh.f.fixed_0, word[0] & 0x3);
mCh.f.fixed_0 = Id_wn;
mCh.f.fixed_1 = Id_wn;
mCh.f.fixed_2 = Id_wn;
}
} else if ((word[0] & 0x3) == Id_w2) {
if (mCh.f.fixed_0 == Id_w0 && mCh.f.fixed_1 == Id_w1) {
mCh.w[2][NWPerGBTW - 1] = 0;
mCh.w[2][NWPerGBTW - 2] = 0;
memcpy((void*)&mCh.w[2][0], (const void*)word, PayloadPerGBTW);
process(mCh);
} else {
LOGF(error, "Wrong word sequence: %04x %08x %08x id=%u %u *%u*", *((uint16_t*)&word[2]), word[1], word[0], mCh.f.fixed_0, mCh.f.fixed_1, word[0] & 0x3);
}
mCh.f.fixed_0 = Id_wn;
mCh.f.fixed_1 = Id_wn;
mCh.f.fixed_2 = Id_wn;
} else {
// Word id not foreseen in payload
LOGF(error, "Event format error on word %04x %08x %08x id=%u", *((uint16_t*)&word[2]), word[1], word[0], word[0] & 0x3);
return 1;
}
return 0;
}
void RawReaderZDC::process(const EventChData& ch)
{
InteractionRecord ir(ch.f.bc, ch.f.orbit);
auto& mydata = mMapData[ir];
int32_t im = ch.f.board;
int32_t ic = ch.f.ch;
mEvents[im][ic]++;
for (int32_t iwb = 0; iwb < NWPerBc; iwb++) {
for (int32_t iwg = 0; iwg < NWPerGBTW; iwg++) {
mydata.data[im][ic].w[iwb][iwg] = mCh.w[iwb][iwg];
}
}
}
// pop digits
int RawReaderZDC::getDigits(std::vector<BCData>& digitsBC, std::vector<ChannelData>& digitsCh, std::vector<OrbitData>& orbitData)
{
const char* thefcn = "RawReaderZDC::getDigits";
if (mModuleConfig == nullptr) {
LOG(fatal) << "Missing ModuleConfig";
return 0;
}
union {
uint16_t uns;
int16_t sig;
} word16;
int bcCounter = mMapData.size();
if (mVerbosity > DbgZero) {
LOG(info) << "Processing #bc " << bcCounter;
for (int ic = 0; ic < NChPerModule; ic++) {
for (int im = 0; im < NModules; im++) {
if (im == 0) {
printf("%6u", mEvents[im][ic]);
} else {
printf(" %6u", mEvents[im][ic]);
}
}
printf("\n");
}
}
for (auto& [ir, ev] : mMapData) {
// TODO: Error check
// Pedestal data
if (ir.bc == 3563) {
auto& pdata = orbitData.emplace_back();
pdata.ir = ir;
for (int32_t im = 0; im < NModules; im++) {
for (int32_t ic = 0; ic < NChPerModule; ic++) {
if (ev.data[im][ic].f.fixed_0 == Id_w0 && ev.data[im][ic].f.fixed_1 == Id_w1 && ev.data[im][ic].f.fixed_2 == Id_w2) {
// Protection for channels that are not supposed to readout but may be present in payload
// These additional channels are used just for scaler and pedestal readout at end of orbit
// for raw data QC only. They are skipped during digitization
if (mModuleConfig->modules[im].readChannel[ic]) {
// Identify connected channel
auto id = mModuleConfig->modules[im].channelID[ic];
word16.uns = ev.data[im][ic].f.offset;
pdata.data[id] = word16.sig;
if (ev.data[im][ic].f.dLoss) {
// Produce a scaler overflow to signal a problem
// Most significant bit indicates data loss
// Default initializer 0x8fff will indicate that orbit data is lost
pdata.scaler[id] = ev.data[im][ic].f.hits | 0x8000;
} else {
pdata.scaler[id] = ev.data[im][ic].f.hits;
}
}
} else if (ev.data[im][ic].f.fixed_0 == 0 && ev.data[im][ic].f.fixed_1 == 0 && ev.data[im][ic].f.fixed_2 == 0) {
// Empty channel
} else {
LOG(error) << "Data format error";
}
}
}
}
// BC data
auto& bcdata = digitsBC.emplace_back();
bcdata.ir = ir;
// An inconsistent event has as at least one inconsistent module
bool inconsistent_event = false;
bool inconsistent_alice_trig = false;
bool inconsistent_auto_trig = false;
bool filled_event = false;
bcdata.ref.setFirstEntry(digitsCh.size());
uint32_t ncd = 0;
bool alice_0 = false;
bool alice_1 = false;
bool alice_2 = false;
bool alice_3 = false;
// Channel data
for (int32_t im = 0; im < NModules; im++) {
ModuleTriggerMapData mt;
mt.w = 0;
bool filled_module = false;
for (int32_t ic = 0; ic < NChPerModule; ic++) {
// Check if payload is present for channel
if (ev.data[im][ic].f.fixed_0 == Id_w0 && ev.data[im][ic].f.fixed_1 == Id_w1 && ev.data[im][ic].f.fixed_2 == Id_w2) {
if (mModuleConfig->modules[im].readChannel[ic] == false) {
// Channel should not be present in payload. It may happen for bc=0 and bc=3563
if (bcdata.ir.bc == 0 || bcdata.ir.bc == 3563) {
mDupOK[im][ic]++;
} else {
mDupKO[im][ic]++;
}
continue;
}
bcdata.channels |= (0x1 << (NChPerModule * im + ic)); // Flag channel as present
auto& ch = ev.data[im][ic];
uint16_t us[12];
us[0] = ch.f.s00;
us[1] = ch.f.s01;
us[2] = ch.f.s02;
us[3] = ch.f.s03;
us[4] = ch.f.s04;
us[5] = ch.f.s05;
us[6] = ch.f.s06;
us[7] = ch.f.s07;
us[8] = ch.f.s08;
us[9] = ch.f.s09;
us[10] = ch.f.s10;
us[11] = ch.f.s11;
// Identify connected channel
auto& chd = digitsCh.emplace_back();
auto id = mModuleConfig->modules[im].channelID[ic];
chd.id = id;
for (int32_t is = 0; is < NTimeBinsPerBC; is++) {
if (us[is] > ADCMax) {
chd.data[is] = us[is] - ADCRange;
} else {
chd.data[is] = us[is];
}
}
// Trigger bits
if (ch.f.Hit) {
bcdata.triggers |= (0x1 << (im * NChPerModule + ic));
}
if (filled_event == false) {
// ALICE trigger bits must be the same for all readout modules
alice_0 = ch.f.Alice_0;
alice_1 = ch.f.Alice_1;
alice_2 = ch.f.Alice_2;
alice_3 = ch.f.Alice_3;
filled_event = true;
} else if (alice_0 != ch.f.Alice_0 || alice_1 != ch.f.Alice_1 || alice_2 != ch.f.Alice_2 || alice_3 != ch.f.Alice_3) {
inconsistent_event = true;
inconsistent_alice_trig = true;
mt.f.AliceErr = true;
LOGF(warn, "%s (m,c)=(%d,%d) Alice [0123] %u%s%u %u%s%u %u%s%u %u%s%u", thefcn, im, ic,
alice_0, alice_0 == ch.f.Alice_0 ? "==" : "!=", ch.f.Alice_0,
alice_1, alice_1 == ch.f.Alice_1 ? "==" : "!=", ch.f.Alice_1,
alice_2, alice_2 == ch.f.Alice_2 ? "==" : "!=", ch.f.Alice_2,
alice_3, alice_3 == ch.f.Alice_3 ? "==" : "!=", ch.f.Alice_3);
}
if (filled_module == false) {
mt.f.Auto_m = ch.f.Auto_m;
mt.f.Auto_0 = ch.f.Auto_0;
mt.f.Auto_1 = ch.f.Auto_1;
mt.f.Auto_2 = ch.f.Auto_2;
mt.f.Auto_3 = ch.f.Auto_3;
mt.f.Alice_0 = ch.f.Alice_0;
mt.f.Alice_1 = ch.f.Alice_1;
mt.f.Alice_2 = ch.f.Alice_2;
mt.f.Alice_3 = ch.f.Alice_3;
filled_module = true;
} else if (mt.f.Auto_m != ch.f.Auto_m || mt.f.Auto_0 != ch.f.Auto_0 || mt.f.Auto_1 != ch.f.Auto_1 || mt.f.Auto_2 != ch.f.Auto_2 || mt.f.Auto_3 != ch.f.Auto_3) {
mt.f.AutoErr = true;
inconsistent_auto_trig = true;
LOGF(warn, "%s (m,c)=(%d,%d) Auto [m0123] %u%s%u %u%s%u %u%s%u %u%s%u %u%s%u", thefcn, im, ic,
mt.f.Auto_m, mt.f.Auto_m == ch.f.Auto_m ? "==" : "!=", ch.f.Auto_m,
mt.f.Auto_0, mt.f.Auto_0 == ch.f.Auto_0 ? "==" : "!=", ch.f.Auto_0,
mt.f.Auto_1, mt.f.Auto_1 == ch.f.Auto_1 ? "==" : "!=", ch.f.Auto_1,
mt.f.Auto_2, mt.f.Auto_2 == ch.f.Auto_2 ? "==" : "!=", ch.f.Auto_2,
mt.f.Auto_3, mt.f.Auto_3 == ch.f.Auto_3 ? "==" : "!=", ch.f.Auto_3);
}
ncd++;
} else if (ev.data[im][ic].f.fixed_0 == 0 && ev.data[im][ic].f.fixed_1 == 0 && ev.data[im][ic].f.fixed_2 == 0) {
// Empty channel
} else {
LOG(error) << thefcn << "RAW Data format error";
}
}
bcdata.moduleTriggers[im] = mt.w;
if (mt.f.AutoErr == true) {
inconsistent_event = true;
}
}
if (ncd == 0) {
// Remove empty orbits (keep pedestal information)
digitsBC.pop_back();
} else {
bcdata.ref.setEntries(ncd);
if (mDumpData) {
bcdata.print(mTriggerMask);
auto first_entry = bcdata.ref.getFirstEntry();
for (Int_t icd = 0; icd < ncd; icd++) {
digitsCh[icd + first_entry].print();
}
}
}
if (inconsistent_event) {
LOGF(error, "%s %u.%04u Inconsistent event:%s%s", thefcn, bcdata.ir.orbit, bcdata.ir.bc, (inconsistent_auto_trig ? " AUTOT" : ""), (inconsistent_alice_trig ? " ALICET" : ""));
}
if ((inconsistent_event && mVerbosity > DbgMinimal) || (mVerbosity >= DbgFull)) {
bcdata.print(mTriggerMask);
for (int32_t im = 0; im < NModules; im++) {
for (int32_t ic = 0; ic < NChPerModule; ic++) {
if (ev.data[im][ic].f.fixed_0 == Id_w0 && ev.data[im][ic].f.fixed_1 == Id_w1 && ev.data[im][ic].f.fixed_2 == Id_w2) {
for (int32_t iw = 0; iw < NWPerBc; iw++) {
o2::zdc::Digits2Raw::print_gbt_word((const uint32_t*)&ev.data[im][ic].w[iw][0]);
}
}
}
}
}
} // Loop on bunch crossings
inspectDup();
mMapData.clear();
return bcCounter;
}
//______________________________________________________________________________
void RawReaderZDC::inspectDup()
{
// This function allows to examine if there are duplicate channels for modules in which it
// is expected and for modules in which is not expected
// A duplicate channel is present in pedestal data for channels that are readout on
// one module but connected to two modules because readout is forced in the FEE.
#ifdef O2_ZDC_DEBUG
LOG(info) << "RawReaderZDC::inspectDup()";
#endif
for (int32_t im = 0; im < NModules; im++) {
for (int32_t ic = 0; ic < NChPerModule; ic++) {
if (mVerbosity > DbgMinimal) {
if (mDupOK[im][ic] > 0) {
LOG(info) << "DupOK module " << im << " ch " << ic << " = " << mDupOK[im][ic];
}
}
if (mDupKO[im][ic] > 0) {
LOG(error) << "DupKO module " << im << " ch " << ic << " = " << mDupKO[im][ic];
}
}
}
}
//______________________________________________________________________________
void RawReaderZDC::setTriggerMask()
{
mTriggerMask = 0;
std::string printTriggerMask{};
for (int im = 0; im < NModules; im++) {
if (im > 0) {
printTriggerMask += " ";
}
printTriggerMask += std::to_string(im);
printTriggerMask += "[";
for (int ic = 0; ic < NChPerModule; ic++) {
if (mModuleConfig->modules[im].trigChannel[ic]) {
uint32_t tmask = 0x1 << (im * NChPerModule + ic);
mTriggerMask = mTriggerMask | tmask;
printTriggerMask += "T";
} else {
printTriggerMask += " ";
}
}
printTriggerMask += "]";
#ifdef O2_ZDC_DEBUG
uint32_t mytmask = mTriggerMask >> (im * NChPerModule);
LOGF(info, "Trigger mask for module %d 0123 %c%c%c%c", im, mytmask & 0x1 ? 'T' : 'N', mytmask & 0x2 ? 'T' : 'N', mytmask & 0x4 ? 'T' : 'N', mytmask & 0x8 ? 'T' : 'N');
#endif
}
LOGF(info, "trigger_mask=0x%08x %s", mTriggerMask, printTriggerMask.c_str());
}
} // namespace zdc
} // namespace o2