Project
Loading...
Searching...
No Matches
GBTEncoder.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_MCH_RAW_ENCODER_GBT_ENCODER_H
13#define O2_MCH_RAW_ENCODER_GBT_ENCODER_H
14
15#include <array>
16#include <vector>
17#include <cstdlib>
20#include <functional>
21#include <fmt/printf.h>
22#include <stdexcept>
23#include "MakeArray.h"
24#include "Assertions.h"
25#include "MoveBuffer.h"
26#include "ElinkEncoder.h"
27#include "ElinkEncoderMerger.h"
28#include <gsl/span>
29#include "DumpBuffer.h"
30
31namespace o2::mch::raw
32{
33
41
42template <typename FORMAT, typename CHARGESUM, int VERSION = 0>
44{
45 public:
48 GBTEncoder(uint16_t linkId);
49
59 void addChannelData(uint8_t elinkGroupId, uint8_t elinkIndexInGroup, uint8_t chId, const std::vector<SampaCluster>& data);
60
65 void addHeartbeat(uint8_t elinkGroupId, uint8_t elinkIndexInGroup, uint20_t bunchCrossing);
66
71
77 size_t moveToBuffer(std::vector<std::byte>& buffer);
79
84 static bool forceNoPhase;
86
88 uint16_t linkId() const { return mLinkId; }
89
91 size_t size() const { return mGbtWords.size(); }
92
93 private:
94 uint16_t mLinkId; //< id of this GBT (0..11)
95 std::array<ElinkEncoder<FORMAT, CHARGESUM, VERSION>, 40> mElinks; //< the 40 Elinks we manage
96 std::vector<uint64_t> mGbtWords; //< the GBT words (each GBT word of 80 bits is represented by 2 64 bits words) we've accumulated so far
98};
99
100inline int phase(int i, bool forceNoPhase)
101{
102 // generate the phase for the i-th ElinkEncoder
103 // the default value of -1 means it will be random and decided
104 // by the ElinkEncoder ctor
105 //
106 // if > 0 it will set a fixed phase at the beginning of the life
107 // of the ElinkEncoder
108 //
109 // returning zero will simply disable the phase
110
111 if (forceNoPhase) {
112 return 0;
113 }
114 return -1;
115}
116
117template <typename FORMAT, typename CHARGESUM, int VERSION>
119
120template <typename FORMAT, typename CHARGESUM, int VERSION>
122 : mLinkId(linkId),
124 mGbtWords{},
125 mElinkMerger{}
126{
127 impl::assertIsInRange("linkId", linkId, 0, 11);
128}
129
130template <typename FORMAT, typename CHARGESUM, int VERSION>
131void GBTEncoder<FORMAT, CHARGESUM, VERSION>::addChannelData(uint8_t elinkGroupId, uint8_t elinkIndexInGroup, uint8_t chId,
132 const std::vector<SampaCluster>& data)
133{
134
135 impl::assertIsInRange("elinkGroupId", elinkGroupId, 0, 7);
136 impl::assertIsInRange("elinkIndexInGroup", elinkIndexInGroup, 0, 4);
137 mElinks.at(elinkGroupId * 5 + elinkIndexInGroup).addChannelData(chId, data);
138}
139
140template <typename FORMAT, typename CHARGESUM, int VERSION>
141void GBTEncoder<FORMAT, CHARGESUM, VERSION>::addHeartbeat(uint8_t elinkGroupId, uint8_t elinkIndexInGroup, uint20_t bunchCrossing)
142{
143
144 impl::assertIsInRange("elinkGroupId", elinkGroupId, 0, 7);
145 impl::assertIsInRange("elinkIndexInGroup", elinkIndexInGroup, 0, 4);
146 mElinks.at(elinkGroupId * 5 + elinkIndexInGroup).addHeartbeat(bunchCrossing);
147}
148
149template <typename FORMAT, typename CHARGESUM, int VERSION>
151{
152 auto s = gsl::span(mElinks.begin(), mElinks.end());
153 mElinkMerger(mLinkId, s, mGbtWords);
154 for (auto& elink : mElinks) {
155 elink.clear();
156 }
157 return impl::moveBuffer(mGbtWords, buffer);
158}
159
160} // namespace o2::mch::raw
161
162#endif
uint64_t phase
Definition RawEventData.h:7
int32_t i
A GBTEncoder manages 40 ElinkEncoder to encode the data of one GBT.
Definition GBTEncoder.h:44
size_t size() const
return the number of bytes our current buffer is
Definition GBTEncoder.h:91
void addHeartbeat(uint8_t elinkGroupId, uint8_t elinkIndexInGroup, uint20_t bunchCrossing)
Definition GBTEncoder.h:141
void addChannelData(uint8_t elinkGroupId, uint8_t elinkIndexInGroup, uint8_t chId, const std::vector< SampaCluster > &data)
Definition GBTEncoder.h:131
size_t moveToBuffer(std::vector< std::byte > &buffer)
Definition GBTEncoder.h:150
uint16_t linkId() const
returns the GBT id
Definition GBTEncoder.h:88
GBTEncoder(uint16_t linkId)
Definition GBTEncoder.h:121
GLuint buffer
Definition glcorearb.h:655
GLboolean * data
Definition glcorearb.h:298
uint32_t uint20_t
Definition DataFormats.h:68