artdaq_core  v3_06_11
FragmentNameHelper_t.cc
1 #include "artdaq-core/Data/ContainerFragmentLoader.hh"
2 #include "artdaq-core/Data/FragmentNameHelper.hh"
3 
4 #define BOOST_TEST_MODULE(FragmentNameHelper_t)
5 #include <cetlib/quiet_unit_test.hpp>
6 
7 BOOST_AUTO_TEST_SUITE(FragmentNameHelper_test)
8 
9 BOOST_AUTO_TEST_CASE(FNH_Construct)
10 {
11  auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
12  auto names = helper->GetAllProductInstanceNames();
13  BOOST_REQUIRE(names.size() > 0);
14  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
15 
16  BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
17 }
18 
19 BOOST_AUTO_TEST_CASE(FNH_ExtraTypesInConstructor)
20 {
21  auto extraType = std::make_pair(artdaq::Fragment::FirstUserFragmentType, "Test");
22 
23  auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {extraType});
24  auto names = helper->GetAllProductInstanceNames();
25  BOOST_REQUIRE(names.size() > 0);
26  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
27  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::FirstUserFragmentType), "Test");
28  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::FirstUserFragmentType + 2), "testunidentified");
29 
30  BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
31 }
32 
33 BOOST_AUTO_TEST_CASE(FNH_ExtraTypesOverwriteInConstructor)
34 {
35  auto extraType = std::make_pair(artdaq::Fragment::DataFragmentType, "Test");
36 
37  auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {extraType});
38  auto names = helper->GetAllProductInstanceNames();
39  BOOST_REQUIRE(names.size() > 0);
40  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Test");
41 
42  BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
43 }
44 
45 BOOST_AUTO_TEST_CASE(FNH_ExtraTypesMethod)
46 {
47  auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
48  auto names = helper->GetAllProductInstanceNames();
49  BOOST_REQUIRE(names.size() > 0);
50  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
51 
52  BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
53 
54  helper->AddExtraType(artdaq::Fragment::FirstUserFragmentType, "Test");
55  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::FirstUserFragmentType), "Test");
56 }
57 
58 BOOST_AUTO_TEST_CASE(FNH_ExtraTypesOverwriteMethod)
59 {
60  auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
61  auto names = helper->GetAllProductInstanceNames();
62  BOOST_REQUIRE(names.size() > 0);
63  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
64 
65  BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
66 
67  helper->AddExtraType(artdaq::Fragment::DataFragmentType, "Test");
68  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Test");
69 }
70 
71 BOOST_AUTO_TEST_CASE(FNH_DecodeFragment)
72 {
73  auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
74  auto names = helper->GetAllProductInstanceNames();
75  BOOST_REQUIRE(names.size() > 0);
76  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
77 
78  BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
79 
81 
82  auto res = helper->GetInstanceNameForFragment(frag);
83  BOOST_REQUIRE_EQUAL(res.first, true);
84  BOOST_REQUIRE_EQUAL(res.second, "Data");
85 
86  frag.setUserType(artdaq::Fragment::FirstUserFragmentType + 2);
87  res = helper->GetInstanceNameForFragment(frag);
88  BOOST_REQUIRE_EQUAL(res.first, false);
89  BOOST_REQUIRE_EQUAL(res.second, "testunidentified");
90 }
91 
92 BOOST_AUTO_TEST_CASE(FNH_DecodeContainerFragment)
93 {
94  auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
95  auto names = helper->GetAllProductInstanceNames();
96  BOOST_REQUIRE(names.size() > 0);
97  BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
98 
99  BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
100 
101  artdaq::Fragment frag;
103  auto res = helper->GetInstanceNameForFragment(frag);
104  BOOST_REQUIRE_EQUAL(res.first, true);
105  BOOST_REQUIRE_EQUAL(res.second, "ContainerData");
106 }
107 
108 BOOST_AUTO_TEST_SUITE_END()
A Read-Write version of the ContainerFragment, used for filling ContainerFragment objects with other ...
static constexpr type_t DataFragmentType
Copy DataFragmentType from RawFragmentHeader.
Definition: Fragment.hh:149
std::shared_ptr< FragmentNameHelper > makeNameHelper(std::string const &plugin_name, std::string const &unidentified_instance_name, std::vector< std::pair< artdaq::Fragment::type_t, std::string >> extraTypes)
Create a FragmentNameHelper.
static constexpr type_t FirstUserFragmentType
Copy FIRST_USER_TYPE from RawFragmentHeader.
Definition: Fragment.hh:154
A Fragment contains the data from one piece of the DAQ system for one event The artdaq::Fragment is t...
Definition: Fragment.hh:85