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