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
22GBTFrameContainer::GBTFrameContainer(int cru, int link) : GBTFrameContainer(0, cru, link, -1) {}
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}
uint8_t channelID
Definition RawEventData.h:8
uint64_t phase
Definition RawEventData.h:7
Container class for the GBT Frames.
int32_t i
uint32_t j
Definition RawData.h:0
std::ostringstream debug
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
GLuint * ids
Definition glcorearb.h:647
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint counter
Definition glcorearb.h:3987
Global TPC definitions and constants.
Definition SimTraits.h:167
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"