00001 #include "artdaq-core/Data/Fragment.hh"
00002
00003 #define BOOST_TEST_MODULE(Fragment_t)
00004 #ifdef HAVE_CANVAS
00005 #include "cetlib/quiet_unit_test.hpp"
00006 #else
00007 #include "boost/test/auto_unit_test.hpp"
00008 #endif
00009
00010 struct MetadataTypeOne {
00011 uint64_t field1;
00012 uint32_t field2;
00013 uint32_t field3;
00014 };
00015
00016 struct MetadataTypeTwo {
00017 uint64_t field1;
00018 uint32_t field2;
00019 uint32_t field3;
00020 uint64_t field4;
00021 uint16_t field5;
00022 };
00023
00024 struct MetadataTypeHuge {
00025 uint64_t fields[300];
00026 };
00027
00028 BOOST_AUTO_TEST_SUITE(Fragment_test)
00029
00030 BOOST_AUTO_TEST_CASE(Construct)
00031 {
00032
00033
00034
00035 artdaq::Fragment f1;
00036 BOOST_REQUIRE_EQUAL(f1.dataSize(), (size_t) 0);
00037 BOOST_REQUIRE_EQUAL(f1.size(), (size_t) 3);
00038 BOOST_REQUIRE_EQUAL(f1.version(), (artdaq::Fragment::version_t) 0);
00039 BOOST_REQUIRE_EQUAL(f1.type(), (artdaq::Fragment::type_t) 0);
00040 BOOST_REQUIRE_EQUAL(f1.sequenceID(), (artdaq::Fragment::sequence_id_t) 0);
00041 BOOST_REQUIRE_EQUAL(f1.fragmentID(), (artdaq::Fragment::fragment_id_t) 0);
00042 BOOST_REQUIRE_EQUAL(f1.hasMetadata(),false);
00043
00044 artdaq::Fragment f2(7);
00045 BOOST_REQUIRE_EQUAL(f2.dataSize(), (size_t) 7);
00046 BOOST_REQUIRE_EQUAL(f2.size(), (size_t) 10);
00047 BOOST_REQUIRE_EQUAL(f2.version(), (artdaq::Fragment::version_t) 0);
00048 BOOST_REQUIRE(f2.type() == artdaq::Fragment::InvalidFragmentType);
00049 BOOST_REQUIRE(f2.sequenceID() == artdaq::Fragment::InvalidSequenceID);
00050 BOOST_REQUIRE(f2.fragmentID() == artdaq::Fragment::InvalidFragmentID);
00051 BOOST_REQUIRE_EQUAL(f2.hasMetadata(),false);
00052
00053 artdaq::Fragment f3(101, 202);
00054 BOOST_REQUIRE_EQUAL(f3.dataSize(), (size_t) 0);
00055 BOOST_REQUIRE_EQUAL(f3.size(), (size_t) 3);
00056 BOOST_REQUIRE_EQUAL(f3.version(), (artdaq::Fragment::version_t) 0);
00057 BOOST_REQUIRE(f3.type() == artdaq::Fragment::DataFragmentType);
00058 BOOST_REQUIRE_EQUAL(f3.sequenceID(), (artdaq::Fragment::sequence_id_t) 101);
00059 BOOST_REQUIRE_EQUAL(f3.fragmentID(), (artdaq::Fragment::fragment_id_t) 202);
00060 BOOST_REQUIRE_EQUAL(f3.hasMetadata(),false);
00061
00062
00063
00064 try {
00065 artdaq::Fragment frag(101, 202, 0);
00066 BOOST_REQUIRE(0 && "Should have thrown exception");
00067 }
00068 catch (cet::exception const & excpt) {
00069 }
00070 catch (...) {
00071 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00072 }
00073
00074 try {
00075 artdaq::Fragment frag(101, 202, 225);
00076 BOOST_REQUIRE(0 && "Should have thrown exception");
00077 }
00078 catch (cet::exception const & excpt) {
00079 }
00080 catch (...) {
00081 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00082 }
00083
00084 try {
00085 artdaq::Fragment frag(101, 202, 255);
00086 BOOST_REQUIRE(0 && "Should have thrown exception");
00087 }
00088 catch (cet::exception const & excpt) {
00089 }
00090 catch (...) {
00091 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00092 }
00093
00094 try {
00095 artdaq::Fragment frag(101, 202, artdaq::Fragment::InvalidFragmentType);
00096 BOOST_REQUIRE(0 && "Should have thrown exception");
00097 }
00098 catch (cet::exception const & excpt) {
00099 }
00100 catch (...) {
00101 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00102 }
00103
00104 try {
00105 artdaq::Fragment
00106 frag(101, 202, artdaq::detail::RawFragmentHeader::FIRST_SYSTEM_TYPE);
00107 BOOST_REQUIRE(0 && "Should have thrown exception");
00108 }
00109 catch (cet::exception const & excpt) {
00110 }
00111 catch (...) {
00112 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00113 }
00114
00115 try {
00116 artdaq::Fragment
00117 frag(101, 202, artdaq::detail::RawFragmentHeader::LAST_SYSTEM_TYPE);
00118 BOOST_REQUIRE(0 && "Should have thrown exception");
00119 }
00120 catch (cet::exception const & excpt) {
00121 }
00122 catch (...) {
00123 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00124 }
00125
00126 try {
00127 artdaq::Fragment
00128 fragA(101, 202, artdaq::detail::RawFragmentHeader::FIRST_USER_TYPE);
00129 artdaq::Fragment
00130 fragB(101, 202, artdaq::detail::RawFragmentHeader::LAST_USER_TYPE);
00131 artdaq::Fragment fragC(101, 202, 1);
00132 artdaq::Fragment fragD(101, 202, 2);
00133 artdaq::Fragment fragE(101, 202, 3);
00134 artdaq::Fragment fragF(101, 202, 100);
00135 artdaq::Fragment fragG(101, 202, 200);
00136 artdaq::Fragment fragH(101, 202, 224);
00137 }
00138 catch (...) {
00139 BOOST_REQUIRE(0 && "Should not have thrown exception");
00140 }
00141 }
00142
00143 BOOST_AUTO_TEST_CASE(FragmentType)
00144 {
00145 artdaq::Fragment frag(15);
00146
00147
00148 try {
00149 frag.setUserType(0);
00150 BOOST_REQUIRE(0 && "Should have thrown exception");
00151 }
00152 catch (cet::exception const & excpt) {
00153 }
00154 catch (...) {
00155 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00156 }
00157
00158 try {
00159 frag.setUserType(225);
00160 BOOST_REQUIRE(0 && "Should have thrown exception");
00161 }
00162 catch (cet::exception const & excpt) {
00163 }
00164 catch (...) {
00165 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00166 }
00167
00168 try {
00169 frag.setUserType(255);
00170 BOOST_REQUIRE(0 && "Should have thrown exception");
00171 }
00172 catch (cet::exception const & excpt) {
00173 }
00174 catch (...) {
00175 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00176 }
00177
00178 try {
00179 frag.setUserType(artdaq::Fragment::InvalidFragmentType);
00180 BOOST_REQUIRE(0 && "Should have thrown exception");
00181 }
00182 catch (cet::exception const & excpt) {
00183 }
00184 catch (...) {
00185 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00186 }
00187
00188 try {
00189 frag.setUserType(artdaq::detail::RawFragmentHeader::FIRST_SYSTEM_TYPE);
00190 BOOST_REQUIRE(0 && "Should have thrown exception");
00191 }
00192 catch (cet::exception const & excpt) {
00193 }
00194 catch (...) {
00195 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00196 }
00197
00198 try {
00199 frag.setUserType(artdaq::detail::RawFragmentHeader::LAST_SYSTEM_TYPE);
00200 BOOST_REQUIRE(0 && "Should have thrown exception");
00201 }
00202 catch (cet::exception const & excpt) {
00203 }
00204 catch (...) {
00205 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00206 }
00207
00208 try {
00209 frag.setUserType(artdaq::detail::RawFragmentHeader::FIRST_USER_TYPE);
00210 frag.setUserType(artdaq::detail::RawFragmentHeader::LAST_USER_TYPE);
00211 frag.setUserType( 1);
00212 frag.setUserType( 2);
00213 frag.setUserType( 3);
00214 frag.setUserType(100);
00215 frag.setUserType(200);
00216 frag.setUserType(224);
00217 }
00218 catch (...) {
00219 BOOST_REQUIRE(0 && "Should not have thrown exception");
00220 }
00221
00222
00223 try {
00224 frag.setSystemType(0);
00225 BOOST_REQUIRE(0 && "Should have thrown exception");
00226 }
00227 catch (cet::exception const & excpt) {
00228 }
00229 catch (...) {
00230 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00231 }
00232
00233 try {
00234 frag.setSystemType(1);
00235 BOOST_REQUIRE(0 && "Should have thrown exception");
00236 }
00237 catch (cet::exception const & excpt) {
00238 }
00239 catch (...) {
00240 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00241 }
00242
00243 try {
00244 frag.setSystemType(224);
00245 BOOST_REQUIRE(0 && "Should have thrown exception");
00246 }
00247 catch (cet::exception const & excpt) {
00248 }
00249 catch (...) {
00250 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00251 }
00252
00253 try {
00254 frag.setSystemType(artdaq::Fragment::InvalidFragmentType);
00255 BOOST_REQUIRE(0 && "Should have thrown exception");
00256 }
00257 catch (cet::exception const & excpt) {
00258 }
00259 catch (...) {
00260 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00261 }
00262
00263 try {
00264 frag.setSystemType(artdaq::detail::RawFragmentHeader::FIRST_USER_TYPE);
00265 BOOST_REQUIRE(0 && "Should have thrown exception");
00266 }
00267 catch (cet::exception const & excpt) {
00268 }
00269 catch (...) {
00270 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00271 }
00272
00273 try {
00274 frag.setSystemType(artdaq::detail::RawFragmentHeader::LAST_USER_TYPE);
00275 BOOST_REQUIRE(0 && "Should have thrown exception");
00276 }
00277 catch (cet::exception const & excpt) {
00278 }
00279 catch (...) {
00280 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00281 }
00282
00283 try {
00284 frag.setSystemType(artdaq::detail::RawFragmentHeader::FIRST_SYSTEM_TYPE);
00285 frag.setSystemType(artdaq::detail::RawFragmentHeader::LAST_SYSTEM_TYPE);
00286 frag.setSystemType(225);
00287 frag.setSystemType(230);
00288 frag.setSystemType(240);
00289 frag.setSystemType(250);
00290 frag.setSystemType(255);
00291 }
00292 catch (...) {
00293 BOOST_REQUIRE(0 && "Should not have thrown exception");
00294 }
00295 }
00296
00297 BOOST_AUTO_TEST_CASE(SequenceID)
00298 {
00299 artdaq::Fragment f1;
00300 f1.setSequenceID(0);
00301 BOOST_REQUIRE_EQUAL(f1.sequenceID(), (uint64_t)0);
00302 f1.setSequenceID(1);
00303 BOOST_REQUIRE_EQUAL(f1.sequenceID(), (uint64_t)1);
00304 f1.setSequenceID(0xffff);
00305 BOOST_REQUIRE_EQUAL(f1.sequenceID(), (uint64_t)0xffff);
00306 f1.setSequenceID(0x0000ffffffffffff);
00307 BOOST_REQUIRE_EQUAL(f1.sequenceID(), (uint64_t)0x0000ffffffffffff);
00308
00309 artdaq::Fragment f2(0x12345, 0xab);
00310 BOOST_REQUIRE_EQUAL(f2.sequenceID(), (uint64_t)0x12345);
00311
00312 artdaq::Fragment f3(0x0000567812345678, 0xab);
00313 BOOST_REQUIRE_EQUAL(f3.sequenceID(), (uint64_t)0x0000567812345678);
00314 }
00315
00316 BOOST_AUTO_TEST_CASE(FragmentID)
00317 {
00318 artdaq::Fragment f1;
00319 f1.setFragmentID(0);
00320 BOOST_REQUIRE_EQUAL(f1.fragmentID(), (uint16_t)0);
00321 f1.setFragmentID(1);
00322 BOOST_REQUIRE_EQUAL(f1.fragmentID(), (uint16_t)1);
00323 f1.setFragmentID(0xffff);
00324 BOOST_REQUIRE_EQUAL(f1.fragmentID(), (uint16_t)0xffff);
00325
00326 artdaq::Fragment f2(0x12345, 0xab);
00327 BOOST_REQUIRE_EQUAL(f2.fragmentID(), (uint16_t)0xab);
00328
00329 artdaq::Fragment f3(0x0000567812345678, 0xffff);
00330 BOOST_REQUIRE_EQUAL(f3.fragmentID(), (uint16_t)0xffff);
00331 }
00332
00333 BOOST_AUTO_TEST_CASE(Resize)
00334 {
00335
00336 artdaq::Fragment f1;
00337 f1.resize(1234);
00338 BOOST_REQUIRE_EQUAL(f1.dataSize(), (size_t) 1234);
00339 BOOST_REQUIRE_EQUAL(f1.size(), (size_t) 1234 +
00340 artdaq::detail::RawFragmentHeader::num_words());
00341
00342
00343 MetadataTypeOne mdOneA;
00344 artdaq::Fragment f2(1, 123, 3, 5, mdOneA);
00345 f2.resize(129);
00346 BOOST_REQUIRE_EQUAL(f2.dataSize(), (size_t) 129);
00347 BOOST_REQUIRE_EQUAL(f2.size(), (size_t) 129 + 2 +
00348 artdaq::detail::RawFragmentHeader::num_words());
00349 }
00350
00351 BOOST_AUTO_TEST_CASE(Empty)
00352 {
00353 artdaq::Fragment f1;
00354 BOOST_REQUIRE_EQUAL(f1.empty(), true);
00355 f1.resize(1234);
00356 BOOST_REQUIRE_EQUAL(f1.empty(), false);
00357
00358 MetadataTypeOne mdOneA;
00359 artdaq::Fragment f2(1, 123, 3, 5, mdOneA);
00360 BOOST_REQUIRE_EQUAL(f2.empty(), false);
00361 f2.resize(129);
00362 BOOST_REQUIRE_EQUAL(f2.empty(), false);
00363 f2.resize(0);
00364 BOOST_REQUIRE_EQUAL(f2.empty(), true);
00365 BOOST_REQUIRE_EQUAL(f2.dataSize(), (size_t) 0);
00366 BOOST_REQUIRE_EQUAL(f2.size(), (size_t) 2 +
00367 artdaq::detail::RawFragmentHeader::num_words());
00368
00369 artdaq::Fragment f3;
00370 BOOST_REQUIRE_EQUAL(f3.empty(), true);
00371 f3.setMetadata(mdOneA);
00372 BOOST_REQUIRE_EQUAL(f3.empty(), true);
00373
00374 artdaq::Fragment f4(14);
00375 BOOST_REQUIRE_EQUAL(f4.empty(), false);
00376 f4.setMetadata(mdOneA);
00377 BOOST_REQUIRE_EQUAL(f4.empty(), false);
00378 }
00379
00380 BOOST_AUTO_TEST_CASE(Clear)
00381 {
00382 artdaq::Fragment f1;
00383 BOOST_REQUIRE_EQUAL(f1.empty(), true);
00384 f1.resize(1234);
00385 BOOST_REQUIRE_EQUAL(f1.empty(), false);
00386 f1.clear();
00387 BOOST_REQUIRE_EQUAL(f1.empty(), true);
00388
00389 MetadataTypeOne mdOneA;
00390 artdaq::Fragment f2(1, 123, 3, 5, mdOneA);
00391 BOOST_REQUIRE_EQUAL(f2.empty(), false);
00392 f2.resize(129);
00393 BOOST_REQUIRE_EQUAL(f2.empty(), false);
00394 f2.clear();
00395 BOOST_REQUIRE_EQUAL(f2.empty(), true);
00396 BOOST_REQUIRE_EQUAL(f2.dataSize(), (size_t) 0);
00397 BOOST_REQUIRE_EQUAL(f2.size(), (size_t) 2 +
00398 artdaq::detail::RawFragmentHeader::num_words());
00399
00400 artdaq::Fragment f3;
00401 BOOST_REQUIRE_EQUAL(f3.empty(), true);
00402 BOOST_REQUIRE_EQUAL(f3.hasMetadata(), false);
00403 f3.setMetadata(mdOneA);
00404 BOOST_REQUIRE_EQUAL(f3.empty(), true);
00405 BOOST_REQUIRE_EQUAL(f3.hasMetadata(), true);
00406 f3.clear();
00407 BOOST_REQUIRE_EQUAL(f3.empty(), true);
00408 BOOST_REQUIRE_EQUAL(f3.hasMetadata(), true);
00409
00410 artdaq::Fragment f4(14);
00411 BOOST_REQUIRE_EQUAL(f4.empty(), false);
00412 BOOST_REQUIRE_EQUAL(f4.hasMetadata(), false);
00413 f4.setMetadata(mdOneA);
00414 BOOST_REQUIRE_EQUAL(f4.empty(), false);
00415 BOOST_REQUIRE_EQUAL(f4.hasMetadata(), true);
00416 f4.clear();
00417 BOOST_REQUIRE_EQUAL(f4.empty(), true);
00418 BOOST_REQUIRE_EQUAL(f4.hasMetadata(), true);
00419 }
00420
00421 BOOST_AUTO_TEST_CASE(Addresses)
00422 {
00423
00424 artdaq::Fragment f1(200);
00425 BOOST_REQUIRE_EQUAL(f1.dataSize(), (size_t) 200);
00426 BOOST_REQUIRE_EQUAL(f1.size(), (size_t) 200 +
00427 artdaq::detail::RawFragmentHeader::num_words());
00428 artdaq::RawDataType* haddr = f1.headerAddress();
00429 artdaq::RawDataType* daddr = f1.dataAddress();
00430 BOOST_REQUIRE_EQUAL(daddr,
00431 (haddr + artdaq::detail::RawFragmentHeader::num_words()));
00432 try {
00433 f1.metadataAddress();
00434 BOOST_REQUIRE(0 && "Should have thrown exception");
00435 }
00436 catch (cet::exception const & excpt) {
00437 }
00438 catch (...) {
00439 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00440 }
00441 BOOST_REQUIRE_EQUAL(haddr, &(*(f1.headerBegin())));
00442 BOOST_REQUIRE_EQUAL(daddr, &(*(f1.dataBegin())));
00443 BOOST_REQUIRE_EQUAL(daddr+200, &(*(f1.dataEnd())));
00444
00445
00446 MetadataTypeOne mdOneA;
00447 artdaq::Fragment f2(135, 101, 0, 3, mdOneA);
00448 BOOST_REQUIRE_EQUAL(f2.dataSize(), (size_t) 135);
00449 BOOST_REQUIRE_EQUAL(f2.size(), (size_t) 135 + 2 +
00450 artdaq::detail::RawFragmentHeader::num_words());
00451 haddr = f2.headerAddress();
00452 daddr = f2.dataAddress();
00453 artdaq::RawDataType* maddr = f2.metadataAddress();
00454 BOOST_REQUIRE_EQUAL(maddr, haddr +
00455 artdaq::detail::RawFragmentHeader::num_words());
00456 BOOST_REQUIRE_EQUAL(daddr, maddr + 2);
00457 BOOST_REQUIRE_EQUAL(haddr, &(*(f2.headerBegin())));
00458 BOOST_REQUIRE_EQUAL(daddr, &(*(f2.dataBegin())));
00459 BOOST_REQUIRE_EQUAL(daddr+135, &(*(f2.dataEnd())));
00460
00461
00462 MetadataTypeTwo mdTwoA;
00463 artdaq::Fragment f3(77, 101, 0, 3, mdTwoA);
00464 BOOST_REQUIRE_EQUAL(f3.dataSize(), (size_t) 77);
00465 BOOST_REQUIRE_EQUAL(f3.size(), (size_t) 77 + 4 +
00466 artdaq::detail::RawFragmentHeader::num_words());
00467 haddr = f3.headerAddress();
00468 daddr = f3.dataAddress();
00469 maddr = f3.metadataAddress();
00470 BOOST_REQUIRE_EQUAL(maddr, haddr +
00471 artdaq::detail::RawFragmentHeader::num_words());
00472 BOOST_REQUIRE_EQUAL(daddr, maddr + 4);
00473 BOOST_REQUIRE_EQUAL(haddr, &(*(f3.headerBegin())));
00474 BOOST_REQUIRE_EQUAL(daddr, &(*(f3.dataBegin())));
00475 BOOST_REQUIRE_EQUAL(daddr+77, &(*(f3.dataEnd())));
00476 }
00477
00478 BOOST_AUTO_TEST_CASE(Metadata)
00479 {
00480 artdaq::Fragment f1(42);
00481 BOOST_REQUIRE_EQUAL(f1.hasMetadata(),false);
00482 try {
00483 f1.metadata<MetadataTypeOne>();
00484 BOOST_REQUIRE(0 && "Should have thrown exception");
00485 }
00486 catch (cet::exception const & excpt) {
00487 }
00488 catch (...) {
00489 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00490 }
00491
00492 MetadataTypeOne mdOneA;
00493 mdOneA.field1 = 5;
00494 mdOneA.field2 = 10;
00495 mdOneA.field3 = 15;
00496
00497 try {
00498 f1.updateMetadata(mdOneA);
00499 BOOST_REQUIRE(0 && "Should have thrown exception");
00500 }
00501 catch (cet::exception const & excpt) {
00502 }
00503 catch (...) {
00504 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00505 }
00506
00507
00508 f1.setMetadata(mdOneA);
00509 MetadataTypeOne* mdOnePtr = f1.metadata<MetadataTypeOne>();
00510 BOOST_REQUIRE_EQUAL(mdOnePtr->field1, (uint64_t) 5);
00511 BOOST_REQUIRE_EQUAL(mdOnePtr->field2, (uint32_t)10);
00512 BOOST_REQUIRE_EQUAL(mdOnePtr->field3, (uint32_t)15);
00513
00514 try {
00515 MetadataTypeOne mdOneB;
00516 f1.setMetadata(mdOneB);
00517 BOOST_REQUIRE(0 && "Should have thrown exception");
00518 }
00519 catch (cet::exception const & excpt) {
00520 }
00521 catch (...) {
00522 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00523 }
00524
00525 f1.updateMetadata( *mdOnePtr );
00526
00527 MetadataTypeTwo mdTwoA;
00528 mdTwoA.field1 = 10;
00529 mdTwoA.field2 = 20;
00530 mdTwoA.field3 = 30;
00531 mdTwoA.field4 = 40;
00532 mdTwoA.field5 = 50;
00533
00534 try {
00535 f1.updateMetadata(mdTwoA);
00536 BOOST_REQUIRE(0 && "Should have thrown exception");
00537 }
00538 catch (cet::exception const & excpt) {
00539 }
00540 catch (...) {
00541 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00542 }
00543
00544 artdaq::Fragment f2(10, 1, 2, 3, mdTwoA);
00545 MetadataTypeTwo* mdTwoPtr = f2.metadata<MetadataTypeTwo>();
00546 BOOST_REQUIRE_EQUAL(mdTwoPtr->field1, (uint64_t)10);
00547 BOOST_REQUIRE_EQUAL(mdTwoPtr->field2, (uint32_t)20);
00548 BOOST_REQUIRE_EQUAL(mdTwoPtr->field3, (uint32_t)30);
00549 BOOST_REQUIRE_EQUAL(mdTwoPtr->field4, (uint32_t)40);
00550 BOOST_REQUIRE_EQUAL(mdTwoPtr->field5, (uint32_t)50);
00551
00552 artdaq::Fragment f3(0xabcdef, 0xc3a5, 123);
00553 BOOST_REQUIRE_EQUAL(f3.sequenceID(), (uint32_t)0xabcdef);
00554 BOOST_REQUIRE_EQUAL(f3.fragmentID(), (uint16_t)0xc3a5);
00555 BOOST_REQUIRE_EQUAL(f3.type(), (uint16_t)123);
00556 f3.resize(5);
00557 BOOST_REQUIRE_EQUAL(f3.sequenceID(), (uint32_t)0xabcdef);
00558 BOOST_REQUIRE_EQUAL(f3.fragmentID(), (uint16_t)0xc3a5);
00559 BOOST_REQUIRE_EQUAL(f3.type(), (uint8_t) 123);
00560 artdaq::RawDataType * dataPtr = f3.dataAddress();
00561 dataPtr[0] = 0x12345678;
00562 dataPtr[1] = 0xabcd;
00563 dataPtr[2] = 0x456789ab;
00564 dataPtr[3] = 0x3c3c3c3c;
00565 dataPtr[4] = 0x5a5a5a5a;
00566 BOOST_REQUIRE_EQUAL(dataPtr[0], (uint64_t)0x12345678);
00567 BOOST_REQUIRE_EQUAL(dataPtr[1], (uint64_t)0xabcd);
00568 BOOST_REQUIRE_EQUAL(dataPtr[2], (uint64_t)0x456789ab);
00569 BOOST_REQUIRE_EQUAL(dataPtr[3], (uint64_t)0x3c3c3c3c);
00570 BOOST_REQUIRE_EQUAL(dataPtr[4], (uint64_t)0x5a5a5a5a);
00571 BOOST_REQUIRE_EQUAL(f3.sequenceID(), (uint32_t)0xabcdef);
00572 BOOST_REQUIRE_EQUAL(f3.fragmentID(), (uint16_t)0xc3a5);
00573 BOOST_REQUIRE_EQUAL(f3.type(), (uint8_t) 123);
00574 MetadataTypeOne mdOneC;
00575 mdOneC.field1 = 505;
00576 mdOneC.field2 = 510;
00577 mdOneC.field3 = 515;
00578 f3.setMetadata(mdOneC);
00579 mdOnePtr = f3.metadata<MetadataTypeOne>();
00580 BOOST_REQUIRE_EQUAL(mdOnePtr->field1, (uint64_t)505);
00581 BOOST_REQUIRE_EQUAL(mdOnePtr->field2, (uint32_t)510);
00582 BOOST_REQUIRE_EQUAL(mdOnePtr->field3, (uint32_t)515);
00583 BOOST_REQUIRE_EQUAL(f3.sequenceID(), (uint32_t)0xabcdef);
00584 BOOST_REQUIRE_EQUAL(f3.fragmentID(), (uint16_t)0xc3a5);
00585 BOOST_REQUIRE_EQUAL(f3.type(), (uint8_t) 123);
00586 dataPtr = f3.dataAddress();
00587 dataPtr[0] = 0x12345678;
00588 dataPtr[1] = 0xabcd;
00589 dataPtr[2] = 0x456789ab;
00590 dataPtr[3] = 0x3c3c3c3c;
00591 dataPtr[4] = 0x5a5a5a5a;
00592 BOOST_REQUIRE_EQUAL(dataPtr[0], (uint64_t)0x12345678);
00593 BOOST_REQUIRE_EQUAL(dataPtr[1], (uint64_t)0xabcd);
00594 BOOST_REQUIRE_EQUAL(dataPtr[2], (uint64_t)0x456789ab);
00595 BOOST_REQUIRE_EQUAL(dataPtr[3], (uint64_t)0x3c3c3c3c);
00596 BOOST_REQUIRE_EQUAL(dataPtr[4], (uint64_t)0x5a5a5a5a);
00597
00598 MetadataTypeHuge mdHuge;
00599 artdaq::Fragment f4(19);
00600 BOOST_REQUIRE_EQUAL(f4.hasMetadata(),false);
00601 try {
00602 f4.setMetadata(mdHuge);
00603 BOOST_REQUIRE(0 && "Should have thrown exception");
00604 }
00605 catch (cet::exception const & excpt) {
00606 }
00607 catch (...) {
00608 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00609 }
00610
00611 try {
00612 artdaq::Fragment f5(127, 1, 2, 3, mdHuge);
00613 BOOST_REQUIRE(0 && "Should have thrown exception");
00614 }
00615 catch (cet::exception const & excpt) {
00616 }
00617 catch (...) {
00618 BOOST_REQUIRE(0 && "Should have thrown cet::exception");
00619 }
00620 }
00621
00622
00623
00624
00625
00626 BOOST_AUTO_TEST_CASE(Bytes) {
00627
00628 std::size_t payload_size = 5;
00629
00630
00631 artdaq::Fragment::sequence_id_t seqID = 1;
00632 artdaq::Fragment::fragment_id_t fragID = 1;
00633 artdaq::Fragment::type_t type = 3;
00634
00635
00636
00637
00638 struct Metadata {
00639 uint8_t byteOne;
00640 uint8_t byteTwo;
00641 uint8_t byteThree;
00642 };
00643
00644 Metadata theMetadata;
00645
00646 BOOST_REQUIRE( sizeof( artdaq::Fragment::byte_t) == 1);
00647
00648
00649 BOOST_REQUIRE( sizeof( artdaq::RawDataType) == 8);
00650
00651
00652
00653
00654
00655
00656 std::unique_ptr<artdaq::Fragment> f1( new artdaq::Fragment(payload_size) );
00657 std::unique_ptr<artdaq::Fragment> f1_factory(artdaq::Fragment::FragmentBytes(
00658 payload_size * sizeof( artdaq::RawDataType ) ) );
00659
00660 BOOST_REQUIRE( f1->size() == f1_factory->size() );
00661 BOOST_REQUIRE( f1->sizeBytes() == f1_factory->sizeBytes() );
00662
00663 std::unique_ptr<artdaq::Fragment> f2( new artdaq::Fragment( payload_size, seqID, fragID, type, theMetadata) );
00664 std::unique_ptr<artdaq::Fragment> f2_factory( artdaq::Fragment::FragmentBytes(
00665 payload_size * sizeof( artdaq::RawDataType ),
00666 seqID, fragID,
00667 type, theMetadata) );
00668
00669 BOOST_REQUIRE( f2->size() == f2_factory->size() );
00670 BOOST_REQUIRE( f2->sizeBytes() == f2_factory->sizeBytes() );
00671
00672
00673
00674
00675 std::size_t offset = 3;
00676 std::unique_ptr<artdaq::Fragment> f3_factory( artdaq::Fragment::FragmentBytes(
00677 payload_size * sizeof( artdaq::RawDataType ) - offset,
00678 seqID, fragID,
00679 type, theMetadata) );
00680
00681 BOOST_REQUIRE( f3_factory->size() == f2->size() );
00682 BOOST_REQUIRE( f3_factory->sizeBytes() == f2->sizeBytes() );
00683
00684
00685
00686
00687
00688 artdaq::Fragment::byte_t* ptr1 = reinterpret_cast<artdaq::Fragment::byte_t*>(
00689 &*f3_factory->dataBegin());
00690
00691 artdaq::Fragment::byte_t* ptr2 = f3_factory->dataBeginBytes();
00692
00693 artdaq::Fragment::byte_t* ptr3 = reinterpret_cast<artdaq::Fragment::byte_t*>( f3_factory->dataAddress() );
00694
00695 BOOST_REQUIRE_EQUAL( ptr1, ptr2 );
00696 BOOST_REQUIRE_EQUAL( ptr2, ptr3 );
00697
00698
00699
00700 BOOST_REQUIRE( f3_factory->dataBeginBytes() -
00701 reinterpret_cast<artdaq::Fragment::byte_t*>(
00702 &*f3_factory->headerBegin() )
00703 == 4 * sizeof(artdaq::RawDataType) );
00704
00705
00706 BOOST_REQUIRE( static_cast<std::size_t>( f3_factory->dataEndBytes() - f3_factory->dataBeginBytes() ) == f3_factory->dataSizeBytes() );
00707
00708
00709 artdaq::Fragment f4( payload_size );
00710 BOOST_REQUIRE_EQUAL( f4.dataSize(), payload_size );
00711 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), (payload_size * sizeof(artdaq::RawDataType)) );
00712 f4.resize( payload_size + 1 );
00713 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 1) );
00714 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 1) * sizeof(artdaq::RawDataType)) );
00715 f4.resizeBytes( f4.dataSizeBytes() + 2 );
00716 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 2) );
00717 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 2) * sizeof(artdaq::RawDataType)) );
00718 f4.resizeBytes( f4.dataSizeBytes() + 1 );
00719 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 3) );
00720 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 3) * sizeof(artdaq::RawDataType)) );
00721 f4.resizeBytes( f4.dataSizeBytes() + 1 );
00722 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 4) );
00723 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 4) * sizeof(artdaq::RawDataType)) );
00724
00725 size_t targetSize = (payload_size + 4) * sizeof(artdaq::RawDataType);
00726 ++targetSize;
00727 f4.resizeBytes( targetSize );
00728 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 5) );
00729 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 5) * sizeof(artdaq::RawDataType)) );
00730 ++targetSize;
00731 f4.resizeBytes( targetSize );
00732 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 5) );
00733 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 5) * sizeof(artdaq::RawDataType)) );
00734 ++targetSize;
00735 f4.resizeBytes( targetSize );
00736 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 5) );
00737 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 5) * sizeof(artdaq::RawDataType)) );
00738 ++targetSize;
00739 f4.resizeBytes( targetSize );
00740 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 5) );
00741 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 5) * sizeof(artdaq::RawDataType)) );
00742 ++targetSize;
00743 f4.resizeBytes( targetSize );
00744 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 5) );
00745 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 5) * sizeof(artdaq::RawDataType)) );
00746 ++targetSize;
00747 f4.resizeBytes( targetSize );
00748 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 5) );
00749 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 5) * sizeof(artdaq::RawDataType)) );
00750 ++targetSize;
00751 f4.resizeBytes( targetSize );
00752 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 5) );
00753 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 5) * sizeof(artdaq::RawDataType)) );
00754 ++targetSize;
00755 f4.resizeBytes( targetSize );
00756 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 5) );
00757 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 5) * sizeof(artdaq::RawDataType)) );
00758 ++targetSize;
00759 f4.resizeBytes( targetSize );
00760 BOOST_REQUIRE_EQUAL( f4.dataSize(), (payload_size + 6) );
00761 BOOST_REQUIRE_EQUAL( f4.dataSizeBytes(), ((payload_size + 6) * sizeof(artdaq::RawDataType)) );
00762
00763
00764 artdaq::Fragment f5( payload_size );
00765 BOOST_REQUIRE_EQUAL( f5.size(), (payload_size + artdaq::detail::RawFragmentHeader::num_words()) );
00766 BOOST_REQUIRE_EQUAL( f5.sizeBytes(), ((payload_size + artdaq::detail::RawFragmentHeader::num_words()) * sizeof(artdaq::RawDataType)));
00767 f5.setMetadata(theMetadata);
00768 BOOST_REQUIRE_EQUAL( f5.dataSize(), payload_size );
00769 BOOST_REQUIRE_EQUAL( f5.dataSizeBytes(), (payload_size * sizeof(artdaq::RawDataType)) );
00770 BOOST_REQUIRE_EQUAL( f5.size(), (payload_size + 1 + artdaq::detail::RawFragmentHeader::num_words()) );
00771 BOOST_REQUIRE_EQUAL( f5.sizeBytes(), ((payload_size + 1 + artdaq::detail::RawFragmentHeader::num_words()) * sizeof(artdaq::RawDataType)));
00772 }
00773
00774 BOOST_AUTO_TEST_SUITE_END()