Project
Loading...
Searching...
No Matches
RawDataDecoder.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#include <fstream>
21#include <boost/range/adaptor/reversed.hpp>
22
23using namespace o2::ctp;
24
25// Inverse of Digits2Raw::makeGBTWord
26void RawDataDecoder::makeGBTWordInverse(std::vector<gbtword80_t>& diglets, gbtword80_t& GBTWord, gbtword80_t& remnant, uint32_t& size_gbt, uint32_t Npld)
27{
28 gbtword80_t diglet = remnant;
29 uint32_t i = 0;
30 while (i < (NGBT - Npld)) {
31 std::bitset<NGBT> masksize = 0;
32 for (uint32_t j = 0; j < (Npld - size_gbt); j++) {
33 masksize[j] = 1;
34 }
35 diglet |= (GBTWord & masksize) << (size_gbt);
36 diglets.push_back(diglet);
37 diglet = 0;
38 i += Npld - size_gbt;
39 GBTWord = GBTWord >> (Npld - size_gbt);
40 size_gbt = 0;
41 }
42 size_gbt = NGBT - i;
43 remnant = GBTWord;
44}
45int RawDataDecoder::addCTPDigit(uint32_t linkCRU, uint32_t orbit, gbtword80_t& diglet, gbtword80_t& pldmask, std::map<o2::InteractionRecord, CTPDigit>& digits)
46{
47 int ret = 0;
48 gbtword80_t pld = (diglet & pldmask);
49 if (pld.count() == 0) {
50 return 0;
51 }
52 pld >>= 12;
53 CTPDigit digit;
54 const gbtword80_t bcidmask = 0xfff;
55 uint16_t bcid = (diglet & bcidmask).to_ulong();
56 LOG(debug) << bcid << " pld:" << pld;
58 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
60 LOG(debug) << "InputMaskCount:" << digits[ir].CTPInputMask.count();
61 LOG(debug) << "ir ir ori:" << ir;
62 if ((ir.orbit <= mTFOrbit) && ((int32_t)ir.bc < BCShiftCorrectionInps)) {
63 // LOG(warning) << "Loosing ir:" << ir;
64 mIRRejected++;
65 return 0;
66 }
67 ir -= BCShiftCorrectionInps;
68 LOG(debug) << "ir ir corrected:" << ir;
69 digit.intRecord = ir;
70 if (digits.count(ir) == 0) {
71 digit.setInputMask(pld);
72 digits[ir] = digit;
73 LOG(debug) << bcid << " inputs case 0 bcid orbit " << orbit << " pld:" << pld;
74 } else if (digits.count(ir) == 1) {
75 if (digits[ir].CTPInputMask.count() == 0) {
77 LOG(debug) << bcid << " inputs bcid case 1 orbit " << orbit << " pld:" << pld;
78 } else {
79 if (mErrorIR < mErrorMax) {
80 LOG(error) << "Two CTP IRs with the same timestamp:" << ir.bc << " " << ir.orbit << " pld:" << pld << " dig:" << digits[ir];
81 }
82 ret = 4;
83 mErrorIR++;
84 mStickyError = true;
85 }
86 } else {
87 LOG(error) << "Two digits with the same timestamp:" << ir.bc << " " << ir.orbit;
88 ret = 8;
89 }
90 } else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
91 int32_t BCShiftCorrection = -o2::ctp::TriggerOffsetsParam::Instance().customOffset[o2::detectors::DetID::CTP];
93 LOG(debug) << "tcr ir ori:" << ir;
94 if ((ir.orbit <= mTFOrbit) && ((int32_t)ir.bc < offset)) {
95 // LOG(warning) << "Loosing tclass:" << ir;
96 mTCRRejected++;
97 return 0;
98 }
99 ir -= offset;
100 LOG(debug) << "tcr ir corrected:" << ir;
101 digit.intRecord = ir;
102 if (digits.count(ir) == 0) {
103 digit.setClassMask(pld);
104 digits[ir] = digit;
105 LOG(debug) << bcid << " class bcid case 0 orbit " << orbit << " pld:" << pld;
106 } else if (digits.count(ir) == 1) {
107 if (digits[ir].CTPClassMask.count() == 0) {
108 digits[ir].setClassMask(pld);
109 LOG(debug) << bcid << " class bcid case 1 orbit " << orbit << " pld:" << pld;
110 } else {
111 if (mErrorTCR < mErrorMax) {
112 LOG(error) << "Two CTP Class masks for same timestamp";
113 mStickyError = true;
114 }
115 mErrorTCR++;
116 ret = 16;
117 }
118 } else {
119 LOG(error) << "Two digits with the same timestamp:" << ir.bc << " " << ir.orbit;
120 ret = 32;
121 }
122 } else {
123 LOG(error) << "Unxpected CTP CRU link:" << linkCRU;
124 }
125 return ret;
126}
127//
128// Decodes one page
129// It is NOT assumed that CTP HBF has never more than one page.
130// 1 HBF/page <= 8000kB = 8*1024*8/120 = 546 GBT words = 546 IRs/page = 5.5 MHz
131int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2::framework::InputSpec>& filter, o2::pmr::vector<CTPDigit>& digits, std::vector<LumiInfo>& lumiPointsHBF1)
132{
133 int ret = 0;
134 static int nwrites = 0;
135 uint64_t countsMBT = 0;
136 uint64_t countsMBV = 0;
137 std::map<o2::InteractionRecord, CTPDigit> digitsMap;
138 //
139 // using InputSpec = o2::framework::InputSpec;
140 // using ConcreteDataTypeMatcher = o2::framework::ConcreteDataTypeMatcher;
141 // using Lifetime = o2::framework::Lifetime;
142 o2::framework::DPLRawParser parser(inputs, filter);
143 uint32_t payloadCTP = 0;
144 gbtword80_t remnant = 0;
145 uint32_t size_gbt = 0;
146 mTFOrbit = 0;
147 uint32_t orbit0 = 0;
148 for (auto it = parser.begin(); it != parser.end(); ++it) {
149 const o2::header::RDHAny* rdh = nullptr;
150 try {
151 rdh = reinterpret_cast<const o2::header::RDHAny*>(it.raw());
152 mPadding = (o2::raw::RDHUtils::getDataFormat(rdh) == 0);
153 } catch (std::exception& e) {
154 LOG(error) << "Failed to extract RDH, abandoning TF sending dummy output, exception was: " << e.what();
155 // dummyOutput();
156 return 1;
157 }
158 // auto triggerOrbit = o2::raw::RDHUtils::getTriggerOrbit(rdh);
159 uint32_t stopBit = o2::raw::RDHUtils::getStop(rdh);
160 uint32_t packetCounter = o2::raw::RDHUtils::getPageCounter(rdh);
162 uint32_t rdhOrbit = o2::raw::RDHUtils::getHeartBeatOrbit(rdh);
163 uint32_t triggerType = o2::raw::RDHUtils::getTriggerType(rdh);
164 // std::cout << "diff orbits:" << triggerOrbit - rdhOrbit << std::endl;
165 bool tf = (triggerType & TF_TRIGGERTYPE_MASK) && (packetCounter == 0);
166 bool hb = (triggerType & HB_TRIGGERTYPE_MASK) && (packetCounter == 0);
167 if (tf) {
168 mTFOrbit = rdhOrbit;
169 // std::cout << "tforbit==================>" << mTFOrbit << " " << std::hex << mTFOrbit << std::endl;
170 mTFOrbits.push_back(mTFOrbit);
171 }
172 static bool prt = true;
173 if (prt) {
174 LOG(info) << "RDH version:" << version << " Padding:" << mPadding;
175 prt = false;
176 }
177 auto feeID = o2::raw::RDHUtils::getFEEID(rdh); // 0 = IR, 1 = TCR
178 auto linkCRU = (feeID & 0xf00) >> 8;
179 // LOG(info) << "CRU link:" << linkCRU;
180 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
181 payloadCTP = o2::ctp::NIntRecPayload;
182 } else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
183 payloadCTP = o2::ctp::NClassPayload;
184 if (!mDoDigits) { // Do not do TCR if only lumi
185 continue;
186 }
187 } else {
188 LOG(error) << "Unxpected CTP CRU link:" << linkCRU;
189 }
190 LOG(debug) << "RDH FEEid: " << feeID << " CTP CRU link:" << linkCRU << " Orbit:" << rdhOrbit << " triggerType:" << triggerType;
191 // LOG(info) << "remnant :" << remnant.count();
192 gbtword80_t pldmask = 0;
193 for (uint32_t i = 0; i < payloadCTP; i++) {
194 pldmask[12 + i] = 1;
195 }
196 // std::cout << (orbit0 != rdhOrbit) << " comp " << (mTFOrbit==rdhOrbit) << std::endl;
197 // if(orbit0 != rdhOrbit) {
198 if (hb) {
199 if ((mDoLumi && payloadCTP == o2::ctp::NIntRecPayload) && !tf) { // create lumi per HB
200 lumiPointsHBF1.emplace_back(LumiInfo{rdhOrbit, 0, 0, countsMBT, countsMBV});
201 // std::cout << "hb:" << nhb << " countsMBT:" << countsMBT << std::endl;
202 countsMBT = 0;
203 countsMBV = 0;
204 // nhb++;
205 }
206 remnant = 0;
207 size_gbt = 0;
208 orbit0 = rdhOrbit;
209 // std::cout << "orbit0============>" << std::dec << orbit0 << " " << std::hex << orbit0 << std::endl;
210 }
211 // Create 80 bit words
212 gsl::span<const uint8_t> payload(it.data(), it.size());
213 gbtword80_t gbtWord80;
214 gbtWord80.set();
215 int wordCount = 0;
216 int wordSize = 10;
217 std::vector<gbtword80_t> gbtwords80;
218 // mPadding = 0;
219 if (mPadding == 1) {
220 wordSize = 16;
221 }
222 // LOG(info) << ii << " payload size:" << payload.size();
223 /* if (payload.size()) {
224 //LOG(info) << "payload size:" << payload.size();
225 // LOG(info) << "RDH FEEid: " << feeID << " CTP CRU link:" << linkCRU << " Orbit:" << triggerOrbit << " stopbit:" << stopBit << " packet:" << packetCounter;
226 // LOGP(info, "RDH FEEid: {} CRU link: {}, Orbit: {}", feeID, linkCRU, triggerOrbit);
227 std::cout << std::hex << "RDH FEEid: " << feeID << " CTP CRU link:" << linkCRU << " Orbit:" << rdhOrbit << std::endl;
228 } */
229 gbtword80_t bcmask = std::bitset<80>("111111111111");
230 for (auto payloadWord : payload) {
231 int wc = wordCount % wordSize;
232 // LOG(info) << wordCount << ":" << wc << " payload:" << int(payloadWord);
233 if ((wc == 0) && (wordCount != 0)) {
234 if (gbtWord80.count() != 80) {
235 gbtwords80.push_back(gbtWord80);
236 }
237 gbtWord80.set();
238 }
239 if (wc < 10) {
240 for (int i = 0; i < 8; i++) {
241 gbtWord80[wc * 8 + i] = bool(int(payloadWord) & (1 << i));
242 }
243 }
244 wordCount++;
245 }
246 if ((gbtWord80.count() != 80) && (gbtWord80.count() > 0)) {
247 gbtwords80.push_back(gbtWord80);
248 }
249 // decode 80 bits payload
250 for (auto word : gbtwords80) {
251 std::vector<gbtword80_t> diglets;
252 gbtword80_t gbtWord = word;
253 makeGBTWordInverse(diglets, gbtWord, remnant, size_gbt, payloadCTP);
254 for (auto diglet : diglets) {
255 if (mDoLumi && payloadCTP == o2::ctp::NIntRecPayload) {
256 gbtword80_t pld = (diglet >> 12) & mTVXMask;
257 if (pld.count() != 0) {
258 countsMBT++;
259 }
260 pld = (diglet >> 12) & mVBAMask;
261 if (pld.count() != 0) {
262 countsMBV++;
263 }
264 }
265 if (!mDoDigits) {
266 continue;
267 }
268 LOG(debug) << "diglet:" << diglet << " " << (diglet & bcmask).to_ullong();
269 ret = addCTPDigit(linkCRU, rdhOrbit, diglet, pldmask, digitsMap);
270 }
271 }
272 if ((remnant.count() > 0) && stopBit) {
273 if (mDoLumi && payloadCTP == o2::ctp::NIntRecPayload) {
274 gbtword80_t pld = (remnant >> 12) & mTVXMask;
275 if (pld.count() != 0) {
276 countsMBT++;
277 }
278 pld = (remnant >> 12) & mVBAMask;
279 if (pld.count() != 0) {
280 countsMBV++;
281 }
282 }
283 if (!mDoDigits) {
284 continue;
285 }
286 ret = addCTPDigit(linkCRU, rdhOrbit, remnant, pldmask, digitsMap);
287 LOG(debug) << "diglet:" << remnant << " " << (remnant & bcmask).to_ullong();
288 remnant = 0;
289 }
290 }
291 if (mDoLumi) {
292 lumiPointsHBF1.emplace_back(LumiInfo{orbit0, 0, 0, countsMBT, countsMBV});
293 // std::cout << "last lumi:" << nhb << std::endl;
294 }
295 if (mDoDigits & mDecodeInps) {
296 uint64_t trgclassmask = 0xffffffffffffffff;
297 uint64_t trgclassmaskNOTRGDet = 0xffffffffffffffff;
298 if (mCTPConfig.getRunNumber() != 0) {
299 trgclassmask = mCTPConfig.getTriggerClassMaskWInputs(); // classes triggered by internal ctp generators not here
300 trgclassmaskNOTRGDet = mCTPConfig.getTriggerClassMaskWInputsNoTrgDets();
301 // mCTPConfig.printStream(std::cout);
302 }
303 // std::cout << "trgclassmask:" << std::hex << trgclassmask << std::dec << std::endl;
304 mLostDueToShiftInps += shiftInputs(digitsMap, digits, mTFOrbit);
305 if (mCheckConsistency) {
306 ret = checkReadoutConsistentncy(digits, trgclassmask, trgclassmaskNOTRGDet);
307 }
308 }
309 if (mDoDigits && !mDecodeInps) {
310 for (auto const& dig : digitsMap) {
311 digits.push_back(dig.second);
312 }
313 }
314 // ret = 1;
315 if (mStickyError) {
316 if (nwrites < mErrorMax) {
317 std::string file = "dumpCTP" + std::to_string(nwrites) + ".bin";
318 std::ofstream dumpctp(file.c_str(), std::ios::out | std::ios::binary);
319 if (!dumpctp.good()) {
320 LOGP(error, "Failed to open file {}", file);
321 } else {
322 LOGP(info, "CTP dump file open {}", file);
323 for (auto it = parser.begin(); it != parser.end(); ++it) {
324 char* dataout = (char*)(it.raw());
325 dumpctp.write(dataout, it.sizeTotal());
326 }
327 dumpctp.close();
328 }
329 nwrites++;
330 }
331 // LOG(error) << "CTP decoding IR errors:" << mErrorIR << " TCR errors:" << mErrorTCR;
332 }
333 return ret;
334}
335//
336int RawDataDecoder::decodeRawFatal(o2::framework::InputRecord& inputs, std::vector<o2::framework::InputSpec>& filter)
337{
338 o2::framework::DPLRawParser parser(inputs, filter);
339 uint32_t payloadCTP = 0;
340 gbtword80_t remnant = 0;
341 uint32_t size_gbt = 0;
342 mTFOrbit = 0;
343 uint32_t orbit0 = 0;
344 std::array<int, o2::ctp::CTP_NCLASSES> rates{};
345 std::array<int, o2::ctp::CTP_NCLASSES> ratesC{};
346 for (auto it = parser.begin(); it != parser.end(); ++it) {
347 const o2::header::RDHAny* rdh = nullptr;
348 try {
349 rdh = reinterpret_cast<const o2::header::RDHAny*>(it.raw());
350 mPadding = (o2::raw::RDHUtils::getDataFormat(rdh) == 0);
351 } catch (std::exception& e) {
352 LOG(error) << "Failed to extract RDH, abandoning TF sending dummy output, exception was: " << e.what();
353 // dummyOutput();
354 return 1;
355 }
356 // auto triggerOrbit = o2::raw::RDHUtils::getTriggerOrbit(rdh);
357 uint32_t stopBit = o2::raw::RDHUtils::getStop(rdh);
358 uint32_t packetCounter = o2::raw::RDHUtils::getPageCounter(rdh);
360 uint32_t rdhOrbit = o2::raw::RDHUtils::getHeartBeatOrbit(rdh);
361 uint32_t triggerType = o2::raw::RDHUtils::getTriggerType(rdh);
362 // std::cout << "diff orbits:" << triggerOrbit - rdhOrbit << std::endl;
363 bool tf = (triggerType & TF_TRIGGERTYPE_MASK) && (packetCounter == 0);
364 bool hb = (triggerType & HB_TRIGGERTYPE_MASK) && (packetCounter == 0);
365 if (tf) {
366 mTFOrbit = rdhOrbit;
367 // std::cout << "tforbit==================>" << mTFOrbit << " " << std::hex << mTFOrbit << std::endl;
368 mTFOrbits.push_back(mTFOrbit);
369 }
370 static bool prt = true;
371 if (prt) {
372 LOG(info) << "RDH version:" << version << " Padding:" << mPadding;
373 prt = false;
374 }
375 auto feeID = o2::raw::RDHUtils::getFEEID(rdh); // 0 = IR, 1 = TCR
376 auto linkCRU = (feeID & 0xf00) >> 8;
377 // LOG(info) << "CRU link:" << linkCRU;
378 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
379 payloadCTP = o2::ctp::NIntRecPayload;
380 } else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
381 payloadCTP = o2::ctp::NClassPayload;
382 } else {
383 LOG(error) << "Unxpected CTP CRU link:" << linkCRU;
384 }
385 LOG(debug) << "RDH FEEid: " << feeID << " CTP CRU link:" << linkCRU << " Orbit:" << rdhOrbit << " triggerType:" << triggerType;
386 // LOG(info) << "remnant :" << remnant.count();
387 gbtword80_t pldmask = 0;
388 for (uint32_t i = 0; i < payloadCTP; i++) {
389 pldmask[12 + i] = 1;
390 }
391 // std::cout << (orbit0 != rdhOrbit) << " comp " << (mTFOrbit==rdhOrbit) << std::endl;
392 // if(orbit0 != rdhOrbit) {
393 if (hb) {
394 remnant = 0;
395 size_gbt = 0;
396 orbit0 = rdhOrbit;
397 // std::cout << "orbit0============>" << std::dec << orbit0 << " " << std::hex << orbit0 << std::endl;
398 }
399 // Create 80 bit words
400 gsl::span<const uint8_t> payload(it.data(), it.size());
401 gbtword80_t gbtWord80;
402 gbtWord80.set();
403 int wordCount = 0;
404 int wordSize = 10;
405 std::vector<gbtword80_t> gbtwords80;
406 // mPadding = 0;
407 if (mPadding == 1) {
408 wordSize = 16;
409 }
410 // LOG(info) << ii << " payload size:" << payload.size();
411 gbtword80_t bcmask = std::bitset<80>("111111111111");
412 for (auto payloadWord : payload) {
413 int wc = wordCount % wordSize;
414 // LOG(info) << wordCount << ":" << wc << " payload:" << int(payloadWord);
415 if ((wc == 0) && (wordCount != 0)) {
416 if (gbtWord80.count() != 80) {
417 gbtwords80.push_back(gbtWord80);
418 }
419 gbtWord80.set();
420 }
421 if (wc < 10) {
422 for (int i = 0; i < 8; i++) {
423 gbtWord80[wc * 8 + i] = bool(int(payloadWord) & (1 << i));
424 }
425 }
426 wordCount++;
427 }
428 if ((gbtWord80.count() != 80) && (gbtWord80.count() > 0)) {
429 gbtwords80.push_back(gbtWord80);
430 }
431 // decode 80 bits payload
432 for (auto word : gbtwords80) {
433 std::vector<gbtword80_t> diglets;
434 gbtword80_t gbtWord = word;
435 makeGBTWordInverse(diglets, gbtWord, remnant, size_gbt, payloadCTP);
436 for (auto diglet : diglets) {
437 int nbits = payloadCTP - 12;
438 for (int i = 0; i < nbits; i++) {
439 gbtword80_t mask = 1ull << i;
440 gbtword80_t pld = (diglet >> 12) & mask;
441 // LOG(info) << "diglet:" << diglet << " pld:" << pld;
442 if (pld.count() != 0) {
443 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
444 rates[i]++;
445 } else {
446 ratesC[i]++;
447 }
448 }
449 }
450 // LOG(debug) << "diglet:" << diglet << " " << (diglet & bcmask).to_ullong();
451 }
452 }
453 if ((remnant.count() > 0) && stopBit) {
454 int nbits = payloadCTP - 12;
455 for (int i = 0; i < nbits; i++) {
456 gbtword80_t mask = 1ull << i;
457 gbtword80_t pld = (remnant >> 12) & mask;
458 // LOG(info) << "diglet:" << remnant << " pld:" << pld;
459 if (pld.count() != 0) {
460 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
461 rates[i]++;
462 } else {
463 ratesC[i]++;
464 }
465 }
466 }
467 remnant = 0;
468 }
469 }
470 // print max rates
471 std::map<int, int> ratesmap;
472 std::map<int, int> ratesmapC;
473 for (int i = 0; i < o2::ctp::CTP_NCLASSES; i++) {
474 if (rates[i]) {
475 ratesmap[rates[i]] = i;
476 }
477 if (ratesC[i]) {
478 ratesmapC[ratesC[i]] = i;
479 }
480 }
482 std::string message = "Ringing inputs [MHz]:";
483 for (auto const& r : boost::adaptors::reverse(ratesmap)) {
484 // LOG(error) << r.second;
485 message += " " + o2::ctp::CTPInputsConfiguration::getInputNameFromIndex(r.second + 1) + ":" + std::to_string(r.first / 32. / o2::constants::lhc::LHCOrbitMUS);
486 }
487 std::string messageC = "Ringing classes [MHz]:";
488 for (auto const& r : boost::adaptors::reverse(ratesmapC)) {
489 messageC += " class" + std::to_string(r.second) + ":" + std::to_string(r.first / 32. / o2::constants::lhc::LHCOrbitMUS);
490 }
491 LOG(error) << messageC;
492 LOG(fatal) << message;
493 return 0;
494}
495//
496int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2::framework::InputSpec>& filter, std::vector<CTPDigit>& digits, std::vector<LumiInfo>& lumiPointsHBF1)
497{
499 int ret = decodeRaw(inputs, filter, pmrdigits, lumiPointsHBF1);
500 for (auto const d : pmrdigits) {
501 digits.push_back(d);
502 }
503 return ret;
504}
505//
506// Not to be called with level LM
507// Keeping shift in params if needed to be generalised
508int RawDataDecoder::shiftNew(const o2::InteractionRecord& irin, uint32_t TFOrbit, std::bitset<48>& inpmask, int64_t shift, int level, std::map<o2::InteractionRecord, CTPDigit>& digmap)
509{
510 //
511 if (irin.orbit > TFOrbit || irin.bc >= shift) {
512 auto lxmask = L0MASKInputs;
513 if (level == 1) {
514 lxmask = L1MASKInputs;
515 }
516 auto ir = irin - shift; // add L0 to prev digit
517 if (digmap.count(ir)) {
518 if ((digmap[ir].CTPInputMask & lxmask).count()) {
519 LOG(error) << " Overwriting LX ? X:" << level;
520 }
521 digmap[ir].CTPInputMask = digmap[ir].CTPInputMask | (inpmask & lxmask);
522 } else {
523 CTPDigit digit = {ir, inpmask & lxmask, 0};
524 digmap[ir] = digit;
525 }
526 } else {
527 // LOG(info) << "LOST:" << irin << " shift:" << shift;
528 return 1;
529 ;
530 }
531 return 0;
532}
533//
534
535int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit, uint64_t trgclassmask)
536{
537 // int nClasswoInp = 0; // counting classes without input which should never happen
538 int lost = 0;
539 std::map<o2::InteractionRecord, CTPDigit> digitsMapShifted;
541 auto L1shift = L0shift + o2::ctp::TriggerOffsetsParam::Instance().L0_L1;
542 for (auto const& dig : digitsMap) {
543 auto inpmask = dig.second.CTPInputMask;
544 auto inpmaskLM = inpmask & LMMASKInputs;
545 auto inpmaskL0 = inpmask & L0MASKInputs;
546 auto inpmaskL1 = inpmask & L1MASKInputs;
547 int lm = inpmaskLM.count() > 0;
548 int l0 = inpmaskL0.count() > 0;
549 int l1 = inpmaskL1.count() > 0;
550 int lut = lm + (l0 << 1) + (l1 << 2);
551 // std::cout << "L0mask:" << L0MASKInputs << std::endl;
552 // std::cout << "L0:" << inpmaskL0 << std::endl;
553 // std::cout << "L1:" << inpmaskL1 << std::endl;
554 if (lut == 0 || lut == 1) { // no inps or LM
555 digitsMapShifted[dig.first] = dig.second;
556 } else if (lut == 2) { // L0
557 lost += shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
558 if (dig.second.CTPClassMask.count()) {
559 // LOG(error) << "Adding class mask without input ?";
560 // This is not needed as it can happen; Full checj done below - see next LOG(error)
561 CTPDigit digi = {dig.first, 0, dig.second.CTPClassMask};
562 digitsMapShifted[dig.first] = digi;
563 }
564 } else if (lut == 4) { // L1
565 lost += shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
566 if (dig.second.CTPClassMask.count()) {
567 CTPDigit digi = {dig.first, 0, dig.second.CTPClassMask};
568 digitsMapShifted[dig.first] = digi;
569 }
570 } else if (lut == 6) { // L0 and L1
571 lost += shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
572 lost += shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
573 if (dig.second.CTPClassMask.count()) {
574 CTPDigit digi = {dig.first, 0, dig.second.CTPClassMask};
575 digitsMapShifted[dig.first] = digi;
576 }
577 } else if (lut == 3) { // LM and L0
578 lost += shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
579 CTPDigit digi = {dig.first, inpmask & (~L0MASKInputs), dig.second.CTPClassMask};
580 // if LM level do not need to add class as LM is not shifted;
581 digitsMapShifted[dig.first] = digi;
582 } else if (lut == 5) { // LM and L1
583 lost += shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
584 CTPDigit digi = {dig.first, inpmask & (~L1MASKInputs), dig.second.CTPClassMask};
585 digitsMapShifted[dig.first] = digi;
586 } else if (lut == 7) { // LM and L0 and L1
587 lost += shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
588 lost += shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
589 CTPDigit digi = {dig.first, inpmaskLM, dig.second.CTPClassMask};
590 digitsMapShifted[dig.first] = digi;
591 } else {
592 LOG(fatal) << "lut = " << lut;
593 }
594 }
595 for (auto const& dig : digitsMapShifted) {
596 digits.push_back(dig.second);
597 }
598 return lost;
599}
600//
601int RawDataDecoder::checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask, uint64_t trgclassmaskNoTrgDet)
602{
603 LOG(debug) << "Checking readout";
604 int ret = 0;
605 static int nerror = 0;
607 for (auto const& digit : digits) {
608 // if class mask => inps
609 for (int i = 0; i < digit.CTPClassMask.size(); i++) {
610 bool trgcls = trgclassmask & (1ull << i);
611 if (digit.CTPClassMask[i] & trgcls) {
612 const CTPClass* cls = mCTPConfig.getCTPClassFromHWIndex(i);
613 if (cls == nullptr) {
614 if (nerror < mErrorMax) {
615 LOG(error) << "Class mask index not found in CTP config:" << i;
616 nerror++;
617 }
618 ret = 128;
619 continue;
620 }
621 mClassCountersA[i]++;
622 if (cls->descriptor == nullptr) {
623 continue;
624 }
625 uint64_t clsinpmask = cls->descriptor->getInputsMask();
626 uint64_t diginpmask = digit.CTPInputMask.to_ullong();
627 if (!((clsinpmask & diginpmask) == clsinpmask)) {
628 bool e = !(((digit.intRecord.bc == magicBC) || (digit.intRecord.bc == (magicBC + 1))) && (clsinpmask & L1MASKInputs.to_ullong()));
629 if (e) {
630 if (nerror < mErrorMax) {
631 LOG(error) << "Cls=>Inps: CTP class:" << cls->name << " inpmask:" << clsinpmask << " not compatible with inputs mask:" << diginpmask << " " << digit.intRecord;
632 nerror++;
633 }
634 mClassErrorsA[i]++;
635 ret = 128;
636 }
637 }
638 }
639 }
640 // if inps => class mask
641 for (auto const& cls : mCTPConfig.getCTPClasses()) {
642 // cls.printStream(std::cout);
643 if (cls.descriptor == nullptr) {
644 continue;
645 }
646 uint64_t clsinpmask = cls.descriptor->getInputsMask(); // class definition
647 uint64_t diginpmask = digit.CTPInputMask.to_ullong();
648 uint64_t digclsmask = digit.CTPClassMask.to_ullong();
649 if ((clsinpmask & diginpmask) == clsinpmask) {
650 if (cls.classMask & trgclassmask) {
651 mClassCountersB[cls.getIndex()]++;
652 if ((cls.classMask & digclsmask) == 0) {
653 int32_t BCShiftCorrection = -o2::ctp::TriggerOffsetsParam::Instance().customOffset[o2::detectors::DetID::CTP];
655 offset = o2::constants::lhc::LHCMaxBunches - offset;
656 if (digit.intRecord.bc < offset) {
657 if ((nerror < mErrorMax) && (cls.classMask & ~trgclassmaskNoTrgDet)) {
658 LOG(info) << "Inp=>Cls: CTP class:" << cls.name << " inpmask:" << clsinpmask << " cls mask:" << cls.classMask << " not found in digit:" << digit;
659 nerror++;
660 }
661 mClassErrorsB[cls.getIndex()]++;
662 ret = 256;
663 } else {
664 mLostDueToShiftCC++;
665 }
666 }
667 }
668 }
669 }
670 }
671 return ret;
672}
673//
674int RawDataDecoder::setLumiInp(int lumiinp, std::string inp)
675{
676 // check if valid input
678 if (index == 0xff) {
679 LOG(fatal) << "CTP raw decoder: input index not found:" << inp;
680 return 0xff;
681 }
682 if (lumiinp == 1) {
683 mTVXMask.reset();
684 mTVXMask[index - 1] = true;
685 } else {
686 mVBAMask.reset();
687 mVBAMask[index - 1] = true;
688 }
689 return index;
690}
691//
693{
694 return 0;
695}
A raw page parser for DPL input.
definition of CTPConfiguration and related CTP structures
std::ostringstream debug
uint64_t orbit
Definition RawEventData.h:6
unsigned short int uint16_t
unsigned int uint32_t
int32_t i
uint32_t packetCounter
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
Helper for geometry and GRP related CCDB requests.
char error[CURL_ERROR_SIZE]
Digits tw Raw translation.
uint32_t j
Definition RawData.h:0
uint32_t version
Definition RawData.h:8
std::vector< CTPClass > & getCTPClasses()
uint64_t getTriggerClassMaskWInputsNoTrgDets() const
const CTPClass * getCTPClassFromHWIndex(const int index) const
uint64_t getTriggerClassMaskWInputs() const
int addCTPDigit(uint32_t linkCRU, uint32_t triggerOrbit, gbtword80_t &diglet, gbtword80_t &pldmask, std::map< o2::InteractionRecord, CTPDigit > &digits)
static int shiftNew(const o2::InteractionRecord &irin, uint32_t TFOrbit, std::bitset< 48 > &inpmask, int64_t shift, int level, std::map< o2::InteractionRecord, CTPDigit > &digmap)
static void makeGBTWordInverse(std::vector< gbtword80_t > &diglets, gbtword80_t &GBTWord, gbtword80_t &remnant, uint32_t &size_gbt, uint32_t Npld)
int checkReadoutConsistentncy(o2::pmr::vector< CTPDigit > &digits, uint64_t trgclassmask=0xffffffffffffffff, uint64_t trigclassmaskNoTrgDets=0xffffffffffffffff)
int setLumiInp(int lumiinp, std::string inp)
int decodeRaw(o2::framework::InputRecord &inputs, std::vector< o2::framework::InputSpec > &filter, o2::pmr::vector< CTPDigit > &digits, std::vector< LumiInfo > &lumiPointsHBF1)
static int shiftInputs(std::map< o2::InteractionRecord, CTPDigit > &digitsMap, o2::pmr::vector< CTPDigit > &digits, uint32_t TFOrbit, uint64_t trgclassmask=0xffffffffffffffff)
int decodeRawFatal(o2::framework::InputRecord &inputs, std::vector< o2::framework::InputSpec > &filter)
The parser handles transparently input in the format of raw pages.
const_iterator end() const
const_iterator begin() const
The input API of the Data Processing Layer This class holds the inputs which are valid for processing...
GLint GLsizei count
Definition glcorearb.h:399
GLuint index
Definition glcorearb.h:781
GLintptr offset
Definition glcorearb.h:660
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
GLint level
Definition glcorearb.h:275
GLint GLuint mask
Definition glcorearb.h:291
GLuint GLsizei const GLenum * rates
Definition glcorearb.h:5738
std::bitset< NGBT > gbtword80_t
Definition Digits.h:36
std::vector< T, fair::mq::pmr::polymorphic_allocator< T > > vector
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::unique_ptr< GPUReconstructionTimeframe > tf
uint32_t orbit
LHC orbit.
uint16_t bc
bunch crossing ID of interaction
Class = Mask+Descriptor+Cluster.
CTPDescriptor const * descriptor
std::uint64_t getInputsMask() const
std::bitset< CTP_NCLASSES > CTPClassMask
Definition Digits.h:53
o2::InteractionRecord intRecord
Definition Digits.h:51
void setInputMask(gbtword80_t mask)
Definition Digits.cxx:31
void setClassMask(gbtword80_t mask)
Definition Digits.cxx:37
static std::string getInputNameFromIndex(uint32_t index)
static int getInputIndexFromName(std::string &name)
static constexpr int getVersion()
get numeric version of the RDH
Definition RDHUtils.h:60
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)
std::vector< Digit > digits