All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Functions | Variables
raw_test.cc File Reference

Tests the raw data compression routines. More...

#include <cmath>
#include <limits>
#include <random>
#include <string>
#include <map>
#include <iostream>
#include "boost/test/unit_test.hpp"
#include "larcoreobj/SimpleTypesAndConstants/PhysicalConstants.h"
#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h"
#include "lardataobj/RawData/raw.h"

Go to the source code of this file.

Classes

class  DataCreatorBase
 Interface of an object creating data to be tested on. More...
 
class  UniformNoiseCreator
 Data creator: uniformly random data, specified range plus offset (pedestal) More...
 
class  GaussianNoiseCreator
 Data creator: Gaussian random data. More...
 
class  SineWaveCreator
 Data creator: sine wave data. More...
 
class  RandomDataCreator
 Data creator: uniformly random data, full range. More...
 

Macros

#define BOOST_TEST_MODULE   ( raw_test )
 

Functions

void RunDataCompressionTest (std::string id, const std::vector< short > &data, raw::Compress_t mode)
 Tests a data set with a given compression. More...
 
void RunDataCompressionTests (DataCreatorBase *pDataCreator)
 Runs data compression tests with selected compression modes. More...
 
 BOOST_AUTO_TEST_CASE (NullData)
 
 BOOST_AUTO_TEST_CASE (ConstantData)
 
 BOOST_AUTO_TEST_CASE (SmallUniformNoiseData)
 
 BOOST_AUTO_TEST_CASE (SmallUniformNoiseOffsetData)
 
 BOOST_AUTO_TEST_CASE (LargeUniformNoiseData)
 
 BOOST_AUTO_TEST_CASE (SmallGaussianNoiseOffsetData)
 
 BOOST_AUTO_TEST_CASE (LargeGaussianNoiseData)
 
 BOOST_AUTO_TEST_CASE (VeryLowFrequencySineWaveData)
 
 BOOST_AUTO_TEST_CASE (LowFrequencySineWaveData)
 
 BOOST_AUTO_TEST_CASE (HighFrequencySineWaveData)
 

Variables

constexpr unsigned int RandomSeed = 12345
 The seed for the default random engine. More...
 

Detailed Description

Tests the raw data compression routines.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
20140716
Version
1.0

This test covers only no compression and Huffman compression. If compresses a data set, uncompresses it back and checks that the result is the same as the original one. As such, it does not support lossy compression (like zero suppression).

See http://www.boost.org/libs/test for the Boost test library home page.

Timing: version 1.0 takes less than 3" on a 3 GHz machine

Definition in file raw_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( raw_test )

Definition at line 37 of file raw_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( NullData  )

Definition at line 291 of file raw_test.cc.

291  {
292  UniformNoiseCreator InputData("null input data", 0.);
293  RunDataCompressionTests(&InputData);
294 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: uniformly random data, specified range plus offset (pedestal)
Definition: raw_test.cc:90
BOOST_AUTO_TEST_CASE ( ConstantData  )

Definition at line 296 of file raw_test.cc.

296  {
297  UniformNoiseCreator InputData("constant input data", 0., 41.);
298  RunDataCompressionTests(&InputData);
299 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: uniformly random data, specified range plus offset (pedestal)
Definition: raw_test.cc:90
BOOST_AUTO_TEST_CASE ( SmallUniformNoiseData  )

Definition at line 301 of file raw_test.cc.

301  {
302  UniformNoiseCreator InputData("uniform small noise", 5.);
303  RunDataCompressionTests(&InputData);
304 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: uniformly random data, specified range plus offset (pedestal)
Definition: raw_test.cc:90
BOOST_AUTO_TEST_CASE ( SmallUniformNoiseOffsetData  )

Definition at line 306 of file raw_test.cc.

306  {
307  UniformNoiseCreator InputData("uniform small noise and offset", 5., 123.2);
308  RunDataCompressionTests(&InputData);
309 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: uniformly random data, specified range plus offset (pedestal)
Definition: raw_test.cc:90
BOOST_AUTO_TEST_CASE ( LargeUniformNoiseData  )

Definition at line 311 of file raw_test.cc.

311  {
312  UniformNoiseCreator InputData("uniform large noise", 40.);
313  RunDataCompressionTests(&InputData);
314 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: uniformly random data, specified range plus offset (pedestal)
Definition: raw_test.cc:90
BOOST_AUTO_TEST_CASE ( SmallGaussianNoiseOffsetData  )

Definition at line 316 of file raw_test.cc.

316  {
317  GaussianNoiseCreator InputData("Gaussian small noise and offset", 5., 123.2);
318  RunDataCompressionTests(&InputData);
319 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: Gaussian random data.
Definition: raw_test.cc:117
BOOST_AUTO_TEST_CASE ( LargeGaussianNoiseData  )

Definition at line 321 of file raw_test.cc.

321  {
322  GaussianNoiseCreator InputData("Gaussian large noise and offset", 40., 194.);
323  RunDataCompressionTests(&InputData);
324 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: Gaussian random data.
Definition: raw_test.cc:117
BOOST_AUTO_TEST_CASE ( VeryLowFrequencySineWaveData  )

Definition at line 326 of file raw_test.cc.

326  {
327  SineWaveCreator InputData("Very low frequency pure sine wave", 1024., 50.);
328  RunDataCompressionTests(&InputData);
329 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: sine wave data.
Definition: raw_test.cc:143
BOOST_AUTO_TEST_CASE ( LowFrequencySineWaveData  )

Definition at line 331 of file raw_test.cc.

331  {
332  SineWaveCreator InputData("Low frequency pure sine wave", 128., 100.);
333  RunDataCompressionTests(&InputData);
334 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: sine wave data.
Definition: raw_test.cc:143
BOOST_AUTO_TEST_CASE ( HighFrequencySineWaveData  )

Definition at line 336 of file raw_test.cc.

336  {
337  SineWaveCreator InputData("High frequency pure sine wave", 16., 100.);
338  RunDataCompressionTests(&InputData);
339 }
void RunDataCompressionTests(DataCreatorBase *pDataCreator)
Runs data compression tests with selected compression modes.
Definition: raw_test.cc:246
Data creator: sine wave data.
Definition: raw_test.cc:143
void RunDataCompressionTest ( std::string  id,
const std::vector< short > &  data,
raw::Compress_t  mode 
)

Tests a data set with a given compression.

Parameters
idstring representing the test (short descriptive text)
datadata set (a vector of short integers)
modecompression mode to be tested
See Also
RunDataCompressionTests

The test consists in compressing and uncompressing back data. The test fails if the uncompressed data does not match the original one.

This is actually a single step of the full test implemented in RunDataCompressionTests.

Definition at line 214 of file raw_test.cc.

215 {
216  // working a copy of the original data:
217  std::vector<short> buffer(data);
218 
219  // compress
220  raw::Compress(buffer, mode);
221  std::cout << id << ": compressed data size: " << buffer.size() << std::endl;
222 
223  // decompress (on an already allocated buffer)
224  std::vector<short> data_again(data.size());
225  raw::Uncompress(buffer, data_again, mode);
226 
227  // Boost provides facilities to compare data and print if it does not match:
228  BOOST_TEST(data_again.size() == data.size());
229 
230  BOOST_CHECK_EQUAL_COLLECTIONS
231  (data.begin(), data.end(), data_again.begin(), data_again.end());
232 
233 } // RunDataCompressionTest()
const char mode
Definition: noise_ana.cxx:20
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
Definition: raw.cxx:19
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
BEGIN_PROLOG could also be cout
void RunDataCompressionTests ( DataCreatorBase pDataCreator)

Runs data compression tests with selected compression modes.

Parameters
pDataCreatoran object to create the input data set
See Also
RunDataCompressionTest()

This function hard-codes some sets of parameters for the tests: the same test in RunDataCompressionTest() is repeated with different data size and different compression modes. This comprises the full test.

Definition at line 246 of file raw_test.cc.

246  {
247 
248  // the compression modes we are going to use, with a human-readable label
249  std::map<raw::Compress_t, std::string> CompressionModes;
250  CompressionModes[raw::kNone] = "uncompressed";
251  CompressionModes[raw::kHuffman] = "Huffman";
252 // CompressionModes[raw::kZeroSuppression] = "zero suppression";
253 // CompressionModes[raw::kZeroHuffman] = "zero suppression plus Huffman";
254 // CompressionModes[raw::kDynamicDec] = "dynamic";
255 
256  // the data sizes we are going to try, with a human-confusing label
257  std::map<size_t, std::string> DataSizes;
258  DataSizes[64] = "small size";
259  DataSizes[9600] = "medium size";
260  DataSizes[1048576] = "large size";
261 
262  for (const auto size_info: DataSizes) {
263  // create the original data:
264  const std::vector<short> data(pDataCreator->create(size_info.first));
265 
266  // test the same data with different compression algorithms:
267  for (const auto test_info: CompressionModes) {
268  // a "nice" label to make output vaguely meaningful...
269  std::string test_id = pDataCreator->name()
270  + " (" + size_info.second + " " + test_info.second + ")";
271 
272  // ... and run the test
273  RunDataCompressionTest(test_id, data, test_info.first);
274  } // for compression modes
275  } // for data sizes
276 
277  // that's it; Boost keeps records of successes and failures
278 } // RunDataCompressionTests()
Huffman Encoding.
Definition: RawTypes.h:10
virtual InputData_t create(size_t size)=0
Creates and returns the data sample; pure virtual.
void RunDataCompressionTest(std::string id, const std::vector< short > &data, raw::Compress_t mode)
Tests a data set with a given compression.
Definition: raw_test.cc:214
no compression
Definition: RawTypes.h:9
std::string name() const
Returns the name of this set.
Definition: raw_test.cc:72

Variable Documentation

constexpr unsigned int RandomSeed = 12345

The seed for the default random engine.

Definition at line 47 of file raw_test.cc.