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