9 #include <ecl/digitization/ECLCompress.h>
10 #include <ecl/digitization/EclConfiguration.h>
16 unsigned int Belle2::ECL::ilog2(
unsigned int v)
18 static const unsigned char MultiplyDeBruijnBitPosition[32] = {
19 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
20 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
29 return MultiplyDeBruijnBitPosition[(v * 0x07C4ACDDU) >> 27];
34 int amin = adc[0], amax = adc[0];
36 amax = std::max(amax, adc[i]);
37 amin = std::min(amin, adc[i]);
41 out.putNBits(amin, 18);
42 unsigned int w = ilog2(amax - amin) + 1;
47 unsigned int d = adc[i] - amin;
54 unsigned int amin = out.getNBits(18), w = out.getNBits(5);
56 adc[i] = amin + out.getNBits(w);
61 int a0 = adc[0], dmin = 0, dmax = 0;
64 dmin = std::min(dmin, d);
65 dmax = std::max(dmax, d);
69 unsigned int w = ilog2(std::max(2 * dmax, -2 * dmin)) + 1;
73 a0 = adc[0] & 0x3ffff;
76 unsigned int base = 1 << (w - 1);
78 unsigned int d = int(adc[i]) - a0 + base;
86 unsigned int w = out.getNBits(4);
87 adc[0] = out.getNBits(18);
88 unsigned int base = 1 << (w - 1);
90 adc[i] = adc[i - 1] + out.getNBits(w) - base;
139 width_t widths_phs2_scale10[] = {
182 int ax = abs(x), m0 = 1 << (w.w0 - 1), m1 = 1 << (w.w1 - 1), m2 = 1 << (w.w2 - 1);
185 }
else if (ax < m1) {
186 OUT.
putNBits((x << w.w0) | m0, w.w1 + w.w0);
187 }
else if (ax < m2) {
188 OUT.
putNBits((m1 << w.w0) | m0, w.w1 + w.w0);
191 OUT.
putNBits((m1 << w.w0) | m0, w.w1 + w.w0);
204 int m0 = 1 << (w.w0 - 1), m1 = 1 << (w.w1 - 1), m2 = 1 << (w.w2 - 1);
213 t = (t << (32 - w.w2)) >> (32 - w.w2);
216 t = (t << (32 - w.w1)) >> (32 - w.w1);
219 t = (t << (32 - w.w0)) >> (32 - w.w0);
229 void e10_31(
const double* I,
double* O);
235 void e01_31(
const double* I,
double* O);
243 double buf[N], out[N];
244 for (
int k = 0; k < N; k++) buf[k] = a[k];
246 for (
int k = 0; k < N; k++) out[k] *= 1.0 / (2 * N);
249 for (; km > 16; --km)
if (lrint(out[km - 1]*
m_scale) != 0)
break;
252 for (
int k = 0; k < km; k++) {
253 int t = lrint(out[k] *
m_scale);
260 const double iscale = 1 /
m_scale;
263 for (
int i = 0; i < N - nz; i++) adc[i] = fetch_int(in,
m_widths[i]);
264 for (
int i = N - nz; i < N; i++) adc[i] = 0;
267 for (
int k = 0; k < N; k++) c[k] = adc[k] * iscale;
272 for (
int k = 0; k < N; k++) adc[k] = lrint(out[k]);
280 }
else if (compAlgo == 2) {
282 }
else if (compAlgo == 3) {
284 }
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
Compress the ECL waveform.
const double m_scale
Scale factor for quantization.
const double m_c0
Average waveform amplitude.
void uncompress(BitStream &out, int *adc) override
Decompress the ECL waveform.
ECL waveform compression/decompression to/from the BitStream storage with the DELTA algorithm.
void compress(BitStream &out, const int *adc) override
Compress the ECL waveform.
void uncompress(BitStream &out, int *adc) override
Decompress the ECL waveform.
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...