5#include <boost/core/demangle.hpp>
7#include "fire/io/Data.h"
9#include "fire/EventHeader.h"
95 return os <<
"Object(pass=" << t.
pass() <<
", name=" << t.
name() <<
"type=" << t.
type() <<
")";
204 return search(
"^" + name +
"$", pass,
"").size() == 1;
241 template <
typename DataType>
243 static const bool ADD_KEEP_DEFAULT =
true;
254 if (
search(
"^"+name+
"$",
"^"+
pass_+
"$",
".*").size() > 0) {
256 "Data named "+full_name+
" already exists in the input file.");
259 boost::core::demangle(
typeid(DataType).name()),
260 io::class_version<DataType>,
261 keep(full_name, ADD_KEEP_DEFAULT))};
276 obj.should_save_ = tag.keep_;
277 obj.should_load_ =
false;
278 obj.updated_ =
false;
284 if (obj.should_save_) {
296 "Data named " + full_name +
" already added to the event"
297 " by a previous producer in the sequence.");
302 obj.getDataRef<DataType>().update(data);
306 "Data corresponding to " + full_name +
" has different type.");
348 template <
typename DataType>
352 if (not pass.empty()) {
359 auto options{
search(
"^" + name +
"$",
".*",
".*")};
360 if (options.size() == 0) {
362 "Data " + name +
" not found.");
363 }
else if (options.size() > 1) {
365 "Data " + name +
" is ambiguous. Provide a pass name.");
369 full_name =
fullName(options.at(0).name(), options.at(0).pass());
370 type = options.
at(0).type();
379 "Data " + full_name +
" was not created by an earlier processor "
380 "and there is no input file to attempt to read it from.");
389 return fullName(tag.name(),tag.pass()) == full_name;
391 tag_it->loaded_ =
true;
406 obj.should_save_ = tag_it->keep();
407 obj.should_load_ =
true;
408 obj.updated_ =
false;
415 if (obj.should_save_) {
427 }
catch (
const HighFive::DataSetException&) {
429 "Data " + full_name +
" could not be loaded into "
430 + boost::core::demangle(
typeid(DataType).name())
431 +
" from the type it was written as " + type);
437 return objects_[full_name].getDataRef<DataType>().
get();
440 "Data " + full_name +
" was initialy loaded with type " + type
441 +
" which cannot be casted into "
442 + boost::core::demangle(
typeid(DataType).name()));
464 return (pass.
empty() ?
pass_ : pass) +
"/" + name;
584 template <
typename DataType>
Serialization class version deduction.
Identification for a specific event object.
Definition: Event.h:42
std::string name_
Name given to the object.
Definition: Event.h:117
const bool keep() const
Get if this object will be kept (i.e.
Definition: Event.h:83
int version_
The version of the type.
Definition: Event.h:132
bool loaded_
If the object represented by this tag has been loaded into a memory object.
Definition: Event.h:148
std::string type_
Type name of the object.
Definition: Event.h:127
std::string pass_
Pass name given when object was generated.
Definition: Event.h:122
friend std::ostream & operator<<(std::ostream &os, const EventObjectTag &t)
String method for printing this tag in a helpful manner.
Definition: Event.h:94
bool match(const std::regex &name, const std::regex &pass, const std::regex &type) const
Checks if we match the passed regex for name, pass, and type.
Definition: Event.h:101
int version() const
Get the version number of the type of this object.
Definition: Event.h:77
EventObjectTag(const std::string &name, const std::string &pass, const std::string &type, int vers, bool keep)
Wrap the three pieces of information in our class.
Definition: Event.h:51
const std::string & pass() const
Get the pass name the object was produced on.
Definition: Event.h:65
const bool loaded() const
Get if this object is currently loaded in memory.
Definition: Event.h:89
const std::string & type() const
Get the name of the type of the object.
Definition: Event.h:71
const std::string & name() const
Get the object name.
Definition: Event.h:59
bool keep_
If the object represented by this tag should be kept.
Definition: Event.h:139
Event class for interfacing with processors.
Definition: Event.h:28
const EventHeader & header() const
Get the event header.
Definition: Event.h:156
EventHeader & header()
Get non-const event header.
Definition: Event.h:168
long unsigned int i_entry_
current index in the datasets
Definition: Event.h:602
std::string pass_
name of current processing pass
Definition: Event.h:564
io::Writer * output_file_
handle to output file (owned by Process)
Definition: Event.h:562
Event(const Event &)=delete
Delete the copy constructor to prevent any in-advertent copies.
std::vector< std::pair< std::regex, bool > > drop_keep_rules_
regular expressions determining if a dataset should be written to output file
Definition: Event.h:605
void operator=(const Event &)=delete
Delete the assignment operator to prevent any in-advertent copies.
void next()
Move to the next event we just need to keep our entry index up-to-date for loading a newly requested ...
Definition: Event.cxx:109
std::string fullName(const std::string &name, const std::string &pass) const
Deduce full data set name given a pass or using our pass.
Definition: Event.h:463
std::vector< EventObjectTag > search(const std::string &namematch, const std::string &passmatch, const std::string &typematch) const
Search through the available objects for a specific match.
Definition: Event.cxx:5
std::unique_ptr< EventHeader > header_
header that we control
Definition: Event.h:558
io::Reader * input_file_
pointer to input file (nullptr if no input files)
Definition: Event.h:560
void load()
Go through and load the next entry into the in-memory objects from the input file.
Definition: Event.cxx:84
const DataType & get(const std::string &name, const std::string &pass="") const
get a piece of data from the event
Definition: Event.h:349
bool keep(const std::string &full_name, bool def) const
Determine if the passed data set should be saved into output file.
Definition: Event.cxx:22
std::unordered_map< std::string, EventObject > objects_
list of event objects being processed
Definition: Event.h:600
void add(const std::string &name, const DataType &data)
add a piece of data to the event
Definition: Event.h:242
void save()
Go through and save the current in-memory objects into the output file.
Definition: Event.cxx:68
bool exists(const std::string &name, const std::string &pass="") const
Check if the input name and (optional) pass exist in the bus.
Definition: Event.h:203
void setInputFile(io::Reader *r)
Attach a file to this event as the input file.
Definition: Event.cxx:90
std::vector< EventObjectTag > available_objects_
list of objects available to us either on disk or newly created
Definition: Event.h:607
std::unordered_map< std::string, std::string > known_lookups_
cache of known lookups when requesting an object without a pass name
Definition: Event.h:609
void done()
Let the event bus know we are done.
Definition: Event.cxx:114
Standard base exception class with some useful output information.
Definition: Exception.h:18
The central object managing the data processing.
Definition: Process.h:16
class for easier reading of files written by fire
Definition: UserReader.h:44
General data set.
Definition: Data.h:90
Prototype for reading files within fire.
Definition: Reader.h:29
virtual void load_into(BaseData &d)=0
Load the current event into the passed data object.
virtual bool canCopy() const
Event::get needs to know if the reader implements a copy that advances the entry index of the data se...
Definition: Reader.h:97
Write the fire DataSets into a deterministic structure in the output HDF5 data file.
Definition: Writer.h:19
fire::Process Process
alias Process into this namespace
Definition: EventProcessor.h:105
structure to hold event data in memory
Definition: Event.h:568
bool should_load_
should we load the data from the input file?
Definition: Event.h:576
void clear()
Clear the event object at the end of an event.
Definition: Event.h:594
std::unique_ptr< io::BaseData > data_
the data for save/load
Definition: Event.h:572
io::Data< DataType > & getDataRef()
Helper for getting a reference to the dataset.
Definition: Event.h:585
bool should_save_
should we save the data into output file?
Definition: Event.h:574
bool updated_
have we been updated on the current event?
Definition: Event.h:578
static const std::string EVENT_GROUP
the name of the group in the file holding all event objects
Definition: Constants.h:22