Project
Loading...
Searching...
No Matches
test_DPLRawParser.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
12#include <catch_amalgamated.hpp>
14#include "RawPageTestData.h"
16#include "Framework/WorkflowSpec.h" // o2::framework::select
17#include "Headers/DataHeader.h"
18#include <vector>
19#include <memory>
20#include <iostream>
21
22using namespace o2::framework;
24auto const PAGESIZE = test::PAGESIZE;
26
28{
29 std::vector<InputSpec> inputspecs = {
30 InputSpec{"tpc0", "TPC", "RAWDATA", 0, Lifetime::Timeframe},
31 InputSpec{"its1", "ITS", "RAWDATA", 0, Lifetime::Timeframe},
32 InputSpec{"its1", "ITS", "RAWDATA", 1, Lifetime::Timeframe}};
33
34 // we create message for the 3 input routes, the messages have different page size
35 // and the second messages has 3 parts, each with the same page size
36 // the test value is written as payload after the RDH and all values are cached for
37 // later checking when parsing the data set
38 std::vector<DataHeader> dataheaders;
39 dataheaders.emplace_back("RAWDATA", "TPC", 0, 5 * PAGESIZE);
40 dataheaders.emplace_back("RAWDATA", "ITS", 0, 3 * PAGESIZE, 0, 3);
41 dataheaders.emplace_back("RAWDATA", "ITS", 1, 4 * PAGESIZE);
42
43 return test::createData(inputspecs, dataheaders);
44}
45
46TEST_CASE("test_DPLRawParser")
47{
48 auto dataset = createData();
49 InputRecord& inputs = dataset.record;
50 REQUIRE(dataset.messages.size() > 0);
51 REQUIRE(dataset.messages[0].at(0) != nullptr);
52 REQUIRE(inputs.size() > 0);
53 REQUIRE((*inputs.begin()).header == dataset.messages[0].at(0)->data());
54 DPLRawParser parser(inputs);
55 int count = 0;
56 o2::header::DataHeader const* last = nullptr;
57 for (auto it = parser.begin(), end = parser.end(); it != end; ++it, ++count) {
58 LOG(info) << "data " << count << " " << *((int*)it.data());
59 // now check the iterator API
60 // retrieving RDH
61 auto const* rdh = it.get_if<test::RAWDataHeader>();
62 // retrieving the raw pointer of the page
63 auto const* raw = it.raw();
64 // retrieving payload pointer of the page
65 auto const* payload = it.data();
66 // size of payload
67 size_t payloadSize = it.size();
68 // offset of payload in the raw page
69 size_t offset = it.offset();
70 REQUIRE(rdh != nullptr);
71 REQUIRE(offset == sizeof(test::RAWDataHeader));
72 REQUIRE(payload == raw + offset);
73 REQUIRE(*reinterpret_cast<int const*>(payload) == dataset.values[count]);
74 REQUIRE(payloadSize == PAGESIZE - sizeof(test::RAWDataHeader));
75 auto const* dh = it.o2DataHeader();
76 if (last != dh) {
77 // this is a special wrapper to print the RDU info and table header, this will
78 // be extended
80 last = dh;
81 }
82 INFO(it << " payload size " << it.size());
83 }
84
85 // test the parser with filter on data specs, this will filter out the first input
86 // route with 5 raw pages in the payload, so we start checking at count 5
87 DPLRawParser filteredparser(inputs, o2::framework::select("its:ITS/RAWDATA"));
88 count = 5;
89 for (auto it = filteredparser.begin(), end = filteredparser.end(); it != end; ++it, ++count) {
90 LOG(info) << "data " << count << " " << *((int*)it.data());
91 REQUIRE(*reinterpret_cast<int const*>(it.data()) == dataset.values[count]);
92 }
93
94 // test with filter not matching any input route
95 DPLRawParser nomatchingparser(inputs, o2::framework::select("nmatch:NO/MATCH"));
96 count = 0;
97 for (auto it = nomatchingparser.begin(), end = nomatchingparser.end(); it != end; ++it, ++count) {
98 LOG(info) << "data " << count << " " << *((int*)it.data());
99 }
100 REQUIRE(count == 0);
101}
A raw page parser for DPL input.
Raw page test data generator.
The parser handles transparently input in the format of raw pages.
const_iterator end() const
typename o2::framework::DPLRawParser< BOUNDS_CHECKS >::const_iterator::template Fmt< raw_parser::FormatSpec::Info > RDHInfo
const_iterator begin() const
The input API of the Data Processing Layer This class holds the inputs which are valid for processing...
const_iterator begin() const
GLint GLsizei count
Definition glcorearb.h:399
GLuint GLuint end
Definition glcorearb.h:469
GLintptr offset
Definition glcorearb.h:660
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
std::vector< InputSpec > select(char const *matcher="")
Simple helper struct to keep the InputRecord and ownership of messages together with some test data.
the main header struct
Definition DataHeader.h:618
DataSet createData()
auto const PAGESIZE
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"