fire v0.19.0
Framework for sImulation and Reconstruction of Events
|
class for easier reading of files written by fire More...
#include <UserReader.h>
Public Member Functions | |
UserReader (bool wrap_around=false) | |
Configure the reading mode. More... | |
UserReader (const std::string &fn, unsigned long int n=0, bool wrap_around=false) | |
Configure the reading mode and open a file. More... | |
void | open (const std::string &fn, unsigned long int n=0) |
Open the provided file, skipping an initial number of entries. More... | |
bool | next () |
go to the next event entry in the file More... | |
unsigned long int | entries () const |
number of events in this file More... | |
bool | is_open () const |
check if reader is open or not More... | |
template<typename T > | |
const T & | get (const std::string &name, const std::string &pass="") const |
get the object for the current entry under the passed name More... | |
Private Attributes | |
Event | event_ |
event bus for this reader | |
std::unique_ptr< io::Reader > | reader_ |
handle of underlying reader | |
unsigned long int | i_entry_ {0} |
index of entry within file that is open | |
bool | wrap_around_ {false} |
do we wrap from end to beginning or throw exception? | |
bool | in_file_ {false} |
have we started yet? | |
class for easier reading of files written by fire
The UserReader uses a specially-configured Event instance to interface with the file it is reading. This allows for it to read everything in the same manner that a processor would see while giving a user control over when to go to the next event in the file.
If the reader is configured to wrap around from the end of the file to the beginning, then the reader cannot be in control of the event loop (since it would be an infinite loop). The dummy example below shows how a user can go through a file of arbitrary number of non-zero events repeating if necessary.
fire::UserReader::UserReader | ( | bool | wrap_around = false | ) |
Configure the reading mode.
[in] | wrap_around | (optional) will we loop from end of file to beginning? |
fire::UserReader::UserReader | ( | const std::string & | fn, |
unsigned long int | n = 0 , |
||
bool | wrap_around = false |
||
) |
Configure the reading mode and open a file.
[in] | fn | file path to be opened |
[in] | n | (optional) number of entries at beginning of file to skip |
[in] | wrap_around | (optional) will we loop from end of file to beginning? |
unsigned long int fire::UserReader::entries | ( | ) | const |
number of events in this file
|
inline |
get the object for the current entry under the passed name
This is a direct call to Event::get so look there for more detailed documentation.
T | type of data |
[in] | name | name of event object |
[in] | pass | (optional) name of pass that produced the event object |
bool fire::UserReader::is_open | ( | ) | const |
check if reader is open or not
bool fire::UserReader::next | ( | ) |
go to the next event entry in the file
Exception | if a file hasn't been opened yet |
We simply mimic the interaction between Process and Event such that Event::next is called "after" the last event and Event::load is called in preparation for the next event. If we have been configured to wrap around, then we simply re-call open and next instead of returning false at the end of the file.
void fire::UserReader::open | ( | const std::string & | fn, |
unsigned long int | n = 0 |
||
) |
Open the provided file, skipping an initial number of entries.
Skipping the initial number of entries is done by just calling next the requested number of times. Without any objects loaded onto the event bus, this is simply moving the entry index within Event.
[in] | fn | file path to be opened |
[in] | n | (optional) number of entries at beginning of file to skip |