1414#define BOOST_TEST_DYN_LINK
1515#include < boost/test/unit_test.hpp>
1616#include " DPLUtils/DPLRawParser.h"
17+ #include " RawPageTestData.h"
1718#include " Framework/InputRecord.h"
18- #include " Framework/InputSpan.h"
1919#include " Framework/WorkflowSpec.h" // o2::framework::select
2020#include " Headers/DataHeader.h"
21- #include " Headers/Stack.h"
2221#include < vector>
2322#include < memory>
2423#include < iostream>
2524
2625using namespace o2 ::framework;
2726using DataHeader = o2::header::DataHeader;
28- using Stack = o2::header::Stack;
29- using RAWDataHeaderV4 = o2::header::RAWDataHeaderV4;
30-
31- static const size_t PAGESIZE = 8192 ;
32-
33- // simple helper struct to keep the InputRecord and ownership of messages
34- struct DataSet {
35- // not nice with the double vector but for quick unit test ok
36- using Messages = std::vector<std::vector<std::unique_ptr<std::vector<char >>>>;
37- DataSet (std::vector<InputRoute>&& s, Messages&& m, std::vector<int >&& v)
38- : schema{std::move (s)},
39- messages{std::move (m)},
40- span{[this ](size_t i, size_t part) {
41- BOOST_REQUIRE (i < this ->messages .size ());
42- BOOST_REQUIRE (part < this ->messages [i].size () / 2 );
43- auto header = static_cast <char const *>(this ->messages [i].at (2 * part)->data ());
44- auto payload = static_cast <char const *>(this ->messages [i].at (2 * part + 1 )->data ());
45- return DataRef{nullptr , header, payload};
46- },
47- [this ](size_t i) { return i < this ->messages .size () ? messages[i].size () / 2 : 0 ; }, this ->messages .size ()},
48- record{schema, span},
49- values{std::move (v)}
50- {
51- BOOST_REQUIRE (messages.size () == schema.size ());
52- }
53-
54- std::vector<InputRoute> schema;
55- Messages messages;
56- InputSpan span;
57- InputRecord record;
58- std::vector<int > values;
59- };
27+ auto const PAGESIZE = test::PAGESIZE ;
28+ using DataSet = test::DataSet;
6029
6130DataSet createData ()
6231{
63- // Create the routes we want for the InputRecord
6432 std::vector<InputSpec> inputspecs = {
6533 InputSpec{" tpc0" , " TPC" , " RAWDATA" , 0 , Lifetime::Timeframe},
6634 InputSpec{" its1" , " ITS" , " RAWDATA" , 0 , Lifetime::Timeframe},
6735 InputSpec{" its1" , " ITS" , " RAWDATA" , 1 , Lifetime::Timeframe}};
6836
69- size_t i = 0 ;
70- auto createRoute = [&i](const char * source, InputSpec& spec) {
71- return InputRoute{
72- spec,
73- i++,
74- source};
75- };
76-
77- std::vector<InputRoute> schema = {
78- createRoute (" tpc_source" , inputspecs[0 ]),
79- createRoute (" its_source" , inputspecs[1 ]),
80- createRoute (" tof_source" , inputspecs[2 ])};
81-
82- std::vector<int > checkValues;
83- DataSet::Messages messages;
84-
85- auto initRawPage = [&checkValues](char * buffer, size_t size, int value) {
86- char * wrtptr = buffer;
87- while (wrtptr < buffer + size) {
88- auto * header = reinterpret_cast <RAWDataHeaderV4*>(wrtptr);
89- *header = RAWDataHeaderV4 ();
90- header->offsetToNext = PAGESIZE ;
91- *reinterpret_cast <decltype (value)*>(wrtptr + header->headerSize ) = value;
92- wrtptr += PAGESIZE ;
93- checkValues.emplace_back (value);
94- ++value;
95- }
96- };
97-
98- auto createMessage = [&messages, &initRawPage](DataHeader dh, int value) {
99- DataProcessingHeader dph{0 , 1 };
100- Stack stack{dh, dph};
101- if (dh.splitPayloadParts == 0 || dh.splitPayloadIndex == 0 ) {
102- // add new message collection
103- messages.emplace_back ();
104- }
105- messages.back ().emplace_back (std::make_unique<std::vector<char >>(stack.size ()));
106- memcpy (messages.back ().back ()->data (), stack.data (), messages.back ().back ()->size ());
107- messages.back ().emplace_back (std::make_unique<std::vector<char >>(dh.payloadSize ));
108- initRawPage (messages.back ().back ()->data (), messages.back ().back ()->size (), value);
109- };
110-
11137 // we create message for the 3 input routes, the messages have different page size
11238 // and the second messages has 3 parts, each with the same page size
11339 // the test value is written as payload after the RDH and all values are cached for
11440 // later checking when parsing the data set
115- DataHeader dh1;
116- dh1.dataDescription = " RAWDATA" ;
117- dh1.dataOrigin = " TPC" ;
118- dh1.subSpecification = 0 ;
119- dh1.payloadSerializationMethod = o2::header::gSerializationMethodNone ;
120- dh1.payloadSize = 5 * PAGESIZE ;
121- DataHeader dh2;
122- dh2.dataDescription = " RAWDATA" ;
123- dh2.dataOrigin = " ITS" ;
124- dh2.subSpecification = 0 ;
125- dh2.payloadSerializationMethod = o2::header::gSerializationMethodNone ;
126- dh2.payloadSize = 3 * PAGESIZE ;
127- dh2.splitPayloadParts = 3 ;
128- dh2.splitPayloadIndex = 0 ;
129- DataHeader dh3;
130- dh3.dataDescription = " RAWDATA" ;
131- dh3.dataOrigin = " ITS" ;
132- dh3.subSpecification = 1 ;
133- dh3.payloadSerializationMethod = o2::header::gSerializationMethodNone ;
134- dh3.payloadSize = 4 * PAGESIZE ;
135- createMessage (dh1, 10 );
136- createMessage (dh2, 20 );
137- dh2.splitPayloadIndex ++;
138- createMessage (dh2, 23 );
139- dh2.splitPayloadIndex ++;
140- createMessage (dh2, 26 );
141- createMessage (dh3, 30 );
41+ std::vector<DataHeader> dataheaders;
42+ dataheaders.emplace_back (" RAWDATA" , " TPC" , 0 , 5 * PAGESIZE );
43+ dataheaders.emplace_back (" RAWDATA" , " ITS" , 0 , 3 * PAGESIZE , 0 , 3 );
44+ dataheaders.emplace_back (" RAWDATA" , " ITS" , 1 , 4 * PAGESIZE );
14245
143- return { std::move (schema), std::move (messages), std::move (checkValues)} ;
46+ return test::createData (inputspecs, dataheaders) ;
14447}
14548
14649BOOST_AUTO_TEST_CASE (test_DPLRawParser)
@@ -157,8 +60,8 @@ BOOST_AUTO_TEST_CASE(test_DPLRawParser)
15760 for (auto it = parser.begin (), end = parser.end (); it != end; ++it, ++count) {
15861 LOG (INFO ) << " data " << count << " " << *((int *)it.data ());
15962 // now check the iterator API
160- // retrieving RDH v4
161- auto const * rdh = it.get_if <o2::header::RAWDataHeaderV4 >();
63+ // retrieving RDH
64+ auto const * rdh = it.get_if <test::RAWDataHeader >();
16265 // retrieving the raw pointer of the page
16366 auto const * raw = it.raw ();
16467 // retrieving payload pointer of the page
@@ -168,10 +71,10 @@ BOOST_AUTO_TEST_CASE(test_DPLRawParser)
16871 // offset of payload in the raw page
16972 size_t offset = it.offset ();
17073 BOOST_REQUIRE (rdh != nullptr );
171- BOOST_REQUIRE (offset == sizeof (o2::header::RAWDataHeaderV4 ));
74+ BOOST_REQUIRE (offset == sizeof (test::RAWDataHeader ));
17275 BOOST_REQUIRE (payload == raw + offset);
17376 BOOST_REQUIRE (*reinterpret_cast <int const *>(payload) == dataset.values [count]);
174- BOOST_REQUIRE (payloadSize == PAGESIZE - sizeof (o2::header::RAWDataHeaderV4 ));
77+ BOOST_REQUIRE (payloadSize == PAGESIZE - sizeof (test::RAWDataHeader ));
17578 auto const * dh = it.o2DataHeader ();
17679 if (last != dh) {
17780 // this is a special wrapper to print the RDU info and table header, this will
0 commit comments