8#ifndef FRAMEWORK_EVENT_H_
9#define FRAMEWORK_EVENT_H_
15#include "Framework/Bus.h"
17#include "Framework/Exception/Exception.h"
46 Event(
const std::string& passName);
110 std::vector<ProductTag>
searchProducts(
const std::string& namematch,
111 const std::string& passmatch,
112 const std::string& typematch,
113 bool full_string_match =
false)
const;
143 bool exists(
const std::string& name,
const std::string& passName,
144 bool unique =
true)
const;
154 void addDrop(
const std::string& exp);
192 template <
typename T>
193 void add(
const std::string& collectionName, T& obj) {
194 if (collectionName.find(
'_') != std::string::npos) {
195 EXCEPTION_RAISE(
"IllegalName",
196 "The product name '" + collectionName +
197 "' is illegal as it contains an underscore.");
201 std::string branch_name;
203 branch_name = collectionName;
208 EXCEPTION_RAISE(
"ProductExists",
209 "A product named '" + collectionName +
210 "' already exists in the event (has been loaded by a "
211 "previous producer in this process).");
225 std::string tname =
typeid(obj).name();
233 std::string class_name{out_branch->GetClassName()};
234 if (not class_name.empty()) tname = class_name;
248 }
catch (
const std::bad_cast&) {
249 EXCEPTION_RAISE(
"TypeMismatch",
250 "Attempting to add an object whose type '" +
251 std::string(
typeid(obj).name()) +
252 "' doesn't match the type stored in the collection.");
296 template <
typename T>
298 const std::string& passName)
const {
300 std::string branch_name;
302 branch_name = collectionName;
303 }
else if (passName.empty()) {
310 if (matches.empty()) {
312 EXCEPTION_RAISE(
"ProductNotFound",
313 "No product found for name '" + collectionName +
"'");
314 }
else if (matches.size() > 1) {
316 std::stringstream names;
317 for (
auto strs : matches) {
318 names <<
"\n" << strs;
320 EXCEPTION_RAISE(
"ProductAmbiguous",
321 "Multiple products found for name '" +
323 "' without specified pass name :" + names.str());
352 "No product found for branch '" + branch_name +
"' on input tree.");
355 branch->SetStatus(1);
369 EXCEPTION_RAISE(
"InTreeInit",
370 "The input tree was un-initialized with read entry " +
371 std::to_string(ientry) +
372 " when attempting to get '" + branch_name +
"'.");
374 branch->GetEntry(ientry);
375 }
else if (not already_on_board) {
378 EXCEPTION_RAISE(
"ProductNotFound",
"No product found for name '" +
379 collectionName +
"' and pass '" +
388 const T& obj =
bus_.
get<T>(branch_name);
390 }
catch (
const std::bad_cast&) {
391 EXCEPTION_RAISE(
"BadType",
392 "Trying to get product from '" + branch_name +
393 "' but asking for wrong type: " +
typeid(T).name());
408 template <
typename ContentType>
410 const std::string& collectionName,
const std::string& passName)
const {
425 template <
typename KeyType,
typename ValType>
426 const std::map<KeyType, ValType>&
getMap(
const std::string& collectionName,
427 const std::string& passName)
const {
513 bool shouldDrop(
const std::string& collName)
const;
532 const std::string& passName)
const {
533 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.
void addIgnore(const std::string &exp)
Add an ignore rule to the list of regex expressions to ignore on input.
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.
std::vector< regex_t > regex_ignore_collections_
Regex of branch names to not even read from the input tree.
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.
bool shouldIgnore(const std::string &branchName) const
Check if a branch from the input tree should be ignored.
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.