Project
Loading...
Searching...
No Matches
RawReader.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
12#ifndef O2_TPC_RAWREADER_H_
13#define O2_TPC_RAWREADER_H_
14
17
18#include <string>
19#include <vector>
20#include <map>
21#include <memory>
22#include <utility>
23#include <tuple>
24
25#include "TPCBase/PadPos.h"
26#include "TPCBase/CalDet.h"
28
29namespace o2
30{
31namespace tpc
32{
33
38{
39 public:
41 struct Header {
49
52 uint64_t timeStamp() { return (timeStamp_w << 32) | (timeStamp_w >> 32); }
53
56 uint64_t eventCount() { return (eventCount_w << 32) | (eventCount_w >> 32); }
57
60 uint64_t reserved_2() { return (reserved_2_w << 32) | (reserved_2_w >> 32); }
61
63 Header() = default;
64
66 Header(const Header& other) = default; // : dataType(h.dataType), reserved_01(h.reserved_01),
67 //headerVersion(h.headerVersion), nWords(h.nWords), timeStamp_w(h.timeStamp_w),
68 //eventCount_w(h.eventCount_w), reserved_2_w(h.reserved_2_w) {};
69 };
70
72 struct EventInfo {
73 std::string path;
76
78 EventInfo() : path(""), posInFile(-1), header(){};
79
81 EventInfo(const EventInfo& other) = default;
82 //: path(e.path), posInFile(e.posInFile), region(e.region),
83 // link(e.link), header(e.header) {};
84 };
85
91 RawReader(int region = -1, int link = -1, int run = -1, int sampaVersion = -1);
92
94 RawReader(const RawReader& other) = default;
95
97 ~RawReader() = default;
98
101 int loadNextEvent();
102
106
109 int loadPreviousEvent();
110
114
118 bool loadEvent(int64_t event);
119
122 // #region/#fec/sampaVersion is a number and sampaVersion optional
124 bool addInputFile(std::string infile);
125
128 // #region/#fec/sampaVersion is a number and sampaVersion optional
130 bool addInputFile(const std::vector<std::string>* infiles);
131
139 bool addInputFile(int region, int link, int sampaVersion, std::string path, int run = -1);
140
143 int64_t getFirstEvent() const { return mEvents.begin()->first; };
144
147 int64_t getLastEvent() const { return (mEvents.size() == 0) ? mEvents.begin()->first : mEvents.rbegin()->first; };
148
151 int64_t getNumberOfEvents() const { return mEvents.size(); };
152
156 uint64_t getTimeStamp(short hf) const { return mTimestampOfFirstData[hf]; };
157
161 std::shared_ptr<std::vector<uint16_t>> getData(const PadPos& padPos);
162
166 std::shared_ptr<std::vector<uint16_t>> getNextData(PadPos& padPos);
167
168 int getRegion() const { return mRegion; };
169 int getLink() const { return mLink; };
170 int getEventNumber() const { return mLastEvent; };
171 int getRunNumber() const { return mRun; };
172 short getSyncPos(short hf) const { return mSyncPos[hf]; };
173
176 void setUseRawInMode3(bool useRaw) { mUseRawInMode3 = useRaw; };
177
180 void setApplyChannelMask(bool applyMask) { mApplyChannelMask = applyMask; };
181
184 void setChannelMask(std::shared_ptr<CalDet<bool>> channelMask) { mChannelMask = channelMask; };
185
188 void setCheckAdcClock(bool checkAdc) { mCheckAdcClock = checkAdc; };
191 void setSampaVersion(int sampaVerson) { mSampaVersion = sampaVerson; };
195 std::shared_ptr<std::vector<EventInfo>> getEventInfo(uint64_t event) const;
196
199 void addEventSynchronizer(std::shared_ptr<RawReaderEventSync> eventSync) { mEventSynchronizer = eventSync; };
200
203 std::shared_ptr<std::vector<std::tuple<short, short, short>>> getAdcError() { return mAdcError; };
204
205 private:
206 bool decodeRawGBTFrames(EventInfo eventInfo);
207 bool decodePreprocessedData(EventInfo eventInfo);
208
209 bool mUseRawInMode3;
210 bool mApplyChannelMask;
211 bool mCheckAdcClock;
212 int mRegion;
213 int mLink;
214 int mRun;
215 int mSampaVersion;
216 int64_t mLastEvent;
217 std::array<uint64_t, 5> mTimestampOfFirstData;
218 std::map<uint64_t, std::shared_ptr<std::vector<EventInfo>>> mEvents;
219 std::map<PadPos, std::shared_ptr<std::vector<uint16_t>>> mData;
220 std::map<PadPos, std::shared_ptr<std::vector<uint16_t>>>::iterator mDataIterator;
221 std::array<short, 5> mSyncPos;
222
223 std::shared_ptr<CalDet<bool>> mChannelMask;
224 std::shared_ptr<std::vector<std::tuple<short, short, short>>> mAdcError;
225
226 std::shared_ptr<RawReaderEventSync> mEventSynchronizer;
227};
228
229inline std::shared_ptr<std::vector<RawReader::EventInfo>> RawReader::getEventInfo(uint64_t event) const
230{
231 auto evIterator = mEvents.find(event);
232 if (evIterator == mEvents.end()) {
233 std::shared_ptr<std::vector<EventInfo>> emptyVecPtr(new std::vector<EventInfo>);
234 return emptyVecPtr;
235 }
236 return evIterator->second;
237};
238
239inline std::shared_ptr<std::vector<uint16_t>> RawReader::getData(const PadPos& padPos)
240{
241 mDataIterator = mData.find(padPos);
242 if (mDataIterator == mData.end()) {
243 std::shared_ptr<std::vector<uint16_t>> emptyVecPtr(new std::vector<uint16_t>);
244 return emptyVecPtr;
245 }
246 return mDataIterator->second;
247};
248
249inline std::shared_ptr<std::vector<uint16_t>> RawReader::getNextData(PadPos& padPos)
250{
251 if (mDataIterator == mData.end()) {
252 return nullptr;
253 }
254 std::map<PadPos, std::shared_ptr<std::vector<uint16_t>>>::iterator last = mDataIterator;
255 mDataIterator++;
256 padPos = last->first;
257 return last->second;
258};
259
261{
262 if (mLastEvent == -1) {
263
264 mSyncPos.fill(-1);
265 mTimestampOfFirstData.fill(0);
266
268 return getFirstEvent();
269
270 } else if (mLastEvent == getLastEvent()) {
271
272 mSyncPos.fill(-1);
273 mTimestampOfFirstData.fill(0);
274
276 return getFirstEvent();
277
278 } else {
279
280 int event = mLastEvent + 1;
282 return event;
283 }
284};
285
287{
288 if (mLastEvent <= getFirstEvent()) {
289
290 mSyncPos.fill(-1);
291 mTimestampOfFirstData.fill(0);
292
295 return getLastEvent();
296
297 } else if (mLastEvent == getFirstEvent() + 1) {
298
299 mSyncPos.fill(-1);
300 mTimestampOfFirstData.fill(0);
301
303 return getFirstEvent();
304
305 } else {
306
307 int event = mLastEvent - 1;
309 return event;
310 }
311};
312
314{
315 if (mLastEvent == -1) {
316
317 mSyncPos.fill(-1);
318 mTimestampOfFirstData.fill(0);
319
321 return getFirstEvent();
322
323 } else if (mLastEvent == getLastEvent()) {
324
325 return -1;
326
327 } else {
328
329 int event = mLastEvent + 1;
331 return event;
332 }
333};
334
336{
337 if (mLastEvent <= getFirstEvent()) {
338 return -1;
339
340 } else if (mLastEvent == getFirstEvent() + 1) {
341
342 mSyncPos.fill(-1);
343 mTimestampOfFirstData.fill(0);
344
346 return getFirstEvent();
347
348 } else {
349
350 int event = mLastEvent - 1;
352 return event;
353 }
354};
355
356} // namespace tpc
357} // namespace o2
358#endif
unsigned short int uint16_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 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
const auto & getData()
Reader for RAW TPC data.
Definition RawReader.h:38
void setSampaVersion(int sampaVerson)
Definition RawReader.h:191
std::shared_ptr< std::vector< uint16_t > > getData(const PadPos &padPos)
Definition RawReader.h:239
int getRunNumber() const
Definition RawReader.h:171
int getLink() const
Definition RawReader.h:169
int getRegion() const
Definition RawReader.h:168
int64_t getLastEvent() const
Definition RawReader.h:147
void setChannelMask(std::shared_ptr< CalDet< bool > > channelMask)
Definition RawReader.h:184
int getEventNumber() const
Definition RawReader.h:170
int64_t getNumberOfEvents() const
Definition RawReader.h:151
int64_t getFirstEvent() const
Definition RawReader.h:143
std::shared_ptr< std::vector< std::tuple< short, short, short > > > getAdcError()
Definition RawReader.h:203
std::shared_ptr< std::vector< uint16_t > > getNextData(PadPos &padPos)
Definition RawReader.h:249
void setUseRawInMode3(bool useRaw)
Definition RawReader.h:176
~RawReader()=default
Destructor.
void addEventSynchronizer(std::shared_ptr< RawReaderEventSync > eventSync)
Definition RawReader.h:199
int loadNextEventNoWrap()
Definition RawReader.h:313
void setApplyChannelMask(bool applyMask)
Definition RawReader.h:180
bool addInputFile(std::string infile)
Definition RawReader.cxx:61
uint64_t getTimeStamp(short hf) const
Definition RawReader.h:156
std::shared_ptr< std::vector< EventInfo > > getEventInfo(uint64_t event) const
Definition RawReader.h:229
int loadPreviousEventNoWrap()
Definition RawReader.h:335
RawReader(const RawReader &other)=default
Copy constructor.
short getSyncPos(short hf) const
Definition RawReader.h:172
bool loadEvent(int64_t event)
void setCheckAdcClock(bool checkAdc)
Definition RawReader.h:188
struct _cl_event * event
Definition glcorearb.h:2982
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
EventInfo(const EventInfo &other)=default
Copy constructor.
int posInFile
Position in data file.
Definition RawReader.h:74
Header header
Header of this evend.
Definition RawReader.h:75
std::string path
Path to data file.
Definition RawReader.h:73
EventInfo()
Default constructor.
Definition RawReader.h:78
Data header struct.
Definition RawReader.h:41
Header()=default
Default constructor.
uint32_t nWords
number of 32 bit words of header + payload
Definition RawReader.h:45
uint64_t eventCount_w
Event counter, high and low fields are reversed.
Definition RawReader.h:47
uint8_t headerVersion
Header version.
Definition RawReader.h:44
Header(const Header &other)=default
Copy constructor.
uint8_t reserved_01
reserved part
Definition RawReader.h:43
uint64_t timeStamp_w
time stamp of header, high and low fields are reversed
Definition RawReader.h:46
uint64_t reserved_2_w
Reserved part, high and low fields are reversed.
Definition RawReader.h:48
uint16_t dataType
readout mode, 1: GBT frames, 2: decoded data, 3: both
Definition RawReader.h:42
VectorOfTObjectPtrs other