Project
Loading...
Searching...
No Matches
ELinkDecoder.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
16#ifndef O2_MID_ELINKDECODER_H
17#define O2_MID_ELINKDECODER_H
18
19#include <cstdint>
20#include <vector>
21#include <gsl/gsl>
22
24
25namespace o2
26{
27namespace mid
28{
30{
31 public:
32 void setBareDecoder(bool isBare);
34 inline void add(const uint8_t byte) { mBytes.emplace_back(byte); }
35 void addAndComputeSize(const uint8_t byte);
36 template <class ITERATOR>
37 bool addCore(ITERATOR& it, const ITERATOR& end)
38 {
40 auto remaining = mMinimumSize - mBytes.size();
41 return add(it, end, remaining);
42 }
43 template <class ITERATOR>
44 bool add(ITERATOR& it, const ITERATOR& end)
45 {
47 auto remaining = mTotalSize - mBytes.size();
48 if (add(it, end, remaining)) {
49 if (mTotalSize == mMinimumSize) {
50 computeSize();
51 remaining = mTotalSize - mBytes.size();
52 if (remaining) {
53 return add(it, end, remaining);
54 }
55 }
56 return true;
57 }
58 return false;
59 }
60
62 inline bool addCore(size_t& idx, gsl::span<const uint8_t> payload, size_t step) { return add(idx, payload, mMinimumSize - mBytes.size(), step); }
63
64 bool add(size_t& idx, gsl::span<const uint8_t> payload, size_t step);
65
67 inline bool isZero(uint8_t byte) const { return (mBytes.empty() && (byte & raw::sSTARTBIT) == 0); }
68
70 inline bool isComplete() const { return mBytes.size() == mTotalSize; };
72 inline uint8_t getStatusWord() const { return mBytes[0]; }
74 inline uint8_t getTriggerWord() const { return mBytes[1]; }
76 inline uint16_t getCounter() const { return joinBytes(2); }
78 inline uint8_t getId() const { return (mBytes[4] >> 4) & 0xF; }
80 inline uint8_t getInputs() const { return (mBytes[4] & 0xF); }
82 inline uint8_t getCrateId() const { return (mBytes[5] >> 4) & 0xF; }
83 uint16_t getPattern(int cathode, int chamber) const;
85 inline size_t getNBytes() const { return mBytes.size(); }
86
87 void reset();
88
89 private:
90 inline uint16_t joinBytes(int idx) const { return (mBytes[idx] << 8 | mBytes[idx + 1]); };
91 template <class ITERATOR>
92 bool add(ITERATOR& it, const ITERATOR& end, size_t nBytes)
93 {
95 auto nToEnd = std::distance(it, end);
96 auto nAdded = nBytes < nToEnd ? nBytes : nToEnd;
97 mBytes.insert(mBytes.end(), it, it + nAdded);
98 it += nAdded;
99 return (nAdded == nBytes);
100 }
101
102 bool add(size_t& idx, gsl::span<const uint8_t> payload, size_t nBytes, size_t step);
103
104 void computeSize();
105
106 size_t mMinimumSize{5};
107 size_t mMaximumSize{21};
108 std::vector<uint8_t> mBytes{};
109 size_t mTotalSize{mMinimumSize};
110};
111} // namespace mid
112} // namespace o2
113
114#endif /* O2_MID_ELINKDECODER_H */
Structure to store the readout board information.
bool isZero(uint8_t byte) const
Checks if this is a zero.
bool addCore(size_t &idx, gsl::span< const uint8_t > payload, size_t step)
Adds the first 5 bytes.
uint8_t getInputs() const
Gets the inputs.
uint8_t getStatusWord() const
Gets the status word.
uint16_t getPattern(int cathode, int chamber) const
bool add(ITERATOR &it, const ITERATOR &end)
uint16_t getCounter() const
Gets the counter.
void add(const uint8_t byte)
Adds a byte.
size_t getNBytes() const
Gets the number of bytes read.
uint8_t getTriggerWord() const
Gets the trigger word.
void setBareDecoder(bool isBare)
uint8_t getCrateId() const
Gets the crate ID when available.
uint8_t getId() const
Gets the card ID.
bool isComplete() const
Checks if we have all of the information needed for the decoding.
bool addCore(ITERATOR &it, const ITERATOR &end)
void addAndComputeSize(const uint8_t byte)
GLuint GLuint end
Definition glcorearb.h:469
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...