HDTree  0.5.2
HDTree C++ API
hdtree::Reader Class Reference

Reading a file generated by fire. More...

#include <Reader.h>

Collaboration diagram for hdtree::Reader:
[legend]

Classes

class  MirrorObject
 A mirror event object. More...
 

Public Member Functions

 Reader (const std::pair< std::string, std::string > &file_tree_path, bool inplace=false)
 Open the file in read mode. More...
 
virtual std::vector< std::pair< std::string, std::string > > availableObjects ()
 Get the event objects available in the file. More...
 
virtual std::pair< std::string, int > type (const std::string &branch_name)
 Get the type of the input object. More...
 
virtual std::string name () const
 Get the name of this file. More...
 
std::vector< std::string > list (const std::string &group_path) const
 List the entries inside of a group. More...
 
HighFive::DataSet getDataSet (const std::string &branch_name) const
 Get data set.
 
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
 Get the number of entries in the file. More...
 
virtual bool canCopy () const
 We can copy. More...
 
virtual void copy (unsigned long int i_entry, const std::string &branch_name, Writer &output)
 Copy the input data set to the output file. More...
 
 Reader (const Reader &)=delete
 never want to copy a reader
 
void operator= (const Reader &)=delete
 never want to copy a reader
 

Private Member Functions

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

Private Attributes

HighFive::File file_
 our highfive file
 
HighFive::Group tree_
 the HighFive group that is our HDTree
 
std::size_t entries_
 the number of entries in this file, set in constructor
 
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
 

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()

hdtree::Reader::Reader ( const std::pair< std::string, std::string > &  file_tree_path,
bool  inplace = false 
)

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 size attribute of the HDTree. This is reliable as long as the HDTree was written/flushed before program termination.

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 > > hdtree::Reader::availableObjects ( )
virtual

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 }

◆ canCopy()

virtual bool hdtree::Reader::canCopy ( ) const
inlinevirtual

We can copy.

Returns
true

◆ copy()

void hdtree::Reader::copy ( unsigned long int  i_entry,
const std::string &  branch_name,
Writer output 
)
virtual

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]branch_namefull event object name
[in]outputhandle to the writer writing the output file

this is where recursing into the subgroups of full_name occurs if this mirror object hasn't been created yet

If a mirror object is being created that means the event object satisfies the following:

  1. The event object exists in the input file
  2. The event object should be written to the output file
  3. The event object HAS NOT been accessed during the processing of this input file yet

This means we should copy over the structure of this event object from the input file into the output file.

◆ entries()

std::size_t hdtree::Reader::entries ( ) const
inline

Get the number of entries in the file.

This value was determined upon construction.

Returns
number of events within the file

◆ getDataSetType()

HighFive::DataType hdtree::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 hdtree::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 hdtree::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 > hdtree::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

◆ mirror()

void hdtree::Reader::mirror ( const std::string &  branch_name,
Writer output 
)
private

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

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

◆ name()

std::string hdtree::Reader::name ( ) const
virtual

Get the name of this file.

Returns
name of the file we are reading

◆ type()

std::pair< std::string, int > hdtree::Reader::type ( const std::string &  branch_name)
virtual

Get the type of the input object.

We retrieve the attributes named TYPE_ATTR_NAME and VERS_ATTR_NAME from the group located at branch_name within the tree.

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

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