Belle II Software development
eclWaveforms.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <ecl/dataobjects/ECLWaveforms.h>
10#include <ecl/digitization/BitStream.h>
11#include <ecl/digitization/ECLCompress.h>
12#include <gtest/gtest.h>
13
14using namespace std;
15
16namespace Belle2 {
21 namespace ECL {
22
24 class ECLWaveformsTest : public ::testing::Test {};
25
27 TEST_F(ECLWaveformsTest, Constructor)
28 {
30 EXPECT_EQ(q.getStore().size(), 0);
31 }
32
34 TEST_F(ECLWaveformsTest, Getter)
35 {
36 const int N = 2;
37 vector<unsigned int> t(N);
39 t.swap(q.getStore());
40 EXPECT_EQ(q.getStore().size(), N);
41 }
42
44 class BitStreamTest : public ::testing::Test {};
45
47 TEST_F(BitStreamTest, Constructor)
48 {
49 BitStream q;
50 EXPECT_EQ(q.getPos(), 0);
51 EXPECT_EQ(q.getStore().size(), 1);
52
53 int N = 128;
54 BitStream q2(N);
55 EXPECT_EQ(q2.getPos(), 0);
56 EXPECT_EQ(q2.getStore().size(), N);
57 }
58
60 TEST_F(BitStreamTest, functionality)
61 {
62 int N = 128;
63 BitStream q(N);
64
65 for (unsigned int i = 0; i < 32; i++) {
66 unsigned int k = 1u << i;
67 q.putNBits(k, i + 1);
68 }
69 EXPECT_EQ(q.getPos(), 528);
70 q.setPos(0);
71 for (unsigned int i = 0; i < 32; i++) {
72 unsigned int k0 = 1u << i, k = q.getNBits(i + 1);
73 EXPECT_EQ(k, k0);
74 }
75 EXPECT_EQ(q.getPos(), 528);
76
77 q.resize();
78 q.setPos(0);
79 for (unsigned int i = 0; i < 32; i++) {
80 unsigned int k0 = 1u << i, k = q.getNBits(i + 1);
81 EXPECT_EQ(k, k0);
82 }
83 EXPECT_EQ(q.getPos(), 528);
84 }
85
87 class ECLBaseCompressTest : public ::testing::Test {};
88
90 TEST_F(ECLBaseCompressTest, functionality)
91 {
93
94 int N = 128;
95 for (int off = 0; off < 32; ++off) {
96 BitStream q2(N);
97
98 q2.setPos(off);
99 int A[31];
100 for (int i = 0; i < 31; i++) A[i] = 4000 + ((i % 2) * 1000 - 500);
101 q.compress(q2, A);
102
103 q2.setPos(off);
104 int B[31];
105 q.uncompress(q2, B);
106 for (int i = 0; i < 31; i++) EXPECT_EQ(A[i], B[i]);
107 }
108 }
109
111 class ECLDeltaCompressTest : public ::testing::Test {};
112
114 TEST_F(ECLDeltaCompressTest, functionality)
115 {
117
118 int N = 128;
119 for (int off = 0; off < 32; ++off) {
120 BitStream q2(N);
121
122 q2.setPos(off);
123 int A[31];
124 for (int i = 0; i < 31; i++) A[i] = 4000 + ((i % 2) * 1000 - 500);
125 q.compress(q2, A);
126
127 q2.setPos(off);
128 int B[31];
129 q.uncompress(q2, B);
130 for (int i = 0; i < 31; i++) EXPECT_EQ(A[i], B[i]);
131 }
132 }
133
135 class ECLDCTCompressTest : public ::testing::Test {};
136
138 TEST_F(ECLDCTCompressTest, functionality)
139 {
140 width_t widths_phs2_scale10[] = {
141 {5, 7, 9, 32},// 5.82104
142 {4, 6, 8, 32},// 4.76806
143 {4, 6, 8, 32},// 4.70815
144 {4, 6, 8, 32},// 4.61517
145 {3, 5, 7, 32},// 4.42656
146 {3, 5, 7, 32},// 4.22157
147 {3, 5, 7, 32},// 4.01412
148 {3, 5, 7, 32},// 3.80959
149 {2, 4, 6, 32},// 3.60224
150 {2, 4, 6, 32},// 3.31705
151 {2, 4, 6, 32},// 3.03457
152 {2, 3, 5, 32},// 2.71501
153 {2, 3, 5, 32},// 2.45094
154 {2, 3, 5, 32},// 2.25788
155 {2, 3, 5, 32},// 2.13303
156 {2, 3, 5, 32},// 2.06428
157 {2, 3, 5, 32},// 2.02847
158 {2, 3, 5, 32},// 2.01253
159 {1, 2, 4, 32},// 1.86085
160 {1, 2, 4, 32},// 1.68465
161 {1, 2, 4, 32},// 1.53003
162 {1, 2, 4, 32},// 1.38031
163 {1, 2, 4, 32},// 1.27103
164 {1, 2, 4, 32},// 1.18264
165 {1, 2, 4, 32},// 1.11546
166 {1, 2, 4, 32},// 1.07223
167 {1, 2, 4, 32},// 1.04641
168 {1, 2, 4, 32},// 1.03003
169 {1, 2, 4, 32},// 1.01772
170 {1, 2, 3, 32},// 1.01304
171 {1, 2, 4, 32},// 1.0107
172 };
173
174 ECLDCTCompress q(1, 3500, widths_phs2_scale10);
175
176 int N = 128;
177 for (int off = 0; off < 1; ++off) {
178 BitStream q2(N);
179
180 q2.setPos(off);
181 int A[31];
182 for (int i = 0; i < 31; i++) A[i] = 4000 + ((i % 2) * 1000 - 500);
183 q.compress(q2, A);
184
185 q2.setPos(off);
186 int B[31];
187 q.uncompress(q2, B);
188 for (int i = 0; i < 31; i++) EXPECT_NEAR(A[i], B[i], 10);
189 }
190 }
191 }
193} // namespace
Class to store ECL waveforms for entire calorimeter.
Definition: ECLWaveforms.h:21
Declare BitStream test.
Definition: eclWaveforms.cc:44
Bit stream struct.
Definition: BitStream.h:19
Declare ECLBaseCompress test.
Definition: eclWaveforms.cc:87
ECL waveform compression/decompression to/from the BitStream storage with the BASE algorithm.
Definition: ECLCompress.h:60
Declare ECLDCTCompress test.
Declare ECLDeltaCompress test.
ECL waveform compression/decompression to/from the BitStream storage with the DELTA algorithm.
Definition: ECLCompress.h:69
Declare ECLWaveforms test.
Definition: eclWaveforms.cc:24
Abstract base class for different kinds of events.
STL namespace.
Bit widths for the prefix coding to encode integers which are mainly concentrated around zero and pro...
Definition: ECLCompress.h:29