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 &&) noexcept
Writer & operator= (Writer &)=delete
 ~Writer ()
template<typename T>
void fill (T)
void flush ()
size_t index () const

Private Member Functions

 Writer (Writer &&other, std::unique_lock< std::recursive_mutex > other_lock) noexcept

Private Attributes

const internal::DSParameters< I, N > m_par
hsize_t m_offset
hsize_t m_buffer_rows
std::vector< internal::data_buffer_t > m_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 352 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 373 of file Writer.h.

◆ consumer_type

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

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

◆ input_type

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

Definition at line 370 of file Writer.h.

Constructor & Destructor Documentation

◆ Writer() [1/5]

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

390 :
393 .name = name, // name
394 .extent = extent, // extent
395 .batch_size = batch_size, // batch_size
396 .chunks = extent, // chunks
397 .deflate = defaults::deflate, // deflate
398 .plist_callbacks = {} // plist_callbacks
399 })
400 {}
Writer.
Definition Writer.h:352
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:387

◆ Writer() [2/5]

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

Definition at line 403 of file Writer.h.

405 :
406 m_par(consumers.getConsumers(), cfg.extent,
407 cfg.batch_size ? *cfg.batch_size : defaults::batch_size),
408 m_offset(0),
409 m_buffer_rows(0),
410 m_consumers(consumers.getConsumers()),
412 {
414 if (m_par.batch_size < 1) {
415 throw std::logic_error("batch size must be > 0");
416 }
417 // create space
419 internal::vec(cfg.extent));
420
421 // create params
424 consumers.getConsumers());
425 params.setFillValue(m_par.type, default_value.data());
426
427 // create ds
430 m_ds = group.createDataSet(cfg.name, packed_type, space, params);
431 m_file_space = m_ds.getSpace();
432 m_file_space.selectNone();
433 }
H5::DataSpace m_file_space
Definition Writer.h:382
H5::DataSet m_ds
Definition Writer.h:381
std::vector< SharedConsumer< I > > m_consumers
Definition Writer.h:380
hsize_t m_offset
Definition Writer.h:377
hsize_t m_buffer_rows
Definition Writer.h:378
const internal::DSParameters< I, N > m_par
Definition Writer.h:376
H5::DSetCreatPropList getChunckedDatasetParams(const WriterConfiguration< N > &)
H5::DataSpace getUnlimitedSpace(const std::vector< hsize_t > &max_length)
void throwIfExists(const std::string &name, const H5::Group &in_group)
std::vector< data_buffer_t > buildDefault(const std::vector< SharedConsumer< I > > &f)
Definition Writer.h:317

◆ Writer() [3/5]

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

◆ Writer() [4/5]

template<size_t N, typename I>
Writer::Writer ( Writer< N, I > && other)
noexcept

Definition at line 437 of file Writer.h.

437 :
439 {
440 }
std::recursive_mutex m_mutex
Definition Writer.h:383

◆ ~Writer()

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

Definition at line 455 of file Writer.h.

455 {
456 using namespace H5Utils;
457 try {
458 flush();
459 } catch (H5::Exception& err) {
460 internal::printDestructorError(err.getDetailMsg());
461 } catch (std::exception& err) {
463 }
464 }
void flush()
Definition Writer.h:529
void printDestructorError(const std::string &msg)

◆ Writer() [5/5]

template<size_t N, typename I>
Writer::Writer ( Writer< N, I > && other,
std::unique_lock< std::recursive_mutex > other_lock )
privatenoexcept

Definition at line 443 of file Writer.h.

Member Function Documentation

◆ fill()

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

Definition at line 468 of file Writer.h.

468 {
469 // lock witin a scope here to check the buffer size and
470 // (potentially) flush, but we can release it to compute the
471 // output array since that's thread local
472 {
474 if (m_buffer_rows == m_par.batch_size) {
475 flush();
476 }
477 }
478
479 // make some assertions to simplify debugging, the errors can be
480 // pretty nasty wtih all these templates.
482 static_assert(
484 "\n\n"
485 " ** H5 Writer rank is greater than the depth of fill(...) input! **"
486 " \n");
487 static_assert(
488 // Suppress cppcheck warning here. It reports that the condition
489 // below is always true if `N = 0`. In N > 0 cases this
490 // condition might be false though, so I consider this a
491 // spurious warning.
492 //
493 // <3 Dan Guest, 2024-07-16 <3
494 //
495 // cppcheck-suppress incorrectLogicOperator
497 "\n\n"
498 " ** H5 Writer input type matches fill(...), but rank is incorrect! **"
499 " \n");
500 static_assert(
502 "\n\n"
503 " ** H5 Writer input type doesn't match input for fill(...)! **"
504 " \n");
505
507 m_consumers, std::move(arg), m_par.extent);
508 hsize_t n_el = buf.element_offsets.size();
510
511 // lock again here since we're done with the local stuff: there's
512 // some access to class variables below which we need to do one
513 // thread at a time.
515 for (const auto& el_local: buf.element_offsets) {
518 std::copy(el_local.begin(), el_local.end(), el_global.begin() + 1);
519 elements.insert(elements.end(), el_global.begin(), el_global.end());
520 }
521 if (n_el > 0) {
522 m_file_space.selectElements(H5S_SELECT_APPEND, n_el, elements.data());
523 }
524 m_buffer.insert(m_buffer.end(), buf.buffer.begin(), buf.buffer.end());
526 }
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.

◆ flush()

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

Definition at line 529 of file Writer.h.

529 {
532 if (buffer_size == 0) return;
533
534 // extend the ds
536 total_dims.insert(total_dims.end(),
537 m_par.extent.begin(),
538 m_par.extent.end());
539 m_ds.extend(total_dims.data());
540 m_file_space.setExtentSimple(total_dims.size(), total_dims.data());
541
542 // write out
543 hsize_t n_buffer_pts = m_buffer.size() / m_consumers.size();
544 assert(m_file_space.getSelectNpoints() >= 0);
545 assert(static_cast<hsize_t>(m_file_space.getSelectNpoints())
546 == n_buffer_pts);
548 m_ds.write(m_buffer.data(), m_par.type, mem_space, m_file_space);
550 m_buffer.clear();
551 m_buffer_rows = 0;
552 m_file_space.selectNone();
553 }

◆ index()

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

Definition at line 556 of file Writer.h.

556 {
557 return m_buffer_rows + m_offset;
558 }

◆ 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 379 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 378 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 380 of file Writer.h.

◆ m_ds

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

Definition at line 381 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 382 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 383 of file Writer.h.

◆ m_offset

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

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


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