fire v0.19.0
Framework for sImulation and Reconstruction of Events
fire::io::h5::Reader::Buffer< AtomicType > Class Template Reference

Read buffer allowing individual element access from a dataset. More...

Inheritance diagram for fire::io::h5::Reader::Buffer< AtomicType >:
[legend]
Collaboration diagram for fire::io::h5::Reader::Buffer< AtomicType >:
[legend]

Public Member Functions

 Buffer (std::size_t max, HighFive::DataSet s)
 Define the size of the buffer and provide the dataset to read from. More...
 
virtual ~Buffer ()=default
 nothing fancy, just clearing in-memory objects
 
void read (AtomicType &out)
 Read the next entry from the dataset into the input variable. More...
 
virtual void load () final override
 Load the next chunk of data into memory. More...
 
- Public Member Functions inherited from fire::io::h5::Reader::BufferHandle
 BufferHandle (std::size_t max, HighFive::DataSet s)
 Define the size of the in-memory buffer and the set we are reading from. More...
 
virtual ~BufferHandle ()=default
 virtual destructor to pass on to derived types
 

Private Attributes

std::vector< AtomicType > buffer_
 the actual buffer of in-memory elements
 
std::size_t i_file_
 the current index of data-set elements in the file
 
std::size_t i_memory_
 the current index of data-set elements in-memory
 
std::size_t entries_
 the number of entries in the entire dataset
 

Additional Inherited Members

- Protected Attributes inherited from fire::io::h5::Reader::BufferHandle
std::size_t max_len_
 the maximum length of the buffer
 
HighFive::DataSet set_
 the HDF5 dataset we are reading from
 

Detailed Description

template<typename AtomicType>
class fire::io::h5::Reader::Buffer< AtomicType >

Read buffer allowing individual element access from a dataset.

Template Parameters
AtomicTypetype of elements in dataset

Constructor & Destructor Documentation

◆ Buffer()

template<typename AtomicType >
fire::io::h5::Reader::Buffer< AtomicType >::Buffer ( std::size_t  max,
HighFive::DataSet  s 
)
inlineexplicit

Define the size of the buffer and provide the dataset to read from.

We initialize ourselves with the indices set to 0, the entries read from the size of the dataset passed, and the buffer empty. Then we call our own Buffer::load method to get the first chunk of data into memory.

Parameters
[in]maxsize of the buffer
[in]sdataset to read from

Member Function Documentation

◆ load()

template<typename AtomicType >
virtual void fire::io::h5::Reader::Buffer< AtomicType >::load ( )
inlinefinaloverridevirtual

Load the next chunk of data into memory.

We determine the size of the next chunk from our own maximum and the number of entries in the data set. We shrink the size of the next chunk depending on how many entries are left if we can't grab a whole maximum sized chunk.

We have a compile-time split in order to patch a bug in HighFive that doesn't allow writing of std::vector<bool> due to the specialization of it and to translate our custom enum fire::io::Bool into bools.

After reading the next chunk into memory, we update our indicies by resetting the in-memory index to 0 and moving the file index by the size of the buffer.

Note
We assume that the downstream objects using this buffer know to stop processing before attempting to read passed the end of the data set. We enforce this with an assertion.

compile-time split for bools which

  1. gets around the std::vector<bool> specialization
  2. allows us to translate io::Bool into bools

Implements fire::io::h5::Reader::BufferHandle.

◆ read()

template<typename AtomicType >
void fire::io::h5::Reader::Buffer< AtomicType >::read ( AtomicType &  out)
inline

Read the next entry from the dataset into the input variable.

If we have reached the end of the in-memory buffer, then we call Buffer::load to retrieve the next chunk of data into memory.

Parameters
[out]outvariable to read entry into

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