|
29 | 29 |
|
30 | 30 | #include <Configuration/ConfigurationInterface.h> |
31 | 31 | #include <Configuration/ConfigurationFactory.h> |
| 32 | +#include <stdexcept> |
32 | 33 |
|
33 | 34 | using namespace o2::configuration; |
34 | 35 | using namespace o2::monitoring; |
@@ -77,6 +78,42 @@ void Dispatcher::init(InitContext& ctx) |
77 | 78 | mDeviceID.runtimeInit(spec.id.substr(0, DataSamplingHeader::deviceIDTypeSize).c_str()); |
78 | 79 | } |
79 | 80 |
|
| 81 | +header::Stack extractAdditionalHeaders(const char* inputHeaderStack) |
| 82 | +{ |
| 83 | + std::array<header::BaseHeader const*, 5> headers; |
| 84 | + int count = 0; |
| 85 | + const auto* first = header::BaseHeader::get(reinterpret_cast<const std::byte*>(inputHeaderStack)); |
| 86 | + for (const auto* current = first; current != nullptr; current = current->next()) { |
| 87 | + if (current->description != header::DataHeader::sHeaderType && current->description != DataProcessingHeader::sHeaderType) { |
| 88 | + headers[count++] = current; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + // Poor man runtime pack expansion. |
| 93 | + switch (count) { |
| 94 | + case 0: |
| 95 | + return header::Stack{}; |
| 96 | + case 1: |
| 97 | + return header::Stack{*headers[0]}; |
| 98 | + case 2: |
| 99 | + return header::Stack{*headers[0], *headers[1]}; |
| 100 | + case 3: |
| 101 | + return header::Stack{*headers[0], *headers[1], *headers[2]}; |
| 102 | + case 4: |
| 103 | + return header::Stack{*headers[0], *headers[1], *headers[2], *headers[3]}; |
| 104 | + case 5: |
| 105 | + return header::Stack{*headers[0], *headers[1], *headers[2], *headers[3], *headers[4]}; |
| 106 | + case 6: |
| 107 | + return header::Stack{*headers[0], *headers[1], *headers[2], *headers[3], *headers[4], *headers[5]}; |
| 108 | + case 7: |
| 109 | + return header::Stack{*headers[0], *headers[1], *headers[2], *headers[3], *headers[4], *headers[5], *headers[6]}; |
| 110 | + case 8: |
| 111 | + return header::Stack{*headers[0], *headers[1], *headers[2], *headers[3], *headers[4], *headers[5], *headers[6], *headers[7]}; |
| 112 | + default: |
| 113 | + throw std::runtime_error(fmt::format("Too many headers to copy {}", count)); |
| 114 | + } |
| 115 | +} |
| 116 | + |
80 | 117 | void Dispatcher::run(ProcessingContext& ctx) |
81 | 118 | { |
82 | 119 | // todo: consider matching (and deciding) in completion policy to save some time |
@@ -106,7 +143,7 @@ void Dispatcher::run(ProcessingContext& ctx) |
106 | 143 | // so that custom data-dependent headers are passed forward, |
107 | 144 | // and we add a DataSamplingHeader. |
108 | 145 | header::Stack headerStack{ |
109 | | - std::move(extractAdditionalHeaders(part.header)), |
| 146 | + extractAdditionalHeaders(part.header), |
110 | 147 | dsheader}; |
111 | 148 | const auto* partInputHeader = DataRefUtils::getHeader<header::DataHeader*>(part); |
112 | 149 |
|
@@ -156,21 +193,6 @@ DataSamplingHeader Dispatcher::prepareDataSamplingHeader(const DataSamplingPolic |
156 | 193 | original}; |
157 | 194 | } |
158 | 195 |
|
159 | | -header::Stack Dispatcher::extractAdditionalHeaders(const char* inputHeaderStack) const |
160 | | -{ |
161 | | - header::Stack headerStack; |
162 | | - |
163 | | - const auto* first = header::BaseHeader::get(reinterpret_cast<const std::byte*>(inputHeaderStack)); |
164 | | - for (const auto* current = first; current != nullptr; current = current->next()) { |
165 | | - if (current->description != header::DataHeader::sHeaderType && |
166 | | - current->description != DataProcessingHeader::sHeaderType) { |
167 | | - headerStack = std::move(header::Stack{std::move(headerStack), *current}); |
168 | | - } |
169 | | - } |
170 | | - |
171 | | - return headerStack; |
172 | | -} |
173 | | - |
174 | 196 | void Dispatcher::send(DataAllocator& dataAllocator, const DataRef& inputData, const Output& output) const |
175 | 197 | { |
176 | 198 | const auto* inputHeader = DataRefUtils::getHeader<header::DataHeader*>(inputData); |
|
0 commit comments