Project
Loading...
Searching...
No Matches
testClosureCoDecDigit.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 ClosureDigit
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15
16#include <boost/test/unit_test.hpp>
17#include <boost/mpl/list.hpp>
18#include <fstream>
22#include "Framework/Logger.h"
23#include <boost/test/data/test_case.hpp>
24#include <boost/test/data/monomorphic.hpp>
25#include <array>
28
29using namespace o2::mch::raw;
30
31constexpr const char* sampaClusterFormat = "{}-CH{}-{}";
32const bool useDummyElecMap = true;
33
34struct DePadId {
35 int deid;
36 int padid;
37 bool operator==(const DePadId& other) const
38 {
39 return deid == other.deid && padid == other.padid;
40 }
41 bool operator<(const DePadId& other) const
42 {
43 if (deid == other.padid) {
44 return padid < other.padid;
45 }
46 return deid < other.padid;
47 }
48};
49
50std::ostream& operator<<(std::ostream& os, const DePadId& dpi)
51{
52 os << fmt::format("DE {:4d} PADID {:4d}", dpi.deid, dpi.padid);
53 return os;
54}
55
56template <typename T>
58
59// method that is called by the decoder each time a SampaCluster is decoded.
60template <>
62{
63 return [&result](DsElecId dsId, DualSampaChannelId channel, SampaCluster sc) {
64 result.emplace_back(fmt::format(sampaClusterFormat, asString(dsId), channel, asString(sc)));
65 };
66}
67
68template <>
70{
72 return [&result, elec2det](DsElecId dsId, DualSampaChannelId channel, SampaCluster sc) {
73 auto dsDet = elec2det(dsId);
74 auto deId = dsDet->deId();
76 auto padId = seg.findPadByFEE(dsDet->dsId(), channel);
77 result.emplace_back(DePadId{dsDet->deId(), padId});
78 };
79}
80
82{
83 std::cout << fmt::format("BEGIN writeDigits({})\n", useDummyElecMap);
84 fair::Logger::SetConsoleSeverity("nolog");
85 {
86 std::vector<o2::mch::Digit> digits;
87 digits.emplace_back(923, 3959, 959, 123, 1);
88 digits.emplace_back(923, 3974, 974, 123, 1);
89 digits.emplace_back(100, 6664, 664, 123, 1);
90
92 opts.splitMode = OutputSplit::None; // to get only one file
93 opts.noGRP = true; // as we don't have a GRP at hand
94 opts.noEmptyHBF = true; // as we don't want to create big files
95 opts.writeHB = false; // as we'd like to keep it simple
96 opts.userLogicVersion = 1; // test only the latest version
98
99 DigitRawEncoder dre(opts);
100
101 uint32_t orbit{0};
102 uint16_t bc{3456};
103
104 fair::Logger::SetConsoleSeverity("info");
106 //dre.addHeartbeats(std::set<DsElecId> dsElecIds, uint32_t orbit);
107 }
108 std::cout << fmt::format("END writeDigits({})\n", useDummyElecMap);
109}
110
111std::vector<std::byte> getBuffer(const char* filename)
112{
113 std::vector<std::byte> buffer;
114 std::ifstream is(filename, std::ifstream::binary);
115
116 is.seekg(0, is.end);
117 int length = is.tellg();
118 is.seekg(0, is.beg);
119
120 buffer.resize(length);
121
122 is.read(reinterpret_cast<char*>(&buffer[0]), length);
123 is.close();
124 return buffer;
125}
126
127template <typename T>
128std::vector<T> readDigits()
129{
130 std::vector<T> result;
131 DataDecoder dd(handlePacketStoreAsVec<T>(result), nullptr, "", "", false, false, useDummyElecMap);
132
133 auto buffer = getBuffer("MCH.raw");
135 return result;
136}
137
138BOOST_AUTO_TEST_CASE(WrittenAndReadBackDigitsShouldBeTheSameStringVersion)
139{
140 std::vector<std::string> expected = {
141 "S481-J5-DS1-CH58-ts-0-bc-3456-cs-1-q-959",
142 "S481-J5-DS1-CH11-ts-0-bc-3456-cs-1-q-974",
143 "S394-J5-DS3-CH35-ts-0-bc-3456-cs-1-q-664"};
144 if (useDummyElecMap) {
145 expected = std::vector<std::string>{
146 "S727-J6-DS4-CH58-ts-0-bc-3456-cs-1-q-959",
147 "S727-J6-DS4-CH11-ts-0-bc-3456-cs-1-q-974",
148 "S363-J4-DS4-CH35-ts-0-bc-3456-cs-1-q-664"};
149 }
150 writeDigits();
151 auto result = readDigits<std::string>();
152
153 bool sameSize = result.size() == expected.size();
155 bool permutation = false;
156 if (sameSize) {
157 permutation = std::is_permutation(begin(result), end(result), begin(expected));
158 BOOST_CHECK_EQUAL(permutation, true);
159 }
160 if (!permutation || !sameSize) {
161 std::cout << "Got " << result.size() << " results:\n";
162 for (auto s : result) {
163 std::cout << s << "\n";
164 }
165 std::cout << "Expected " << expected.size() << ":\n";
166 for (auto s : expected) {
167 std::cout << s << "\n";
168 }
169 }
170}
171
172BOOST_AUTO_TEST_CASE(WrittenAndReadBackDigitsShouldBeTheSame)
173{
174 std::vector<DePadId> expected = {
175 DePadId{923, 3959},
176 DePadId{923, 3974},
177 DePadId{100, 6664}};
178 writeDigits();
179 auto result = readDigits<DePadId>();
180
181 bool sameSize = result.size() == expected.size();
183 bool permutation = false;
184 if (sameSize) {
185 permutation = std::is_permutation(begin(result), end(result), begin(expected));
186 BOOST_CHECK_EQUAL(permutation, true);
187 }
188 if (!permutation || !sameSize) {
189 std::cout << "Got " << result.size() << " results:\n";
190 for (auto s : result) {
191 std::cout << s << "\n";
192 }
193 std::cout << "Expected " << expected.size() << ":\n";
194 for (auto s : expected) {
195 std::cout << s << "\n";
196 }
197 }
198}
o2::mch::mapping::CathodeSegmentation seg
Definition of the decoder for the MCH data.
uint64_t orbit
Definition RawEventData.h:6
uint64_t bc
Definition RawEventData.h:5
unsigned short int uint16_t
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
int findPadByFEE(int dualSampaId, int dualSampaChannel) const
bool decodeBuffer(gsl::span< const std::byte > buf)
void encodeDigits(gsl::span< o2::mch::Digit > digits, uint32_t orbit, uint16_t bc)
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint buffer
Definition glcorearb.h:655
GLuint GLuint end
Definition glcorearb.h:469
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
O2MCHMAPPINGIMPL3_EXPORT const Segmentation & segmentation(int detElemId)
std::function< std::optional< DsDetId >(DsElecId)> createElec2DetMapper< ElectronicMapperGenerated >(uint64_t)
std::function< void(DsElecId dsId, DualSampaChannelId channel, SampaCluster)> SampaChannelHandler
std::function< std::optional< DsDetId >(DsElecId)> createElec2DetMapper< ElectronicMapperDummy >(uint64_t timestamp)
std::string asString(const SampaCluster &sc)
BOOST_AUTO_TEST_CASE(FlatHisto)
bool sameSize(T0 const &first, Ts const &... rest)
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
std::string filename()
bool operator==(const DePadId &other) const
bool operator<(const DePadId &other) const
Piece of data for one Sampa channel.
std::vector< T > readDigits()
constexpr const char * sampaClusterFormat
SampaChannelHandler handlePacketStoreAsVec(std::vector< T > &result)
void writeDigits()
std::vector< std::byte > getBuffer(const char *filename)
const bool useDummyElecMap
std::map< std::string, ID > expected
VectorOfTObjectPtrs other
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
std::vector< Digit > digits