Project
Loading...
Searching...
No Matches
testBareElinkEncoder.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
12#define BOOST_TEST_MODULE Test MCHRaw BareElinkEncoder
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15
16#include <boost/test/unit_test.hpp>
17#include <iostream>
18#include "BareElinkEncoder.h"
20#include <fstream>
21#include <fmt/printf.h>
22
23using namespace o2::mch::raw;
24
26{
27 uint8_t linkId{0};
28
30
31 enc.addChannelData(1, {SampaCluster{20, 21, std::vector<uint16_t>{20}},
32 SampaCluster{24, 21, std::vector<uint16_t>{10}}});
33 enc.addChannelData(5, {SampaCluster{100, 101, std::vector<uint16_t>{100, 101}}});
34 enc.addChannelData(13, {SampaCluster{260, 261, std::vector<uint16_t>{260, 261, 262}}});
35 enc.addChannelData(31, {SampaCluster{620, 621, std::vector<uint16_t>{620, 621, 622, 623}}});
36
37 return enc;
38}
39
41{
42 uint8_t linkId{0};
43
45
46 enc.addChannelData(1, {SampaCluster{20, 21, 101, 202}});
47 enc.addChannelData(5, {SampaCluster{100, 101, 505, 606}});
48 enc.addChannelData(13, {SampaCluster{260, 261, 1313, 141}});
49 enc.addChannelData(31, {SampaCluster{620, 621, 3131, 414}});
50
51 return enc;
52}
53
54BOOST_AUTO_TEST_SUITE(o2_mch_raw)
55
56BOOST_AUTO_TEST_SUITE(elinkencoder)
57
58BOOST_AUTO_TEST_CASE(CtorBuildsAnEmptyBitSet)
59{
61 BOOST_CHECK_EQUAL(enc.len(), 0);
62}
63
64BOOST_AUTO_TEST_CASE(AddSingleHitShouldIncreaseSizeBy140Bits)
65{
67 auto initialSize = enc.len();
68 std::vector<SampaCluster> data = {SampaCluster(20, 21, 10, 11)};
69 enc.addChannelData(31, data);
70 // 100 = 50 (sync) + 50 (header)
71 // 40 = 10 (ts) + 10 (cluster size) + 20 (charge sum)
72 int expectedSize = initialSize + 100 + 40;
74}
75
76BOOST_AUTO_TEST_CASE(AddMultipleHitsShouldIncreateSizeBy40BitsTimeN)
77{
79 auto initialSize = enc.len();
80 uint8_t chId{31};
81
82 std::vector<SampaCluster> data = {
83 SampaCluster(10, 11, 1000, 100),
84 SampaCluster(20, 11, 2000, 200),
85 SampaCluster(30, 11, 3000, 300),
86 };
87
88 enc.addChannelData(chId, data);
89
90 int expectedSize = initialSize + 100 + 40 * data.size();
92}
93
94BOOST_AUTO_TEST_CASE(OneChipChargeSumOneCluster)
95{
97 auto initialSize = enc.len();
98 enc.addChannelData(1, {SampaCluster(20, 21, 101, 202)});
99 enc.addChannelData(5, {SampaCluster(100, 101, 505, 606)});
100 enc.addChannelData(13, {SampaCluster(260, 261, 1313, 141)});
101 enc.addChannelData(31, {SampaCluster(620, 621, 3131, 414)});
102 // 50 = 50 (sync)
103 // 90 = 50 (header) + 10 (ts) + 10 (cluster size) + 20 (charge sum)
104 BOOST_CHECK_EQUAL(enc.len(), initialSize + 50 + 4 * 90);
105}
106
107BOOST_AUTO_TEST_CASE(OneChipSamplesOneCluster)
108{
109 uint8_t linkId{0};
111 auto initialSize = enc.len();
112 enc.addChannelData(1, {SampaCluster(20, 21, std::vector<uint16_t>{1, 10, 100, 10, 1})});
113 enc.addChannelData(5, {SampaCluster(100, 101, std::vector<uint16_t>{5, 50, 5})});
114 enc.addChannelData(13, {SampaCluster(260, 261, std::vector<uint16_t>{13, 14, 15, 15, 13})});
115 enc.addChannelData(31, {SampaCluster(620, 621, std::vector<uint16_t>{31})});
116 BOOST_CHECK_EQUAL(enc.len(), initialSize + 50 + 4 * (50 + 20) + 14 * 10);
117}
118
119template <typename FORMAT, typename CHARGESUM>
120void print(const char* msg, const ElinkEncoder<FORMAT, CHARGESUM>& enc)
121{
122 std::cout << msg << "=";
123 for (auto i = 0; i < enc.len(); i++) {
124 std::cout << (enc.get(i) ? "1" : "0");
125 }
126 std::cout << "\n";
127}
128
129BOOST_AUTO_TEST_CASE(GetShouldThrowIfBitNumberIsBeyondLen20)
130{
131 auto enc = createBareElinkEncoder20();
132 print("encoder20", enc);
133 BOOST_CHECK_THROW(enc.get(enc.len()), std::invalid_argument);
134 BOOST_CHECK_NO_THROW(enc.get(enc.len() - 1));
135}
136
137BOOST_AUTO_TEST_CASE(GetShouldThrowIfBitNumberIsBeyondLen10)
138{
139 auto enc = createBareElinkEncoder10();
140 print("encoder10", enc);
141 BOOST_CHECK_THROW(enc.get(enc.len()), std::invalid_argument);
142 BOOST_CHECK_NO_THROW(enc.get(enc.len() - 1));
143}
144
146{
147 auto enc = createBareElinkEncoder20();
148 auto s = enc.len();
149 enc.fillWithSync(s + 154);
150 BOOST_CHECK_EQUAL(enc.len(), s + 154);
151 BOOST_CHECK_EQUAL(enc.range(s, s + 49), sampaSync().uint64());
152 BOOST_CHECK_EQUAL(enc.range(s + 50, s + 99), sampaSync().uint64());
153 BOOST_CHECK_EQUAL(enc.range(s + 100, s + 149), sampaSync().uint64());
154}
155
156BOOST_AUTO_TEST_SUITE_END()
157BOOST_AUTO_TEST_SUITE_END()
void print() const
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
SampaHeader sampaSync()
The 50-bits Sampa SYNC word.
BOOST_AUTO_TEST_CASE(FlatHisto)
Piece of data for one Sampa channel.
ElinkEncoder< BareFormat, SampleMode > createBareElinkEncoder10()
ElinkEncoder< BareFormat, ChargeSumMode > createBareElinkEncoder20()
float expectedSize()
BOOST_CHECK_NO_THROW(algorithm::merge(target, other))
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
uint64_t const void const *restrict const msg
Definition x9.h:153