Project
Loading...
Searching...
No Matches
test_InputRecordWalker.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include "Framework/InputSpan.h"
15#include "Framework/WorkflowSpec.h" // o2::framework::select
17#include "Headers/DataHeader.h"
19#include "Headers/Stack.h"
20#include <catch_amalgamated.hpp>
21#include <vector>
22#include <memory>
23#include <string>
24#include <unordered_map>
25
26using namespace o2::framework;
29
30// simple helper struct to keep the InputRecord and ownership of messages
31struct DataSet {
32 // not nice with the double vector but for quick unit test ok
33 using MessageSet = std::vector<std::unique_ptr<std::vector<char>>>;
34 using TaggedSet = std::pair<o2::header::DataOrigin, MessageSet>;
35 using Messages = std::vector<TaggedSet>;
36 using CheckType = std::vector<std::string>;
37 DataSet(std::vector<InputRoute>&& s, Messages&& m, CheckType&& v, ServiceRegistryRef registry)
38 : schema{std::move(s)}, messages{std::move(m)}, span{[this](size_t i, size_t part) {
39 REQUIRE(i < this->messages.size());
40 REQUIRE(part < this->messages[i].second.size() / 2);
41 auto header = static_cast<char const*>(this->messages[i].second.at(2 * part)->data());
42 auto payload = static_cast<char const*>(this->messages[i].second.at(2 * part + 1)->data());
43 return DataRef{nullptr, header, payload};
44 },
45 [this](size_t i) { return i < this->messages.size() ? messages[i].second.size() / 2 : 0; }, this->messages.size()},
46 record{schema, span, registry},
47 values{std::move(v)}
48 {
49 REQUIRE(messages.size() == schema.size());
50 }
51
52 std::vector<InputRoute> schema;
57};
58
60{
61 static ServiceRegistry registry;
62 // Create the routes we want for the InputRecord
63 std::vector<InputSpec> inputspecs = {
64 InputSpec{"tpc", "TPC", "SOMEDATA", 0, Lifetime::Timeframe},
65 InputSpec{"its", ConcreteDataTypeMatcher{"ITS", "SOMEDATA"}, Lifetime::Timeframe},
66 InputSpec{"tof", "TOF", "SOMEDATA", 1, Lifetime::Timeframe}};
67
68 size_t i = 0;
69 auto createRoute = [&i](const char* source, InputSpec& spec) {
70 return InputRoute{
71 spec,
72 i++,
73 source};
74 };
75
76 std::vector<InputRoute> schema = {
77 createRoute("tpc_source", inputspecs[0]),
78 createRoute("its_source", inputspecs[1]),
79 createRoute("tof_source", inputspecs[2])};
80
81 decltype(DataSet::values) checkValues;
82 DataSet::Messages messages;
83
84 auto createMessage = [&messages, &checkValues](DataHeader dh) {
85 checkValues.emplace_back(fmt::format("{}_{}_{}", dh.dataOrigin, dh.dataDescription, dh.subSpecification));
86 std::string const& data = checkValues.back();
87 dh.payloadSize = data.size();
88 DataProcessingHeader dph{0, 1};
89 Stack stack{dh, dph};
90 auto it = messages.begin(), end = messages.end();
91 for (; it != end; ++it) {
92 if (it->first == dh.dataOrigin) {
93 break;
94 }
95 }
96 if (it == end) {
97 messages.resize(messages.size() + 1);
98 it = messages.end() - 1;
99 it->first = dh.dataOrigin;
100 }
101 auto& routemessages = it->second;
102 routemessages.emplace_back(std::make_unique<std::vector<char>>(stack.size()));
103 memcpy(routemessages.back()->data(), stack.data(), routemessages.back()->size());
104 routemessages.emplace_back(std::make_unique<std::vector<char>>(dh.payloadSize));
105 memcpy(routemessages.back()->data(), data.data(), routemessages.back()->size());
106 };
107
108 // we create message for the 3 input routes, the messages have different page size
109 // and the second messages has 3 parts, each with the same page size
110 // the test value is written as payload after the RDH and all values are cached for
111 // later checking when parsing the data set
112 DataHeader dh1;
113 dh1.dataDescription = "SOMEDATA";
114 dh1.dataOrigin = "TPC";
115 dh1.subSpecification = 0;
117 DataHeader dh2;
118 dh2.dataDescription = "SOMEDATA";
119 dh2.dataOrigin = "ITS";
120 dh2.subSpecification = 0;
122 DataHeader dh3;
123 dh3.dataDescription = "SOMEDATA";
124 dh3.dataOrigin = "ITS";
125 dh3.subSpecification = 1;
127 DataHeader dh4;
128 dh4.dataDescription = "SOMEDATA";
129 dh4.dataOrigin = "TOF";
130 dh4.subSpecification = 255;
132 createMessage(dh1);
133 createMessage(dh2);
134 createMessage(dh3);
135 createMessage(dh4);
136
137 return {std::move(schema), std::move(messages), std::move(checkValues), registry};
138}
139
140TEST_CASE("test_DPLRawParser")
141{
142 auto dataset = createData();
143 InputRecord& inputs = dataset.record;
144 REQUIRE(dataset.messages.size() > 0);
145 REQUIRE(dataset.messages[0].second.at(0) != nullptr);
146 REQUIRE(inputs.size() == 3);
147 REQUIRE((*inputs.begin()).header == dataset.messages[0].second.at(0)->data());
148
149 int count = 0;
150 for (auto const& ref : InputRecordWalker(inputs)) {
151 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
152 auto const data = inputs.get<std::string>(ref);
153 REQUIRE(data == dataset.values[count]);
154 count++;
155 }
156 REQUIRE(count == 4);
157
158 std::vector<InputSpec> filter{
159 {"tpc", "TPC", "SOMEDATA", 0, Lifetime::Timeframe},
160 {"its", ConcreteDataTypeMatcher{"ITS", "SOMEDATA"}, Lifetime::Timeframe},
161 };
162
163 count = 0;
164 for (auto const& ref : InputRecordWalker(inputs, filter)) {
165 auto const data = inputs.get<std::string>(ref);
166 REQUIRE(data == dataset.values[count]);
167 count++;
168 }
169 REQUIRE(count == 3);
170}
int32_t i
A helper class to iteratate over all parts of all input routes.
uint32_t stack
Definition RawData.h:1
A helper class to iteratate over all parts of all input routes.
The input API of the Data Processing Layer This class holds the inputs which are valid for processing...
const_iterator begin() const
decltype(auto) get(R binding, int part=0) const
const GLfloat * m
Definition glcorearb.h:4066
GLint GLsizei count
Definition glcorearb.h:399
GLuint GLuint end
Definition glcorearb.h:469
const GLdouble * v
Definition glcorearb.h:832
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLenum GLsizei GLsizei GLint * values
Definition glcorearb.h:1576
GLboolean * data
Definition glcorearb.h:298
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
GLint ref
Definition glcorearb.h:291
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
constexpr o2::header::SerializationMethod gSerializationMethodNone
Definition DataHeader.h:327
Defining DataPointCompositeObject explicitly as copiable.
std::vector< InputRoute > schema
std::vector< std::string > CheckType
std::vector< std::unique_ptr< std::vector< char > > > MessageSet
DataSet(std::vector< InputRoute > &&s, Messages &&m, CheckType &&v, ServiceRegistryRef registry)
std::vector< TaggedSet > Messages
std::pair< o2::header::DataOrigin, MessageSet > TaggedSet
the main header struct
Definition DataHeader.h:618
SerializationMethod payloadSerializationMethod
Definition DataHeader.h:651
DataDescription dataDescription
Definition DataHeader.h:636
SubSpecificationType subSpecification
Definition DataHeader.h:656
a move-only header stack with serialized headers This is the flat buffer where all the headers in a m...
Definition Stack.h:36
DataSet createData()