8#ifndef FRAMEWORK_EVENT_H_
9#define FRAMEWORK_EVENT_H_
15#include "Framework/Bus.h"
17#include "Framework/Exception/Exception.h"
47 Event(
const std::string &passName);
101 std::vector<ProductTag>
searchProducts(
const std::string &namematch,
102 const std::string &passmatch,
103 const std::string &typematch,
104 bool full_string_match =
false)
const;
134 bool exists(
const std::string &name,
const std::string &passName =
"",
135 bool unique =
true)
const;
145 void addDrop(
const std::string &exp);
172 template <
typename T>
173 void add(
const std::string &collectionName, T &obj) {
174 if (collectionName.find(
'_') != std::string::npos) {
175 EXCEPTION_RAISE(
"IllegalName",
176 "The product name '" + collectionName +
177 "' is illegal as it contains an underscore.");
181 std::string branchName;
183 branchName = collectionName;
188 EXCEPTION_RAISE(
"ProductExists",
189 "A product named '" + collectionName +
190 "' already exists in the event (has been loaded by a "
191 "previous producer in this process).");
205 std::string tname =
typeid(obj).name();
213 std::string class_name{outBranch->GetClassName()};
214 if (not class_name.empty()) tname = class_name;
228 }
catch (
const std::bad_cast &) {
229 EXCEPTION_RAISE(
"TypeMismatch",
230 "Attempting to add an object whose type '" +
231 std::string(
typeid(obj).name()) +
232 "' doesn't match the type stored in the collection.");
276 template <
typename T>
278 const std::string &passName =
"")
const {
280 std::string branchName;
282 branchName = collectionName;
283 }
else if (passName.empty()) {
290 if (matches.empty()) {
292 EXCEPTION_RAISE(
"ProductNotFound",
293 "No product found for name '" + collectionName +
"'");
294 }
else if (matches.size() > 1) {
296 std::stringstream names;
297 for (
auto strs : matches) {
298 names <<
"\n" << strs;
300 EXCEPTION_RAISE(
"ProductAmbiguous",
301 "Multiple products found for name '" +
303 "' without specified pass name :" + names.str());
330 EXCEPTION_RAISE(
"ProductNotFound",
"No product found for branch '" +
331 branchName +
"' on input tree.");
334 branch->SetStatus(1);
345 long long int ientry{
inputTree_->GetReadEntry()};
348 EXCEPTION_RAISE(
"InTreeInit",
349 "The input tree was un-initialized with read entry " +
350 std::to_string(ientry) +
351 " when attempting to get '" + branchName +
"'.");
353 branch->GetEntry(ientry);
354 }
else if (not already_on_board) {
357 EXCEPTION_RAISE(
"ProductNotFound",
"No product found for name '" +
358 collectionName +
"' and pass '" +
367 const T &obj =
bus_.
get<T>(branchName);
369 }
catch (
const std::bad_cast &) {
370 EXCEPTION_RAISE(
"BadType",
"Trying to get product from '" + branchName +
371 "' but asking for wrong type.");
385 template <
typename ContentType>
387 const std::string &collectionName,
388 const std::string &passName =
"")
const {
389 return getObject<std::vector<ContentType> >(collectionName, passName);
403 template <
typename KeyType,
typename ValType>
404 const std::map<KeyType, ValType> &
getMap(
405 const std::string &collectionName,
406 const std::string &passName =
"")
const {
407 return getObject<std::map<KeyType, ValType> >(collectionName, passName);
493 bool shouldDrop(
const std::string &collName)
const;
501 const std::string &passName)
const {
502 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.
std::string makeBranchName(const std::string &collectionName) const
Make a branch name from a collection and the default(current) pass name.
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 Print() const
Print event bus.
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.
std::vector< regex_t > regexDropCollections_
Regex of collection names to not store in event.
std::map< std::string, std::string > knownLookups_
Efficiency cache for empty pass name lookups.
~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.
void setElectronCount(const int &electronCount)
Set the beam electron count.
std::string passName_
The default pass name.
TTree * inputTree_
The input tree for reading existing data.
void setOutputTree(TTree *tree)
Set the output data tree.
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).
void Clear()
Clear this object's data (including passengers).
const std::vector< ProductTag > & getProducts() const
Get a list of the data products in the event.
TTree * outputTree_
The output tree for writing a new file.
ldmx::EventHeader eventHeader_
The event header object.
framework::Bus bus_
The Bus.
bool nextEvent()
Go to the next event by retrieving the event header.
ldmx::EventHeader & getEventHeader()
Get the event header.
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.
const ldmx::EventHeader * getEventHeaderPtr()
Get the event header as a pointer.
std::set< std::string > branchesFilled_
Names of branches filled during this event.
void setInputTree(TTree *tree)
Set the input data tree.
std::string getPassName()
Get the current/default pass name.
int electronCount_
The total number of electrons in the event.
const T & getObject(const std::string &collectionName, const std::string &passName="") const
Get an general object from the event bus.
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.
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.
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.