1 #include "artdaq-core/Data/ContainerFragmentLoader.hh"
3 #define BOOST_TEST_MODULE(ContainerFragment_t)
4 #include "cetlib/quiet_unit_test.hpp"
6 BOOST_AUTO_TEST_SUITE(ContainerFragment_test)
8 BOOST_AUTO_TEST_CASE(Construct)
14 BOOST_REQUIRE_EQUAL(f.dataSize(), 1);
15 BOOST_REQUIRE_EQUAL(cf->block_count(), 0);
17 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
21 BOOST_AUTO_TEST_CASE(AddEmptyFragment)
24 frag->setSequenceID(0);
31 cfl.addFragment(*frag);
34 BOOST_REQUIRE_EQUAL(cf->block_count(), 1);
36 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
41 BOOST_AUTO_TEST_CASE(AddFragment_Ptr)
43 std::vector<artdaq::Fragment::value_type> fakeData{1, 2, 3, 4};
55 cfl.addFragment(tmpFrag);
59 BOOST_REQUIRE_EQUAL(cf->block_count(), 1);
61 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
62 BOOST_REQUIRE_EQUAL(cf->fragSize(0), tmpFrag->sizeBytes());
64 auto outfrag = cf->at(0);
65 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
66 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
67 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
68 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
69 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
72 BOOST_AUTO_TEST_CASE(AddFragment_Ref)
74 std::vector<artdaq::Fragment::value_type> fakeData{1, 2, 3, 4};
81 auto frag = *tmpFrag.get();
87 cfl.addFragment(frag);
91 BOOST_REQUIRE_EQUAL(cf->block_count(), 1);
93 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
94 BOOST_REQUIRE_EQUAL(cf->fragSize(0), tmpFrag->sizeBytes());
96 auto outfrag = cf->at(0);
97 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
98 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
99 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
100 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
101 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
104 BOOST_AUTO_TEST_CASE(AddFragments)
106 std::vector<artdaq::Fragment::value_type> fakeData1{1, 2, 3, 4};
107 std::vector<artdaq::Fragment::value_type> fakeData2{5, 6, 7, 8};
121 frags.push_back(std::move(tmpFrag1));
122 frags.push_back(std::move(tmpFrag2));
128 cfl.addFragments(frags);
132 BOOST_REQUIRE_EQUAL(cf->block_count(), 2);
134 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
136 auto outfrag = cf->at(0);
137 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
138 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
139 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
140 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
141 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
143 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
144 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 1);
145 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
146 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 5);
147 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 6);
150 #define PERF_TEST_FRAGMENT_COUNT 1000
151 BOOST_AUTO_TEST_CASE(Performance)
154 std::vector<artdaq::Fragment::value_type> fakeData1{1, 2, 3, 4};
155 for (
int ii = 0; ii < PERF_TEST_FRAGMENT_COUNT; ++ii)
163 frags.push_back(std::move(tmpFrag1));
171 auto start_time = std::chrono::steady_clock::now();
172 for (
auto& it : frags)
176 auto end_time = std::chrono::steady_clock::now();
178 BOOST_REQUIRE_EQUAL(cf->block_count(), PERF_TEST_FRAGMENT_COUNT);
180 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
189 start_time = std::chrono::steady_clock::now();
190 cfl2.addFragments(frags);
191 end_time = std::chrono::steady_clock::now();
193 BOOST_REQUIRE_EQUAL(cf->block_count(), PERF_TEST_FRAGMENT_COUNT);
194 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
198 BOOST_AUTO_TEST_CASE(Exceptions)
206 BOOST_REQUIRE_EXCEPTION(cf->at(0), cet::exception, [&](cet::exception e) {
return e.category() ==
"ArgumentOutOfRange"; });
207 BOOST_REQUIRE_EXCEPTION(cf->fragSize(0), cet::exception, [&](cet::exception e) {
return e.category() ==
"ArgumentOutOfRange"; });
208 BOOST_REQUIRE_EXCEPTION(cf->fragmentIndex(1), cet::exception, [&](cet::exception e) {
return e.category() ==
"ArgumentOutOfRange"; });
215 BOOST_REQUIRE_EXCEPTION(
artdaq::ContainerFragmentLoader cfl2(f2), cet::exception, [&](cet::exception e) {
return e.category() ==
"InvalidFragment"; });
228 cfl3.addFragment(f2);
230 BOOST_REQUIRE_EXCEPTION(cfl3.addFragment(f2), cet::exception, [&](cet::exception e) {
return e.category() ==
"WrongFragmentType"; });
236 BOOST_REQUIRE_EXCEPTION(cfl3.addFragments(ff1), cet::exception, [&](cet::exception e) {
return e.category() ==
"WrongFragmentType"; });
239 BOOST_AUTO_TEST_CASE(Upgrade)
245 oldMetadata.
index[0] = f.dataSizeBytes();
247 f.setMetadata(oldMetadata);
249 std::vector<artdaq::Fragment::value_type> fakeData{1, 2, 3, 4};
256 memcpy(f.dataBegin(), tmpFrag->headerAddress(), tmpFrag->sizeBytes());
259 auto md = cf.metadata();
260 BOOST_REQUIRE_EQUAL(md->version, 0);
262 auto outfrag = cf.at(0);
263 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
264 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
265 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
266 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
267 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
270 BOOST_AUTO_TEST_SUITE_END()
std::unique_ptr< Fragment > FragmentPtr
A std::unique_ptr to a Fragment object.
The artdaq::ContainerFragment class represents a Fragment which contains other Fragments.
A Read-Write version of the ContainerFragment, used for filling ContainerFragment objects with other ...
static constexpr type_t EmptyFragmentType
Copy EmptyFragmentType from RawFragmentHeader.
static FragmentPtr dataFrag(sequence_id_t sequenceID, fragment_id_t fragID, InputIterator i, InputIterator e)
Creates a Fragment, copying data from given location. 12-Apr-2013, KAB - this method is deprecated...
static constexpr type_t DataFragmentType
Copy DataFragmentType from RawFragmentHeader.
size_t GetElapsedTimeMicroseconds(std::chrono::steady_clock::time_point then, std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now())
Gets the number of microseconds in the given time interval
static constexpr size_t CONTAINER_MAGIC
Marker word used in index.
QuickVec< RawDataType >::value_type value_type
Alias value_type type from QuickVec<RawDataType>
static constexpr type_t FirstUserFragmentType
Copy FIRST_USER_TYPE from RawFragmentHeader.
std::list< FragmentPtr > FragmentPtrs
A std::list of FragmentPtrs.
A Fragment contains the data from one piece of the DAQ system for one event The artdaq::Fragment is t...