test_LarsoftHuffmanCompressService.cxx
Go to the documentation of this file.
1 // test_LarsoftHuffmanCompressService.cxx
2 
3 // David Adams
4 // February 2015
5 //
6 // Test LarsoftHuffmanCompressService.
7 
9 #include "../LarsoftHuffmanCompressService.h"
10 #include <string>
11 #include <iostream>
12 #include <sstream>
13 
14 using std::string;
15 using std::cout;
16 using std::endl;
17 using std::istringstream;
18 
19 typedef std::vector<short> AdcVector;
20 
21 #undef NDEBUG
22 #include <cassert>
23 
24 int test_LarsoftHuffmanCompressService(bool useBlock, bool useHuffman, int logLevel) {
25  const string myname = "test_LarsoftHuffmanCompressService: ";
26 #ifdef NDEBUG
27  cout << myname << "NDEBUG must be off." << endl;
28  abort();
29 #endif
30  string line = "-----------------------------";
31 
32  cout << line << endl;
33  cout << myname << "Testing with UseBlock=" << useBlock
34  << ", useHuffman=" << useHuffman
35  << ", LogLevel=" << logLevel
36  << endl;
37  raw::Compress_t ctypeexp = raw::kNone;
38  if ( useBlock && useHuffman ) ctypeexp = raw::kZeroHuffman;
39  else if ( useBlock ) ctypeexp = raw::kZeroSuppression;
40  else if ( useHuffman ) ctypeexp = raw::kHuffman;
41  raw::Compress_t ctypeout = raw::kNone;
42 
43  const unsigned int nadc = 3200;
44  AdcVector adc0(nadc, 50);
45  cout << myname << " Initial ADC size: " << adc0.size() << endl;
46  assert( adc0.size() == nadc );
47 
48  AdcFilterVector keep(nadc, true);
49  AdcCount offset = 1800;
50 
51  // Compress.
52  AdcVector adc1(adc0);
53  LarsoftHuffmanCompressService cmp(useBlock, useHuffman, logLevel);
54  cout << myname << "Compressing." << endl;
55  int rstat = cmp.compress(adc1, keep, offset, ctypeout);
56  cout << myname << " Return status: " << rstat << endl;
57  cout << myname << " Compressed ADC size: " << adc1.size() << endl;
58  cout << myname << " Compression type: " << ctypeexp << endl;
59  assert( rstat == 0 );
60  assert( ctypeout == ctypeexp );
61  assert( adc1.size() > 0 );
62  //assert( adc1.size() <= adc0.size() );
63 
64  // Check result.
65  AdcVector adc2(nadc, 0);
66  cout << myname << "Uncompressing." << endl;
67  int uoffset = offset;
68  raw::Uncompress(adc1, adc2, uoffset, ctypeout);
69  cout << myname << "Uncompressed ADC size: " << adc2.size() << endl;
70  assert( adc2.size() == adc0.size() );
71  int nbad = 0;
72  for ( unsigned int iadc=0; iadc<adc0.size(); ++iadc ) {
73  if ( adc0[iadc] != adc2[iadc] ) {
74  cout << myname << " Mismatch for entry " << iadc << ": " << adc0[iadc] << " != " << adc2[iadc] << endl;
75  ++nbad;
76  if ( nbad > 20 ) break;
77  }
78  }
79  assert( nbad == 0 );
80  assert( uoffset == offset );
81 
82  cout << myname << "Done." << endl;
83  return 0;
84 }
85 
86 int main(int argc, char* argv[]) {
87  int logLevel = 1;
88  if ( argc > 1 ) {
89  istringstream ssarg(argv[1]);
90  ssarg >> logLevel;
91  }
92  test_LarsoftHuffmanCompressService(false, false, logLevel);
93  test_LarsoftHuffmanCompressService(false, true, logLevel);
94  test_LarsoftHuffmanCompressService(true, false, logLevel);
95  test_LarsoftHuffmanCompressService(true, true, logLevel);
96  return 0;
97 }
Huffman Encoding.
Definition: RawTypes.h:10
enum raw::_compress Compress_t
std::string string
Definition: nybbler.cc:12
std::vector< short > AdcVector
Zero Suppression followed by Huffman Encoding.
Definition: RawTypes.h:12
no compression
Definition: RawTypes.h:9
Zero Suppression algorithm.
Definition: RawTypes.h:11
std::vector< short > AdcVector
std::vector< bool > AdcFilterVector
Definition: AdcTypes.h:27
void line(double t, double *p, double &x, double &y, double &z)
short AdcCount
Definition: AdcTypes.h:18
int compress(AdcCountVector &sigs, const AdcFilterVector &keep, AdcCount offset, raw::Compress_t &comp) const
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
int main(int argc, char *argv[])
int test_LarsoftHuffmanCompressService(bool useBlock, bool useHuffman, int logLevel)
QTextStream & endl(QTextStream &s)