3#include "TBranchElement.h"
7Event::Event(
const std::string& thePassName) : passName_(thePassName) {}
17 std::cout << tag << std::endl;
23 if (!regcomp(®, exp.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB)) {
26 EXCEPTION_RAISE(
"InvalidRegex",
"The passed drop rule regex '" + exp +
27 "' is not a valid regex.");
48 bool full_string_match) {
49 std::string pattern_regex{pattern};
50 if (pattern_regex.empty())
52 else if (full_string_match)
53 pattern_regex =
"^" + pattern_regex +
"$";
56 if (regcomp(®, pattern_regex.c_str(),
57 REG_EXTENDED | REG_ICASE | REG_NOSUB)) {
60 EXCEPTION_RAISE(
"InvalidRegex",
"The passed regex '" + pattern +
61 "' is not a valid regular expression.");
67 const std::string& passmatch,
68 const std::string& typematch,
69 bool full_string_match)
const {
70 std::vector<ProductTag> retval;
76 const std::vector<ProductTag>& products =
getProducts();
77 for (std::vector<ProductTag>::const_iterator i = products.begin();
78 i != products.end(); i++) {
79 if (!regexec(®_name, i->name().c_str(), 0, 0, 0) &&
80 !regexec(®_pass, i->passname().c_str(), 0, 0, 0) &&
81 !regexec(®_type, i->type().c_str(), 0, 0, 0))
94 static const bool require_full_string_match =
true;
95 auto matches =
searchProducts(name, passName,
"", require_full_string_match);
97 return (matches.size() == 1);
99 return (matches.size() > 0);
103 outputTree_ =
new TTree(
"LDMX_Events",
"LDMX Events");
123 TObjArray* branches =
inputTree_->GetListOfBranches();
127 "Input tree doesn't have a list of branches but still made it to this "
128 "point. This is bad and has never been seen before!");
131 for (
int i = 0; i < branches->GetEntriesFast(); i++) {
133 if (branches->At(i)) {
134 brname = branches->At(i)->GetName();
137 size_t j = brname.find(
"_");
138 auto br =
dynamic_cast<TBranchElement*
>(branches->At(i));
145 brname.substr(j + 1),
146 br ? br->GetClassName() :
"BSILFD");
183 if (!regexec(&exp, branchName.c_str(), 0, 0, 0))
return true;
Class implementing an event buffer system for storing event data.
void clear()
Reset the objects carried by the passengers.
void everybodyOff()
Kicks all of the passengers off the bus and therefore destroys any objects they are carrying.
void Print() const
Print event bus.
std::vector< ProductTag > products_
List of all the event products.
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.
TTree * createTree()
Create the output data tree.
TTree * inputTree_
The input tree for reading existing data.
void setOutputTree(TTree *tree)
Set the output data tree.
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.
std::set< std::string > branchesFilled_
Names of branches filled during this event.
void setInputTree(TTree *tree)
Set the input data tree.
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.
Defines the identity of a product and can be used for searches.
All classes in the ldmx-sw project use this namespace.
static regex_t construct_regex(const std::string &pattern, bool full_string_match)
Construct an actual regex from the pass pattern (and full-string flag)