Project
Loading...
Searching...
No Matches
CruRawReader.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// Cru raw data reader, this is the part that parses the raw data
13// it runs on the flp(pre compression) or on the epn(pre tracklet64 array generation)
14// it hands off blocks of cru pay load to the parsers.
15
16#ifndef O2_TRD_CRURAWREADER
17#define O2_TRD_CRURAWREADER
18
19#include <string>
20#include <cstdint>
21#include <bitset>
22#include <set>
23#include <utility>
24#include <array>
26#include "Headers/RDHAny.h"
34
35namespace o2::trd
36{
37class Tracklet64;
38class TriggerRecord;
39class Digit;
40
42{
43 public:
44 CruRawReader() = default;
45 ~CruRawReader() = default;
46
47 // both the tracklet and the digit parsing is implemented as a state machine
58
59 // top-level method, takes the full payload data of the DPL raw data message and delegates to processHBFs()
60 // probably this method can be removed and we can directly go to processHBFs()
61 void run();
62
63 // configure the raw reader, done once at the init() stage
64 void configure(int tracklethcheader, int halfchamberwords, int halfchambermajor, std::bitset<16> options);
65
66 // set number of time bins to fixed value instead of reading from DigitHCHeader
67 // (but still complain if DigitHCHeader is not consistent)
69 {
70 mTimeBins = tb;
71 mTimeBinsFixed = true;
72 }
73
74 // settings in order to avoid InfoLogger flooding
75 void setMaxErrWarnPrinted(int nerr, int nwar)
76 {
77 mMaxErrsPrinted = nerr < 0 ? std::numeric_limits<int>::max() : nerr;
78 mMaxWarnPrinted = nwar < 0 ? std::numeric_limits<int>::max() : nwar;
79 }
80 void checkNoWarn(bool silently = true);
81 void checkNoErr();
82
83 // set the input data buffer
84 void setDataBuffer(const char* val) { mDataBufferPtr = val; }
85
86 // set the input data buffer size in bytes
87 void setDataBufferSize(long val) { mDataBufferSize = val; }
88
89 // set the mapping from Link ID to HCID and vice versa
90 void setLinkMap(const LinkToHCIDMapping* map) { mLinkMap = map; }
91
92 // assemble output for full TF and send it out
94
95 int getDigitsFound() const { return mDigitsFound; }
96 int getTrackletsFound() const { return mTrackletsFound; }
97
98 int getWordsRejected() const { return mWordsRejected + mDigitWordsRejected + mTrackletWordsRejected; }
99
100 // reset the event storage and the counters
101 void reset();
102
103 // the parsing starts here, payload from all available RDHs is copied into mHBFPayload and afterwards processHalfCRU() is called
104 // returns the total number of bytes read, including RDH header
105 int processHBFs();
106
107 // process the data which is stored inside the mHBFPayload for the current half-CRU. The iteration corresponds to the trigger index inside the HBF
108 bool processHalfCRU(int iteration);
109
110 // parse the digit HC headers, possibly update settings as the number of time bins from the header word
111 bool parseDigitHCHeaders(int hcid);
112
113 // helper function to compare two consecutive RDHs
114 bool compareRDH(const o2::header::RDHAny* rdhPrev, const o2::header::RDHAny* rdhCurr);
115
116 // sanity check on individual RDH (can find unconfigured FLP or invalid data)
117 bool checkRDH(const o2::header::RDHAny* rdh);
118
119 // given the total link size and the hcid from the RDH
120 // parse the tracklet data. Overwrite hcid from TrackletHCHeader if mismatch is detected
121 // trackletWordsRejected: count the number of words which were skipped (subset of words read)
122 // trackletWordsReadOK: count the number of words which could be read consecutively w/o errors
123 // numberOfTrackletsFound: count the number of tracklets found
124 // returns total number of words read (no matter if parsed successfully or not) or -1 in case of failure
125 int parseTrackletLinkData(int linkSize32, int& hcid, int& trackletWordsRejected, int& trackletWordsReadOK, int& numberOfTrackletsFound);
126
127 // the parsing begins after the DigitHCHeaders have been parsed already
128 // maxWords32 is the remaining number of words for the given link
129 // digitWordsRejected: count the number of words which were skipped (subset of words read)
130 // returns total number of words read (no matter if parsed successfully or not)
131 int parseDigitLinkData(int maxWords32, int hcid, int& digitWordsRejected);
132
133 // check validity of TrackletHCHeader (always once bit needs to be set and hcid needs to be consistent with what we expect from RDH)
134 // FIXME currently hcid can be overwritten from TrackletHCHeader
135 bool isTrackletHCHeaderOK(const TrackletHCHeader& header, int& hcid);
136
137 // helper function to create Tracklet64 from link data
138 Tracklet64 assembleTracklet64(int format, TrackletMCMHeader& mcmHeader, TrackletMCMData& mcmData, int cpu, int hcid) const;
139
140 // important function to keep track of all errors, if possible accounted to a certain link / half-chamber ID
141 // FIXME:
142 // - whenever we don't know the half-chamber, fill it for HCID == 1080 so that we can still disentangle errors from half-chamber 0?
143 // - probably enough to only pass the half-chamber ID, if we know it
144 // - or what about being more granular? dump ROB or MCM, if we know it?
145 void incrementErrors(int error, int hcid = -1, std::string message = "");
146
147 // helper function to dump the whole input payload including RDH headers
148 void dumpInputPayload() const;
149
150 // to check for which half-chambers we have seen correct headers and for which we have seen wrong ones
151 void printHalfChamberHeaderReport() const;
152
153 private:
154 // these variables are configured externally
155 int mTrackletHCHeaderState{0};
156 int mHalfChamberWords{0};
157 int mHalfChamberMajor{0};
158 std::bitset<16> mOptions;
159
160 std::array<uint32_t, constants::HBFBUFFERMAX> mHBFPayload; // the full input data payload excluding the RDH header(s)
161
162 // InfoLogger flood protection settings
163 int mMaxErrsPrinted = 20;
164 int mMaxWarnPrinted = 20;
165
166 // helper pointers, counters for the input buffer
167 const char* mDataBufferPtr = nullptr; // pointer to the beginning of the whole payload data
168 long mDataBufferSize; // the total payload size of the raw data message from the FLP (typically a single HBF from one half-CRU)
169 const char* mCurrRdhPtr = nullptr; // points inside the payload data at the current RDH position
170 uint32_t mTotalHBFPayLoad = 0; // total data payload of the heart beat frame in question (up to wich array index mHBFPayload is filled with data)
171 uint32_t mHBFoffset32 = 0; // points to the current position inside mHBFPayload we are currently reading
172
173 HalfCRUHeader mCurrentHalfCRUHeader; // are we waiting for new header or currently parsing the payload of on
174 HalfCRUHeader mPreviousHalfCRUHeader; // are we waiting for new header or currently parsing the payload of on
175 bool mPreviousHalfCRUHeaderSet; // flag, whether we can use mPreviousHalfCRUHeader for additional sanity checks
176 DigitHCHeader mDigitHCHeader; // Digit HalfChamber header we are currently on.
177 uint16_t mTimeBins{constants::TIMEBINS}; // the number of time bins to be read out (default 30, can be overwritten from digit HC header)
178 bool mTimeBinsFixed{false}; // flag, whether number of time bins different from default was configured
179 bool mHaveSeenDigitHCHeader3{false}; // flag, whether we can compare an incoming DigitHCHeader3 with a header we have seen before
180 uint32_t mPreviousDigitHCHeadersvnver; // svn ver in the digithalfchamber header, used for validity checks
181 uint32_t mPreviousDigitHCHeadersvnrver; // svn release ver also used for validity checks
182 uint8_t mPreTriggerPhase = 0; // Pre trigger phase of the adcs producing the digits, its comes from an optional DigitHCHeader
183 // It is stored here to carry it around after parsing it from the DigitHCHeader1 if it exists in the data.
184 uint16_t mCRUEndpoint; // the upper or lower half of the currently parsed cru 0-14 or 15-29
185 uint16_t mCRUID; // CRU ID taken from the FEEID of the RDH
186 TRDFeeID mFEEID; // current Fee ID working on
187
188 std::set<int> mHalfChamberHeaderOK; // keep track of the half chambers for which we have seen correct headers
189 std::set<std::pair<int, int>> mHalfChamberMismatches; // first element is HCID from RDH and second element is HCID from TrackletHCHeader
190
192 std::array<uint16_t, 15> mCurrentHalfCRULinkLengths;
193 std::array<uint8_t, 15> mCurrentHalfCRULinkErrorFlags;
194
195 const LinkToHCIDMapping* mLinkMap = nullptr; // to retrieve HCID from Link ID
196
197 // these counters are reset after every TF
198 uint32_t mTrackletsFound{0}; // accumulated number of tracklets found
199 uint32_t mDigitsFound{0}; // accumulated number of digits found
200 uint32_t mDigitWordsRead = 0; // number of words read by the digit parser
201 uint32_t mDigitWordsRejected = 0; // number of words rejected by the digit parser
202 uint32_t mTrackletWordsRejected = 0; // number of words read by the tracklet parser
203 uint32_t mTrackletWordsRead = 0; // number of words rejected by the tracklet parser
204 uint32_t mWordsRejected = 0; // those words rejected before tracklet and digit parsing could start
205
206 EventRecordContainer mEventRecords; // store data range indexes into the above vectors.
207};
208
209} // namespace o2::trd
210// namespace o2
211
212#endif
Global TRD definitions and constants.
Definition of the RAW Data Header.
uint32_t cpu
Definition RawData.h:6
int getWordsRejected() const
int parseTrackletLinkData(int linkSize32, int &hcid, int &trackletWordsRejected, int &trackletWordsReadOK, int &numberOfTrackletsFound)
void setDataBufferSize(long val)
Tracklet64 assembleTracklet64(int format, TrackletMCMHeader &mcmHeader, TrackletMCMData &mcmData, int cpu, int hcid) const
void incrementErrors(int error, int hcid=-1, std::string message="")
void setLinkMap(const LinkToHCIDMapping *map)
bool checkRDH(const o2::header::RDHAny *rdh)
int getTrackletsFound() const
bool processHalfCRU(int iteration)
int parseDigitLinkData(int maxWords32, int hcid, int &digitWordsRejected)
int getDigitsFound() const
void printHalfChamberHeaderReport() const
void buildDPLOutputs(o2::framework::ProcessingContext &outputs)
bool isTrackletHCHeaderOK(const TrackletHCHeader &header, int &hcid)
bool parseDigitHCHeaders(int hcid)
void setMaxErrWarnPrinted(int nerr, int nwar)
void setDataBuffer(const char *val)
bool compareRDH(const o2::header::RDHAny *rdhPrev, const o2::header::RDHAny *rdhCurr)
void configure(int tracklethcheader, int halfchamberwords, int halfchambermajor, std::bitset< 16 > options)
void dumpInputPayload() const
void checkNoWarn(bool silently=true)
void setNumberOfTimeBins(int tb)
GLuint GLfloat * val
Definition glcorearb.h:1582
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
GLint GLint GLsizei GLint GLenum format
Definition glcorearb.h:275
uint8_t itsSharedClusterMap uint8_t
o2::cpv::Digit Digit
constexpr int TIMEBINS
the number of time bins
Definition Constants.h:74
Header for each half chamber.
Definition RawData.h:129
Header for MCM tracklet data outuput.
Definition RawData.h:162