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
std::recursive_mutex m_mutex

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 351 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 372 of file Writer.h.

◆ consumer_type

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

Definition at line 368 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 371 of file Writer.h.

◆ input_type

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

Definition at line 369 of file Writer.h.

Constructor & Destructor Documentation

◆ Writer() [1/4]

template<size_t N, typename I>
Writer::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 385 of file Writer.h.

388 :
391 .name = name, // name
392 .extent = extent, // extent
393 .batch_size = batch_size, // batch_size
394 .chunks = extent, // chunks
395 .deflate = defaults::deflate, // deflate
396 .plist_callbacks = {} // plist_callbacks
397 })
398 {}
Writer.
Definition Writer.h:351
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:385

◆ Writer() [2/4]

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

Definition at line 401 of file Writer.h.

403 :
404 m_par(consumers.getConsumers(), cfg.extent,
405 cfg.batch_size ? *cfg.batch_size : defaults::batch_size),
406 m_offset(0),
407 m_buffer_rows(0),
408 m_consumers(consumers.getConsumers()),
410 {
412 if (m_par.batch_size < 1) {
413 throw std::logic_error("batch size must be > 0");
414 }
415 // create space
417 internal::vec(cfg.extent));
418
419 // create params
422 consumers.getConsumers());
423 params.setFillValue(m_par.type, default_value.data());
424
425 // create ds
428 m_ds = group.createDataSet(cfg.name, packed_type, space, params);
429 m_file_space = m_ds.getSpace();
430 m_file_space.selectNone();
431 }
H5::DataSpace m_file_space
Definition Writer.h:380
H5::DataSet m_ds
Definition Writer.h:379
std::vector< SharedConsumer< I > > m_consumers
Definition Writer.h:378
hsize_t m_offset
Definition Writer.h:375
hsize_t m_buffer_rows
Definition Writer.h:376
const internal::DSParameters< I, N > m_par
Definition Writer.h:374
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:316

◆ 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>
Writer::~Writer ( )

Definition at line 434 of file Writer.h.

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

Member Function Documentation

◆ fill()

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

Definition at line 447 of file Writer.h.

447 {
448 // lock witin a scope here to check the buffer size and
449 // (potentially) flush, but we can release it to compute the
450 // output array since that's thread local
451 {
453 if (m_buffer_rows == m_par.batch_size) {
454 flush();
455 }
456 }
457
458 // make some assertions to simplify debugging, the errors can be
459 // pretty nasty wtih all these templates.
461 static_assert(
463 "\n\n"
464 " ** H5 Writer rank is greater than the depth of fill(...) input! **"
465 " \n");
466 static_assert(
467 // Suppress cppcheck warning here. It reports that the condition
468 // below is always true if `N = 0`. In N > 0 cases this
469 // condition might be false though, so I consider this a
470 // spurious warning.
471 //
472 // <3 Dan Guest, 2024-07-16 <3
473 //
474 // cppcheck-suppress incorrectLogicOperator
476 "\n\n"
477 " ** H5 Writer input type matches fill(...), but rank is incorrect! **"
478 " \n");
479 static_assert(
481 "\n\n"
482 " ** H5 Writer input type doesn't match input for fill(...)! **"
483 " \n");
484
486 m_consumers, std::move(arg), m_par.extent);
487 hsize_t n_el = buf.element_offsets.size();
489
490 // lock again here since we're done with the local stuff: there's
491 // some access to class variables below which we need to do one
492 // thread at a time.
494 for (const auto& el_local: buf.element_offsets) {
497 std::copy(el_local.begin(), el_local.end(), el_global.begin() + 1);
498 elements.insert(elements.end(), el_global.begin(), el_global.end());
499 }
500 if (n_el > 0) {
501 m_file_space.selectElements(H5S_SELECT_APPEND, n_el, elements.data());
502 }
503 m_buffer.insert(m_buffer.end(), buf.buffer.begin(), buf.buffer.end());
505 }
std::vector< internal::data_buffer_t > m_buffer
Definition Writer.h:377
std::recursive_mutex m_mutex
Definition Writer.h:381

◆ flush()

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

Definition at line 508 of file Writer.h.

508 {
511 if (buffer_size == 0) return;
512
513 // extend the ds
515 total_dims.insert(total_dims.end(),
516 m_par.extent.begin(),
517 m_par.extent.end());
518 m_ds.extend(total_dims.data());
519 m_file_space.setExtentSimple(total_dims.size(), total_dims.data());
520
521 // write out
522 hsize_t n_buffer_pts = m_buffer.size() / m_consumers.size();
523 assert(m_file_space.getSelectNpoints() >= 0);
524 assert(static_cast<hsize_t>(m_file_space.getSelectNpoints())
525 == n_buffer_pts);
527 m_ds.write(m_buffer.data(), m_par.type, mem_space, m_file_space);
529 m_buffer.clear();
530 m_buffer_rows = 0;
531 m_file_space.selectNone();
532 }

◆ index()

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

Definition at line 535 of file Writer.h.

535 {
536 return m_buffer_rows + m_offset;
537 }

◆ 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 377 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 376 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 378 of file Writer.h.

◆ m_ds

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

Definition at line 379 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 380 of file Writer.h.

◆ m_mutex

template<size_t N, typename I>
std::recursive_mutex H5Utils::Writer< N, I >::m_mutex
private

Definition at line 381 of file Writer.h.

◆ m_offset

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

Definition at line 375 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 374 of file Writer.h.


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