RawDigit_test.cc
Go to the documentation of this file.
1 /**
2  * @file RawDigit_test.cc
3  * @brief Simple test on a raw::RawDigit object
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date 20150114
6  * @version 1.0
7  *
8  * This test simply creates raw::RawDigit objects and verifies that the values
9  * it can access are the right ones.
10  *
11  * See http://www.boost.org/libs/test for the Boost test library home page.
12  *
13  * Timing:
14  * version 1.0: <1" (debug mode)
15  */
16 
17 // C/C++ standard library
18 #include <algorithm> // std::equal()
19 
20 
21 // Boost libraries
22 /*
23  * Boost Magic: define the name of the module;
24  * and do that before the inclusion of Boost unit test headers
25  * because it will change what they provide.
26  * Among the those, there is a main() function and some wrapping catching
27  * unhandled exceptions and considering them test failures, and probably more.
28  * This also makes fairly complicate to receive parameters from the command line
29  * (for example, a random seed).
30  */
31 #define BOOST_TEST_MODULE ( rawdigit_test )
32 #include "boost/test/unit_test.hpp"
33 
34 // LArSoft libraries
35 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
36 #include "lardataobj/RawData/raw.h"
38 
39 
40 
41 //------------------------------------------------------------------------------
42 //--- Test code
43 //
44 
45 
47  raw::RawDigit const& digits,
49  unsigned short samples,
50  raw::RawDigit::ADCvector_t const& uncompressed_adclist,
51  raw::Compress_t compression
52 ) {
53 
54  // this is a parameters validation check
55  BOOST_TEST(samples == uncompressed_adclist.size());
56 
57  // verify that the values are as expected
58  // - channel ID
59  BOOST_TEST(digits.Channel() == channel);
60 
61  // - compression mode
62  BOOST_TEST(digits.Compression() == compression);
63 
64  // - uncompressed size
65  BOOST_TEST(digits.Samples() == samples);
66  BOOST_TEST(digits.Samples() == uncompressed_adclist.size());
67 
68  // - digits
69 
70  // decompress (on an already allocated buffer)
71  raw::RawDigit::ADCvector_t ADCs(digits.Samples());
72  raw::Uncompress(digits.ADCs(), ADCs, digits.Compression());
73 
74  BOOST_WARN(digits.NADC() <= samples); // is this always the case?
75  BOOST_TEST
76  (std::equal(ADCs.begin(), ADCs.end(), uncompressed_adclist.begin()));
77 
78  // - others
79  BOOST_TEST(digits.GetPedestal() == 0.);
80  BOOST_TEST(digits.GetSigma() == 0.);
81 
82 } // CheckRawDigit()
83 
84 
86 
87  //
88  // Part I: initialization of wire inputs
89  //
90  // these are the values expected for a default-constructed wire
92  const unsigned short samples = 0;
94  const raw::Compress_t compression = raw::kNone;
95 // raw::RawDigit::Flags_t flags;
96 
97  //
98  // Part II: default constructor
99  //
100  // step II.1: create a wire with the signal-copying constructor
101  raw::RawDigit digits;
102 
103 
104  // step II.2: verify that the values are as expected
105  CheckRawDigit(digits, channel, samples, adclist, compression);
106 
107 } // RawDigitTestDefaultConstructor()
108 
109 
111 
112  //
113  // Part I: initialization of wire inputs
114  //
115  const raw::ChannelID_t channel = 12;
116  const unsigned short samples = 1000;
117  raw::RawDigit::ADCvector_t adclist(samples);
118  for (size_t i = 0; i < samples; ++i)
119  adclist[i] = (i % 3)? 0: i;
120  const raw::Compress_t compression = raw::kHuffman;
121 // raw::RawDigit::Flags_t flags;
122 
123  // working a copy of the original data:
124  std::vector<short> buffer(adclist);
125  raw::Compress(buffer, compression); // compression happens in place
126 
127 
128  //
129  // Part II: constructor with signal copy
130  //
131  // step II.1: create a wire with the signal-copying constructor
132  raw::RawDigit digits1(channel, samples, buffer, compression /*, flags */);
133 
134  // step II.2: verify that the values are as expected
135  CheckRawDigit(digits1, channel, samples, adclist, compression);
136 
137 
138  //
139  // Part III: constructor with signal move
140  //
141  // step III.1: create a wire with the signal-moving constructor
142  std::vector<short> buffer_copy(buffer);
143  raw::RawDigit digits2
144  (channel, samples, std::move(buffer_copy), compression /*, flags */);
145 
146  // step III.2: verify that the values are as expected
147  CheckRawDigit(digits2, channel, samples, adclist, compression);
148 
149  // step III.3: verify that the data was actually moved
150  BOOST_TEST(buffer_copy.empty());
151 
152 } // RawDigitTestCustomConstructors()
153 
154 
156 
157  //
158  // Part I: initialization of wire inputs
159  //
160  const raw::ChannelID_t channel = 12;
161  const unsigned short samples = 1000;
162  raw::RawDigit::ADCvector_t adclist(samples);
163  for (size_t i = 0; i < samples; ++i)
164  adclist[i] = (i % 3)? 0: i;
165  const raw::Compress_t compression = raw::kHuffman;
166 
167 // working a copy of the original data:
168  std::vector<short> buffer(adclist);
169  raw::Compress(buffer, compression); // compression happens in place
170 
171  //
172  // Part II: constructor with signal copy
173  //
174  // step II.1: create a wire with the signal-copying constructor
175  raw::RawDigit digits1(channel, samples, buffer, compression /*, flags */);
176 
177  // step II.2: verify that the values are as expected
178  CheckRawDigit(digits1, channel, samples, adclist, compression);
179 
180 } // FibonacciCompressionTestCustomConstructors()
181 
182 
183 //------------------------------------------------------------------------------
184 //--- registration of tests
185 //
186 // Boost needs now to know which tests we want to run.
187 // Tests are "automatically" registered, hence the BOOST_AUTO_TEST_CASE()
188 // macro name. The argument is the name of the test; each step may have a
189 // number of checks and it will fail if any of them does.
190 //
191 
192 BOOST_AUTO_TEST_CASE(RawDigitDefaultConstructor) {
194 }
195 
196 BOOST_AUTO_TEST_CASE(RawDigitCustomConstructors) {
198 }
199 
200 BOOST_AUTO_TEST_CASE(FibonacciCompressionConstructor) {
202 }
float GetPedestal() const
Definition: RawDigit.h:214
Huffman Encoding.
Definition: RawTypes.h:10
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:210
enum raw::_compress Compress_t
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:213
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
void RawDigitTestCustomConstructors()
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
void CheckRawDigit(raw::RawDigit const &digits, raw::ChannelID_t channel, unsigned short samples, raw::RawDigit::ADCvector_t const &uncompressed_adclist, raw::Compress_t compression)
uint8_t channel
Definition: CRTFragment.hh:201
void RawDigitTestDefaultConstructor()
no compression
Definition: RawTypes.h:9
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
void FibonacciCompressionTestCustomConstructor()
def move(depos, offset)
Definition: depos.py:107
size_t NADC() const
Number of elements in the compressed ADC sample vector.
Definition: RawDigit.h:207
BOOST_AUTO_TEST_CASE(RawDigitDefaultConstructor)
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:216
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
Definition: raw.cxx:19
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
float GetSigma() const
TODO RMS of the pedestal level?
Definition: RawDigit.h:215