Project
Loading...
Searching...
No Matches
test_DataDeflater.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//****************************************************************************
13//* This file is free software: you can redistribute it and/or modify *
14//* it under the terms of the GNU General Public License as published by *
15//* the Free Software Foundation, either version 3 of the License, or *
16//* (at your option) any later version. *
17//* *
18//* Primary Authors: Matthias Richter <richterm@scieq.net> *
19//* *
20//* The authors make no claims about the suitability of this software for *
21//* any purpose. It is provided "as is" without express or implied warranty. *
22//****************************************************************************
23
24// @file test_DataDeflater.cxx
25// @author Matthias Richter
26// @since 2017-06-21
27// @brief Test program for the DataDeflater template class
28
29#define BOOST_TEST_MODULE Utility test
30#define BOOST_TEST_MAIN
31#define BOOST_TEST_DYN_LINK
32#include <boost/test/unit_test.hpp>
33#include <iostream>
34#include <iomanip>
35#include <vector>
36#include <array>
37#include <bitset>
38#include <thread>
39#include <stdexcept> // exeptions, runtime_error
40#include "../include/DataCompression/DataDeflater.h"
41#include "../include/DataCompression/TruncatedPrecisionConverter.h"
42#include "DataGenerator.h"
43#include "Fifo.h"
44
45namespace o2dc = o2::data_compression;
46
47template <typename DataContainerT, typename DeflatedDataT>
48bool compare(const DataContainerT& container, std::size_t bitwidth, const DeflatedDataT& targetBuffer)
49{
50 unsigned wordcount = 0;
51 auto bufferWord = targetBuffer[wordcount];
52 using target_type = typename DeflatedDataT::value_type;
53 auto targetWidth = 8 * sizeof(target_type);
54 int position = targetWidth;
55 for (const auto c : container) {
56 int length = bitwidth;
57 while (length > 0) {
58 if (position == 0) {
59 ++wordcount;
60 BOOST_REQUIRE(wordcount < targetBuffer.size());
61 position = targetWidth;
62 bufferWord = targetBuffer[wordcount];
63 }
64 auto comparing = length;
65 if (comparing > position) {
66 comparing = position;
67 }
68 position -= comparing;
69 target_type mask = ((target_type)1 << comparing) - 1;
70 if (((bufferWord >> position) & mask) != ((c >> (length - comparing)) & mask)) {
71 std::cout << "Decoding error at wordcount: " << wordcount << std::endl
72 << " length: " << length << std::endl
73 << " comparing: " << comparing << std::endl
74 << " position: " << position << std::endl
75 << " mask: " << std::hex << mask << std::endl
76 << std::endl
77 << " bufferWord: " << std::hex << bufferWord << std::endl
78 << " c: " << std::hex << c << std::endl;
79 }
80
81 BOOST_REQUIRE(((bufferWord >> position) & mask) == ((c >> (length - comparing)) & mask));
82
83 length -= comparing;
84 }
85 }
86
87 return true;
88}
89
90BOOST_AUTO_TEST_CASE(test_DataDeflaterRaw)
91{
92 using TestDataDeflater = o2dc::DataDeflater<uint8_t>;
93 TestDataDeflater deflater;
94
95 using target_type = TestDataDeflater::target_type;
96 std::vector<target_type> targetBuffer;
97 auto writerfct = [&](const target_type& value) -> bool {
98 targetBuffer.emplace_back(value);
99 return true;
100 };
101
102 std::array<char, 8> data = {'d', 'e', 'a', 'd', 'b', 'e', 'e', 'f'};
103
104 const auto bitwidth = 7;
105 for (auto c : data) {
106 deflater.writeRaw(c, bitwidth, writerfct);
107 }
108 deflater.close(writerfct);
109 compare(data, bitwidth, targetBuffer);
110}
111
112BOOST_AUTO_TEST_CASE(test_DataDeflaterCodec)
113{
114 constexpr auto bitwidth = 7;
116 using TestDataDeflater = o2dc::DataDeflater<uint8_t, Codec>;
117 using target_type = TestDataDeflater::target_type;
118 TestDataDeflater deflater;
119
120 std::vector<target_type> targetBuffer;
121 auto writerfct = [&](const target_type& value) -> bool {
122 targetBuffer.emplace_back(value);
123 return true;
124 };
125
126 std::array<char, 8> data = {'d', 'e', 'a', 'd', 'b', 'e', 'e', 'f'};
127
128 for (auto c : data) {
129 deflater.write(c, writerfct);
130 }
131 deflater.close(writerfct);
132 compare(data, bitwidth, targetBuffer);
133}
134
135// define a simple parameter model to mask a data value
136template <int NBits>
138{
139 public:
142
143 static const int sBitlength = NBits;
145
146 template <typename T>
147 int convert(T value, converted_type& content, uint8_t& bitlength)
148 {
149 bitlength = sBitlength; // number of valid bits in the value
150 uint32_t mask = 0x1 << bitlength;
151 mask -= 1;
152 content = value & mask;
153 return 0;
154 }
155
156 void reset() {}
157
158 private:
159};
160
161BOOST_AUTO_TEST_CASE(test_TruncatedPrecisionConverter)
162{
164 using TestDataDeflater = o2dc::DataDeflater<uint8_t, Codec>;
165 using target_type = TestDataDeflater::target_type;
166 TestDataDeflater deflater;
167
168 std::vector<target_type> targetBuffer;
169 auto writerfct = [&](const target_type& value) -> bool {
170 targetBuffer.emplace_back(value);
171 return true;
172 };
173
174 std::array<char, 8> data = {'d', 'e', 'a', 'd', 'b', 'e', 'e', 'f'};
175
176 for (auto c : data) {
177 deflater.write(c, writerfct);
178 }
179 deflater.close(writerfct);
180 compare(data, Codec::sMaxLength, targetBuffer);
181}
A simple data generator.
Thread safe FIFO.
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 First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
uint32_t c
Definition RawData.h:2
Acts::Vector3 position
ParameterModelBitMask()=default
~ParameterModelBitMask()=default
int convert(T value, converted_type &content, uint8_t &bitlength)
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLboolean * data
Definition glcorearb.h:298
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
GLint GLuint mask
Definition glcorearb.h:291
bool compare(const DataContainerT &container, std::size_t bitwidth, const DeflatedDataT &targetBuffer)
BOOST_AUTO_TEST_CASE(test_DataDeflaterRaw)