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);
102 std::vector<ProductTag>
searchProducts(
const std::string &namematch,
103 const std::string &passmatch,
104 const std::string &typematch,
105 bool full_string_match =
false)
const;
135 bool exists(
const std::string &name,
const std::string &passName =
"",
136 bool unique =
true)
const;
146 void addDrop(
const std::string &exp);
173 template <
typename T>
174 void add(
const std::string &collectionName, T &obj) {
175 if (collectionName.find(
'_') != std::string::npos) {
176 EXCEPTION_RAISE(
"IllegalName",
177 "The product name '" + collectionName +
178 "' is illegal as it contains an underscore.");
182 std::string branchName;
184 branchName = collectionName;
189 EXCEPTION_RAISE(
"ProductExists",
190 "A product named '" + collectionName +
191 "' already exists in the event (has been loaded by a "
192 "previous producer in this process).");
206 std::string tname =
typeid(obj).name();
214 std::string class_name{outBranch->GetClassName()};
215 if (not class_name.empty()) tname = class_name;
229 }
catch (
const std::bad_cast &) {
230 EXCEPTION_RAISE(
"TypeMismatch",
231 "Attempting to add an object whose type '" +
232 std::string(
typeid(obj).name()) +
233 "' doesn't match the type stored in the collection.");
174 void add(
const std::string &collectionName, T &obj) {
…}
277 template <
typename T>
279 const std::string &passName =
"")
const {
281 std::string branchName;
283 branchName = collectionName;
284 }
else if (passName.empty()) {
291 if (matches.empty()) {
293 EXCEPTION_RAISE(
"ProductNotFound",
294 "No product found for name '" + collectionName +
"'");
295 }
else if (matches.size() > 1) {
297 std::stringstream names;
298 for (
auto strs : matches) {
299 names <<
"\n" << strs;
301 EXCEPTION_RAISE(
"ProductAmbiguous",
302 "Multiple products found for name '" +
304 "' without specified pass name :" + names.str());
331 EXCEPTION_RAISE(
"ProductNotFound",
"No product found for branch '" +
332 branchName +
"' on input tree.");
335 branch->SetStatus(1);
346 long long int ientry{
inputTree_->GetReadEntry()};
349 EXCEPTION_RAISE(
"InTreeInit",
350 "The input tree was un-initialized with read entry " +
351 std::to_string(ientry) +
352 " when attempting to get '" + branchName +
"'.");
354 branch->GetEntry(ientry);
355 }
else if (not already_on_board) {
358 EXCEPTION_RAISE(
"ProductNotFound",
"No product found for name '" +
359 collectionName +
"' and pass '" +
368 const T &obj =
bus_.
get<T>(branchName);
370 }
catch (
const std::bad_cast &) {
371 EXCEPTION_RAISE(
"BadType",
372 "Trying to get product from '" + branchName +
373 "' but asking for wrong type: " +
typeid(T).name());
387 template <
typename ContentType>
389 const std::string &collectionName,
390 const std::string &passName =
"")
const {
405 template <
typename KeyType,
typename ValType>
406 const std::map<KeyType, ValType> &
getMap(
407 const std::string &collectionName,
408 const std::string &passName =
"")
const {
495 bool shouldDrop(
const std::string &collName)
const;
503 const std::string &passName)
const {
504 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.
Event(const std::string &passName)
Class constructor.
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.