Skip to content

Commit d354bfc

Browse files
committed
StoreChunk completely moved over to new syntax
1 parent 3f3cd80 commit d354bfc

6 files changed

Lines changed: 60 additions & 60 deletions

File tree

include/openPMD/LoadStoreChunk.hpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ class ConfigureStoreChunk : protected internal::ConfigureStoreChunkData
6868
/*then*/ ConfigureStoreChunk<void>,
6969
/*else*/ ChildClass>;
7070
template <typename T>
71-
using normalize_dataset_type =
72-
std::remove_cv_t<std::remove_extent_t<T>> const;
71+
using normalize_dataset_type = std::remove_cv_t<std::remove_extent_t<T>>;
7372

7473
auto offset(Offset) -> return_type &;
7574
auto extent(Extent) -> return_type &;
7675

7776
// @todo rvalue references..?
7877
template <typename T>
7978
auto fromSharedPtr(std::shared_ptr<T>)
80-
-> TypedConfigureStoreChunk<std::shared_ptr<normalize_dataset_type<T>>>;
79+
-> TypedConfigureStoreChunk<
80+
std::shared_ptr<normalize_dataset_type<T> const>>;
8181
template <typename T>
8282
auto fromUniquePtr(UniquePtrWithLambda<T>)
8383
-> TypedConfigureStoreChunk<
@@ -87,13 +87,15 @@ class ConfigureStoreChunk : protected internal::ConfigureStoreChunkData
8787
-> TypedConfigureStoreChunk<
8888
UniquePtrWithLambda<normalize_dataset_type<T>>>;
8989
template <typename T>
90-
auto fromRawPtr(T *data) -> TypedConfigureStoreChunk<std::shared_ptr<T>>;
90+
auto
91+
fromRawPtr(T *data) -> TypedConfigureStoreChunk<
92+
std::shared_ptr<normalize_dataset_type<T> const>>;
9193
template <typename T_ContiguousContainer>
9294
auto fromContiguousContainer(T_ContiguousContainer &data) ->
9395
typename std::enable_if_t<
9496
auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
95-
TypedConfigureStoreChunk<
96-
std::shared_ptr<typename T_ContiguousContainer::value_type>>>;
97+
TypedConfigureStoreChunk<std::shared_ptr<normalize_dataset_type<
98+
typename T_ContiguousContainer::value_type> const>>>;
9799

98100
template <typename T>
99101
auto enqueue() -> DynamicMemoryView<T>;
@@ -135,15 +137,18 @@ class TypedConfigureStoreChunk
135137
template <typename ChildClass>
136138
template <typename T>
137139
auto ConfigureStoreChunk<ChildClass>::fromSharedPtr(std::shared_ptr<T> data)
138-
-> TypedConfigureStoreChunk<std::shared_ptr<normalize_dataset_type<T>>>
140+
-> TypedConfigureStoreChunk<
141+
std::shared_ptr<normalize_dataset_type<T> const>>
139142
{
140143
if (!data)
141144
{
142145
throw std::runtime_error(
143146
"Unallocated pointer passed during chunk store.");
144147
}
145-
return TypedConfigureStoreChunk<std::shared_ptr<normalize_dataset_type<T>>>(
146-
std::static_pointer_cast<normalize_dataset_type<T>>(std::move(data)),
148+
return TypedConfigureStoreChunk<
149+
std::shared_ptr<normalize_dataset_type<T> const>>(
150+
std::static_pointer_cast<normalize_dataset_type<T> const>(
151+
std::move(data)),
147152
{std::move(*this)});
148153
}
149154
template <typename ChildClass>
@@ -164,14 +169,16 @@ auto ConfigureStoreChunk<ChildClass>::fromUniquePtr(UniquePtrWithLambda<T> data)
164169
template <typename ChildClass>
165170
template <typename T>
166171
auto ConfigureStoreChunk<ChildClass>::fromRawPtr(T *data)
167-
-> TypedConfigureStoreChunk<std::shared_ptr<T>>
172+
-> TypedConfigureStoreChunk<
173+
std::shared_ptr<normalize_dataset_type<T> const>>
168174
{
169175
if (!data)
170176
{
171177
throw std::runtime_error(
172178
"Unallocated pointer passed during chunk store.");
173179
}
174-
return TypedConfigureStoreChunk<std::shared_ptr<T>>(
180+
return TypedConfigureStoreChunk<
181+
std::shared_ptr<normalize_dataset_type<T> const>>(
175182
auxiliary::shareRaw(data), {std::move(*this)});
176183
}
177184

@@ -189,8 +196,8 @@ auto ConfigureStoreChunk<ChildClass>::fromContiguousContainer(
189196
T_ContiguousContainer &data) ->
190197
typename std::enable_if_t<
191198
auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
192-
TypedConfigureStoreChunk<
193-
std::shared_ptr<typename T_ContiguousContainer::value_type>>>
199+
TypedConfigureStoreChunk<std::shared_ptr<normalize_dataset_type<
200+
typename T_ContiguousContainer::value_type> const>>>
194201
{
195202
if (!m_extent.has_value() && dim() == 1)
196203
{

include/openPMD/RecordComponent.tpp

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -199,63 +199,52 @@ template <typename T>
199199
inline void
200200
RecordComponent::storeChunk(UniquePtrWithLambda<T> data, Offset o, Extent e)
201201
{
202-
if (!data)
203-
throw std::runtime_error(
204-
"Unallocated pointer passed during chunk store.");
205-
Datatype dtype = determineDatatype<>(data);
206-
207-
storeChunk_impl(
208-
auxiliary::WriteBuffer{std::move(data).template static_cast_<void>()},
209-
dtype,
210-
{std::move(o), std::move(e), std::nullopt});
202+
prepareStoreChunk()
203+
.offset(std::move(o))
204+
.extent(std::move(e))
205+
.fromUniquePtr(std::move(data))
206+
.enqueue();
211207
}
212208

213209
template <typename T, typename Del>
214210
inline void
215211
RecordComponent::storeChunk(std::unique_ptr<T, Del> data, Offset o, Extent e)
216212
{
217-
storeChunk(
218-
UniquePtrWithLambda<T>(std::move(data)), std::move(o), std::move(e));
213+
prepareStoreChunk()
214+
.offset(std::move(o))
215+
.extent(std::move(e))
216+
.fromUniquePtr(std::move(data))
217+
.enqueue();
219218
}
220219

221220
template <typename T>
222221
void RecordComponent::storeChunkRaw(T *ptr, Offset offset, Extent extent)
223222
{
224-
storeChunk(auxiliary::shareRaw(ptr), std::move(offset), std::move(extent));
223+
prepareStoreChunk()
224+
.offset(std::move(offset))
225+
.extent(std::move(extent))
226+
.fromRawPtr(ptr)
227+
.enqueue();
225228
}
226229

227230
template <typename T_ContiguousContainer>
228231
inline typename std::enable_if_t<
229232
auxiliary::IsContiguousContainer_v<T_ContiguousContainer>>
230233
RecordComponent::storeChunk(T_ContiguousContainer &data, Offset o, Extent e)
231234
{
232-
uint8_t dim = getDimensionality();
235+
auto storeChunkConfig = prepareStoreChunk();
233236

234-
// default arguments
235-
// offset = {0u}: expand to right dim {0u, 0u, ...}
236-
Offset offset = o;
237-
if (o.size() == 1u && o.at(0) == 0u)
237+
auto joined_dim = joinedDimension();
238+
if (!joined_dim.has_value() && (o.size() != 1 || o.at(0) != 0u))
238239
{
239-
if (joinedDimension().has_value())
240-
{
241-
offset.clear();
242-
}
243-
else if (dim > 1u)
244-
{
245-
offset = Offset(dim, 0u);
246-
}
240+
storeChunkConfig.offset(std::move(o));
241+
}
242+
if (e.size() != 1 || e.at(0) != -1u)
243+
{
244+
storeChunkConfig.extent(std::move(e));
247245
}
248246

249-
// extent = {-1u}: take full size
250-
Extent extent(dim, 1u);
251-
// avoid outsmarting the user:
252-
// - stdlib data container implement 1D -> 1D chunk to write
253-
if (e.size() == 1u && e.at(0) == -1u && dim == 1u)
254-
extent.at(0) = data.size();
255-
else
256-
extent = e;
257-
258-
storeChunk(auxiliary::shareRaw(data.data()), offset, extent);
247+
std::move(storeChunkConfig).fromContiguousContainer(data).enqueue();
259248
}
260249

261250
template <typename T, typename F>

include/openPMD/auxiliary/Memory.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ namespace auxiliary
180180
WriteBuffer() : m_buffer(UniquePtrWithLambda<void>())
181181
{}
182182

183-
template <typename... Args>
184-
explicit WriteBuffer(Args &&...args)
185-
: m_buffer(std::forward<Args>(args)...)
183+
WriteBuffer(std::shared_ptr<void const> ptr) : m_buffer(std::move(ptr))
184+
{}
185+
186+
WriteBuffer(UniquePtrWithLambda<void> ptr) : m_buffer(std::move(ptr))
186187
{}
187188

188189
WriteBuffer(WriteBuffer &&) = default;
@@ -196,7 +197,7 @@ namespace auxiliary
196197
return *this;
197198
}
198199

199-
WriteBuffer const &operator=(UniquePtrWithLambda<void const> ptr)
200+
WriteBuffer const &operator=(UniquePtrWithLambda<void> ptr)
200201
{
201202
m_buffer = std::move(ptr);
202203
return *this;

include/openPMD/auxiliary/UniquePtr.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@ template <typename U>
170170
UniquePtrWithLambda<U> UniquePtrWithLambda<T>::static_cast_() &&
171171
{
172172
using other_type = std::remove_extent_t<U>;
173+
auto original_ptr = this->release();
173174
return UniquePtrWithLambda<U>{
174-
static_cast<other_type *>(this->release()),
175-
[deleter = std::move(this->get_deleter())](other_type *ptr) {
176-
deleter(static_cast<T_decayed *>(ptr));
175+
static_cast<other_type *>(original_ptr),
176+
[deleter = std::move(this->get_deleter()), original_ptr](other_type *) {
177+
deleter(original_ptr);
177178
}};
178179
}
179180
} // namespace openPMD

src/LoadStoreChunk.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace
3737
template <typename T>
3838
auto asWriteBuffer(UniquePtrWithLambda<T> &&ptr) -> auxiliary::WriteBuffer
3939
{
40-
return auxiliary::WriteBuffer{
41-
std::move(ptr).template static_cast_<void const>()};
40+
return auxiliary::WriteBuffer(
41+
std::move(ptr).template static_cast_<void>());
4242
}
4343
} // namespace
4444

@@ -178,12 +178,12 @@ OPENPMD_FOREACH_DATASET_DATATYPE(INSTANTIATE_METHOD_TEMPLATES_FOR_BASE)
178178
ConfigureStoreChunk< \
179179
TypedConfigureStoreChunk<std::shared_ptr<dtype const>>>, \
180180
dtype) \
181-
template class TypedConfigureStoreChunk<UniquePtrWithLambda<dtype const>>; \
181+
template class TypedConfigureStoreChunk<UniquePtrWithLambda<dtype>>; \
182182
template class ConfigureStoreChunk< \
183-
TypedConfigureStoreChunk<UniquePtrWithLambda<dtype const>>>; \
183+
TypedConfigureStoreChunk<UniquePtrWithLambda<dtype>>>; \
184184
INSTANTIATE_METHOD_TEMPLATES( \
185185
ConfigureStoreChunk< \
186-
TypedConfigureStoreChunk<UniquePtrWithLambda<dtype const>>>, \
186+
TypedConfigureStoreChunk<UniquePtrWithLambda<dtype>>>, \
187187
dtype)
188188

189189
OPENPMD_FOREACH_DATASET_DATATYPE(INSTANTIATE_TYPED_STORE_CHUNK)

test/SerialIOTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include <unistd.h>
4141
#endif
4242

43+
#include <execinfo.h>
44+
4345
using namespace openPMD;
4446

4547
struct BackendSelection

0 commit comments

Comments
 (0)