Project
Loading...
Searching...
No Matches
RCUTrailer.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#ifndef ALICEO2_EMCAL_RCUTRAILER_H
12#define ALICEO2_EMCAL_RCUTRAILER_H
13
14#include <exception>
15#include <iosfwd>
16#include <string>
17#include <cstdint>
18#include <gsl/span>
19#include <Rtypes.h>
20
21namespace o2
22{
23
24namespace emcal
25{
26
75{
76 public:
79 class Error : public std::exception
80 {
81 public:
90
97 Error(ErrorType_t errtype, const char* message) : mErrorType(errtype), mErrorMessage(message) {}
98
100 ~Error() noexcept override = default;
101
104 const char* what() const noexcept override { return mErrorMessage.data(); }
105
108 ErrorType_t getErrorType() const noexcept { return mErrorType; }
109
110 private:
111 ErrorType_t mErrorType;
112 std::string mErrorMessage;
113 };
114
121
123 RCUTrailer() = default;
124
126 ~RCUTrailer() = default;
127
131 void reset();
132
135 void printStream(std::ostream& stream) const;
136
142 void constructFromRawPayload(const gsl::span<const uint32_t> payloadwords);
143
146 int getRCUID() const { return mRCUId; }
147
150 uint32_t getTrailerSize() const { return mTrailerSize; }
151
154 uint32_t getPayloadSize() const { return mPayloadSize; }
155
158 uint32_t getTrailerWordCorruptions() const { return mWordCorruptions; }
159
162 uint8_t getFirmwareVersion() const { return mFirmwareVersion; }
163
166 void setFirmwareVersion(uint8_t version) { mFirmwareVersion = version; }
167
170 void setRCUID(int rcuid) { mRCUId = rcuid; }
171
174 void setPayloadSize(uint32_t size) { mPayloadSize = size; }
175
179 double getTimeSampleNS() const;
180
183 double getL1PhaseNS() const;
184
191 void setTimeSamplePhaseNS(uint64_t triggertime, uint64_t timesample);
192
193 //
194 // Error counters
195 //
196
199 uint16_t getNumberOfChannelAddressMismatch() const { return mErrorCounter.mNumChannelAddressMismatch; }
200
203 uint16_t getNumberOfChannelLengthMismatch() const { return mErrorCounter.mNumChannelLengthMismatch; }
204
207 void setNumberOfChannelAddressMismatch(uint16_t nchannel) { mErrorCounter.mNumChannelAddressMismatch = nchannel; }
208
211 void setNumberOfChannelLengthMismatch(uint8_t nchannel) { mErrorCounter.mNumChannelLengthMismatch = nchannel; }
212
213 uint32_t getFECErrorsA() const { return mFECERRA; }
214 uint32_t getFECErrorsB() const { return mFECERRB; }
215 uint16_t getActiveFECsA() const { return mActiveFECsA; }
216 uint16_t getActiveFECsB() const { return mActiveFECsB; }
217 void setFECErrorsA(uint32_t value) { mFECERRA = value; }
218 void setFECErrorsB(uint32_t value) { mFECERRB = value; }
219 void setActiveFECsA(uint16_t value) { mActiveFECsA = value; }
220 void setActiveFECsB(uint16_t value) { mActiveFECsB = value; }
221
222 //
223 // ALTRO configuration
224 //
225
228 uint16_t getBaselineCorrection() const { return mAltroConfig.mBaselineCorrection; }
229
232 bool getPolarity() const { return mAltroConfig.mPolarity; }
233
236 uint16_t getNumberOfPresamples() const { return mAltroConfig.mNumPresamples; }
237
240 uint16_t getNumberOfPostsamples() const { return mAltroConfig.mNumPostsamples; }
241
244 bool hasSecondBaselineCorr() const { return mAltroConfig.mSecondBaselineCorrection; }
245
248 uint16_t getGlitchFilter() const { return mAltroConfig.mGlitchFilter; }
249
252 uint16_t getNumberOfNonZeroSuppressedPostsamples() const { return mAltroConfig.mNumPostsamplesNoZS; }
253
256 uint16_t getNumberOfNonZeroSuppressedPresamples() const { return mAltroConfig.mNumPresamplesNoZS; }
257
260 bool hasZeroSuppression() const { return mAltroConfig.mZeroSuppression; }
261
264 uint16_t getNumberOfPretriggerSamples() const { return mAltroConfig.mNumSamplesPretrigger; }
265
268 uint16_t getNumberOfSamplesPerChannel() const { return mAltroConfig.mNumSamplesChannel; }
269
272 uint16_t getNumberOfAltroBuffers() const { return BufferMode_t(mAltroConfig.mAltroBuffers) == BufferMode_t::NBUFFERS4 ? 4 : 8; }
273
276 bool isSparseReadout() const { return mAltroConfig.mSparseReadout; }
277
280 void setBaselineCorrection(uint16_t baselineCorrection) { mAltroConfig.mBaselineCorrection = baselineCorrection; }
281
284 void setPolarity(bool doSet) { mAltroConfig.mPolarity = doSet; }
285
288 void setNumberOfPresamples(uint16_t npresamples) { mAltroConfig.mNumPresamples = npresamples; }
289
292 void setNumberOfPostsamples(uint16_t npostsamples) { mAltroConfig.mNumPostsamples = npostsamples; }
293
296 void setSecondBaselineCorrection(bool doHave) { mAltroConfig.mSecondBaselineCorrection = doHave; }
297
300 void setGlitchFilter(uint16_t glitchfilter) { mAltroConfig.mGlitchFilter = glitchfilter; }
301
304 void setNumberOfNonZeroSuppressedPostsamples(uint16_t npostsamples) { mAltroConfig.mNumPostsamplesNoZS = npostsamples; }
305
308 void setNumberOfNonZeroSuppressedPresamples(uint16_t npresamples) { mAltroConfig.mNumPresamplesNoZS = npresamples; }
309
312 void setNumberOfPretriggerSamples(uint16_t nsamples) { mAltroConfig.mNumSamplesPretrigger = nsamples; }
313
316 void setNumberOfSamplesPerChannel(uint16_t nsamples) { mAltroConfig.mNumSamplesChannel = nsamples; }
317
320 void setZeroSuppression(bool doHave) { mAltroConfig.mZeroSuppression = doHave ? 1 : 0; }
321
324 void setSparseReadout(bool isSparse) { mAltroConfig.mSparseReadout = isSparse; }
325
328 void setNumberOfAltroBuffers(BufferMode_t bufmode) { mAltroConfig.mAltroBuffers = uint8_t(bufmode); }
329
333
336 uint16_t getErrorsG2() const { return mErrorCounter.mErrorRegister2; }
337
341 uint32_t getErrorsG3() const { return mErrorCounter.mErrorRegister3; }
342
346 uint32_t getAltroCFGReg1() const { return mAltroConfig.mWord1; }
347
351 uint32_t getAltroCFGReg2() const { return mAltroConfig.mWord2; }
352
355 void setErrorsG2(uint16_t value) { mErrorCounter.mErrorRegister2 = value; }
356
360 void setErrorsG3(uint32_t value) { mErrorCounter.mErrorRegister3 = value; }
361
365 void setAltroCFGReg1(uint32_t value) { mAltroConfig.mWord1 = value; }
366
370 void setAltroCFGReg2(uint32_t value) { mAltroConfig.mWord2 = value; }
371
374 bool isInitialized() const { return mIsInitialized; }
375
381 std::vector<uint32_t> encode() const;
382
389 static RCUTrailer constructFromPayloadWords(const gsl::span<const uint32_t> payloadwords);
390
394 static bool checkLastTrailerWord(uint32_t trailerword);
395
396 private:
399 struct AltroConfig {
400 union {
401 uint32_t mWord1 = 0;
402 struct {
403 uint32_t mBaselineCorrection : 4;
404 uint32_t mPolarity : 1;
405 uint32_t mNumPresamples : 2;
406 uint32_t mNumPostsamples : 4;
407 uint32_t mSecondBaselineCorrection : 1;
408 uint32_t mGlitchFilter : 2;
409 uint32_t mNumPostsamplesNoZS : 3;
410 uint32_t mNumPresamplesNoZS : 2;
411 uint32_t mZeroSuppression : 1;
412 uint32_t mZero1_1 : 12;
413 };
414 };
415
416 union {
417 uint32_t mWord2 = 0;
418 struct {
419 uint32_t mL1Phase : 5;
420 uint32_t mSampleTime : 4;
421 uint32_t mSparseReadout : 1;
422 uint32_t mNumSamplesChannel : 10;
423 uint32_t mNumSamplesPretrigger : 4;
424 uint32_t mAltroBuffers : 1;
425 uint32_t mZero2_2 : 7;
426 };
427 };
428 };
429
432 struct ErrorCounters {
433 union {
434 uint32_t mErrorRegister2 = 0;
435 };
436 union {
437 uint32_t mErrorRegister3 = 0;
438 struct {
439 uint32_t mNumChannelAddressMismatch : 12;
440 uint32_t mNumChannelLengthMismatch : 13;
441 uint32_t mZero3_1 : 7;
442 };
443 };
444 };
445
446 int mRCUId = -1;
447 uint8_t mFirmwareVersion = 0;
448 uint32_t mTrailerSize = 0;
449 uint32_t mPayloadSize = 0;
450 uint32_t mWordCorruptions = 0;
451 uint32_t mFECERRA = 0;
452 uint32_t mFECERRB = 0;
453 ErrorCounters mErrorCounter = {0, 0};
454 uint16_t mActiveFECsA = 0;
455 uint16_t mActiveFECsB = 0;
456 AltroConfig mAltroConfig = {0, 0};
457 bool mIsInitialized = false;
458
459 ClassDefNV(RCUTrailer, 1);
460};
461
462std::ostream& operator<<(std::ostream& stream, const RCUTrailer& trailer);
463
464} // namespace emcal
465
466} // namespace o2
467
468#endif
std::vector< uint16_t > nsamples
Definition testDigit.cxx:38
uint32_t version
Definition RawData.h:8
Error handling of the RCU trailer.
Definition RCUTrailer.h:80
Error(ErrorType_t errtype, const char *message)
Constructor.
Definition RCUTrailer.h:97
const char * what() const noexcept override
Access to the error message.
Definition RCUTrailer.h:104
ErrorType_t
Error codes for different error types.
Definition RCUTrailer.h:84
@ SAMPLINGFREQ_INVALID
Invalid sampling frequency.
@ DECODING_INVALID
Invalid words during decoding.
~Error() noexcept override=default
Destructor.
ErrorType_t getErrorType() const noexcept
Access to error code.
Definition RCUTrailer.h:108
Information stored in the RCU trailer.
Definition RCUTrailer.h:75
void reset()
Reset the RCU trailer.
void setNumberOfNonZeroSuppressedPostsamples(uint16_t npostsamples)
Set the number of postsamples before zero suppression.
Definition RCUTrailer.h:304
uint32_t getErrorsG3() const
Get value stored in error counter register 3.
Definition RCUTrailer.h:341
void setPayloadSize(uint32_t size)
set the payload size in number of DDL (32-bit) words
Definition RCUTrailer.h:174
uint16_t getNumberOfChannelAddressMismatch() const
Get the number of channels with address mismatch.
Definition RCUTrailer.h:199
uint32_t getTrailerWordCorruptions() const
Get number of corrupted trailer words (undefined trailer word code)
Definition RCUTrailer.h:158
bool hasZeroSuppression() const
Check whether zero suppression has been applied.
Definition RCUTrailer.h:260
void setTimeSamplePhaseNS(uint64_t triggertime, uint64_t timesample)
Set the time sample length and L1 phase based on the trigger time.
void setNumberOfNonZeroSuppressedPresamples(uint16_t npresamples)
Set the number of presamples after zero suppression.
Definition RCUTrailer.h:308
void setNumberOfChannelAddressMismatch(uint16_t nchannel)
Set the number of channels with address mismatch.
Definition RCUTrailer.h:207
static RCUTrailer constructFromPayloadWords(const gsl::span< const uint32_t > payloadwords)
Decode RCU trailer from payload.
void setErrorsG3(uint32_t value)
Set error counter register 3.
Definition RCUTrailer.h:360
void setFECErrorsB(uint32_t value)
Definition RCUTrailer.h:218
uint16_t getNumberOfPostsamples() const
Get the number of postsamples (after zero suppression)
Definition RCUTrailer.h:240
uint16_t getBaselineCorrection() const
Get baseline correction method.
Definition RCUTrailer.h:228
uint16_t getNumberOfSamplesPerChannel() const
Get the number of samples per channel.
Definition RCUTrailer.h:268
void printStream(std::ostream &stream) const
Prints the contents of the RCU trailer data.
uint16_t getErrorsG2() const
Get value stored in error counter register 2.
Definition RCUTrailer.h:336
void setSparseReadout(bool isSparse)
Set sparse readout mode.
Definition RCUTrailer.h:324
uint32_t getFECErrorsB() const
Definition RCUTrailer.h:214
bool hasSecondBaselineCorr() const
Check if second baseline correction is applied.
Definition RCUTrailer.h:244
uint16_t getNumberOfPretriggerSamples() const
Get the number of pretrigger samples.
Definition RCUTrailer.h:264
BufferMode_t
Handler for encoding of the number of ALTRO buffers in the configuration.
Definition RCUTrailer.h:117
@ NBUFFERS8
8 ALTRO buffers
Definition RCUTrailer.h:119
@ NBUFFERS4
4 ALTRO buffers
Definition RCUTrailer.h:118
void setNumberOfAltroBuffers(BufferMode_t bufmode)
Set the number of ALTRO buffers.
Definition RCUTrailer.h:328
uint16_t getGlitchFilter() const
Get the glitch filter.
Definition RCUTrailer.h:248
uint32_t getPayloadSize() const
Get size of the payload as number of DDL (32-bit) words.
Definition RCUTrailer.h:154
RCUTrailer()=default
Constructor.
void setNumberOfPretriggerSamples(uint16_t nsamples)
Set the number of pretrigger samples.
Definition RCUTrailer.h:312
uint32_t getFECErrorsA() const
Definition RCUTrailer.h:213
uint8_t getFirmwareVersion() const
Get the firmware version.
Definition RCUTrailer.h:162
uint32_t getAltroCFGReg1() const
Get value stored in ALTRO config register 1.
Definition RCUTrailer.h:346
static bool checkLastTrailerWord(uint32_t trailerword)
Check whether the word is a valid last trailer word.
void setBaselineCorrection(uint16_t baselineCorrection)
Set baseline correction method.
Definition RCUTrailer.h:280
uint32_t getAltroCFGReg2() const
Get value stored in ALTRO config register 1.
Definition RCUTrailer.h:351
void setSecondBaselineCorrection(bool doHave)
Specify whether second basedline correction has been applied.
Definition RCUTrailer.h:296
~RCUTrailer()=default
destructor
void constructFromRawPayload(const gsl::span< const uint32_t > payloadwords)
Decode RCU trailer from the 32-bit words in the raw buffer.
void setGlitchFilter(uint16_t glitchfilter)
Set the glitch filter.
Definition RCUTrailer.h:300
void setActiveFECsA(uint16_t value)
Definition RCUTrailer.h:219
uint16_t getNumberOfNonZeroSuppressedPresamples() const
Get the number of presamples before zero suppression.
Definition RCUTrailer.h:256
uint32_t getTrailerSize() const
Get the trailer size in number of DDL (32 bit) words.
Definition RCUTrailer.h:150
int getRCUID() const
Get index of the RCU the trailer belongs to.
Definition RCUTrailer.h:146
void setActiveFECsB(uint16_t value)
Definition RCUTrailer.h:220
void setAltroCFGReg2(uint32_t value)
Set ALTRO config register 2.
Definition RCUTrailer.h:370
void setZeroSuppression(bool doHave)
Specify whether zero suppression has been applied.
Definition RCUTrailer.h:320
double getL1PhaseNS() const
Access to the L1 phase.
bool isSparseReadout() const
Check whether readout is in sparse mode.
Definition RCUTrailer.h:276
void setFirmwareVersion(uint8_t version)
Set the firmware version.
Definition RCUTrailer.h:166
uint16_t getNumberOfAltroBuffers() const
Get the number of ALTRO buffers.
Definition RCUTrailer.h:272
uint16_t getActiveFECsA() const
Definition RCUTrailer.h:215
double getTimeSampleNS() const
Access to the sampling time.
std::vector< uint32_t > encode() const
Encode RCU trailer as array of DDL (32-bit) words.
void setNumberOfSamplesPerChannel(uint16_t nsamples)
Set the number of samples per channel.
Definition RCUTrailer.h:316
void setNumberOfChannelLengthMismatch(uint8_t nchannel)
Set the number of channels with length mismatch.
Definition RCUTrailer.h:211
bool getPolarity() const
Check polarity setting.
Definition RCUTrailer.h:232
void setFECErrorsA(uint32_t value)
Definition RCUTrailer.h:217
uint16_t getActiveFECsB() const
Definition RCUTrailer.h:216
void setRCUID(int rcuid)
Set the ID of the RCU.
Definition RCUTrailer.h:170
uint16_t getNumberOfNonZeroSuppressedPostsamples() const
Get the number of postsamples before zero suppression.
Definition RCUTrailer.h:252
uint16_t getNumberOfPresamples() const
Get the number of presamples (after zero suppression)
Definition RCUTrailer.h:236
uint16_t getNumberOfChannelLengthMismatch() const
Get the number of channels with length mismatch.
Definition RCUTrailer.h:203
bool isInitialized() const
checlks whether the RCU trailer is initialzied
Definition RCUTrailer.h:374
void setPolarity(bool doSet)
Set the polarity.
Definition RCUTrailer.h:284
void setNumberOfPostsamples(uint16_t npostsamples)
Set the number of postsamples (after zero suppression)
Definition RCUTrailer.h:292
void setErrorsG2(uint16_t value)
Set error counter register 2.
Definition RCUTrailer.h:355
void setNumberOfPresamples(uint16_t npresamples)
Set the number of presamples (after zero suppression)
Definition RCUTrailer.h:288
void setAltroCFGReg1(uint32_t value)
Set ALTRO config register 1.
Definition RCUTrailer.h:365
GLsizeiptr size
Definition glcorearb.h:659
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
GLuint GLuint stream
Definition glcorearb.h:1806
uint8_t itsSharedClusterMap uint8_t
std::ostream & operator<<(std::ostream &stream, const Cell &cell)
Stream operator for EMCAL cell.
Definition Cell.cxx:355
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...