Typedefs | Functions
test_LarsoftHuffmanCompressService.cxx File Reference
#include "lardataobj/RawData/raw.h"
#include "../LarsoftHuffmanCompressService.h"
#include <string>
#include <iostream>
#include <sstream>
#include <cassert>

Go to the source code of this file.

Typedefs

typedef std::vector< short > AdcVector
 

Functions

int test_LarsoftHuffmanCompressService (bool useBlock, bool useHuffman, int logLevel)
 
int main (int argc, char *argv[])
 

Typedef Documentation

typedef std::vector<short> AdcVector

Definition at line 19 of file test_LarsoftHuffmanCompressService.cxx.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 86 of file test_LarsoftHuffmanCompressService.cxx.

86  {
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 }
int test_LarsoftHuffmanCompressService(bool useBlock, bool useHuffman, int logLevel)
int test_LarsoftHuffmanCompressService ( bool  useBlock,
bool  useHuffman,
int  logLevel 
)

Definition at line 24 of file test_LarsoftHuffmanCompressService.cxx.

24  {
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 }
Huffman Encoding.
Definition: RawTypes.h:10
enum raw::_compress Compress_t
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
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
QTextStream & endl(QTextStream &s)