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);
194 template <
typename T>
195 void add(
const std::string &collectionName, T &obj) {
196 if (collectionName.find(
'_') != std::string::npos) {
197 EXCEPTION_RAISE(
"IllegalName",
198 "The product name '" + collectionName +
199 "' is illegal as it contains an underscore.");
203 std::string branch_name;
205 branch_name = collectionName;
210 EXCEPTION_RAISE(
"ProductExists",
211 "A product named '" + collectionName +
212 "' already exists in the event (has been loaded by a "
213 "previous producer in this process).");
227 std::string tname =
typeid(obj).name();
235 std::string class_name{out_branch->GetClassName()};
236 if (not class_name.empty()) tname = class_name;
250 }
catch (
const std::bad_cast &) {
251 EXCEPTION_RAISE(
"TypeMismatch",
252 "Attempting to add an object whose type '" +
253 std::string(
typeid(obj).name()) +
254 "' doesn't match the type stored in the collection.");
298 template <
typename T>
300 const std::string &passName)
const {
302 std::string branch_name;
304 branch_name = collectionName;
305 }
else if (passName.empty()) {
312 if (matches.empty()) {
314 EXCEPTION_RAISE(
"ProductNotFound",
315 "No product found for name '" + collectionName +
"'");
316 }
else if (matches.size() > 1) {
318 std::stringstream names;
319 for (
auto strs : matches) {
320 names <<
"\n" << strs;
322 EXCEPTION_RAISE(
"ProductAmbiguous",
323 "Multiple products found for name '" +
325 "' without specified pass name :" + names.str());
354 "No product found for branch '" + branch_name +
"' on input tree.");
357 branch->SetStatus(1);
371 EXCEPTION_RAISE(
"InTreeInit",
372 "The input tree was un-initialized with read entry " +
373 std::to_string(ientry) +
374 " when attempting to get '" + branch_name +
"'.");
376 branch->GetEntry(ientry);
377 }
else if (not already_on_board) {
380 EXCEPTION_RAISE(
"ProductNotFound",
"No product found for name '" +
381 collectionName +
"' and pass '" +
390 const T &obj =
bus_.
get<T>(branch_name);
392 }
catch (
const std::bad_cast &) {
393 EXCEPTION_RAISE(
"BadType",
394 "Trying to get product from '" + branch_name +
395 "' but asking for wrong type: " +
typeid(T).name());
410 template <
typename ContentType>
412 const std::string &collectionName,
const std::string &passName)
const {
427 template <
typename KeyType,
typename ValType>
428 const std::map<KeyType, ValType> &
getMap(
const std::string &collectionName,
429 const std::string &passName)
const {
515 bool shouldDrop(
const std::string &collName)
const;
534 const std::string &passName)
const {
535 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.