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(), 0);
15 BOOST_REQUIRE_EQUAL(cf->block_count(), 0);
17 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
20 BOOST_AUTO_TEST_CASE(AddEmptyFragment)
23 frag->setSequenceID(0);
29 cfl.addFragment(*frag);
32 BOOST_REQUIRE_EQUAL(cf->block_count(), 1);
34 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
37 BOOST_AUTO_TEST_CASE(AddFragment_Ptr)
39 std::vector<artdaq::Fragment::value_type> fakeData{ 1, 2, 3, 4 };
51 cfl.addFragment(tmpFrag);
55 BOOST_REQUIRE_EQUAL(cf->block_count(), 1);
57 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
58 BOOST_REQUIRE_EQUAL(cf->fragSize(0), tmpFrag->sizeBytes());
60 auto outfrag = cf->at(0);
61 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
62 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
63 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
64 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
65 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
68 BOOST_AUTO_TEST_CASE(AddFragment_Ref)
70 std::vector<artdaq::Fragment::value_type> fakeData{ 1, 2, 3, 4 };
77 auto frag = *tmpFrag.get();
83 cfl.addFragment(frag);
87 BOOST_REQUIRE_EQUAL(cf->block_count(), 1);
89 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
90 BOOST_REQUIRE_EQUAL(cf->fragSize(0), tmpFrag->sizeBytes());
92 auto outfrag = cf->at(0);
93 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
94 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
95 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
96 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
97 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
101 BOOST_AUTO_TEST_CASE(AddFragments)
103 std::vector<artdaq::Fragment::value_type> fakeData1{ 1, 2, 3, 4 };
104 std::vector<artdaq::Fragment::value_type> fakeData2{ 5, 6, 7, 8 };
118 frags.push_back(std::move(tmpFrag1));
119 frags.push_back(std::move(tmpFrag2));
125 cfl.addFragments(frags);
129 BOOST_REQUIRE_EQUAL(cf->block_count(), 2);
131 BOOST_REQUIRE_EQUAL(cf->fragment_type(), type);
133 auto outfrag = cf->at(0);
134 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
135 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 0);
136 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
137 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 1);
138 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 2);
140 BOOST_REQUIRE_EQUAL(outfrag->sequenceID(), 1);
141 BOOST_REQUIRE_EQUAL(outfrag->fragmentID(), 1);
142 BOOST_REQUIRE_EQUAL(outfrag->dataSize(), 4);
143 BOOST_REQUIRE_EQUAL(*outfrag->dataBegin(), 5);
144 BOOST_REQUIRE_EQUAL(*(outfrag->dataBegin() + 1), 6);
147 BOOST_AUTO_TEST_CASE(Exceptions)
155 BOOST_REQUIRE_EXCEPTION(cf->at(0), cet::exception, [&](cet::exception e) {
return e.category() ==
"ArgumentOutOfRange"; });
156 BOOST_REQUIRE_EXCEPTION(cf->fragSize(0), cet::exception, [&](cet::exception e) {
return e.category() ==
"ArgumentOutOfRange"; });
157 BOOST_REQUIRE_EXCEPTION(cf->fragmentIndex(1), cet::exception, [&](cet::exception e) {
return e.category() ==
"ArgumentOutOfRange"; });
164 BOOST_REQUIRE_EXCEPTION(
artdaq::ContainerFragmentLoader cfl2(f2), cet::exception, [&](cet::exception e) {
return e.category() ==
"InvalidFragment"; });
171 BOOST_REQUIRE_EXCEPTION(cfl.addFragment(f2), cet::exception, [&](cet::exception e) {
return e.category() ==
"ContainerFull"; });
177 cfl3.addFragment(f2);
179 BOOST_REQUIRE_EXCEPTION(cfl3.addFragment(f2), cet::exception, [&](cet::exception e) {
return e.category() ==
"WrongFragmentType"; });
183 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 const int CONTAINER_FRAGMENT_COUNT_MAX
The maximum capacity of the ContainerFragment (in fragments)
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...