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

Event class for interfacing with processors. More...

#include <Event.h>

Collaboration diagram for fire::Event:
[legend]

Classes

struct  EventObject
 structure to hold event data in memory More...
 
class  EventObjectTag
 Identification for a specific event object. More...
 

Public Member Functions

const EventHeaderheader () const
 Get the event header. More...
 
EventHeaderheader ()
 Get non-const event header. More...
 
std::vector< EventObjectTagsearch (const std::string &namematch, const std::string &passmatch, const std::string &typematch) const
 Search through the available objects for a specific match. More...
 
bool exists (const std::string &name, const std::string &pass="") const
 Check if the input name and (optional) pass exist in the bus. More...
 
template<typename DataType >
void add (const std::string &name, const DataType &data)
 add a piece of data to the event More...
 
template<typename DataType >
const DataType & get (const std::string &name, const std::string &pass="") const
 get a piece of data from the event More...
 
 Event (const Event &)=delete
 Delete the copy constructor to prevent any in-advertent copies.
 
void operator= (const Event &)=delete
 Delete the assignment operator to prevent any in-advertent copies.
 

Private Member Functions

std::string fullName (const std::string &name, const std::string &pass) const
 Deduce full data set name given a pass or using our pass. More...
 
bool keep (const std::string &full_name, bool def) const
 Determine if the passed data set should be saved into output file. More...
 
 Event (io::Writer *output_file, const std::string &pass, const std::vector< config::Parameters > &dk_rules)
 Only our good friend Process can construct us. More...
 
void save ()
 Go through and save the current in-memory objects into the output file.
 
void load ()
 Go through and load the next entry into the in-memory objects from the input file.
 
void setInputFile (io::Reader *r)
 Attach a file to this event as the input file. More...
 
void next ()
 Move to the next event we just need to keep our entry index up-to-date for loading a newly requested object. More...
 
void done ()
 Let the event bus know we are done. More...
 

Private Attributes

std::unique_ptr< EventHeaderheader_
 header that we control
 
io::Readerinput_file_
 pointer to input file (nullptr if no input files)
 
io::Writeroutput_file_
 handle to output file (owned by Process)
 
std::string pass_
 name of current processing pass
 
std::unordered_map< std::string, EventObjectobjects_
 list of event objects being processed
 
long unsigned int i_entry_
 current index in the datasets
 
std::vector< std::pair< std::regex, bool > > drop_keep_rules_
 regular expressions determining if a dataset should be written to output file
 
std::vector< EventObjectTagavailable_objects_
 list of objects available to us either on disk or newly created
 
std::unordered_map< std::string, std::stringknown_lookups_
 cache of known lookups when requesting an object without a pass name
 

Friends

class Process
 The Process is the Event's friend, this allows the Process to handle the core iteration procedure while preventing other classes from accessing these methods. More...
 
class UserReader
 The UserReader is the Event's friend, so it can construct it.
 

Detailed Description

Event class for interfacing with processors.

This class is what is given to the processors to 'get' data from and/or 'add' data to.

The 'Process' class is a friend class so that it can do all the orginizational work behind the scenes using private methods while the public methods are the only ones available to processors written by users.

Constructor & Destructor Documentation

◆ Event()

fire::Event::Event ( io::Writer output_file,
const std::string pass,
const std::vector< config::Parameters > &  dk_rules 
)
private

Only our good friend Process can construct us.

Besides the name of the pass, the input_file handle is initialized to a nullptr to signify that no input file has been "registered" yet and i_entry_ is started at zero.

Pass drop/keep rules for determining if a data set is going to be written to the output file or not.

The regex grammar is set to "extended", case is ignored, and the 'nosubs' parameter is passed.

Parameters
[in]passname of current processing pass
[in]dk_rulesconfiguration for the drop/keep rules

register our event header with a data set for save/load

Member Function Documentation

◆ add()

template<typename DataType >
void fire::Event::add ( const std::string name,
const DataType &  data 
)
inline

add a piece of data to the event

If the data isn't already in the list of in-memory objects, we do the initialization procedure defined below. After init, we check if the object has already been updated by another processor, and if it hasn't, we give the input data to the event object to update the in-memory copy.

Initilialization

To initilialize a new in-memory object, we first check that a object with the same name and pass doesn't exist in the available objects. This prevents processors from silently overwriting data that could have been read in from the input file. Then, we create a new event object to hold the in-memory data, wrapping the event object with h5::Data. We also set the event object flags. should_save : determined by Event::keep with the default set to true should_load : false, this is a new object and is not being read in updated : false, we haven't updated it yet

Finally, if we end up needing to save this object, we also making sure to call h5::Data::save enough times to align the number of entries in the serialized data with the current number of entries we are on (Event::i_entry_).

Exceptions
Exceptionif two data sets of the same name and the same pass are added
Exceptionif input DataType doesn't match the type stored in the data set
Template Parameters
DataTypetype of data being added
Parameters
[in]namename of data being added
[in]dataactual value of data being added

maybe throw bad_cast exception

◆ done()

void fire::Event::done ( )
private

Let the event bus know we are done.

This gives us an opportunity to go through the products in the output file and attach the 'type' attributes to them

◆ exists()

bool fire::Event::exists ( const std::string name,
const std::string pass = "" 
) const
inline

Check if the input name and (optional) pass exist in the bus.

Note
This checks for unique existence, i.e. it can be used to make sure that a following 'get' call will only fail if the wrong type is provided. In order to check for any existence, use Event::search.
Parameters
[in]nameName of event object
[in]pass(optional) name of pass that created the event object
Returns
true if there is exactly one available object matching the name and pass

◆ fullName()

std::string fire::Event::fullName ( const std::string name,
const std::string pass 
) const
inlineprivate

Deduce full data set name given a pass or using our pass.

'inline' because we call this at least once per event for each dataset, having it 'inline' means that it will be in the same compilation unit as where it is used and therefore will hopefully improve performance.

Parameters
[in]nameobject name
[in]passpass name, if empty use current pass

◆ get()

template<typename DataType >
const DataType & fire::Event::get ( const std::string name,
const std::string pass = "" 
) const
inline

get a piece of data from the event

Object Deduction

Optionally providing a pass name means we need some automatic deduction of what the pass name should be. If the pass name is provided, all of the deduction procedure is skippped. A cache of known name -> name+pass deductions is kept in Event::known_lookups_ to save time. The deduction is pretty simple, we use Event::search with the input name and the demangled input type in order to retrieve a list of options. If the list of options is empty or has more than one element, we throw an exception, otherwise, we have successfully deduced the pass name.

If the requested object is not in the list of in-memory objects, then we must have an input file. This assumption is enforced with an exception the pointer to the input file is nullptr. If we do have an input file, then we create a new in-memory object to read this data set. After wrapping the input data type with h5::Data, we deduce the other tags: should_save: use Event::keep with the default of false should_load: true since this is a reading updated: false We also use h5::Data::load to get the reading pointer to the entry in the data set corresponding to the current entry we are on (Event::i_entry_).

After all of this setup, we attempt to retrieve the a constant reference to the data stored in the in-memory object.

Exceptions
Exceptionif requested data doesn't exist
Exceptionif requested DataType doesn't match type in data set
Template Parameters
DataTypetype of requested data
Parameters
[in]nameName of requested data
[in]passoptional pass name to use for getting the data
Returns
const reference to data in event

◆ header() [1/2]

EventHeader & fire::Event::header ( )
inline

Get non-const event header.

Note
should we name this differently than the const version? Having them have the same name means that a (potentially helpful) compiler error about const-ness would never be thrown and the compiler will automatically deduce which to use (perferring const).
Returns
reference to event header

◆ header() [2/2]

const EventHeader & fire::Event::header ( ) const
inline

Get the event header.

Returns
const reference to event header

◆ keep()

bool fire::Event::keep ( const std::string full_name,
bool  def 
) const
private

Determine if the passed data set should be saved into output file.

We apply all of the rules in order i.e. the last matching regex rule is the one that makes the actual decision for a data set. This behavior is helpful for our use case because we can have general rules and then various exceptions.

Parameters
[in]full_nameobject name including the pass prefix
[in]defdefault drop/keep decision value
Returns
true if object should be saved into the output file

◆ next()

void fire::Event::next ( )
private

Move to the next event we just need to keep our entry index up-to-date for loading a newly requested object.

and reset the other event objects to their empty state.

◆ search()

std::vector< Event::EventObjectTag > fire::Event::search ( const std::string namematch,
const std::string passmatch,
const std::string typematch 
) const

Search through the available objects for a specific match.

This can be helpful for higher-level processors that require some amount of introsepction. Additionally, the EventObjectTag has the demangled type name for a specific event object, so the processor could use this functionality to more dynamically handle various types of event objects.

An empty matching string is interpreted as the "match anything" regex '.*'.

Parameters
[in]namematchregex to match name of event object
[in]passmatchregex to match pass of event object
[in]typematchregex to match demangled type of event object
Returns
list of event object tags that match all of the regex

◆ setInputFile()

void fire::Event::setInputFile ( io::Reader r)
private

Attach a file to this event as the input file.

Note
We store the input file as a pointer, but don't clean-up later.
Parameters
[in]rreference to input file reader

Friends And Related Function Documentation

◆ Process

friend class Process
friend

The Process is the Event's friend, this allows the Process to handle the core iteration procedure while preventing other classes from accessing these methods.

While the Process class has access to all of Event's private members, the methods below are the ones used by it.


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