Project
Loading...
Searching...
No Matches
UserLogicElinkEncoder.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_USER_LOGIC_ELINK_ENCODER_H
13#define O2_MCH_RAW_USER_LOGIC_ELINK_ENCODER_H
14
15#include "Assertions.h"
16#include "ElinkEncoder.h"
17#include "EncoderImplHelper.h"
21#include "MoveBuffer.h"
22#include "NofBits.h"
23#include <cstdlib>
24#include <fmt/printf.h>
25#include <vector>
26#include "Framework/Logger.h"
27
28namespace o2::mch::raw
29{
30
31template <typename CHARGESUM, int VERSION>
32class ElinkEncoder<UserLogicFormat, CHARGESUM, VERSION>
33{
34 public:
35 explicit ElinkEncoder(uint8_t elinkId, int phase = 0);
36
37 void addChannelData(uint8_t chId, const std::vector<SampaCluster>& data);
38
39 void addHeartbeat(uint20_t bunchCrossing);
40
41 size_t moveToBuffer(std::vector<uint64_t>& buffer, uint16_t gbtId);
42
43 void clear();
44
45 private:
46 uint8_t mElinkId; //< Elink id 0..39
47 bool mHasSync; //< whether or not we've already added a sync word
48 std::vector<uint10_t> mBuffer;
49};
50
51template <typename CHARGESUM, int VERSION>
53 int phase)
54 : mElinkId{elinkId},
55 mHasSync{false},
56 mBuffer{}
57{
58 impl::assertIsInRange("elinkId", elinkId, 0, 39);
59}
60
61template <typename CHARGESUM, int VERSION>
63 const std::vector<SampaCluster>& data)
64{
65 if (data.empty()) {
66 throw std::invalid_argument("cannot add empty data");
67 }
68 assertNotMixingClusters<CHARGESUM>(data);
69
71 mElinkId,
72 chId,
73 !mHasSync);
74
75 if (!mHasSync) {
76 mHasSync = true;
77 }
78}
79
80template <typename CHARGESUM, int VERSION>
82{
83 if (!mHasSync) {
84 impl::appendSync(mBuffer);
85 mHasSync = true;
86 }
87 for (auto chipAddress : std::array<uint8_t, 2>{0, 1}) {
88 SampaHeader sh = sampaHeartbeat(chipAddress, bunchCrossing);
89 impl::addPadding(mBuffer);
90 impl::append(mBuffer, sh.uint64());
91 }
92}
93
94template <typename CHARGESUM, int VERSION>
96{
97 mBuffer.clear();
98 mHasSync = false;
99}
100
101template <typename CHARGESUM, int VERSION>
103{
104 if (mBuffer.empty()) {
105 return 0;
106 }
107
108 ULHeaderWord<VERSION> header{0};
109
110 header.linkID = gbtId;
111 header.dsID = mElinkId;
112 header.incomplete = 0; // FIXME: what to do with incomplete ?
113 header.error = 0; // FIXME: what to do with error ?
114
115 uint16_t b14 = static_cast<uint16_t>((header.word >> 50) & 0xFFFF); // keep only 14 most significant bits of header word
116
117 auto n = buffer.size();
118 impl::b10to64(mBuffer, buffer, b14);
119 clear();
120 return buffer.size() - n;
121}
122} // namespace o2::mch::raw
123
124#endif
uint64_t phase
Definition RawEventData.h:7
SampaHeader is the 50-bits header word used in Sampa data transmission protocol.
Definition SampaHeader.h:51
constexpr uint64_t uint64() const
return the header as a 64-bits integer
GLdouble n
Definition glcorearb.h:1982
GLuint buffer
Definition glcorearb.h:655
GLboolean * data
Definition glcorearb.h:298
void addPadding(std::vector< uint10_t > &b10)
void fillUserLogicBuffer10(std::vector< uint10_t > &b10, gsl::span< const SampaCluster > clusters, uint8_t elinkId, DualSampaChannelId chId, bool addSync)
void append(std::vector< uint10_t > &b10, uint50_t value)
int assertIsInRange(std::string what, uint64_t value, uint64_t min, uint64_t max)
Definition Assertions.h:20
void appendSync(std::vector< uint10_t > &b10)
void b10to64(std::vector< uint10_t > b10, std::vector< uint64_t > &b64, uint16_t prefix14)
SampaHeader sampaHeartbeat(uint8_t elinkId, uint20_t bunchCrossing)
Heartbeat packet.
uint32_t uint20_t
Definition DataFormats.h:68
vec clear()