Skip to content

Commit e2fc948

Browse files
committed
Remove references to boost::container::pmr
Use fair::mq::pmr instead, so that we can then easily migrate fair::mq to std::pmr while still having backward compatibility.
1 parent 2d6e21c commit e2fc948

File tree

8 files changed

+62
-50
lines changed

8 files changed

+62
-50
lines changed

DataFormats/Headers/include/Headers/Stack.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
#include "MemoryResources/MemoryResources.h"
1515
#include "Headers/DataHeader.h"
1616

17-
namespace o2
18-
{
19-
20-
namespace header
17+
namespace o2::header
2118
{
2219
//__________________________________________________________________________________________________
2320
/// @struct Stack
@@ -45,20 +42,20 @@ struct Stack {
4542
};
4643

4744
public:
48-
using allocator_type = boost::container::pmr::polymorphic_allocator<std::byte>;
45+
using allocator_type = fair::mq::pmr::polymorphic_allocator<std::byte>;
4946
using value_type = std::byte;
5047
using BufferType = std::unique_ptr<value_type[], freeobj>; //this gives us proper default move semantics for free
5148

5249
Stack() = default;
5350
Stack(Stack&&) = default;
5451
Stack(Stack&) = delete;
5552
Stack& operator=(Stack&) = delete;
56-
Stack& operator=(Stack&&) = default;
53+
Stack& operator=(Stack&&) = delete;
5754

58-
value_type* data() const { return buffer.get(); }
59-
size_t size() const { return bufferSize; }
55+
[[nodiscard]] value_type* data() const { return buffer.get(); }
56+
[[nodiscard]] size_t size() const { return bufferSize; }
6057
allocator_type get_allocator() const { return allocator; }
61-
const BaseHeader* first() const { return reinterpret_cast<const BaseHeader*>(this->data()); }
58+
[[nodiscard]] const BaseHeader* first() const { return reinterpret_cast<const BaseHeader*>(this->data()); }
6259
static const BaseHeader* firstHeader(std::byte const* buf) { return BaseHeader::get(buf); }
6360
static const BaseHeader* lastHeader(std::byte const* buf)
6461
{
@@ -90,9 +87,9 @@ struct Stack {
9087
/// all headers must derive from BaseHeader, in addition also other stacks can be passed to ctor.
9188
template <typename FirstArgType, typename... Headers,
9289
typename std::enable_if_t<
93-
!std::is_convertible<FirstArgType, boost::container::pmr::polymorphic_allocator<std::byte>>::value, int> = 0>
90+
!std::is_convertible<FirstArgType, fair::mq::pmr::polymorphic_allocator<std::byte>>::value, int> = 0>
9491
Stack(FirstArgType&& firstHeader, Headers&&... headers)
95-
: Stack(boost::container::pmr::new_delete_resource(), std::forward<FirstArgType>(firstHeader),
92+
: Stack(fair::mq::pmr::new_delete_resource(), std::forward<FirstArgType>(firstHeader),
9693
std::forward<Headers>(headers)...)
9794
{
9895
}
@@ -143,7 +140,7 @@ struct Stack {
143140
constexpr static size_t calculateSize() { return 0; }
144141

145142
private:
146-
allocator_type allocator{boost::container::pmr::new_delete_resource()};
143+
allocator_type allocator{fair::mq::pmr::new_delete_resource()};
147144
size_t bufferSize{0};
148145
BufferType buffer{nullptr, freeobj{allocator.resource()}};
149146

@@ -231,7 +228,7 @@ struct Stack {
231228
}
232229
};
233230

234-
} // namespace header
235-
} // namespace o2
231+
} // namespace o2::header
232+
236233

237234
#endif // HEADERS_STACK_H

DataFormats/Headers/test/testDataHeader.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ BOOST_AUTO_TEST_CASE(headerStack_test)
314314
BOOST_CHECK(h3->secret == 42);
315315

316316
//test constructing from a buffer and an additional header
317-
using namespace boost::container::pmr;
317+
using namespace fair::mq::pmr;
318318
Stack s5(new_delete_resource(), s1.data(), Stack{}, meta);
319319
BOOST_CHECK(s5.size() == s1.size() + sizeof(meta));
320320
// check if we can find the header even though there was an empty stack in the middle

DataFormats/MemoryResources/include/MemoryResources/MemoryResources.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class MessageResource : public FairMQMemoryResource
115115
// A spectator pmr memory resource which only watches the memory of the underlying buffer, does not
116116
// carry out real allocation. It owns the underlying buffer which is destroyed on deallocation.
117117
template <typename BufferType>
118-
class SpectatorMemoryResource : public boost::container::pmr::memory_resource
118+
class SpectatorMemoryResource : public fair::mq::pmr::memory_resource
119119
{
120120
public:
121121
using buffer_type = BufferType;
@@ -183,10 +183,10 @@ class SpectatorMemoryResource : public boost::container::pmr::memory_resource
183183
// This in general (as in STL) is a bad idea, but here it is safe to inherit from an allocator since we
184184
// have no additional data and only override some methods so we don't get into slicing and other problems.
185185
template <typename T>
186-
class SpectatorAllocator : public boost::container::pmr::polymorphic_allocator<T>
186+
class SpectatorAllocator : public fair::mq::pmr::polymorphic_allocator<T>
187187
{
188188
public:
189-
using boost::container::pmr::polymorphic_allocator<T>::polymorphic_allocator;
189+
using fair::mq::pmr::polymorphic_allocator<T>::polymorphic_allocator;
190190
using propagate_on_container_move_assignment = std::true_type;
191191

192192
// skip default construction of empty elements
@@ -243,7 +243,7 @@ class OwningMessageSpectatorAllocator
243243
return OwningMessageSpectatorAllocator();
244244
}
245245

246-
boost::container::pmr::memory_resource* resource() { return &mResource; }
246+
fair::mq::pmr::memory_resource* resource() { return &mResource; }
247247

248248
// skip default construction of empty elements
249249
// this is important for two reasons: one: it allows us to adopt an existing buffer (e.g. incoming message) and
@@ -269,14 +269,14 @@ class OwningMessageSpectatorAllocator
269269

270270
// The NoConstructAllocator behaves like the normal pmr vector but does not call constructors / destructors
271271
template <typename T>
272-
class NoConstructAllocator : public boost::container::pmr::polymorphic_allocator<T>
272+
class NoConstructAllocator : public fair::mq::pmr::polymorphic_allocator<T>
273273
{
274274
public:
275-
using boost::container::pmr::polymorphic_allocator<T>::polymorphic_allocator;
275+
using fair::mq::pmr::polymorphic_allocator<T>::polymorphic_allocator;
276276
using propagate_on_container_move_assignment = std::true_type;
277277

278278
template <typename... Args>
279-
NoConstructAllocator(Args&&... args) : boost::container::pmr::polymorphic_allocator<T>(std::forward<Args>(args)...)
279+
NoConstructAllocator(Args&&... args) : fair::mq::pmr::polymorphic_allocator<T>(std::forward<Args>(args)...)
280280
{
281281
}
282282

@@ -302,9 +302,9 @@ class NoConstructAllocator : public boost::container::pmr::polymorphic_allocator
302302
//__________________________________________________________________________________________________
303303

304304
using ByteSpectatorAllocator = SpectatorAllocator<std::byte>;
305-
using BytePmrAllocator = boost::container::pmr::polymorphic_allocator<std::byte>;
305+
using BytePmrAllocator = fair::mq::pmr::polymorphic_allocator<std::byte>;
306306
template <class T>
307-
using vector = std::vector<T, o2::pmr::polymorphic_allocator<T>>;
307+
using vector = std::vector<T, fair::mq::pmr::polymorphic_allocator<T>>;
308308

309309
//__________________________________________________________________________________________________
310310
/// Return a std::vector spanned over the contents of the message, takes ownership of the message

DataFormats/MemoryResources/test/testMemoryResources.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(transportallocatormap_test)
6060
BOOST_CHECK(_tmp == allocZMQ);
6161
}
6262

63-
using namespace boost::container::pmr;
63+
using namespace fair::mq::pmr;
6464

6565
BOOST_AUTO_TEST_CASE(allocator_test)
6666
{

Framework/Core/include/Framework/Output.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,7 @@ struct Output {
5959

6060
Output& operator=(const Output&) = delete;
6161

62-
Output& operator=(Output&& rhs)
63-
{
64-
origin = rhs.origin;
65-
description = rhs.description;
66-
subSpec = rhs.subSpec;
67-
metaHeader = std::move(rhs.metaHeader);
68-
return *this;
69-
}
62+
Output& operator=(Output&& rhs) = delete;
7063

7164
bool operator==(const Output& that) const
7265
{

Framework/Core/test/test_FairMQ.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ TEST_CASE("addDataBlockForEach_test")
174174
int i;
175175
int j;
176176
};
177-
using namespace boost::container::pmr;
177+
using namespace fair::mq::pmr;
178178
fair::mq::Parts message;
179179
std::vector<elem, polymorphic_allocator<elem>> vec(polymorphic_allocator<elem>{allocZMQ});
180180
vec.reserve(100);

Utilities/DataSampling/include/DataSampling/Dispatcher.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class Dispatcher : public framework::Task
6565

6666
private:
6767
DataSamplingHeader prepareDataSamplingHeader(const DataSamplingPolicy& policy, header::DataHeader const& original);
68-
header::Stack extractAdditionalHeaders(const char* inputHeaderStack) const;
6968
void reportStats(monitoring::Monitoring& monitoring) const;
7069
void send(framework::DataAllocator& dataAllocator, const framework::DataRef& inputData, const framework::Output& output) const;
7170

Utilities/DataSampling/src/Dispatcher.cxx

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <Configuration/ConfigurationInterface.h>
3131
#include <Configuration/ConfigurationFactory.h>
32+
#include <stdexcept>
3233

3334
using namespace o2::configuration;
3435
using namespace o2::monitoring;
@@ -77,6 +78,42 @@ void Dispatcher::init(InitContext& ctx)
7778
mDeviceID.runtimeInit(spec.id.substr(0, DataSamplingHeader::deviceIDTypeSize).c_str());
7879
}
7980

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+
80117
void Dispatcher::run(ProcessingContext& ctx)
81118
{
82119
// todo: consider matching (and deciding) in completion policy to save some time
@@ -106,7 +143,7 @@ void Dispatcher::run(ProcessingContext& ctx)
106143
// so that custom data-dependent headers are passed forward,
107144
// and we add a DataSamplingHeader.
108145
header::Stack headerStack{
109-
std::move(extractAdditionalHeaders(part.header)),
146+
extractAdditionalHeaders(part.header),
110147
dsheader};
111148
const auto* partInputHeader = DataRefUtils::getHeader<header::DataHeader*>(part);
112149

@@ -156,20 +193,6 @@ DataSamplingHeader Dispatcher::prepareDataSamplingHeader(const DataSamplingPolic
156193
original};
157194
}
158195

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-
}
173196

174197
void Dispatcher::send(DataAllocator& dataAllocator, const DataRef& inputData, const Output& output) const
175198
{

0 commit comments

Comments
 (0)