9#include <ecl/digitization/BitStream.h>
10#include <ecl/digitization/ECLCompress.h>
11#include <ecl/digitization/EclConfiguration.h>
19unsigned int Belle2::ECL::ilog2(
unsigned int v)
21 static const unsigned char MultiplyDeBruijnBitPosition[32] = {
22 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
23 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
32 return MultiplyDeBruijnBitPosition[(v * 0x07C4ACDDU) >> 27];
37 int amin = adc[0], amax = adc[0];
39 amax = std::max(amax, adc[i]);
40 amin = std::min(amin, adc[i]);
44 out.putNBits(amin, 18);
45 unsigned int w = ilog2(amax - amin) + 1;
50 unsigned int d = adc[i] - amin;
57 unsigned int amin = out.getNBits(18), w = out.getNBits(5);
59 adc[i] = amin + out.getNBits(w);
64 int a0 = adc[0], dmin = 0, dmax = 0;
67 dmin = std::min(dmin, d);
68 dmax = std::max(dmax, d);
72 unsigned int w = ilog2(std::max(2 * dmax, -2 * dmin)) + 1;
76 a0 = adc[0] & 0x3ffff;
79 unsigned int base = 1 << (w - 1);
81 unsigned int d = int(adc[i]) - a0 + base;
89 unsigned int w = out.getNBits(4);
90 adc[0] = out.getNBits(18);
91 unsigned int base = 1 << (w - 1);
93 adc[i] = adc[i - 1] + out.getNBits(w) - base;
142 width_t widths_phs2_scale10[] = {
185 int ax = abs(x), m0 = 1 << (w.w0 - 1), m1 = 1 << (w.w1 - 1), m2 = 1 << (w.w2 - 1);
188 }
else if (ax < m1) {
189 OUT.
putNBits((x << w.w0) | m0, w.w1 + w.w0);
190 }
else if (ax < m2) {
191 OUT.
putNBits((m1 << w.w0) | m0, w.w1 + w.w0);
194 OUT.
putNBits((m1 << w.w0) | m0, w.w1 + w.w0);
207 int m0 = 1 << (w.w0 - 1), m1 = 1 << (w.w1 - 1), m2 = 1 << (w.w2 - 1);
216 t = (t << (32 - w.w2)) >> (32 - w.w2);
219 t = (t << (32 - w.w1)) >> (32 - w.w1);
222 t = (t << (32 - w.w0)) >> (32 - w.w0);
232 void e10_31(
const double* I,
double* O);
238 void e01_31(
const double* I,
double* O);
246 double buf[N], out[N];
247 for (
int k = 0; k < N; k++) buf[k] = a[k];
249 for (
int k = 0; k < N; k++) out[k] *= 1.0 / (2 * N);
252 for (; km > 16; --km)
if (lrint(out[km - 1]*
m_scale) != 0)
break;
255 for (
int k = 0; k < km; k++) {
256 int t = lrint(out[k] *
m_scale);
263 const double iscale = 1 /
m_scale;
266 for (
int i = 0; i < N - nz; i++) adc[i] = fetch_int(in,
m_widths[i]);
267 for (
int i = N - nz; i < N; i++) adc[i] = 0;
270 for (
int k = 0; k < N; k++) c[k] = adc[k] * iscale;
275 for (
int k = 0; k < N; k++) adc[k] = lrint(out[k]);
283 }
else if (compAlgo == 2) {
285 }
else if (compAlgo == 3) {
287 }
else if (compAlgo == 4) {
unsigned int getNBits(unsigned int n)
Fetch n bits.
void putNBits(unsigned int value, unsigned int n)
Push n least significant bits of "value" to the stream.
ECL waveform compression/decompression to/from the BitStream storage with the BASE algorithm.
void compress(BitStream &out, const int *adc) override
Compress the ECL waveform.
void uncompress(BitStream &out, int *adc) override
Decompress the ECL waveform.
Abstract class (interface) for ECL waveform compression/decompression to/from the BitStream storage.
ECL waveform compression/decompression to/from the BitStream storage based on the Discrete Cosine Tra...
const width_t * m_widths
Bit widths for the DCT coefficients for prefix encoding.
ECLDCTCompress(double scale, double c0, width_t *w)
Constructor for DCT based compression algorithm.
void compress(BitStream &out, const int *adc) override
function to compress
const double m_scale
Scale factor for quantization.
const double m_c0
Average waveform amplitude.
void uncompress(BitStream &in, int *adc) override
function to decompress
ECL waveform compression/decompression to/from the BitStream storage with the DELTA algorithm.
void compress(BitStream &out, const int *adc) override
function to compress the ECL waveform with the DELTA algorithm
void uncompress(BitStream &out, int *adc) override
function to decompress the ECL waveform with the DELTA algorithm
static constexpr int m_nsmp
number of ADC measurements for signal fitting
Abstract base class for different kinds of events.
Bit widths for the prefix coding to encode integers which are mainly concentrated around zero and pro...