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

Reading a file generated by fire. More...

#include <Reader.h>

Inheritance diagram for fire::io::h5::Reader:
[legend]
Collaboration diagram for fire::io::h5::Reader:
[legend]

Classes

class  Buffer
 Read buffer allowing individual element access from a dataset. More...
 
class  BufferHandle
 Type-less handle to the Buffer. More...
 
class  MirrorObject
 A mirror event object. More...
 

Public Member Functions

 Reader (const std::string &name)
 Open the file in read mode. More...
 
virtual void load_into (BaseData &d) final override
 Load the next event into the passed data. More...
 
virtual std::vector< std::pair< std::string, std::string > > availableObjects () final override
 Get the event objects available in the file. More...
 
virtual std::pair< std::string, int > type (const std::string &path) final override
 Get the type of the input object. More...
 
virtual std::string name () const final override
 Get the name of this file. More...
 
std::vector< std::stringlist (const std::string &group_path) const
 List the entries inside of a group. More...
 
HighFive::DataType getDataSetType (const std::string &dataset) const
 Deduce the type of the dataset requested. More...
 
HighFive::ObjectType getH5ObjectType (const std::string &path) const
 Get the H5 type of object at the input path. More...
 
std::string getTypeName (const std::string &obj_name) const
 Get the 'type' attribute from the input group name. More...
 
std::size_t entries () const final override
 Get the number of entries in the file. More...
 
std::size_t runs () const final override
 Get the number of runs in the file. More...
 
virtual bool canCopy () const final override
 We can copy. More...
 
virtual void copy (unsigned long int i_entry, const std::string &path, Writer &output) final override
 Copy the input data set to the output file. More...
 
template<typename AtomicType >
void load (const std::string &path, AtomicType &val)
 Try to load a single value of an atomic type into the input handle. More...
 
 Reader (const Reader &)=delete
 never want to copy a reader
 
void operator= (const Reader &)=delete
 never want to copy a reader
 
- Public Member Functions inherited from fire::io::Reader
 Reader (const std::string &file_name)
 open the file at the passed location More...
 
virtual ~Reader ()=default
 virtual destructor so derived classes can be closed
 
virtual void copy (long unsigned int i_entry, const std::string &path, Writer &output)
 Copy the input object into the output file. More...
 

Private Member Functions

void mirror (const std::string &path, Writer &output)
 Mirror the structure of the passed path from us into the output file. More...
 

Private Attributes

HighFive::File file_
 our highfive file
 
const std::size_t entries_
 the number of entries in this file, set in constructor
 
const std::size_t runs_
 the number of runs in this file, set in constructor
 
std::size_t rows_per_chunk_ {10000}
 the number of rows to keep in each chunk, read from DataSet?
 
std::unordered_map< std::string, std::unique_ptr< BufferHandle > > buffers_
 our in-memory buffers for the data to be read in from disk
 
std::unordered_map< std::string, std::unique_ptr< MirrorObject > > mirror_objects_
 our in-memory mirror objects for data being copied to the output file without processing
 

Additional Inherited Members

- Public Types inherited from fire::io::Reader
using Factory = ::fire::factory::Factory< Reader, std::unique_ptr< Reader >, const std::string & >
 Type of factory used to create readers.
 

Detailed Description

Reading a file generated by fire.

See also
Writer for our files are written with fire

This reader handles the buffering of data read in from an HDF5 file in a seamless manner so that individual entries can be requested at a time without making disk read operation each time Reader::load is called.

Constructor & Destructor Documentation

◆ Reader()

fire::io::h5::Reader::Reader ( const std::string name)

Open the file in read mode.

Our read mode is the same as HDF5 Read Only mode

We also read the number of entries in this file by retrieving the size of the data set at constants::EVENT_GROUP / constants::EVENT_HEADER_NAME / constants::NUMBER_NAME This is reliable as long as

  1. EventHeader attaches the event number (or a similar once-per-event atomic type) under the name constants::EVENT_HEADER_NUMBER
  2. The EventHeader is created under a io::Data named constants::EVENT_GROUP/constants::EVENT_HEADER_NAME

We inspect the size of the dataset located at constants::RUN_HEADER_NAME/constants::NUMBER_NAME in the file to get the number of runs. This will work as long as

  1. The RunHeader is written to the file as RUN_HEADER_NAME.
  2. The RunHeader attaches an atomic type member under the name number
Exceptions
HighFive::Exceptionif file is not accessible.
Parameters
[in]namefile name to open and read

Member Function Documentation

◆ availableObjects()

std::vector< std::pair< std::string, std::string > > fire::io::h5::Reader::availableObjects ( )
finaloverridevirtual

Get the event objects available in the file.

We crawl the internal directory structure of the file we have open.

See also
type for how we get the name of the class that was used to write the data
Returns
vector of string pairs { obj_name, pass }

Implements fire::io::Reader.

◆ canCopy()

virtual bool fire::io::h5::Reader::canCopy ( ) const
inlinefinaloverridevirtual

We can copy.

Returns
true

Reimplemented from fire::io::Reader.

◆ copy()

virtual void fire::io::h5::Reader::copy ( unsigned long int  i_entry,
const std::string path,
Writer output 
)
finaloverridevirtual

Copy the input data set to the output file.

This happens when the input data set has passed all of the drop/keep rules so it is supposed to be copied into the output file; however, noone has accessed it with Event::get yet so an in-memory class object has not been created for it yet.

Parameters
[in]i_entryentry we are currently on
[in]pathfull event object name
[in]outputhandle to the writer writing the output file

◆ entries()

std::size_t fire::io::h5::Reader::entries ( ) const
inlinefinaloverridevirtual

Get the number of entries in the file.

This value was determined upon construction.

Returns
number of events within the file

Implements fire::io::Reader.

◆ getDataSetType()

HighFive::DataType fire::io::h5::Reader::getDataSetType ( const std::string dataset) const

Deduce the type of the dataset requested.

Note
This is low-level and is only being used in io::ParameterStorage for more flexibility in the parameter maps.
Parameters
[in]datasetfull in-file path to H5 dataset
Returns
HighFive::DataType specifying the atomic type of the set

◆ getH5ObjectType()

HighFive::ObjectType fire::io::h5::Reader::getH5ObjectType ( const std::string path) const

Get the H5 type of object at the input path.

Parameters
[in]pathin-file path to an HDF5 object
Returns
HighFive::ObjectType defining the type that the object there is

◆ getTypeName()

std::string fire::io::h5::Reader::getTypeName ( const std::string obj_name) const

Get the 'type' attribute from the input group name.

We retrieve the attribute named TYPE_ATTR_NAME from the group located at EVENT_GROUP/obj_name. This enables us to construct the list of products within an inputfile in Event::setInputFile.

See also
io::Writer::setTypeName for where the type attr is set
Parameters
[in]obj_nameName of event object to retrieve type of
Returns
demangled type name in string format

◆ list()

std::vector< std::string > fire::io::h5::Reader::list ( const std::string group_path) const

List the entries inside of a group.

Note
This is low-level and is only being used in io::ParameterStorage for more flexibility in the parameter maps and Event::setInputFile to obtain the event products within a file.
Parameters
[in]group_pathfull in-file path to H5 group to list elements of
Returns
list of elements in the group, empty if group does not exist

◆ load()

template<typename AtomicType >
void fire::io::h5::Reader::load ( const std::string path,
AtomicType &  val 
)
inline

Try to load a single value of an atomic type into the input handle.

If the input path does not exist in our list of buffers, then we create a new buffer for the requested type and load the first chunk of data into memory.

Besides that, we access the Buffer and call its Buffer::read method, allowing the Buffer to handle the necessary disk reading operations.

Exceptions
std::bad_castif mismatched type is passed
HighFive::DataSetExceptionif requested dataset doesn't exist
Parameters
[in]pathFull in-file path to dataset to load
[out]valSet to the next entry in the dataset

◆ load_into()

void fire::io::h5::Reader::load_into ( BaseData d)
finaloverridevirtual

Load the next event into the passed data.

As instructed by fire::io::Reader, we simply call the data's load function with a reference to ourselves.

Parameters
[in]dData to load data into

Implements fire::io::Reader.

◆ mirror()

void fire::io::h5::Reader::mirror ( const std::string path,
Writer output 
)
private

Mirror the structure of the passed path from us into the output file.

Parameters
[in]pathpath to the group (and potential subgroups) to mirror
[in]outputoutput file to mirror this structure to

◆ name()

std::string fire::io::h5::Reader::name ( ) const
finaloverridevirtual

Get the name of this file.

Returns
name of the file we are reading

Implements fire::io::Reader.

◆ runs()

std::size_t fire::io::h5::Reader::runs ( ) const
inlinefinaloverridevirtual

Get the number of runs in the file.

This value was determined upon construction

Returns
number of runs within the file

Implements fire::io::Reader.

◆ type()

std::pair< std::string, int > fire::io::h5::Reader::type ( const std::string path)
finaloverridevirtual

Get the type of the input object.

We retrieve the attributes named TYPE_ATTR_NAME and VERS_ATTR_NAME from the group located at EVENT_GROUP/obj_name. This enables us to construct the list of products within an inputfile in Event::setInputFile.

See also
io::Writer::setTypeName for where the type attr is set
Parameters
[in]obj_nameName of event object to retrieve type of
Returns
demangled type name in string format and its version number

Implements fire::io::Reader.


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