Project
Loading...
Searching...
No Matches
BareElinkEncoderMerger.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_BARE_ELINK_ENCODER_MERGER_H
13#define O2_MCH_RAW_ENCODER_BARE_ELINK_ENCODER_MERGER_H
14
15#include "ElinkEncoder.h"
16#include "ElinkEncoderMerger.h"
18#include <gsl/span>
19
20namespace o2::mch::raw
21{
22
23template <typename CHARGESUM>
25{
26 auto len = elinks[0].len();
27 for (auto i = 1; i < elinks.size(); i++) {
28 if (elinks[i].len() != len) {
29 return false;
30 }
31 }
32 return true;
33}
34
35template <typename CHARGESUM>
37{
38 if (areElinksAligned(elinks)) {
39 return;
40 }
41 auto e = std::max_element(elinks.begin(), elinks.end(),
43 return a.len() < b.len();
44 });
45
46 // align all elink sizes by adding sync bits
47 for (auto& elink : elinks) {
48 elink.fillWithSync(e->len());
49 }
50}
51
52template <typename CHARGESUM>
53uint64_t aggregate(gsl::span<ElinkEncoder<BareFormat, CHARGESUM>> elinks, int jstart, int jend, int i)
54{
55 uint64_t w{0};
56 for (int j = jstart; j < jend; j += 2) {
57 for (int k = 0; k <= 1; k++) {
58 bool v = elinks[j / 2].get(i + 1 - k);
59 uint64_t mask = static_cast<uint64_t>(1) << (j + k);
60 if (v) {
61 w |= mask;
62 } else {
63 w &= ~mask;
64 }
65 }
66 }
67 return w;
68}
69
70template <typename CHARGESUM>
71void elink2gbt(gsl::span<ElinkEncoder<BareFormat, CHARGESUM>> elinks, std::vector<uint64_t>& b64)
72{
73 int n = elinks[0].len();
74
75 for (int i = 0; i < n - 1; i += 2) {
76 uint64_t w0 = aggregate(elinks, 0, 64, i);
77 uint64_t w1 = aggregate(elinks, 64, 80, i);
78 b64.push_back(w0);
79 b64.push_back(w1);
80 }
81}
82
83template <typename CHARGESUM>
84struct ElinkEncoderMerger<BareFormat, CHARGESUM> {
85 void operator()(uint16_t /*gbtId*/,
87 std::vector<uint64_t>& b64)
88 {
89 // align sizes of all elinks by adding sync bits
90 align(elinks);
91
92 // convert elinks to GBT words
93 elink2gbt(elinks, b64);
94 }
95};
96
97} // namespace o2::mch::raw
98#endif
int32_t i
uint32_t j
Definition RawData.h:0
GLdouble n
Definition glcorearb.h:1982
const GLdouble * v
Definition glcorearb.h:832
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLenum GLenum GLsizei len
Definition glcorearb.h:4232
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
GLint GLuint mask
Definition glcorearb.h:291
void elink2gbt(gsl::span< ElinkEncoder< BareFormat, CHARGESUM > > elinks, std::vector< uint64_t > &b64)
bool areElinksAligned(gsl::span< ElinkEncoder< BareFormat, CHARGESUM > > elinks)
uint64_t aggregate(gsl::span< ElinkEncoder< BareFormat, CHARGESUM > > elinks, int jstart, int jend, int i)
void align(gsl::span< ElinkEncoder< BareFormat, CHARGESUM > > elinks)
void operator()(uint16_t, gsl::span< ElinkEncoder< BareFormat, CHARGESUM > > elinks, std::vector< uint64_t > &b64)