Macros | Functions
DUNE_MilliSlice_t.cc File Reference
#include "dune-raw-data/Overlays/MilliSliceWriter.hh"
#include <vector>
#include <stdint.h>
#include <memory>
#include "cetlib/quiet_unit_test.hpp"

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE(MilliSlice_t)
 

Functions

 BOOST_AUTO_TEST_CASE (BaselineTest)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE (   MilliSlice_t)

Definition at line 19 of file DUNE_MilliSlice_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( BaselineTest  )

Definition at line 25 of file DUNE_MilliSlice_t.cc.

26 {
27  const uint16_t CHANNEL_NUMBER = 123;
28  const uint32_t MILLISLICE_BUFFER_SIZE = 8192;
29  const uint32_t MICROSLICE_BUFFER_SIZE = 1024;
30  const uint32_t NANOSLICE_BUFFER_SIZE = 128;
31  const uint16_t SAMPLE1 = 0x1234;
32  const uint16_t SAMPLE2 = 0xc3c3;
33  const uint16_t SAMPLE3 = 0xbeef;
34  const uint16_t SAMPLE4 = 0xfe87;
35  const uint16_t SAMPLE5 = 0x5a5a;
36  std::vector<uint8_t> work_buffer(MILLISLICE_BUFFER_SIZE);
37  std::unique_ptr<dune::MicroSlice> microslice_ptr;
38  std::shared_ptr<dune::MicroSliceWriter> microslice_writer_ptr;
39  std::shared_ptr<dune::NanoSliceWriter> nanoslice_writer_ptr;
40  uint16_t value;
41 
42  // *** Use a MilliSliceWriter to build up a MilliSlice, checking
43  // *** that everything looks good as we go.
44 
45  dune::MilliSliceWriter millislice_writer(&work_buffer[0], MILLISLICE_BUFFER_SIZE);
46  BOOST_REQUIRE_EQUAL(millislice_writer.size(), sizeof(dune::MilliSlice::Header));
47  BOOST_REQUIRE_EQUAL(millislice_writer.microSliceCount(), 0);
48  microslice_ptr = millislice_writer.microSlice(0);
49  BOOST_REQUIRE(microslice_ptr.get() == 0);
50  microslice_ptr = millislice_writer.microSlice(999);
51  BOOST_REQUIRE(microslice_ptr.get() == 0);
52 
53  // test a request for a microslice that is too large
54 
55  {
56  bool threw_exception = false;
57 
58  try {
59  millislice_writer.reserveMicroSlice(MILLISLICE_BUFFER_SIZE);
60  } catch (const cet::exception& ) {
61  threw_exception = true;
62  }
63 
64  BOOST_REQUIRE_EQUAL(threw_exception, true);
65  }
66 
67  // resume the building of the microslices in the millislice
68  microslice_writer_ptr = millislice_writer.reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
69  BOOST_REQUIRE(microslice_writer_ptr.get() != 0);
70  BOOST_REQUIRE_EQUAL(millislice_writer.size(),
71  sizeof(dune::MilliSlice::Header) + MICROSLICE_BUFFER_SIZE);
72  BOOST_REQUIRE_EQUAL(millislice_writer.microSliceCount(), 1);
73  if (microslice_writer_ptr.get() != 0) {
74  nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
75  BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
76  BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(),
77  sizeof(dune::MicroSlice::Header) + NANOSLICE_BUFFER_SIZE);
78  BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 1);
79  if (nanoslice_writer_ptr.get() != 0) {
80  nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER);
81  nanoslice_writer_ptr->addSample(SAMPLE1);
82  }
83  }
84 
85  microslice_writer_ptr = millislice_writer.reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
86  BOOST_REQUIRE(microslice_writer_ptr.get() != 0);
87  BOOST_REQUIRE_EQUAL(millislice_writer.size(), sizeof(dune::MilliSlice::Header) +
89  sizeof(uint16_t) + MICROSLICE_BUFFER_SIZE);
90  BOOST_REQUIRE_EQUAL(millislice_writer.microSliceCount(), 2);
91  if (microslice_writer_ptr.get() != 0) {
92  nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
93  BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
94  BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(),
95  sizeof(dune::MicroSlice::Header) + NANOSLICE_BUFFER_SIZE);
96  BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 1);
97  if (nanoslice_writer_ptr.get() != 0) {
98  nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER+1);
99  nanoslice_writer_ptr->addSample(SAMPLE2);
100  }
101 
102  nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
103  BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
104  BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(), sizeof(dune::MicroSlice::Header) +
105  sizeof(dune::MicroSlice::Header) + sizeof(uint16_t) +
106  NANOSLICE_BUFFER_SIZE);
107  BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 2);
108  if (nanoslice_writer_ptr.get() != 0) {
109  nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER+1);
110  nanoslice_writer_ptr->addSample(SAMPLE3);
111  }
112  }
113 
114  microslice_writer_ptr = millislice_writer.reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
115  BOOST_REQUIRE(microslice_writer_ptr.get() != 0);
116  BOOST_REQUIRE_EQUAL(millislice_writer.size(), sizeof(dune::MilliSlice::Header) +
117  2*sizeof(dune::MicroSlice::Header) + 3*sizeof(dune::NanoSlice::Header) +
118  3*sizeof(uint16_t) + MICROSLICE_BUFFER_SIZE);
119  BOOST_REQUIRE_EQUAL(millislice_writer.microSliceCount(), 3);
120  if (microslice_writer_ptr.get() != 0) {
121  nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
122  BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
123  BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(),
124  sizeof(dune::MicroSlice::Header) + NANOSLICE_BUFFER_SIZE);
125  BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 1);
126  if (nanoslice_writer_ptr.get() != 0) {
127  nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER+2);
128  nanoslice_writer_ptr->addSample(SAMPLE4);
129  nanoslice_writer_ptr->addSample(SAMPLE5);
130  }
131  }
132 
133  // *** Finish off the creation of the MilliSlice and verify that we can't
134  // *** add any more MicroSlices after it is finalized
135 
136  int32_t size_diff = millislice_writer.finalize();
137  BOOST_REQUIRE_EQUAL(size_diff, MILLISLICE_BUFFER_SIZE -
138  sizeof(dune::MilliSlice::Header) -
139  3*sizeof(dune::MicroSlice::Header) -
140  4*sizeof(dune::NanoSlice::Header) - 5*sizeof(uint16_t));
141 
142  {
143  bool threw_exception = false;
144 
145  try {
146  millislice_writer.reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
147  } catch (const cet::exception& ) {
148  threw_exception = true;
149  }
150 
151  BOOST_REQUIRE_EQUAL(threw_exception, true);
152  }
153 
154  // *** Now we construct an instance of a read-only MicroSlice from
155  // *** the fragment and verify that everything still looks good
156 
157  dune::MilliSlice millislice(&work_buffer[0]);
158  BOOST_REQUIRE_EQUAL(millislice.size(), sizeof(dune::MilliSlice::Header) +
159  3*sizeof(dune::MicroSlice::Header) +
160  4*sizeof(dune::NanoSlice::Header) + 5*sizeof(uint16_t));
161  BOOST_REQUIRE_EQUAL(millislice.microSliceCount(), 3);
162 
163  microslice_ptr = millislice.microSlice(1);
164  BOOST_REQUIRE(microslice_ptr.get() != 0);
165  if (microslice_ptr.get() != 0) {
166  BOOST_REQUIRE_EQUAL(microslice_ptr->nanoSliceCount(), 2);
167  std::unique_ptr<dune::NanoSlice> nanoslice_ptr = microslice_ptr->nanoSlice(1);
168  BOOST_REQUIRE(nanoslice_ptr.get() != 0);
169  if (nanoslice_ptr.get() != 0) {
170  BOOST_REQUIRE_EQUAL(nanoslice_ptr->sampleCount(), 1);
171  BOOST_REQUIRE(nanoslice_ptr->sampleValue(0, value));
172  BOOST_REQUIRE_EQUAL(value, SAMPLE3);
173  }
174  }
175 
176  microslice_ptr = millislice.microSlice(2);
177  BOOST_REQUIRE(microslice_ptr.get() != 0);
178  if (microslice_ptr.get() != 0) {
179  BOOST_REQUIRE_EQUAL(microslice_ptr->nanoSliceCount(), 1);
180  std::unique_ptr<dune::NanoSlice> nanoslice_ptr = microslice_ptr->nanoSlice(0);
181  BOOST_REQUIRE(nanoslice_ptr.get() != 0);
182  if (nanoslice_ptr.get() != 0) {
183  BOOST_REQUIRE_EQUAL(nanoslice_ptr->sampleCount(), 2);
184  BOOST_REQUIRE(nanoslice_ptr->sampleValue(0, value));
185  BOOST_REQUIRE_EQUAL(value, SAMPLE4);
186  BOOST_REQUIRE(nanoslice_ptr->sampleValue(1, value));
187  BOOST_REQUIRE_EQUAL(value, SAMPLE5);
188  }
189  }
190 }
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33