Project
Loading...
Searching...
No Matches
test_DPLRawPageSequencer.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
16
17#include <catch_amalgamated.hpp>
19#include "RawPageTestData.h"
21#include "Headers/DataHeader.h"
22#include <vector>
23#include <memory>
24#include <random>
25
26using namespace o2::framework;
28auto const PAGESIZE = test::PAGESIZE;
29
30#define CHECK_MESSAGE(cond, msg) \
31 do { \
32 INFO(msg); \
33 CHECK(cond); \
34 } while ((void)0, 0)
35#define REQUIRE_MESSAGE(cond, msg) \
36 do { \
37 INFO(msg); \
38 REQUIRE(cond); \
39 } while ((void)0, 0)
40
41TEST_CASE("test_DPLRawPageSequencer")
42{
43 const int nPages = 64;
44 const int nParts = 16;
45 std::vector<InputSpec> inputspecs = {
46 InputSpec{"tpc", "TPC", "RAWDATA", 0, Lifetime::Timeframe}};
47
48 std::vector<DataHeader> dataheaders;
49 dataheaders.emplace_back("RAWDATA", "TPC", 0, nPages * PAGESIZE, 0, nParts);
50
51 std::random_device rd;
52 std::uniform_int_distribution<> lengthDist(1, nPages);
53 auto randlength = [&rd, &lengthDist]() {
54 return lengthDist(rd);
55 };
56
57 int rdhCount = 0;
58 // whenever a new id is created, it is done from the current counter
59 // position, so we also have the possibility to calculate the length
60 std::vector<uint16_t> feeids;
61 auto nextlength = randlength();
62 auto createFEEID = [&rdhCount, &feeids, &nPages, &randlength, &nextlength]() {
63 if (rdhCount % nPages == 0 || rdhCount - feeids.back() > nextlength) {
64 feeids.emplace_back(rdhCount);
65 nextlength = randlength();
66 }
67 return feeids.back();
68 };
69 auto amendRdh = [&rdhCount, createFEEID](test::RAWDataHeader& rdh) {
70 rdh.feeId = createFEEID();
71 rdhCount++;
72 };
73
74 auto dataset = test::createData(inputspecs, dataheaders, amendRdh);
75 InputRecord& inputs = dataset.record;
76 REQUIRE(dataset.messages.size() > 0);
77 REQUIRE(dataset.messages[0].at(0) != nullptr);
78 REQUIRE(inputs.size() > 0);
79 CHECK((*inputs.begin()).header == dataset.messages[0].at(0)->data());
80 REQUIRE(rdhCount == nPages * nParts);
81 DPLRawPageSequencer parser(inputs);
82
83 auto isSameRdh = [](const char* left, const char* right) -> bool {
84 if (left == right) {
85 return true;
86 }
87 if (left == nullptr || right == nullptr) {
88 return true;
89 }
90
91 return reinterpret_cast<test::RAWDataHeader const*>(left)->feeId == reinterpret_cast<test::RAWDataHeader const*>(right)->feeId;
92 };
93 std::vector<std::pair<const char*, size_t>> pages;
94 auto insertPages = [&pages](const char* ptr, size_t n, uint32_t subSpec) -> void {
95 pages.emplace_back(ptr, n);
96 };
97 int retVal = parser(isSameRdh, insertPages);
98 REQUIRE(retVal == 0);
99
100 // a second parsing step based on forward search
101 std::vector<std::pair<const char*, size_t>> pagesByForwardSearch;
102 auto insertForwardPages = [&pagesByForwardSearch](const char* ptr, size_t n, uint32_t subSpec) -> void {
103 pagesByForwardSearch.emplace_back(ptr, n);
104 };
105 DPLRawPageSequencer(inputs).forward(isSameRdh, insertForwardPages);
106
107 LOG(info) << "called RDH amend: " << rdhCount;
108 LOG(info) << "created " << feeids.size() << " id(s), got " << pages.size() << " page(s)";
109 REQUIRE(pages.size() == feeids.size());
110 REQUIRE(pages.size() == pagesByForwardSearch.size());
111
112 feeids.emplace_back(rdhCount);
113 for (auto i = 0; i < pages.size(); i++) {
114 auto length = feeids[i + 1] - feeids[i];
115 CHECK_MESSAGE(pages[i].second == length, fmt::format("sequence {} at {} length {}: got {}", i, feeids[i], length, pages[i].second));
116 REQUIRE_MESSAGE(((pages[i].first == pagesByForwardSearch[i].first) && (pages[i].second == pagesByForwardSearch[i].second)),
117 fmt::format("{} [{},{}][{},{}]", i, ((void*)pages[i].first), (void*)pagesByForwardSearch[i].first, pages[i].second, pagesByForwardSearch[i].second));
118 }
119}
A parser and sequencer utility for raw pages within DPL input.
int32_t i
int32_t retVal
Raw page test data generator.
TBranch * ptr
This utility handles transparently the DPL inputs and triggers a customizable action on sequences of ...
int forward(Predicate pred, Inserter inserter)
The input API of the Data Processing Layer This class holds the inputs which are valid for processing...
const_iterator begin() const
#define CHECK
GLdouble n
Definition glcorearb.h:1982
GLdouble GLdouble right
Definition glcorearb.h:4077
GLint left
Definition glcorearb.h:1979
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
the main header struct
Definition DataHeader.h:618
uint64_t feeId
bit 8 to 15: header size
auto const PAGESIZE
#define CHECK_MESSAGE(cond, msg)
#define REQUIRE_MESSAGE(cond, msg)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::random_device rd