Project
Loading...
Searching...
No Matches
RawPageTestData.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 "RawPageTestData.h"
18#include "Headers/Stack.h"
19#include <random>
20
22{
23
24DataSet createData(std::vector<InputSpec> const& inputspecs, std::vector<DataHeader> const& dataheaders, AmendRawDataHeader amendRdh)
25{
26 // Create the routes we want for the InputRecord
27 size_t i = 0;
28 auto createRoute = [&i](std::string const& source, InputSpec const& spec) {
29 return InputRoute{
30 spec,
31 i++,
32 source};
33 };
34
35 std::vector<InputRoute> schema;
36 for (auto const& spec : inputspecs) {
37 auto routename = spec.binding + "_source";
38 schema.emplace_back(createRoute(routename, spec));
39 }
40
41 std::random_device rd;
42 std::uniform_int_distribution<> testvals(0, 42);
43 auto randval = [&rd, &testvals]() {
44 return testvals(rd);
45 };
46 std::vector<int> checkValues;
47 DataSet::Messages messages;
48 unsigned char packetCounter = 0;
49
50 auto initRawPage = [&checkValues, &amendRdh, &packetCounter](char* buffer, size_t size, auto value) {
51 int pageCounter = 0;
52 unsigned int lastFEEID = 0;
53 unsigned int lastOrbit = 0;
54 char* wrtptr = buffer;
55 while (wrtptr < buffer + size) {
56 auto* header = reinterpret_cast<RAWDataHeader*>(wrtptr);
57 *header = RAWDataHeader();
58 if (amendRdh) {
59 amendRdh(*header);
60 }
61 if (wrtptr == buffer || header->feeId != lastFEEID || header->orbit != lastOrbit) {
62 pageCounter = 0;
63 }
64 lastFEEID = header->feeId;
65 lastOrbit = header->orbit;
66 header->memorySize = PAGESIZE;
67 header->offsetToNext = PAGESIZE;
68 header->pageCnt = pageCounter++;
69 header->packetCounter = packetCounter++;
70 *reinterpret_cast<decltype(value)*>(wrtptr + header->headerSize) = value;
71 wrtptr += PAGESIZE;
72 checkValues.emplace_back(value);
73 ++value;
74 }
75 };
76
77 auto createMessage = [&messages, &initRawPage, &randval](DataHeader dh) {
78 DataProcessingHeader dph{0, 1};
79 Stack stack{dh, dph};
80 if (dh.splitPayloadParts == 0 || dh.splitPayloadIndex == 0) {
81 // add new message collection
82 messages.emplace_back();
83 }
84 messages.back().emplace_back(std::make_unique<std::vector<char>>(stack.size()));
85 memcpy(messages.back().back()->data(), stack.data(), messages.back().back()->size());
86 messages.back().emplace_back(std::make_unique<std::vector<char>>(dh.payloadSize));
87 int value = randval();
88 initRawPage(messages.back().back()->data(), messages.back().back()->size(), value);
89 };
90
91 // create messages for the provided dataheaders
92 for (auto header : dataheaders) {
93 for (DataHeader::SplitPayloadIndexType index = 0; index == 0 || index < header.splitPayloadParts; index++) {
94 header.splitPayloadIndex = index;
95 createMessage(header);
96 }
97 }
98
99 static ServiceRegistry registry;
100 return {std::move(schema), std::move(messages), std::move(checkValues), {registry}};
101}
102
103} // namespace o2::framework
int32_t i
uint32_t stack
Definition RawData.h:1
Raw page test data generator.
auto const PAGESIZE
GLuint buffer
Definition glcorearb.h:655
GLsizeiptr size
Definition glcorearb.h:659
GLuint index
Definition glcorearb.h:781
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLsizei const GLfloat * value
Definition glcorearb.h:819
RAWDataHeaderV6 RAWDataHeader
std::function< void(RAWDataHeader &)> AmendRawDataHeader
Simple helper struct to keep the InputRecord and ownership of messages together with some test data.
the main header struct
Definition DataHeader.h:618
uint32_t SplitPayloadIndexType
Definition DataHeader.h:621
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()
std::random_device rd