Macros | Functions
DUNE_MilliSliceFragment_t.cc File Reference
#include "dune-raw-data/Overlays/MilliSliceFragmentWriter.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(MilliSliceFragment_t)
 

Functions

 BOOST_AUTO_TEST_CASE (BaselineTest)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE (   MilliSliceFragment_t)

Definition at line 16 of file DUNE_MilliSliceFragment_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( BaselineTest  )

Definition at line 22 of file DUNE_MilliSliceFragment_t.cc.

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