Project
Loading...
Searching...
No Matches
testBareElinkDecoder.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
14
15#define BOOST_TEST_MODULE Test MCHRaw BareElinkDecoder
16#define BOOST_TEST_MAIN
17#define BOOST_TEST_DYN_LINK
18
19#include "BareElinkDecoder.h"
20#include <boost/test/unit_test.hpp>
21#include <fmt/printf.h>
22#include <fstream>
23#include <iostream>
24#include <sstream>
25
26using namespace o2::mch::raw;
27using ::operator<<;
28
30{
31 return [msg](DsElecId dsId, DualSampaChannelId channel, SampaCluster sc) {
32 std::stringstream s;
33 s << dsId;
34 std::cout << fmt::format("{} {} ch={:2d} ", msg, s.str(), channel);
35 std::cout << sc << "\n";
36 };
37}
38
39BOOST_AUTO_TEST_SUITE(o2_mch_raw)
40
41BOOST_AUTO_TEST_SUITE(elinkdecoder)
42
44{
45 int npackets{0};
46 auto helper = handlePacketPrint("Decoding10:");
47
48 auto hp = [&npackets, helper](DsElecId dsId, DualSampaChannelId channel, SampaCluster sh) {
49 npackets++;
50 helper(dsId, channel, sh);
51 };
52
54 rh.sampaChannelHandler = hp;
56
57 std::string enc("1100100010000000000011110000001010101010101010101011111010011100000000000010000000000000000000000000100000000000101000000010100000010000100100100000000000101000000000000000000000000100000000001001100000100110001010011000111110100110100000000000101100000000000000000000001100000000001000001000100000101010000010011000001001001000010110000000000011111000000000000000000000001000000000110110010011011001101101100101110110011111011001");
58
59 for (int i = 0; i < enc.size() - 1; i += 2) {
60 e.append(enc[i] == '1', enc[i + 1] == '1');
61 }
62
63 BOOST_CHECK_EQUAL(npackets, 4);
64}
65
67{
68 int npackets{0};
69 auto helper = handlePacketPrint("Decoding20:");
70
71 auto hp = [&npackets, helper](DsElecId dsId, DualSampaChannelId channel, SampaCluster sh) {
72 npackets++;
73 helper(dsId, channel, sh);
74 };
75
77 rh.sampaChannelHandler = hp;
79 std::string enc("11001000100000000000111100000010101010101010101010110110100100100000000000100000000000000000000000001000000000001010000010100110000000000000010000100100100000000000101000000000000000000000001000000000001001100010011111100000000000000110100100100000000000101100000000000000000000001000000000001000001010000100101000000000110110100100100000000000111110000000000000000000001000000000001101100111011100001100000000");
80
81 for (int i = 0; i < enc.size() - 1; i += 2) {
82 e.append(enc[i] == '1', enc[i + 1] == '1');
83 }
84
85 BOOST_CHECK_EQUAL(npackets, 4);
86
87 // same thing but with a decoder without a channel handler
88 // so we don't "see" any packet in this case
89 npackets = 0;
91 for (int i = 0; i < enc.size() - 1; i += 2) {
92 e2.append(enc[i] == 1, enc[i + 1] == 1);
93 }
94
95 BOOST_CHECK_EQUAL(npackets, 0);
96}
97
98BOOST_AUTO_TEST_SUITE_END()
99BOOST_AUTO_TEST_SUITE_END()
int32_t i
Main element of the MCH Bare Raw Data Format decoder.
void append(bool bit0, bool bit1)
Append two bits (from the same dual sampa, one per sampa) to the Elink.
std::function< void(DsElecId dsId, DualSampaChannelId channel, SampaCluster)> SampaChannelHandler
uint6_t DualSampaChannelId
Definition DataFormats.h:65
BOOST_AUTO_TEST_CASE(FlatHisto)
Piece of data for one Sampa channel.
SampaChannelHandler handlePacketPrint(std::string_view msg)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
uint64_t const void const *restrict const msg
Definition x9.h:153