ATLAS Offline Software
Loading...
Searching...
No Matches
H5Utils::Writer< N, I > Class Template Reference

Writer. More...

#include <Writer.h>

Collaboration diagram for H5Utils::Writer< N, I >:

Public Types

using consumer_type = Consumers<I>
using input_type = I
template<typename T>
using function_type = typename consumer_type::template function_type<T>
using configuration_type = WriterConfiguration<N>

Public Member Functions

 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)
 Writer (H5::Group &group, const Consumers< I > &consumers, const WriterConfiguration< N > &=WriterConfiguration< N >())
 Writer (const Writer &)=delete
 Writer (Writer &&)=default
Writeroperator= (Writer &)=delete
 ~Writer ()
template<typename T>
void fill (T)
void flush ()
size_t index () const

Private Attributes

const internal::DSParameters< I, N > m_par
hsize_t m_offset
hsize_t m_buffer_rows
std::vector< internal::data_buffer_tm_buffer
std::vector< SharedConsumer< I > > m_consumers
H5::DataSet m_ds
H5::DataSpace m_file_space

Detailed Description

template<size_t N, typename I>
class H5Utils::Writer< N, I >

Writer.

You'll have to specify the H5::Group to write the dataset to, the name of the new dataset, and the extent of the dataset.

To fill, use the fill(...) method.

Definition at line 350 of file Writer.h.

Member Typedef Documentation

◆ configuration_type

template<size_t N, typename I>
using H5Utils::Writer< N, I >::configuration_type = WriterConfiguration<N>

Definition at line 371 of file Writer.h.

◆ consumer_type

template<size_t N, typename I>
using H5Utils::Writer< N, I >::consumer_type = Consumers<I>

Definition at line 367 of file Writer.h.

◆ function_type

template<size_t N, typename I>
template<typename T>
using H5Utils::Writer< N, I >::function_type = typename consumer_type::template function_type<T>

Definition at line 370 of file Writer.h.

◆ input_type

template<size_t N, typename I>
using H5Utils::Writer< N, I >::input_type = I

Definition at line 368 of file Writer.h.

Constructor & Destructor Documentation

◆ Writer() [1/4]

template<size_t N, typename I>
H5Utils::Writer< N, I >::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 )

Definition at line 383 of file Writer.h.

386 :
389 name, // name
390 extent, // extent
391 batch_size, // batch_size
392 extent, // chunks
393 defaults::deflate // deflate
394 })
395 {}
Writer.
Definition Writer.h:350
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)
Definition Writer.h:383

◆ Writer() [2/4]

template<size_t N, typename I>
H5Utils::Writer< N, I >::Writer ( H5::Group & group,
const Consumers< I > & consumers,
const WriterConfiguration< N > & cfg = WriterConfiguration<N>() )

Definition at line 398 of file Writer.h.

400 :
401 m_par(consumers.getConsumers(), cfg.extent,
402 cfg.batch_size ? *cfg.batch_size : defaults::batch_size),
403 m_offset(0),
404 m_buffer_rows(0),
405 m_consumers(consumers.getConsumers()),
407 {
409 if (m_par.batch_size < 1) {
410 throw std::logic_error("batch size must be > 0");
411 }
412 // create space
414 internal::vec(cfg.extent));
415
416 // create params
419 consumers.getConsumers());
420 params.setFillValue(m_par.type, default_value.data());
421
422 // create ds
425 m_ds = group.createDataSet(cfg.name, packed_type, space, params);
426 m_file_space = m_ds.getSpace();
427 m_file_space.selectNone();
428 }
H5::DataSpace m_file_space
Definition Writer.h:379
H5::DataSet m_ds
Definition Writer.h:378
std::vector< SharedConsumer< I > > m_consumers
Definition Writer.h:377
hsize_t m_offset
Definition Writer.h:374
hsize_t m_buffer_rows
Definition Writer.h:375
const internal::DSParameters< I, N > m_par
Definition Writer.h:373
H5::DSetCreatPropList getChunckedDatasetParams(const WriterConfiguration< N > &)
H5::DataSpace getUnlimitedSpace(const std::vector< hsize_t > &max_length)
Definition common.cxx:31
void throwIfExists(const std::string &name, const H5::Group &in_group)
Definition common.cxx:46
std::vector< data_buffer_t > buildDefault(const std::vector< SharedConsumer< I > > &f)
Definition Writer.h:315

◆ Writer() [3/4]

template<size_t N, typename I>
H5Utils::Writer< N, I >::Writer ( const Writer< N, I > & )
delete

◆ Writer() [4/4]

template<size_t N, typename I>
H5Utils::Writer< N, I >::Writer ( Writer< N, I > && )
default

◆ ~Writer()

template<size_t N, typename I>
H5Utils::Writer< N, I >::~Writer ( )

Definition at line 431 of file Writer.h.

431 {
432 using namespace H5Utils;
433 try {
434 flush();
435 } catch (H5::Exception& err) {
436 internal::printDestructorError(err.getDetailMsg());
437 } catch (std::exception& err) {
439 }
440 }
void flush()
Definition Writer.h:494
void printDestructorError(const std::string &msg)
Definition common.cxx:24

Member Function Documentation

◆ fill()

template<size_t N, typename I>
template<typename T>
void H5Utils::Writer< N, I >::fill ( T arg)

Definition at line 444 of file Writer.h.

444 {
445 if (m_buffer_rows == m_par.batch_size) {
446 flush();
447 }
448
449 // make some assertions to simplify debugging, the errors can be
450 // pretty nasty wtih all these templates.
452 static_assert(
454 "\n\n"
455 " ** H5 Writer rank is greater than the depth of fill(...) input! **"
456 " \n");
457 static_assert(
458 // Suppress cppcheck warning here. It reports that the condition
459 // below is always true if `N = 0`. In N > 0 cases this
460 // condition might be false though, so I consider this a
461 // spurious warning.
462 //
463 // <3 Dan Guest, 2024-07-16 <3
464 //
465 // cppcheck-suppress incorrectLogicOperator
467 "\n\n"
468 " ** H5 Writer input type matches fill(...), but rank is incorrect! **"
469 " \n");
470 static_assert(
472 "\n\n"
473 " ** H5 Writer input type doesn't match input for fill(...)! **"
474 " \n");
475
477 m_consumers, std::move(arg), m_par.extent);
478 hsize_t n_el = buf.element_offsets.size();
480 for (const auto& el_local: buf.element_offsets) {
483 std::copy(el_local.begin(), el_local.end(), el_global.begin() + 1);
484 elements.insert(elements.end(), el_global.begin(), el_global.end());
485 }
486 if (n_el > 0) {
487 m_file_space.selectElements(H5S_SELECT_APPEND, n_el, elements.data());
488 }
489 m_buffer.insert(m_buffer.end(), buf.buffer.begin(), buf.buffer.end());
491 }
std::vector< internal::data_buffer_t > m_buffer
Definition Writer.h:376

◆ flush()

template<size_t N, typename I>
void H5Utils::Writer< N, I >::flush ( )

Definition at line 494 of file Writer.h.

494 {
496 if (buffer_size == 0) return;
497
498 // extend the ds
500 total_dims.insert(total_dims.end(),
501 m_par.extent.begin(),
502 m_par.extent.end());
503 m_ds.extend(total_dims.data());
504 m_file_space.setExtentSimple(total_dims.size(), total_dims.data());
505
506 // write out
507 hsize_t n_buffer_pts = m_buffer.size() / m_consumers.size();
508 assert(m_file_space.getSelectNpoints() >= 0);
509 assert(static_cast<hsize_t>(m_file_space.getSelectNpoints())
510 == n_buffer_pts);
512 m_ds.write(m_buffer.data(), m_par.type, mem_space, m_file_space);
514 m_buffer.clear();
515 m_buffer_rows = 0;
516 m_file_space.selectNone();
517 }

◆ index()

template<size_t N, typename I>
size_t H5Utils::Writer< N, I >::index ( ) const

Definition at line 520 of file Writer.h.

520 {
521 return m_buffer_rows + m_offset;
522 }

◆ operator=()

template<size_t N, typename I>
Writer & H5Utils::Writer< N, I >::operator= ( Writer< N, I > & )
delete

Member Data Documentation

◆ m_buffer

template<size_t N, typename I>
std::vector<internal::data_buffer_t> H5Utils::Writer< N, I >::m_buffer
private

Definition at line 376 of file Writer.h.

◆ m_buffer_rows

template<size_t N, typename I>
hsize_t H5Utils::Writer< N, I >::m_buffer_rows
private

Definition at line 375 of file Writer.h.

◆ m_consumers

template<size_t N, typename I>
std::vector<SharedConsumer<I> > H5Utils::Writer< N, I >::m_consumers
private

Definition at line 377 of file Writer.h.

◆ m_ds

template<size_t N, typename I>
H5::DataSet H5Utils::Writer< N, I >::m_ds
private

Definition at line 378 of file Writer.h.

◆ m_file_space

template<size_t N, typename I>
H5::DataSpace H5Utils::Writer< N, I >::m_file_space
private

Definition at line 379 of file Writer.h.

◆ m_offset

template<size_t N, typename I>
hsize_t H5Utils::Writer< N, I >::m_offset
private

Definition at line 374 of file Writer.h.

◆ m_par

template<size_t N, typename I>
const internal::DSParameters<I,N> H5Utils::Writer< N, I >::m_par
private

Definition at line 373 of file Writer.h.


The documentation for this class was generated from the following file: