1 #include "artdaq-core/Data/ContainerFragmentLoader.hh"
3 #define BOOST_TEST_MODULE(ContainerFragment_t)
4 #include "cetlib/quiet_unit_test.hpp"
6 constexpr
size_t artdaq::ContainerFragment::CONTAINER_MAGIC;
8 BOOST_AUTO_TEST_SUITE(ContainerFragment_test)
10 BOOST_AUTO_TEST_CASE(Construct)
16 BOOST_REQUIRE_EQUAL(f.dataSize(), 1);
17 BOOST_REQUIRE_EQUAL(cf->block_count(), 0);
19 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
20 BOOST_REQUIRE_EQUAL(*reinterpret_cast<const size_t*>(cf->dataBegin()), artdaq::ContainerFragment::CONTAINER_MAGIC);
23 BOOST_AUTO_TEST_CASE(AddEmptyFragment)
26 frag->setSequenceID(0);
32 cfl.addFragment(*frag);
35 BOOST_REQUIRE_EQUAL(cf->block_count(), 1);
37 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
42 BOOST_AUTO_TEST_CASE(AddFragment_Ptr)
44 std::vector<artdaq::Fragment::value_type> fakeData{ 1, 2, 3, 4 };
56 cfl.addFragment(tmpFrag);
60 BOOST_REQUIRE_EQUAL(cf->block_count(), 1);
62 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
63 BOOST_REQUIRE_EQUAL(cf->fragSize(0), tmpFrag->sizeBytes());
65 auto outfrag = cf->at(0);
66 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
67 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
68 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
69 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
70 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
73 BOOST_AUTO_TEST_CASE(AddFragment_Ref)
75 std::vector<artdaq::Fragment::value_type> fakeData{ 1, 2, 3, 4 };
82 auto frag = *tmpFrag.get();
88 cfl.addFragment(frag);
92 BOOST_REQUIRE_EQUAL(cf->block_count(), 1);
94 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
95 BOOST_REQUIRE_EQUAL(cf->fragSize(0), tmpFrag->sizeBytes());
97 auto outfrag = cf->at(0);
98 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
99 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
100 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
101 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
102 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
106 BOOST_AUTO_TEST_CASE(AddFragments)
108 std::vector<artdaq::Fragment::value_type> fakeData1{ 1, 2, 3, 4 };
109 std::vector<artdaq::Fragment::value_type> fakeData2{ 5, 6, 7, 8 };
123 frags.push_back(std::move(tmpFrag1));
124 frags.push_back(std::move(tmpFrag2));
130 cfl.addFragments(frags);
134 BOOST_REQUIRE_EQUAL(cf->block_count(), 2);
136 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
138 auto outfrag = cf->at(0);
139 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
140 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
141 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
142 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
143 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
145 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
146 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 1);
147 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
148 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 5);
149 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 6);
152 BOOST_AUTO_TEST_CASE(Exceptions)
160 BOOST_REQUIRE_EXCEPTION(cf->at(0), cet::exception, [&](cet::exception e) {
return e.category() ==
"ArgumentOutOfRange"; });
161 BOOST_REQUIRE_EXCEPTION(cf->fragSize(0), cet::exception, [&](cet::exception e) {
return e.category() ==
"ArgumentOutOfRange"; });
162 BOOST_REQUIRE_EXCEPTION(cf->fragmentIndex(1), cet::exception, [&](cet::exception e) {
return e.category() ==
"ArgumentOutOfRange"; });
169 BOOST_REQUIRE_EXCEPTION(
artdaq::ContainerFragmentLoader cfl2(f2), cet::exception, [&](cet::exception e) {
return e.category() ==
"InvalidFragment"; });
182 cfl3.addFragment(f2);
184 BOOST_REQUIRE_EXCEPTION(cfl3.addFragment(f2), cet::exception, [&](cet::exception e) {
return e.category() ==
"WrongFragmentType"; });
188 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...
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...