55 virtual std::string
name()
const = 0;
60 template <
typename T,
typename I>
65 const std::function<T(
I)>&,
66 const T default_value = T(),
70 H5::DataType
getType()
const override;
72 std::string
name()
const override;
79 template <
typename T,
typename I>
81 const std::function<T(
I)>& func,
82 const T default_value,
90 template <
typename T,
typename I>
96 template <
typename T,
typename I>
100 return default_value;
102 template <
typename T,
typename I>
106 template <
typename T,
typename I>
110 template <
typename T,
typename I>
126 template <
typename I>
128 template <
typename I>
134 template <
typename T>
135 void add(
const std::string& name,
const std::function<T(
I)>&,
136 const T& default_value = T(),
142 typename R=
decltype(std::declval<F>()(std::declval<I>())),
145 void add(
const std::string& name,
const F func,
const T& def = T(),
147 add<R>(name, std::function<R(
I)>(std::move(func)), R(def), comp);
154 template <
typename T>
163 template <
typename I>
164 template <
typename T>
166 const std::function<T(
I)>& fun,
171 throw std::logic_error(
"tried to insert '" + name +
"' twice");
178 template <
typename I>
195 template <
size_t N,
typename T,
typename I,
typename =
void>
197 static const bool ok_type = std::is_convertible<T,I>::value;
201 template <
size_t N,
typename T,
typename I>
202 struct CheckType <N,T,
I,decltype(*begin(std::declval<T&>()), void())> {
209 template <
typename T,
typename I>
210 struct CheckType <0,T,
I,decltype(*begin(std::declval<T&>()), void())> {
212 static const bool ok_type = std::is_convertible<T,I>::value;
224 template <
size_t N,
typename F,
typename T,
size_t M = N>
230 const std::array<hsize_t,M>& extent):
233 for (
const auto& arg: args) {
234 const size_t this_dim_max = extent.at(extent.size() - N);
235 if (offset >= this_dim_max)
return;
237 buffer.insert(
buffer.end(), in.buffer.begin(), in.buffer.end());
238 for (
const auto& in_ele: in.element_offsets){
239 std::array<hsize_t, N> element_pos;
240 element_pos.at(0) = offset;
241 std::copy(in_ele.begin(), in_ele.end(), element_pos.begin() + 1);
248 template <
typename F,
typename T,
size_t M>
253 const std::array<hsize_t,M>& ):
256 for (
const auto& filler: f) {
257 buffer.push_back(filler->getBuffer(args));
266 if (consumers.size() < 1) {
267 throw std::logic_error(
268 "you must specify at least one consumer when initializing the HDF5"
273 size_t dt_offset = 0;
275 type.insertMember(filler->name(), dt_offset, filler->getType());
283 size_t dt_offset = 0;
285 type.insertMember(filler->name(), dt_offset, filler->getWriteType());
293 template <
typename I,
size_t N>
296 const std::array<hsize_t,N>&
extent,
304 template <
typename I,
size_t N>
306 const std::array<hsize_t,N>& extent_,
307 hsize_t batch_size_):
317 std::vector<data_buffer_t> def;
319 def.push_back(filler->getDefault());
326 std::vector<hsize_t>
vec(std::array<hsize_t,N>
a) {
327 return std::vector<hsize_t>(
a.begin(),
a.end());
333 std::array<hsize_t, N> ar;
350 template <
size_t N,
typename I>
353 Writer(H5::Group& group,
const std::string& name,
364 template <
typename T>
370 template <
typename T>
384 template <
size_t N,
typename I>
387 const std::array<hsize_t,N>& extent,
393 .batch_size = batch_size,
396 .plist_callbacks = {}
400 template <
size_t N,
typename I>
405 cfg.batch_size ? *cfg.batch_size :
defaults::batch_size),
412 if (
m_par.batch_size < 1) {
413 throw std::logic_error(
"batch size must be > 0");
423 params.setFillValue(
m_par.type, default_value.data());
427 H5::CompType packed_type = buildWriteType(consumers.
getConsumers());
428 m_ds = group.createDataSet(cfg.name, packed_type, space, params);
433 template <
size_t N,
typename I>
438 }
catch (H5::Exception& err) {
440 }
catch (std::exception& err) {
445 template <
size_t N,
typename I>
446 template <
typename T>
462 checkType::depth >= N,
464 " ** H5 Writer rank is greater than the depth of fill(...) input! **"
475 !(checkType::any_type && !checkType::ok_type),
477 " ** H5 Writer input type matches fill(...), but rank is incorrect! **"
482 " ** H5 Writer input type doesn't match input for fill(...)! **"
487 hsize_t n_el = buf.element_offsets.size();
488 std::vector<hsize_t> elements;
494 for (
const auto& el_local: buf.element_offsets) {
495 std::array<hsize_t, N+1> el_global;
497 std::copy(el_local.begin(), el_local.end(), el_global.begin() + 1);
498 elements.insert(elements.end(), el_global.begin(), el_global.end());
501 m_file_space.selectElements(H5S_SELECT_APPEND, n_el, elements.data());
507 template <
size_t N,
typename I>
511 if (buffer_size == 0)
return;
514 std::vector<hsize_t> total_dims{buffer_size +
m_offset};
515 total_dims.insert(total_dims.end(),
516 m_par.extent.begin(),
518 m_ds.extend(total_dims.data());
519 m_file_space.setExtentSimple(total_dims.size(), total_dims.data());
524 assert(
static_cast<hsize_t
>(
m_file_space.getSelectNpoints())
526 H5::DataSpace mem_space(1, &n_buffer_pts);
534 template <
size_t N,
typename I>
549 template <
size_t N,
class I>
551 H5::Group& group,
const std::string& name,
558 config.batch_size = batch_size;
561 template <
size_t N,
class I>
575 template <
typename T>
585 template <
size_t N,
typename T>
595 template <
typename T>
std::vector< size_t > vec
const std::vector< SharedConsumer< I > > & getConsumers() const
std::function< T(I)> function_type
void add(const std::string &name, const std::function< T(I)> &, const T &default_value=T(), Compression=Compression::STANDARD)
This should be the only method you need in this class.
std::vector< SharedConsumer< const T & > > m_consumers
std::set< std::string > m_used
void add(const std::string &name, const F func, const T &def=T(), Compression comp=Compression::STANDARD)
overload to cast lambdas into functions
Writer(const Writer &)=delete
Writer(Writer &&)=default
Writer & operator=(Writer &)=delete
H5::DataSpace m_file_space
std::vector< internal::data_buffer_t > m_buffer
std::vector< SharedConsumer< const T & > > m_consumers
Writer(H5::Group &group, const Consumers< I > &consumers, const WriterConfiguration< N > &=WriterConfiguration< N >())
const internal::DSParameters< const T &, N > m_par
Writer(H5::Group &group, const std::string &name, const Consumers< I > &consumers, const std::array< hsize_t, N > &extent=internal::uniform< N >(5), hsize_t batch_size=defaults::batch_size)
std::recursive_mutex m_mutex
Consumers< I > consumer_type
WriterConfiguration< N > configuration_type
typename consumer_type::template function_type< T > function_type
implementation for variable filler
data_buffer_t getDefault() const override
DataConsumer(const std::string &, const std::function< T(I)> &, const T default_value=T(), Compression=Compression::STANDARD)
H5::DataType getWriteType() const override
H5::DataType getType() const override
std::string name() const override
data_buffer_t getBuffer(I) const override
H5::DataType m_write_type
std::function< T(I)> m_getter
virtual std::string name() const =0
virtual data_buffer_t getDefault() const =0
virtual H5::DataType getWriteType() const =0
virtual data_buffer_t getBuffer(I) const =0
virtual H5::DataType getType() const =0
clssses to add type traits for H5
H5::DSetCreatPropList getChunckedDatasetParams(const WriterConfiguration< N > &)
H5::CompType buildWriteType(const std::vector< SharedConsumer< I > > &con)
std::vector< hsize_t > vec(std::array< hsize_t, N > a)
H5::DataType getCompressedType(Compression comp)
H5::DataSpace getUnlimitedSpace(const std::vector< hsize_t > &max_length)
std::array< hsize_t, N > uniform(size_t val)
void printDestructorError(const std::string &msg)
const H5::DataType H5Traits< int >::type
void throwIfExists(const std::string &name, const H5::Group &in_group)
std::vector< data_buffer_t > buildDefault(const std::vector< SharedConsumer< I > > &f)
H5::CompType buildType(const std::vector< SharedConsumer< I > > &consumers)
Adapter to translate configuration info into the objects needed by the writer.
std::shared_ptr< internal::IDataConsumer< I > > SharedConsumer
Consumer Class.
Writer< N, const T & > CRefWriter
CRefWriter.
Writer< N, I > makeWriter(H5::Group &group, const std::string &name, const Consumers< I > &consumers, const std::array< hsize_t, N > &extent=internal::uniform< N >(5), hsize_t batch_size=defaults::batch_size)
makeWriter
Writer< 0, const T & > SimpleWriter
SimpleWriter.
Consumers< const T & > CRefConsumer
CRefConsumer.
static const bool any_type
CheckType< 0, decltype(*begin(std::declval< T & >())), I > subtype
static const bool ok_type
CheckType< N-1, decltype(*begin(std::declval< T & >())), I > subtype
static const bool ok_type
static const bool any_type
static const bool ok_type
static const bool any_type
Constant parameters for the writer.
std::array< hsize_t, N > extent
DSParameters(const std::vector< SharedConsumer< I > > &fillers, const std::array< hsize_t, N > &extent, hsize_t batch_size)
std::vector< data_buffer_t > buffer
DataFlattener(const F &f, T args, const std::array< hsize_t, M > &)
std::vector< std::array< hsize_t, 0 > > element_offsets
Data flattener class: this is used by the writer to read in the elements one by one and put them in a...
DataFlattener(const F &filler, T args, const std::array< hsize_t, M > &extent)
std::vector< data_buffer_t > buffer
std::vector< std::array< hsize_t, N > > element_offsets
We have lots of code to get around HDF5's rather weak typing.
consumer_t getConsumers()