Project
Loading...
Searching...
No Matches
ELinkDecoder.cxx
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
17#include "MIDRaw/ELinkDecoder.h"
18
19namespace o2
20{
21namespace mid
22{
23
25{
27 mMinimumSize = isBare ? 5 : 6;
28 mMaximumSize = isBare ? 21 : 22;
29 mTotalSize = mMinimumSize;
30}
31
32bool ELinkDecoder::add(size_t& idx, gsl::span<const uint8_t> payload, size_t nBytes, size_t step)
33{
35 auto size = payload.size();
36 auto end = idx + step * nBytes;
37 if (size < end) {
38 end = size;
39 }
40 size_t nAdded = 0;
41 for (; idx < end; idx += step) {
42 mBytes.emplace_back(payload[idx]);
43 ++nAdded;
44 }
45 return (nAdded == nBytes);
46}
47
48bool ELinkDecoder::add(size_t& idx, gsl::span<const uint8_t> payload, size_t step)
49{
51 auto remaining = mTotalSize - mBytes.size();
52 if (add(idx, payload, remaining, step)) {
53 if (mTotalSize == mMinimumSize) {
54 computeSize();
55 remaining = mTotalSize - mBytes.size();
56 if (remaining) {
57 return add(idx, payload, remaining, step);
58 }
59 }
60 return true;
61 }
62 return false;
63}
64
66{
68 mBytes.emplace_back(byte);
69 if (mBytes.size() == mMinimumSize) {
70 computeSize();
71 }
72}
73
74void ELinkDecoder::computeSize()
75{
77 if (raw::isLoc(mBytes[0])) {
78 // This is a local card
79 uint8_t mask = getInputs();
80 for (int ich = 0; ich < 4; ++ich) {
81 if ((mask >> ich) & 0x1) {
82 // We expect 2 bytes for the BP and 2 for the NBP
83 mTotalSize += 4;
84 }
85 }
86 }
87}
88
90{
92 mBytes.clear();
93 mTotalSize = mMinimumSize;
94}
95
96uint16_t ELinkDecoder::getPattern(int cathode, int chamber) const
97{
99 uint8_t mask = getInputs();
100 if (((mask >> chamber) & 0x1) == 0) {
101 return 0;
102 }
103
104 int idx = mBytes.size();
105 for (int ich = 0; ich <= chamber; ++ich) {
106 if ((mask >> ich) & 0x1) {
107 idx -= 4;
108 }
109 }
110
111 idx += 2 * cathode;
112
113 return joinBytes(idx);
114}
115
116} // namespace mid
117} // namespace o2
MID e-link decoder.
uint8_t getInputs() const
Gets the inputs.
uint16_t getPattern(int cathode, int chamber) const
void add(const uint8_t byte)
Adds a byte.
void setBareDecoder(bool isBare)
void addAndComputeSize(const uint8_t byte)
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLint GLuint mask
Definition glcorearb.h:291
bool isLoc(uint8_t statusWord)
Definition ROBoard.h:65
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...