All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Wire_test.cc
Go to the documentation of this file.
1 /**
2  * @file Wire_test.cc
3  * @brief Simple test on a recob::Wire object
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date 20150113
6  * @version 1.0
7  *
8  * This test simply creates recob::Wire objects and verifies that the values it
9  * 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.5" (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 ( wire_test )
32 #include "boost/test/unit_test.hpp"
33 
34 // LArSoft libraries
35 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
36 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::View_t
39 
40 
41 
42 //------------------------------------------------------------------------------
43 //--- Test code
44 //
45 
46 
47 void CheckWire(
48  recob::Wire const& wire,
49  recob::Wire::RegionsOfInterest_t const& sigROIlist,
50  raw::ChannelID_t channel,
51  geo::View_t view
52 ) {
53 
54  // verify that the values are as expected
55  // - channel ID
56  BOOST_TEST(wire.Channel() == channel);
57 
58  // - view
59  BOOST_TEST(wire.View() == view);
60 
61  // - region of interest
62  BOOST_TEST(wire.NSignal() == sigROIlist.size());
63 
64  recob::Wire::RegionsOfInterest_t const& wireROI = wire.SignalROI();
65  BOOST_TEST(wireROI.n_ranges() == sigROIlist.n_ranges());
66 
67  unsigned int index = 0;
68  for (auto sample: wireROI) {
69  BOOST_TEST(sample == sigROIlist[index++]);
70  }
71 
72  // - other elements of interface
73  auto const& wire_signal = wire.Signal();
74  BOOST_TEST
75  (std::equal(wire_signal.begin(), wire_signal.end(), sigROIlist.cbegin()));
76 
77 } // CheckWire()
78 
79 
81 
82  //
83  // Part I: initialization of wire inputs
84  //
85  // these are the values expected for a default-constructed wire
89 
90  //
91  // Part II: default constructor
92  //
93  // step II.1: create a wire with the default constructor
94  recob::Wire wire;
95 
96 
97  // step II.2: verify that the values are as expected
98  CheckWire(wire, sigROIlist, channel, view);
99 
100 } // WireTestDefaultConstructor()
101 
102 
104 
105  //
106  // Part I: initialization of wire inputs
107  //
108  raw::ChannelID_t channel = 12;
109  geo::View_t view = geo::kV;
110 
111  recob::Wire::RegionsOfInterest_t sigROIlist(20);
112  sigROIlist.add_range
113  (5, recob::Wire::RegionsOfInterest_t::vector_t({ 5., 6., 7. }));
114  sigROIlist.add_range
115  (11, recob::Wire::RegionsOfInterest_t::vector_t({ 11., 12., 13., 14. }));
116 
117  // this is not a recob::Wire test, but I want to make sure anyway...
118  BOOST_TEST(sigROIlist.size() == 20U);
119  BOOST_TEST(sigROIlist.n_ranges() == 2U);
120  size_t index = 0;
121  for (auto sample: sigROIlist) {
122  BOOST_TEST(((sample == (float) index) || (sample == 0.)));
123  ++index;
124  } // for
125 
126 
127  //
128  // Part II: constructor with signal copy
129  //
130  // step II.1: create a wire with the signal-copying constructor
131  recob::Wire wire1(sigROIlist, channel, view);
132 
133 
134  // step II.2: verify that the values are as expected
135  CheckWire(wire1, sigROIlist, channel, view);
136 
137 
138  //
139  // Part III: constructor with signal move
140  //
141  // step III.1: create a wire with the signal-copying constructor
142  recob::Wire::RegionsOfInterest_t sigROIlistCopy(sigROIlist); // need a copy for check
143  recob::Wire wire2(std::move(sigROIlistCopy), channel, view);
144 
145  // step III.2: verify that the values are as expected
146  CheckWire(wire2, sigROIlist, channel, view);
147 
148  // step III.3: verify that the values were actually moved
149  BOOST_TEST(sigROIlistCopy.empty());
150 
151 } // WireTestCustomConstructors()
152 
153 
154 //------------------------------------------------------------------------------
155 //--- registration of tests
156 //
157 // Boost needs now to know which tests we want to run.
158 // Tests are "automatically" registered, hence the BOOST_AUTO_TEST_CASE()
159 // macro name. The argument is the name of the test; each step may have a
160 // number of checks and it will fail if any of them does.
161 //
162 
163 BOOST_AUTO_TEST_CASE(WireDefaultConstructor) {
165 }
166 
167 BOOST_AUTO_TEST_CASE(WireCustomConstructors) {
169 }
BOOST_AUTO_TEST_CASE(AllTests)
std::vector< value_type > vector_t
type of STL vector holding this data
size_type n_ranges() const
Returns the internal list of non-void ranges.
size_type size() const
Returns the size of the vector.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Planes which measure V.
Definition: geo_types.h:130
Unknown view.
Definition: geo_types.h:136
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
void CheckWire(recob::Wire const &wire, recob::Wire::RegionsOfInterest_t const &sigROIlist, raw::ChannelID_t channel, geo::View_t view)
Definition: Wire_test.cc:47
geo::View_t View() const
Returns the view the channel belongs to.
Definition: Wire.h:230
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
void WireTestCustomConstructors()
Definition: Wire_test.cc:103
void WireTestDefaultConstructor()
Definition: Wire_test.cc:80
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:231
const RegionsOfInterest_t & SignalROI() const
Returns the list of regions of interest.
Definition: Wire.h:228
Definition of data types for geometry description.
std::vector< float > Signal() const
Return a zero-padded full length vector filled with RoI signal.
Definition: Wire.cxx:47
bool equal(double a, double b)
Comparison tolerance, in centimeters.
bool empty() const
Returns whether the vector is empty.
Class holding the regions of interest of signal from a channel.
Definition: Wire.h:118
Declaration of basic channel signal object.
const_iterator cbegin() const
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
Class defining a sparse vector (holes are zeroes)
std::size_t NSignal() const
Returns the number of time ticks, or samples, in the channel.
Definition: Wire.h:229