fire v0.19.0
Framework for sImulation and Reconstruction of Events
fire::io::Writer Class Reference

Write the fire DataSets into a deterministic structure in the output HDF5 data file. More...

#include <Writer.h>

Collaboration diagram for fire::io::Writer:
[legend]

Classes

class  Buffer
 Buffer atomic data types in-memory for efficient disk operations. More...
 
class  BufferHandle
 Type-less handle to buffers. More...
 

Public Member Functions

 Writer (const int &event_limit, const config::Parameters &ps)
 Open the file in write mode. More...
 
 ~Writer ()
 Close up our file, making sure to flush contents to disk.
 
void flush ()
 Flush the data to disk. More...
 
const std::stringname () const
 Get the name of this file.
 
void structure (const std::string &path, const std::pair< std::string, int > &type)
 Persist the structure of the event object at the input path. More...
 
std::size_t entries () const
 Get the number of entries in the file.
 
template<typename AtomicType >
void save (const std::string &path, const AtomicType &val)
 Save an atomic type into the dataset at the passed path. More...
 
 Writer (const Writer &)=delete
 don't allow copies of the Writer
 
void operator= (const Writer &)=delete
 don't allow copies of the Writer
 

Private Attributes

std::unique_ptr< HighFive::File > file_
 our highfive file More...
 
HighFive::DataSetCreateProps create_props_
 the creation properties to be used on datasets we are writing
 
HighFive::DataSpace space_
 the dataspace shared amongst all of our datasets
 
std::size_t entries_
 the expected number of entries in this file
 
std::size_t rows_per_chunk_
 number of rows to keep in each chunk
 
std::unordered_map< std::string, std::unique_ptr< BufferHandle > > buffers_
 our in-memory buffers for data to be written to disk
 

Friends

std::ostreamoperator<< (std::ostream &s, const Writer &w)
 Stream this writer. More...
 

Detailed Description

Write the fire DataSets into a deterministic structure in the output HDF5 data file.

See also
h5::Reader for where our files are read

Constructor & Destructor Documentation

◆ Writer()

fire::io::Writer::Writer ( const int &  event_limit,
const config::Parameters ps 
)

Open the file in write mode.

Our write mode is the HDF5 TRUNC (overwrite) mode.

Parameters
[in]event_limitMaximum number of events that could end up here
[in]psParameters used to configure the writing of the output file

Member Function Documentation

◆ flush()

void fire::io::Writer::flush ( )

Flush the data to disk.

We flush all buffers and then flush the file.

◆ save()

template<typename AtomicType >
void fire::io::Writer::save ( const std::string path,
const AtomicType &  val 
)
inline

Save an atomic type into the dataset at the passed path.

If the path does not have a Buffer created for it yet, we create a new one. Creating this new buffer is when HDF5 creates the DataSet in the file and so it may throw an exception at this time if it is unable to create the DataSet for some reason.

If the path already has a Buffer, we simply pass the new value to be saved into the Buffer.

Exceptions
std::bad_castif mismatched type is passed to buffer
HighFive::DataSetExceptionif unable to create data set

◆ structure()

void fire::io::Writer::structure ( const std::string path,
const std::pair< std::string, int > &  type 
)

Persist the structure of the event object at the input path.

The "structure" is simply the type and the type's version at the correct location within the EVENT_GROUP.

Note
The save method creates the DataSets so this method should only be called on levels of the hierarchy that DO NOT correspond to HDF5 data sets.
Parameters
[in]pathfull path to the group
[in]{type,version}pair demangled type name of object and its version number
[in]versionversion number of type

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream s,
const Writer w 
)
friend

Stream this writer.

We stream 'Writer' and the name of the file we are writing to

Parameters
[in]sostream to stream into
[in]wwriter to stream
Returns
modified ostream

Member Data Documentation

◆ file_

std::unique_ptr<HighFive::File> fire::io::Writer::file_
private

our highfive file

we need it to be a smart pointer because we want to do some parameter validation before creating the file in the constructor


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