8#ifndef FRAMEWORK_EVENT_H_
9#define FRAMEWORK_EVENT_H_
15#include "Framework/Bus.h"
17#include "Framework/Exception/Exception.h"
48 Event(
const std::string &passName);
112 std::vector<ProductTag>
searchProducts(
const std::string &namematch,
113 const std::string &passmatch,
114 const std::string &typematch,
115 bool full_string_match =
false)
const;
145 bool exists(
const std::string &name,
const std::string &passName,
146 bool unique =
true)
const;
156 void addDrop(
const std::string &exp);
183 template <
typename T>
184 void add(
const std::string &collectionName, T &obj) {
185 if (collectionName.find(
'_') != std::string::npos) {
186 EXCEPTION_RAISE(
"IllegalName",
187 "The product name '" + collectionName +
188 "' is illegal as it contains an underscore.");
192 std::string branch_name;
194 branch_name = collectionName;
199 EXCEPTION_RAISE(
"ProductExists",
200 "A product named '" + collectionName +
201 "' already exists in the event (has been loaded by a "
202 "previous producer in this process).");
216 std::string tname =
typeid(obj).name();
224 std::string class_name{out_branch->GetClassName()};
225 if (not class_name.empty()) tname = class_name;
239 }
catch (
const std::bad_cast &) {
240 EXCEPTION_RAISE(
"TypeMismatch",
241 "Attempting to add an object whose type '" +
242 std::string(
typeid(obj).name()) +
243 "' doesn't match the type stored in the collection.");
287 template <
typename T>
289 const std::string &passName)
const {
291 std::string branch_name;
293 branch_name = collectionName;
294 }
else if (passName.empty()) {
301 if (matches.empty()) {
303 EXCEPTION_RAISE(
"ProductNotFound",
304 "No product found for name '" + collectionName +
"'");
305 }
else if (matches.size() > 1) {
307 std::stringstream names;
308 for (
auto strs : matches) {
309 names <<
"\n" << strs;
311 EXCEPTION_RAISE(
"ProductAmbiguous",
312 "Multiple products found for name '" +
314 "' without specified pass name :" + names.str());
343 "No product found for branch '" + branch_name +
"' on input tree.");
346 branch->SetStatus(1);
360 EXCEPTION_RAISE(
"InTreeInit",
361 "The input tree was un-initialized with read entry " +
362 std::to_string(ientry) +
363 " when attempting to get '" + branch_name +
"'.");
365 branch->GetEntry(ientry);
366 }
else if (not already_on_board) {
369 EXCEPTION_RAISE(
"ProductNotFound",
"No product found for name '" +
370 collectionName +
"' and pass '" +
379 const T &obj =
bus_.
get<T>(branch_name);
381 }
catch (
const std::bad_cast &) {
382 EXCEPTION_RAISE(
"BadType",
383 "Trying to get product from '" + branch_name +
384 "' but asking for wrong type: " +
typeid(T).name());
399 template <
typename ContentType>
401 const std::string &collectionName,
const std::string &passName)
const {
416 template <
typename KeyType,
typename ValType>
417 const std::map<KeyType, ValType> &
getMap(
const std::string &collectionName,
418 const std::string &passName)
const {
504 bool shouldDrop(
const std::string &collName)
const;
512 const std::string &passName)
const {
513 return collectionName +
"_" + passName;
Class defining the identity of a data product in the event.
const BaggageType & get(const std::string &name)
Get the baggage carried by the passenger with the passed name.
void update(const std::string &name, const BaggageType &obj)
Update the object a passenger is carrying.
bool isOnBoard(const std::string &name)
Check if a passenger is on the bus.
TBranch * attach(TTree *tree, const std::string &name, bool can_create)
Attach the input tree to the object a passenger is carrying.
void board(const std::string &name)
Board a new passenger onto the bus.
Implements an event buffer system for storing event data.
const ldmx::EventHeader & getEventHeader() const
Get the event header.
std::string makeBranchName(const std::string &collectionName) const
Make a branch name from a collection and the default(current) pass name.
bool exists(const std::string &name, const std::string &passName, bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
TTree * input_tree_
The input tree for reading existing data.
std::vector< ProductTag > products_
List of all the event products.
int getEventNumber() const
Get the event number.
std::vector< ProductTag > searchProducts(const std::string &namematch, const std::string &passmatch, const std::string &typematch, bool full_string_match=false) const
Get a list of products which match the given POSIX-Extended, case-insenstive regular-expressions.
int electron_count_
The total number of electrons in the event.
void clear()
Clear this object's data (including passengers).
~Event()
Class destructor.
void onEndOfFile()
Perform end of file action.
std::string makeBranchName(const std::string &collectionName, const std::string &passName) const
Make a branch name from a collection and pass name.
TTree * createTree()
Create the output data tree.
ldmx::EventHeader event_header_
The event header object.
void setElectronCount(const int &electronCount)
Set the beam electron count.
const std::map< KeyType, ValType > & getMap(const std::string &collectionName, const std::string &passName) const
Get a map (std::map) of objects from the event bus.
void setOutputTree(TTree *tree)
Set the output data tree.
std::string pass_name_
The default pass name.
double getEventWeight() const
Get the event weight.
void beforeFill()
Action to be executed before the tree is filled.
void onEndOfEvent()
Perform end of event action (doesn't do anything right now).
const std::vector< ProductTag > & getProducts() const
Get a list of the data products in the event.
framework::Bus bus_
The Bus.
Event(const std::string &passName)
Class constructor.
const T & getObject(const std::string &collectionName, const std::string &passName) const
Get an general object from the event bus.
std::set< std::string > branches_filled_
Names of branches filled during this event.
bool nextEvent()
Go to the next event by retrieving the event header.
ldmx::EventHeader & getEventHeader()
Get the event header.
const ldmx::EventHeader * getEventHeaderPtr()
Get the event header as a pointer.
std::vector< regex_t > regex_drop_collections_
Regex of collection names to not store in event.
const std::vector< ContentType > & getCollection(const std::string &collectionName, const std::string &passName) const
Get a collection (std::vector) of objects from the event bus.
void setInputTree(TTree *tree)
Set the input data tree.
void print() const
Print event bus.
std::string getPassName()
Get the current/default pass name.
void add(const std::string &collectionName, T &obj)
Adds an object to the event bus.
bool shouldDrop(const std::string &collName) const
Check if collection should be dropped.
TTree * output_tree_
The output tree for writing a new file.
std::map< std::string, std::string > known_lookups_
Efficiency cache for empty pass name lookups.
void addDrop(const std::string &exp)
Add a drop rule to the list of regex expressions to drop.
int getElectronCount() const
All classes in the ldmx-sw project use this namespace.