Project
Loading...
Searching...
No Matches
GBTFrameContainer.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
16#include <bitset>
17#include <iostream>
18
19using namespace o2::tpc;
20
23GBTFrameContainer::GBTFrameContainer(int size, int cru, int link, int sampaVersion)
24 : mAdcMutex(),
25 mEnableAdcClockWarning(true),
26 mEnableSyncPatternWarning(true),
27 mEnableStoreGBTFrames(true),
28 mEnableCompileAdcValues(true),
29 mAdcClock({AdcClockMonitor(0), AdcClockMonitor(1), AdcClockMonitor(2)}),
30 mSyncPattern({SyncPatternMonitor(0, 0), SyncPatternMonitor(0, 1), SyncPatternMonitor(1, 0),
32 mPositionForHalfSampa({-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}),
33 mGBTFrames(),
34 mGBTFramesAnalyzed(0),
35 mCRU(cru),
36 mLink(link),
37 mSampaVersion(sampaVersion),
38 mTimebin(0)
39{
40 mGBTFrames.reserve(size);
41
42 for (auto& aAdcValues : mAdcValues) {
43 aAdcValues = new std::queue<short>;
44 }
45}
46
48{
49 for (auto& aAdcValues : mAdcValues) {
50 delete aAdcValues;
51 }
52}
53
55{
56 std::cout << "Reading from file " << fileName << std::endl;
57 std::ifstream file(fileName);
58
59 if (!file.is_open()) {
60 LOG(error) << "Can't read file " << fileName;
61 return;
62 }
63
64 /* Expected format in file is
65 *
66 * decimal-counter : hex-GBTframe
67 * e.g.
68 *
69 * ...
70 * 0016 : 0x00000da2d80702e17aaeb0f0052faaa5
71 * 0017 : 0x0000078a7805825272261050870502f0
72 * 0018 : 0x000007207a0722e1da0bc0520f0582da
73 * ...
74 *
75 */
76
77 int counter;
78 short colon;
79 std::string frameString;
80 unsigned word0, word1, word2, word3;
81
82 while (file >> counter >> colon >> frameString) {
83 sscanf(frameString.substr(2, 8).c_str(), "%x", &word3);
84 sscanf(frameString.substr(10, 8).c_str(), "%x", &word2);
85 sscanf(frameString.substr(18, 8).c_str(), "%x", &word1);
86 sscanf(frameString.substr(26, 8).c_str(), "%x", &word0);
87
88 addGBTFrame(word3, word2, word1, word0);
89 }
90}
91
92void GBTFrameContainer::addGBTFramesFromBinaryFile(std::string fileName, std::string type, int frames)
93{
94 std::cout << "Reading from file " << fileName << std::endl;
95 std::ifstream file(fileName);
96
97 if (!file.is_open()) {
98 LOG(error) << "Can't read file " << fileName;
99 return;
100 }
101
102 uint32_t rawData;
103 uint32_t rawMarker;
104 uint32_t words[8];
105 if (type == "grorc") {
106 while (!file.eof() && ((frames == -1) || (mGBTFramesAnalyzed < frames))) {
107 file.read((char*)&rawData, sizeof(rawData));
108 rawMarker = rawData & 0xFFFF0000;
109 if ((rawMarker == 0xDEF10000) || (rawMarker == 0xDEF40000)) {
110 file.read((char*)&words, 3 * sizeof(words[0]));
111 addGBTFrame(rawData, words[0], words[1], words[2]);
112 }
113 }
114 } else if (type == "trorc") {
115 while (!file.eof() && ((frames == -1) || (mGBTFramesAnalyzed < frames))) {
116 file.read((char*)&words, 4 * sizeof(words[0]));
117 addGBTFrame(words[0], words[1], words[2], words[3]);
118 }
119 } else if (type == "trorc2") {
120 //
121 // reading header
122 //
123 file.read((char*)&words, 8 * sizeof(words[0]));
124
125 // decoding header
126 uint32_t headerVersion = (words[0] >> 24) & 0xF;
127 if (headerVersion == 0) {
128 uint32_t readoutMode = words[0] & 0xFFFF;
129 uint32_t reserved_0 = (words[0] >> 16) & 0xF;
130 uint32_t channelID = (words[0] >> 20) & 0xF;
131 uint32_t n_words = words[1];
132 uint64_t timestamp = words[2];
133 timestamp = (timestamp << 32) | words[3];
134 uint64_t event_count = words[4];
135 event_count = (event_count << 32) | words[5];
136 uint64_t reserved_1 = words[6];
137 reserved_1 = (reserved_1 << 32) | words[7];
138 LOG(debug) << "Header version: " << headerVersion;
139 LOG(debug) << "ChannelID: " << channelID;
140 LOG(debug) << "reserved_0: 0x" << std::hex << std::setfill('0') << std::right << std::setw(1) << reserved_0 << std::dec;
141 LOG(debug) << "Readout mode: " << readoutMode;
142 LOG(debug) << "n_words: " << n_words;
143 LOG(debug) << "Timestamp: 0x" << std::hex << std::setfill('0') << std::right << std::setw(16) << timestamp << std::dec;
144 LOG(debug) << "Event counter: " << event_count;
145 LOG(debug) << "reserved_1: 0x" << std::hex << std::setfill('0') << std::right << std::setw(16) << reserved_1 << std::dec;
146
147 switch (readoutMode) {
148 case 1: { // raw GBT frames
149 for (int i = 0; i < (n_words - 8); i = i + 4) {
150 file.read((char*)&words, 4 * sizeof(words[0]));
151 addGBTFrame(words[0], words[1], words[2], words[3]);
152 }
153 break;
154 }
155
156 case 2: { // already decoded data
157 mAdcMutex.lock();
158 uint32_t ids[5];
159 std::array<bool, 5> writeValue;
160 writeValue.fill(false);
161 std::array<std::array<uint32_t, 16>, 5> adcValues;
162
163 for (int i = 0; i < (n_words - 8); i = i + 4) {
164 file.read((char*)&words, 4 * sizeof(words[0]));
165
166 ids[4] = (words[0] >> 4) & 0xF;
167 ids[3] = (words[0] >> 8) & 0xF;
168 ids[2] = (words[0] >> 12) & 0xF;
169 ids[1] = (words[0] >> 16) & 0xF;
170 ids[0] = (words[0] >> 20) & 0xF;
171
172 adcValues[4][((ids[4] & 0x7) * 2) + 1] = (((ids[4] >> 3) & 0x1) == 0) ? 0 : words[3] & 0x3FF;
173 adcValues[4][((ids[4] & 0x7) * 2)] = (((ids[4] >> 3) & 0x1) == 0) ? 0 : (words[3] >> 10) & 0x3FF;
174 adcValues[3][((ids[3] & 0x7) * 2) + 1] = (((ids[3] >> 3) & 0x1) == 0) ? 0 : (words[3] >> 20) & 0x3FF;
175 adcValues[3][((ids[3] & 0x7) * 2)] = (((ids[3] >> 3) & 0x1) == 0) ? 0 : ((words[2] & 0xFF) << 2) | ((words[3] >> 30) & 0x3);
176 adcValues[2][((ids[2] & 0x7) * 2) + 1] = (((ids[2] >> 3) & 0x1) == 0) ? 0 : (words[2] >> 8) & 0x3FF;
177 adcValues[2][((ids[2] & 0x7) * 2)] = (((ids[2] >> 3) & 0x1) == 0) ? 0 : (words[2] >> 18) & 0x3FF;
178 adcValues[1][((ids[1] & 0x7) * 2) + 1] = (((ids[1] >> 3) & 0x1) == 0) ? 0 : ((words[1] & 0x3F) << 4) | ((words[2] >> 28) & 0xF);
179 adcValues[1][((ids[1] & 0x7) * 2)] = (((ids[1] >> 3) & 0x1) == 0) ? 0 : (words[1] >> 6) & 0x3FF;
180 adcValues[0][((ids[0] & 0x7) * 2) + 1] = (((ids[0] >> 3) & 0x1) == 0) ? 0 : (words[1] >> 16) & 0x3FF;
181 adcValues[0][((ids[0] & 0x7) * 2)] = (((ids[0] >> 3) & 0x1) == 0) ? 0 : ((words[0] & 0xF) << 6) | ((words[1] >> 26) & 0x3F);
182
183 for (int j = 0; j < 5; ++j) {
184 std::cout << std::bitset<4>(ids[j]) << " " << adcValues[0][((ids[0] & 0x7) * 2)] << " " << adcValues[0][((ids[0] & 0x7) * 2) + 1] << std::endl;
185 }
186 std::cout << std::endl;
187
188 for (int j = 0; j < 5; ++j) {
189 if (ids[j] == 0x8) {
190 writeValue[j] = true;
191 }
192 }
193 for (int j = 0; j < 5; ++j) {
194 if ((writeValue[j] & ids[j]) == 0xF) {
195 for (int k = 0; k < 16; ++k) {
196 mAdcValues[j]->push(adcValues[j][k]);
197 std::cout << adcValues[j][k] << " ";
198 }
199 std::cout << std::endl;
200 }
201 }
202 std::cout << std::endl;
203 }
204
205 mAdcMutex.unlock();
206 break;
207 }
208
209 case 3: { // raw GBT frames
210 mAdcMutex.lock();
211 uint32_t ids[5];
212 std::array<bool, 5> writeValue;
213 writeValue.fill(false);
214 std::array<std::array<uint32_t, 16>, 5> adcValues;
215
216 for (int i = 0; i < (n_words - 8); i = i + 4) {
217 file.read((char*)&words, 8 * sizeof(words[0]));
218
219 ids[4] = (words[4] >> 4) & 0xF;
220 ids[3] = (words[4] >> 8) & 0xF;
221 ids[2] = (words[4] >> 12) & 0xF;
222 ids[1] = (words[4] >> 16) & 0xF;
223 ids[0] = (words[4] >> 20) & 0xF;
224
225 adcValues[4][((ids[4] & 0x7) * 2) + 1] = (((ids[4] >> 3) & 0x1) == 0) ? 0 : words[7] & 0x3FF;
226 adcValues[4][((ids[4] & 0x7) * 2)] = (((ids[4] >> 3) & 0x1) == 0) ? 0 : (words[7] >> 10) & 0x3FF;
227 adcValues[3][((ids[3] & 0x7) * 2) + 1] = (((ids[3] >> 3) & 0x1) == 0) ? 0 : (words[7] >> 20) & 0x3FF;
228 adcValues[3][((ids[3] & 0x7) * 2)] = (((ids[3] >> 3) & 0x1) == 0) ? 0 : ((words[6] & 0xFF) << 2) | ((words[7] >> 30) & 0x3);
229 adcValues[2][((ids[2] & 0x7) * 2) + 1] = (((ids[2] >> 3) & 0x1) == 0) ? 0 : (words[6] >> 8) & 0x3FF;
230 adcValues[2][((ids[2] & 0x7) * 2)] = (((ids[2] >> 3) & 0x1) == 0) ? 0 : (words[6] >> 18) & 0x3FF;
231 adcValues[1][((ids[1] & 0x7) * 2) + 1] = (((ids[1] >> 3) & 0x1) == 0) ? 0 : ((words[5] & 0x3F) << 4) | ((words[6] >> 28) & 0xF);
232 adcValues[1][((ids[1] & 0x7) * 2)] = (((ids[1] >> 3) & 0x1) == 0) ? 0 : (words[5] >> 6) & 0x3FF;
233 adcValues[0][((ids[0] & 0x7) * 2) + 1] = (((ids[0] >> 3) & 0x1) == 0) ? 0 : (words[5] >> 16) & 0x3FF;
234 adcValues[0][((ids[0] & 0x7) * 2)] = (((ids[0] >> 3) & 0x1) == 0) ? 0 : ((words[4] & 0xF) << 6) | ((words[5] >> 26) & 0x3F);
235
236 for (int j = 0; j < 5; ++j) {
237 if (ids[j] == 0x8) {
238 writeValue[j] = true;
239 }
240 }
241 for (int j = 0; j < 5; ++j) {
242 if ((writeValue[j] & ids[j]) == 0xF) {
243 for (int k = 0; k < 16; ++k) {
244 mAdcValues[j]->push(adcValues[j][k]);
245 }
246 }
247 }
248 }
249
250 mAdcMutex.unlock();
251 break;
252 }
253 // for (int i=0; i<(n_words-8); i= i+8) {
254 // file.read((char*)&words,8*sizeof(words[0]));
255 // addGBTFrame(words[0],words[1],words[2],words[3]);
256 // }
257 // break;
258
259 default:
260 break;
261 }
262 }
263 // while (!file.eof() && ((frames == -1) || (mGBTFramesAnalyzed < frames))) {
264 // file.read((char*)&words,8*sizeof(words[0]));
265 // addGBTFrame(words[0],words[1],words[2],words[3]);
266 // }
267 }
268}
269
270//void GBTFrameContainer::fillOutputContainer(TClonesArray* output)
271//{
272//
273// TClonesArray &clref = *output;
274// for (auto &aGBTFrame : mGBTFrames) {
275// new(clref[clref.GetEntriesFast()]) GBTFrame(aGBTFrame);
276// }
277//}
278
280{
281 resetAdcClock();
282 resetSyncPattern();
283 resetAdcValues();
284 mGBTFramesAnalyzed = 0;
285
286 processAllFrames();
287}
288
289void GBTFrameContainer::processAllFrames()
290{
291
292 mAdcMutex.lock();
293 for (std::array<std::queue<short>*, 5>::iterator it = mAdcValues.begin(); it != mAdcValues.end(); ++it) {
294 if ((*it)->size() > 0) {
295 LOG(warning) << "There are already some ADC values for half SAMPA " << std::distance(mAdcValues.begin(), it)
296 << " , maybe the frames were already processed.";
297 }
298 }
299 mAdcMutex.unlock();
300
301 for (auto it = mGBTFrames.begin(); it != mGBTFrames.end(); ++it) {
302 processFrame(it);
303 }
304}
305
306void GBTFrameContainer::processFrame(std::vector<GBTFrame>::iterator iFrame)
307{
308 ++mGBTFramesAnalyzed;
309
310 if (mEnableAdcClockWarning) {
311 checkAdcClock(iFrame);
312 }
313
314 searchSyncPattern(iFrame);
315
316 if (mEnableCompileAdcValues) {
317 compileAdcValues(iFrame);
318 }
319}
320
321void GBTFrameContainer::compileAdcValues(std::vector<GBTFrame>::iterator iFrame)
322{
323 short value1;
324 short value2;
325 mAdcMutex.lock();
326 for (short iHalfSampa = 0; iHalfSampa < 5; ++iHalfSampa) {
327 if (mPositionForHalfSampa[iHalfSampa] == -1) {
328 continue;
329 }
330 if (mPositionForHalfSampa[iHalfSampa + 5] == -1) {
331 continue;
332 }
333
334 switch (mPositionForHalfSampa[iHalfSampa]) {
335 case 0:
336 value1 = (iFrame->getHalfWord(iHalfSampa / 2, 1, iHalfSampa % 2) << 5) |
337 iFrame->getHalfWord(iHalfSampa / 2, 0, iHalfSampa % 2);
338 value2 = (iFrame->getHalfWord(iHalfSampa / 2, 3, iHalfSampa % 2) << 5) |
339 iFrame->getHalfWord(iHalfSampa / 2, 2, iHalfSampa % 2);
340 break;
341
342 case 1:
343 value1 = ((iFrame - 1)->getHalfWord(iHalfSampa / 2, 2, iHalfSampa % 2) << 5) |
344 (iFrame - 1)->getHalfWord(iHalfSampa / 2, 1, iHalfSampa % 2);
345 value2 = (iFrame->getHalfWord(iHalfSampa / 2, 0, iHalfSampa % 2) << 5) |
346 (iFrame - 1)->getHalfWord(iHalfSampa / 2, 3, iHalfSampa % 2);
347 break;
348
349 case 2:
350 value1 = ((iFrame - 1)->getHalfWord(iHalfSampa / 2, 3, iHalfSampa % 2) << 5) |
351 (iFrame - 1)->getHalfWord(iHalfSampa / 2, 2, iHalfSampa % 2);
352 value2 = (iFrame->getHalfWord(iHalfSampa / 2, 1, iHalfSampa % 2) << 5) |
353 iFrame->getHalfWord(iHalfSampa / 2, 0, iHalfSampa % 2);
354 break;
355
356 case 3:
357 value1 = (iFrame->getHalfWord(iHalfSampa / 2, 0, iHalfSampa % 2) << 5) |
358 (iFrame - 1)->getHalfWord(iHalfSampa / 2, 3, iHalfSampa % 2);
359 value2 = (iFrame->getHalfWord(iHalfSampa / 2, 2, iHalfSampa % 2) << 5) |
360 iFrame->getHalfWord(iHalfSampa / 2, 1, iHalfSampa % 2);
361 break;
362
363 default:
364 LOG(error) << "Position " << mPositionForHalfSampa[iHalfSampa] << " not known.";
365 return;
366 }
367
368 if (mSampaVersion == 1 || mSampaVersion == 2) {
369 mAdcValues[iHalfSampa]->emplace(value1 ^ (1 << 9)); // Invert bit 9 vor SAMPA v1 and v2
370 mAdcValues[iHalfSampa]->emplace(value2 ^ (1 << 9)); // Invert bit 9 vor SAMPA v1 and v2
371 } else {
372 mAdcValues[iHalfSampa]->emplace(value1);
373 mAdcValues[iHalfSampa]->emplace(value2);
374 }
375 // std::cout << iHalfSampa << " " << std::hex
376 // << "0x" << std::setfill('0') << std::setw(3) << *(mAdcValues[iHalfSampa]->rbegin()+1) << " "
377 // << "0x" << std::setfill('0') << std::setw(3) << *(mAdcValues[iHalfSampa]->rbegin()) << std::dec << std::endl;
378 }
379 mAdcMutex.unlock();
380}
381
382void GBTFrameContainer::checkAdcClock(std::vector<GBTFrame>::iterator iFrame)
383{
384 if (mAdcClock[0].addSequence(iFrame->getAdcClock(0))) {
385 LOG(warning) << "ADC clock error of SAMPA 0 in GBT Frame " << std::distance(mGBTFrames.begin(), iFrame);
386 }
387 if (mAdcClock[1].addSequence(iFrame->getAdcClock(1))) {
388 LOG(warning) << "ADC clock error of SAMPA 1 in GBT Frame " << std::distance(mGBTFrames.begin(), iFrame);
389 }
390 if (mAdcClock[2].addSequence(iFrame->getAdcClock(2))) {
391 LOG(warning) << "ADC clock error of SAMPA 2 in GBT Frame " << std::distance(mGBTFrames.begin(), iFrame);
392 }
393}
394
395void GBTFrameContainer::searchSyncPattern(std::vector<GBTFrame>::iterator iFrame)
396{
397 for (short iHalfSampa = 0; iHalfSampa < 5; ++iHalfSampa) {
398 mPositionForHalfSampa[iHalfSampa + 5] = mPositionForHalfSampa[iHalfSampa];
399 }
400
401 if (mSyncPattern[0].addSequence(
402 iFrame->getHalfWord(0, 0, 0),
403 iFrame->getHalfWord(0, 1, 0),
404 iFrame->getHalfWord(0, 2, 0),
405 iFrame->getHalfWord(0, 3, 0))) {
406 mPositionForHalfSampa[0] = mSyncPattern[0].getPosition();
407 }
408
409 if (mSyncPattern[1].addSequence(
410 iFrame->getHalfWord(0, 0, 1),
411 iFrame->getHalfWord(0, 1, 1),
412 iFrame->getHalfWord(0, 2, 1),
413 iFrame->getHalfWord(0, 3, 1))) {
414 mPositionForHalfSampa[1] = mSyncPattern[1].getPosition();
415 }
416
417 if (mSyncPattern[2].addSequence(
418 iFrame->getHalfWord(1, 0, 0),
419 iFrame->getHalfWord(1, 1, 0),
420 iFrame->getHalfWord(1, 2, 0),
421 iFrame->getHalfWord(1, 3, 0))) {
422 mPositionForHalfSampa[2] = mSyncPattern[2].getPosition();
423 }
424
425 if (mSyncPattern[3].addSequence(
426 iFrame->getHalfWord(1, 0, 1),
427 iFrame->getHalfWord(1, 1, 1),
428 iFrame->getHalfWord(1, 2, 1),
429 iFrame->getHalfWord(1, 3, 1))) {
430 mPositionForHalfSampa[3] = mSyncPattern[3].getPosition();
431 }
432
433 if (mSyncPattern[4].addSequence(
434 iFrame->getHalfWord(2, 0),
435 iFrame->getHalfWord(2, 1),
436 iFrame->getHalfWord(2, 2),
437 iFrame->getHalfWord(2, 3))) {
438 mPositionForHalfSampa[4] = mSyncPattern[4].getPosition();
439 }
440
441 if (mEnableSyncPatternWarning) {
442 if (mPositionForHalfSampa[0] != mPositionForHalfSampa[1]) {
443 LOG(warning) << "The two half words from SAMPA 0 don't start at the same position, lower bits start at "
444 << mPositionForHalfSampa[0] << ", higher bits at " << mPositionForHalfSampa[1];
445 }
446 if (mPositionForHalfSampa[2] != mPositionForHalfSampa[3]) {
447 LOG(warning) << "The two half words from SAMPA 1 don't start at the same position, lower bits start at "
448 << mPositionForHalfSampa[2] << ", higher bits at " << mPositionForHalfSampa[3];
449 }
450 if (mPositionForHalfSampa[0] != mPositionForHalfSampa[2] || mPositionForHalfSampa[0] != mPositionForHalfSampa[4]) {
451 LOG(warning) << "The three SAMPAs don't have the same position, SAMPA0 = " << mPositionForHalfSampa[0]
452 << ", SAMPA1 = " << mPositionForHalfSampa[2] << ", SAMPA2 = " << mPositionForHalfSampa[4];
453 }
454 }
455}
456
457bool GBTFrameContainer::getData(std::vector<Digit>& container)
458{
459 // std::vector<std::vector<int>> iData(5);
460 // mAdcMutex.lock();
461 // for (int iHalfSampa = 0; iHalfSampa < 5; ++iHalfSampa)
462 // {
463 // if (mAdcValues[iHalfSampa]->size() < 16) continue;
464 // for (int iChannel = 0; iChannel < 16; ++iChannel)
465 // {
466 // iData[iHalfSampa].push_back(mAdcValues[iHalfSampa]->front());
467 // mAdcValues[iHalfSampa]->pop();
468 // }
469 // }
470 // mAdcMutex.unlock();
471 bool dataAvailable = false;
472
473 mAdcMutex.lock();
474 for (int iHalfSampa = 0; iHalfSampa < 5; ++iHalfSampa) {
475 if (mAdcValues[iHalfSampa]->size() < 16) {
476 mTmpData[iHalfSampa].fill(0);
477 continue;
478 }
479 dataAvailable = true;
480 for (int iChannel = 0; iChannel < 16; ++iChannel) {
481 mTmpData[iHalfSampa][iChannel] = mAdcValues[iHalfSampa]->front();
482 mAdcValues[iHalfSampa]->pop();
483 }
484 }
485 mAdcMutex.unlock();
486
487 if (!dataAvailable) {
488 return dataAvailable;
489 }
490
491 const Mapper& mapper = Mapper::instance();
492 int iTimeBin = mTimebin;
493 int iSampaChannel;
494 int iSampa;
495 float iCharge;
496 int iRow;
497 int iPad;
498 for (int iHalfSampa = 0; iHalfSampa < 5; ++iHalfSampa) {
499 iSampaChannel =
500 (iHalfSampa == 4) // 5th half SAMPA corresponds to SAMPA2
501 ? ((mCRU % 2) ? 16 : 0) // every even CRU receives channel 0-15 from SAMPA 2, the odd ones channel 16-31
502 : ((iHalfSampa % 2) ? 16 : 0); // every even half SAMPA containes channel 0-15, the odd ones channel 16-31
503 iSampa = (iHalfSampa == 4) ? 2 : (mCRU % 2) ? iHalfSampa / 2 + 3 : iHalfSampa / 2;
504 for (std::array<short, 16>::iterator it = mTmpData[iHalfSampa].begin(); it != mTmpData[iHalfSampa].end(); ++it) {
505 const PadPos& padPos = mapper.padPosRegion(
506 mCRU, /* region */
507 mLink, /* FEC in region*/
508 iSampa,
509 iSampaChannel);
510 iRow = padPos.getRow();
511 iPad = padPos.getPad();
512 iCharge = *it;
513
514 container.emplace_back(mCRU, iCharge, iRow, iPad, iTimeBin);
515 ++iSampaChannel;
516 }
517 }
518
519 if (dataAvailable) {
520 ++mTimebin;
521 }
522 return dataAvailable;
523}
524
525bool GBTFrameContainer::getData(std::vector<HalfSAMPAData>& container)
526{
527 bool dataAvailable = false;
528
529 mAdcMutex.lock();
530 for (int iHalfSampa = 0; iHalfSampa < 5; ++iHalfSampa) {
531 if (mAdcValues[iHalfSampa]->size() < 16) {
532 mTmpData[iHalfSampa].fill(0);
533 continue;
534 }
535 dataAvailable = true;
536 for (int iChannel = 0; iChannel < 16; ++iChannel) {
537 mTmpData[iHalfSampa][iChannel] = mAdcValues[iHalfSampa]->front();
538 mAdcValues[iHalfSampa]->pop();
539 }
540 }
541 mAdcMutex.unlock();
542
543 if (!dataAvailable) {
544 return dataAvailable;
545 }
546
547 // if (container.size() != 5) {
549 // container.resize(5);
550 // }
551 // container.at(0).reset();
552 // container.at(1).reset();
553 // container.at(2).reset();
554 // container.at(3).reset();
555 // container.at(4).reset();
556
557 int iSampaChannel;
558 int iSampa;
559
560 for (int iHalfSampa = 0; iHalfSampa < 5; ++iHalfSampa) {
561 iSampa = (iHalfSampa == 4) ? 2 : (mCRU % 2) ? iHalfSampa / 2 + 3 : iHalfSampa / 2;
562
563 container.emplace_back(iSampa, !((bool)mCRU % 2), mTmpData[iHalfSampa]);
564 }
565 return dataAvailable;
566}
567
569{
570 LOG(info) << "Resetting GBT-Frame container";
571 resetAdcClock();
572 resetSyncPattern();
573 resetAdcValues();
574
575 mGBTFrames.clear();
576 mGBTFramesAnalyzed = 0;
577}
578
579void GBTFrameContainer::resetAdcClock()
580{
581 for (auto& aAdcClock : mAdcClock) {
582 aAdcClock.reset();
583 }
584}
585
586void GBTFrameContainer::resetSyncPattern()
587{
588 for (auto& aSyncPattern : mSyncPattern) {
589 aSyncPattern.reset();
590 }
591 for (auto& aPositionForHalfSampa : mPositionForHalfSampa) {
592 aPositionForHalfSampa = -1;
593 }
594 // mPositionForHalfSampa.clear();
595}
596
597void GBTFrameContainer::resetAdcValues()
598{
599 mAdcMutex.lock();
600 for (std::array<std::queue<short>*, 5>::iterator it = mAdcValues.begin(); it != mAdcValues.end(); ++it) {
601 delete (*it);
602 (*it) = new std::queue<short>;
603 }
604 mAdcMutex.unlock();
605}
606
608{
609 int counter = 0;
610 mAdcMutex.lock();
611 for (auto& aAdcValues : mAdcValues) {
612 counter += aAdcValues->size();
613 }
614 mAdcMutex.unlock();
615 return counter;
616}
617
618void GBTFrameContainer::overwriteAdcClock(int sampa, unsigned short phase)
619{
620 phase %= 17;
621 unsigned clock = (0xFFFF0000 >> phase);
622
623 for (std::vector<GBTFrame>::iterator it = mGBTFrames.begin(); it != mGBTFrames.end(); ++it) {
624 it->setAdcClock(sampa, (clock >> 28) & 0xF);
625 clock = (clock << 4) | (clock >> 28);
626 }
627}
std::ostringstream debug
uint8_t channelID
Definition RawEventData.h:8
uint64_t phase
Definition RawEventData.h:7
unsigned int uint32_t
Container class for the GBT Frames.
int32_t i
std::vector< uint16_t > adcValues
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 frames(excluding borders)") AddOption(eventStride
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
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 true
char error[CURL_ERROR_SIZE]
uint32_t j
Definition RawData.h:0
Class to monitor the ADC smapling clock contained in the GBT frame.
GBT Frame container class.
bool getData(std::vector< Digit > &container)
void reset()
Reset function to clear container.
void addGBTFramesFromBinaryFile(std::string fileName, std::string type="grorc", int frames=-1)
void overwriteAdcClock(int sampa, unsigned short phase)
std::vector< GBTFrame >::iterator begin()
void addGBTFrame(GBTFrame &frame)
void reProcessAllFrames()
Re-Processes all frames after resetting ADC clock and sync Pattern.
void addGBTFramesFromFile(std::string fileName)
GBTFrameContainer()
Default constructor.
const PadPos padPosRegion(const int cruNumber, const int fecInPartition, const int sampaOnFEC, const int channelOnSAMPA) const
Definition Mapper.h:236
static Mapper & instance(const std::string mappingDir="")
Definition Mapper.h:44
Class to monitor the data stream and detect synchronization patterns.
GLsizeiptr size
Definition glcorearb.h:659
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint counter
Definition glcorearb.h:3987
Global TPC definitions and constants.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"