Project
Loading...
Searching...
No Matches
GBTFrameContainer.h
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
15#ifndef ALICEO2_TPC_GBTFRAMECONTAINER_H_
16#define ALICEO2_TPC_GBTFRAMECONTAINER_H_
17
19#include "TPCBase/Mapper.h"
24
25#include <iterator>
26#include <vector>
27#include <queue>
28#include <array>
29#include <mutex>
30
31#include <thread>
32
33#include <fstream>
34#include <iosfwd>
35#include <iomanip>
36
37#include <fairlogger/Logger.h>
38
39namespace o2
40{
41namespace tpc
42{
43
46
48{
49 public:
52
56 GBTFrameContainer(int cru, int link);
57
63 GBTFrameContainer(int size, int cru, int link, int sampaVersion = -1);
64
67
69 void reset();
70
73 int getSize() { return mGBTFrames.size(); };
74
77 int getNentries();
78
81 void addGBTFrame(GBTFrame& frame);
82
88 void addGBTFrame(unsigned word3, unsigned word2, unsigned word1, unsigned word0);
89
115 void addGBTFrame(short s0hw0l, short s0hw1l, short s0hw2l, short s0hw3l, short s0hw0h, short s0hw1h, short s0hw2h,
116 short s0hw3h, short s1hw0l, short s1hw1l, short s1hw2l, short s1hw3l, short s1hw0h, short s1hw1h,
117 short s1hw2h, short s1hw3h, short s2hw0, short s2hw1, short s2hw2, short s2hw3, short s0adc,
118 short s1adc, short s2adc, unsigned marker = 0);
119
122 void addGBTFramesFromFile(std::string fileName);
123
128 void addGBTFramesFromBinaryFile(std::string fileName, std::string type = "grorc", int frames = -1);
129
130 // /// Fill output TClonesArray
131 // /// @param output Output container
132 // void fillOutputContainer(TClonesArray* output);
133
136 void setEnableAdcClockWarning(bool val) { mEnableAdcClockWarning = val; };
137
140 void setEnableSyncPatternWarning(bool val) { mEnableSyncPatternWarning = val; };
141
144 void setEnableCompileAdcValues(bool val) { mEnableCompileAdcValues = val; };
145
149 {
150 mEnableStoreGBTFrames = val;
151 if (!mEnableStoreGBTFrames) {
152 mGBTFrames.resize(2);
153 }
154 };
155
159 bool getData(std::vector<Digit>& container);
160
161 bool getData(std::vector<HalfSAMPAData>& container);
162
163 int getNFramesAnalyzed() const { return mGBTFramesAnalyzed; };
164
168 GBTFrame getGBTFrame(int index) const { return mGBTFrames[index]; };
169 GBTFrame operator[](int index) const { return mGBTFrames[index]; };
170 GBTFrame& operator[](int index) { return mGBTFrames[index]; };
171
172 std::vector<GBTFrame>::iterator begin() { return mGBTFrames.begin(); };
173 std::vector<GBTFrame>::const_iterator begin() const { return mGBTFrames.begin(); };
174 std::vector<GBTFrame>::const_iterator cbegin() const { return mGBTFrames.cbegin(); };
175 std::vector<GBTFrame>::iterator end() { return mGBTFrames.end(); };
176 std::vector<GBTFrame>::const_iterator end() const { return mGBTFrames.end(); };
177 std::vector<GBTFrame>::const_iterator cend() const { return mGBTFrames.cend(); };
178
179 std::vector<GBTFrame>::reverse_iterator rbegin() { return mGBTFrames.rbegin(); };
180 std::vector<GBTFrame>::const_reverse_iterator rbegin() const { return mGBTFrames.rbegin(); };
181 std::vector<GBTFrame>::const_reverse_iterator crbegin() const { return mGBTFrames.crbegin(); };
182 std::vector<GBTFrame>::reverse_iterator rend() { return mGBTFrames.rend(); };
183 std::vector<GBTFrame>::const_reverse_iterator rend() const { return mGBTFrames.rend(); };
184 std::vector<GBTFrame>::const_reverse_iterator crend() const { return mGBTFrames.crend(); };
185
188 void setTimebin(int val) { mTimebin = val; };
189
192 int getTimebin() const { return mTimebin; };
193
195 void reProcessAllFrames();
196
200 void overwriteAdcClock(int sampa, unsigned short phase);
201
202 private:
204 void processAllFrames();
205
208 void processFrame(std::vector<GBTFrame>::iterator iFrame);
209
212 void checkAdcClock(std::vector<GBTFrame>::iterator iFrame);
213
216 void searchSyncPattern(std::vector<GBTFrame>::iterator iFrame);
217
218 // Compiles the ADC values
220 void compileAdcValues(std::vector<GBTFrame>::iterator iFrame);
221
222 void resetAdcClock();
223 void resetSyncPattern();
224 void resetAdcValues();
225
226 std::mutex mAdcMutex;
227
228 std::vector<GBTFrame> mGBTFrames;
229 std::array<AdcClockMonitor, 3> mAdcClock;
230 std::array<SyncPatternMonitor, 5> mSyncPattern;
231 std::array<short, 10> mPositionForHalfSampa;
232 std::array<std::queue<short>*, 5> mAdcValues;
233
234 bool mEnableAdcClockWarning;
235 bool mEnableSyncPatternWarning;
236 bool mEnableStoreGBTFrames;
237 bool mEnableCompileAdcValues;
238 int mCRU;
239 int mLink;
240 int mSampaVersion;
241 int mTimebin;
242 int mGBTFramesAnalyzed;
243
244 std::array<std::array<short, 16>, 5> mTmpData;
245};
246
247//template<typename... Args>
248//inline
249//void GBTFrameContainer::addGBTFrame(Args&&... args)
250//{
251// if (!mEnableStoreGBTFrames && (mGBTFrames.size() > 1)) {
252// mGBTFrames[0] = mGBTFrames[1];
253// mGBTFrames[1].setData(std::forward<Args>(args)...);
254// } else {
255// mGBTFrames.emplace_back(std::forward<Args>(args)...);
256// }
257// processFrame(mGBTFrames.end()-1);
258//};
259
260inline void GBTFrameContainer::addGBTFrame(unsigned word3, unsigned word2, unsigned word1, unsigned word0)
261{
262 if (!mEnableStoreGBTFrames && (mGBTFrames.size() > 1)) {
263 mGBTFrames[0] = mGBTFrames[1];
264 mGBTFrames[1].setData(word3, word2, word1, word0);
265 } else {
266 mGBTFrames.emplace_back(word3, word2, word1, word0);
267 }
268 processFrame(mGBTFrames.end() - 1);
269};
270
271inline void GBTFrameContainer::addGBTFrame(short s0hw0l, short s0hw1l, short s0hw2l, short s0hw3l, short s0hw0h,
272 short s0hw1h, short s0hw2h, short s0hw3h, short s1hw0l, short s1hw1l,
273 short s1hw2l, short s1hw3l, short s1hw0h, short s1hw1h, short s1hw2h,
274 short s1hw3h, short s2hw0, short s2hw1, short s2hw2, short s2hw3,
275 short s0adc, short s1adc, short s2adc, unsigned marker)
276{
277 if (!mEnableStoreGBTFrames && (mGBTFrames.size() > 1)) {
278 mGBTFrames[0] = mGBTFrames[1];
279 mGBTFrames[1].setData(s0hw0l, s0hw1l, s0hw2l, s0hw3l, s0hw0h, s0hw1h, s0hw2h, s0hw3h,
280 s1hw0l, s1hw1l, s1hw2l, s1hw3l, s1hw0h, s1hw1h, s1hw2h, s1hw3h,
281 s2hw0, s2hw1, s2hw2, s2hw3, s0adc, s1adc, s2adc, marker);
282 } else {
283 mGBTFrames.emplace_back(s0hw0l, s0hw1l, s0hw2l, s0hw3l, s0hw0h, s0hw1h, s0hw2h, s0hw3h,
284 s1hw0l, s1hw1l, s1hw2l, s1hw3l, s1hw0h, s1hw1h, s1hw2h, s1hw3h,
285 s2hw0, s2hw1, s2hw2, s2hw3, s0adc, s1adc, s2adc, marker);
286 }
287 processFrame(mGBTFrames.end() - 1);
288};
289
291{
292 if (!mEnableStoreGBTFrames && (mGBTFrames.size() > 1)) {
293 mGBTFrames[0] = mGBTFrames[1];
294 mGBTFrames[1] = frame;
295 } else {
296 mGBTFrames.emplace_back(frame);
297 }
298
299 processFrame(mGBTFrames.end() - 1);
300};
301
302} // namespace tpc
303} // namespace o2
304
305#endif
Class to monitor the ADC smapling clock contained in the GBT frame.
Definition of the TPC Digit.
uint64_t phase
Definition RawEventData.h:7
GBT Frame object.
Class for data from one half SAMPA.
Class to monitor the data stream and detect synchronization patterns.
const auto & getData()
GBT Frame container class.
void reset()
Reset function to clear container.
void setEnableSyncPatternWarning(bool val)
std::vector< GBTFrame >::const_reverse_iterator rend() const
GBTFrame & operator[](int index)
std::vector< GBTFrame >::reverse_iterator rbegin()
void addGBTFramesFromBinaryFile(std::string fileName, std::string type="grorc", int frames=-1)
void overwriteAdcClock(int sampa, unsigned short phase)
std::vector< GBTFrame >::iterator end()
void setEnableCompileAdcValues(bool val)
std::vector< GBTFrame >::iterator begin()
GBTFrame operator[](int index) const
std::vector< GBTFrame >::const_reverse_iterator rbegin() const
void setEnableAdcClockWarning(bool val)
GBTFrame getGBTFrame(int index) const
std::vector< GBTFrame >::const_reverse_iterator crbegin() const
void addGBTFrame(GBTFrame &frame)
void reProcessAllFrames()
Re-Processes all frames after resetting ADC clock and sync Pattern.
std::vector< GBTFrame >::const_iterator cbegin() const
std::vector< GBTFrame >::reverse_iterator rend()
std::vector< GBTFrame >::const_iterator end() const
std::vector< GBTFrame >::const_reverse_iterator crend() const
void addGBTFramesFromFile(std::string fileName)
GBTFrameContainer()
Default constructor.
std::vector< GBTFrame >::const_iterator cend() const
std::vector< GBTFrame >::const_iterator begin() const
GBTFrame class for the TPC.
Definition GBTFrame.h:64
GLsizeiptr size
Definition glcorearb.h:659
GLuint index
Definition glcorearb.h:781
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLfloat * val
Definition glcorearb.h:1582
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...