1#ifndef FIRE_IO_H5_WRITER_H
2#define FIRE_IO_H5_WRITER_H
5#include <highfive/H5File.hpp>
7#include "fire/config/Parameters.h"
84 template <
typename AtomicType>
87 is_atomic_v<AtomicType>,
88 "Type unsupported by HighFive as Atomic made its way to Writer::save");
98 if constexpr (std::is_same_v<AtomicType,bool>) {
101 t = HighFive::AtomicType<AtomicType>();
122 return s <<
"Writer(" << w.
name() <<
")";
174 template <
typename AtomicType>
208 void save(
const AtomicType& val) {
242 virtual void flush() final
override {
243 if (
buffer_.size() == 0)
return;
246 if (this->
set_.getDimensions().at(0) < new_extent) {
247 this->
set_.resize({new_extent});
249 if constexpr (std::is_same_v<AtomicType, bool>) {
254 this->
set_.select({i_file_}, {
buffer_.size()}).write(buff);
Definitions for names of structures required by serialization methods.
Class encapsulating parameters for configuring a processor.
Definition: Parameters.h:28
Type-less handle to buffers.
Definition: Writer.h:138
std::size_t max_len_
the maximum size of the buffer
Definition: Writer.h:141
virtual ~BufferHandle()=default
virtual destructor so derived Buffer can be destructed properly
BufferHandle(std::size_t max, HighFive::DataSet s)
Define the maximum size of the buffer and the dataset we are writing to.
Definition: Writer.h:152
HighFive::DataSet set_
the H5 dataset we are writing to
Definition: Writer.h:143
virtual void flush()=0
Pure virtual flush mechanism.
Buffer atomic data types in-memory for efficient disk operations.
Definition: Writer.h:175
std::size_t i_file_
the index of the file we will write to on the next flush
Definition: Writer.h:179
void save(const AtomicType &val)
Put the new value into the buffer.
Definition: Writer.h:208
virtual void flush() final override
Flush our in-memory buffer onto disk.
Definition: Writer.h:242
virtual ~Buffer()=default
destruct the in-memory buffer
Buffer(std::size_t max, HighFive::DataSet s)
Define the buffer size and the set we will write to.
Definition: Writer.h:194
std::vector< AtomicType > buffer_
the actual buffer of data in-memory
Definition: Writer.h:177
Write the fire DataSets into a deterministic structure in the output HDF5 data file.
Definition: Writer.h:19
void save(const std::string &path, const AtomicType &val)
Save an atomic type into the dataset at the passed path.
Definition: Writer.h:85
std::size_t rows_per_chunk_
number of rows to keep in each chunk
Definition: Writer.h:280
void structure(const std::string &path, const std::pair< std::string, int > &type)
Persist the structure of the event object at the input path.
Definition: Writer.cxx:40
HighFive::DataSetCreateProps create_props_
the creation properties to be used on datasets we are writing
Definition: Writer.h:274
friend std::ostream & operator<<(std::ostream &s, const Writer &w)
Stream this writer.
Definition: Writer.h:121
std::size_t entries() const
Get the number of entries in the file.
Definition: Writer.h:67
Writer(const int &event_limit, const config::Parameters &ps)
Open the file in write mode.
Definition: Writer.cxx:7
Writer(const Writer &)=delete
don't allow copies of the Writer
std::unordered_map< std::string, std::unique_ptr< BufferHandle > > buffers_
our in-memory buffers for data to be written to disk
Definition: Writer.h:282
HighFive::DataSpace space_
the dataspace shared amongst all of our datasets
Definition: Writer.h:276
void flush()
Flush the data to disk.
Definition: Writer.cxx:31
std::unique_ptr< HighFive::File > file_
our highfive file
Definition: Writer.h:272
void operator=(const Writer &)=delete
don't allow copies of the Writer
const std::string & name() const
Get the name of this file.
Definition: Writer.cxx:38
~Writer()
Close up our file, making sure to flush contents to disk.
Definition: Writer.cxx:29
std::size_t entries_
the expected number of entries in this file
Definition: Writer.h:278
Geant4 does a GLOBAL definition of the keyword TRUE.
Definition: AbstractData.h:11
HighFive::EnumType< Bool > create_enum_bool()
HighFive method for creating the enum data type.
Definition: Atomic.cxx:5
static const std::string VERS_ATTR_NAME
the name of the fire version attribute
Definition: Constants.h:28
static const std::string TYPE_ATTR_NAME
the name of the HDF5 object attribute that holds the event object type
Definition: Constants.h:26