LDMX Software
framework::Event Class Reference

Implements an event buffer system for storing event data. More...

#include <Event.h>

Public Member Functions

 Event (const std::string &passName)
 Class constructor.
 
 ~Event ()
 Class destructor.
 
ldmx::EventHeadergetEventHeader ()
 Get the event header.
 
const ldmx::EventHeadergetEventHeader () const
 Get the event header.
 
const ldmx::EventHeadergetEventHeaderPtr ()
 Get the event header as a pointer.
 
int getEventNumber () const
 Get the event number.
 
double getEventWeight () const
 Get the event weight.
 
void print () const
 Print event bus.
 
std::vector< ProductTagsearchProducts (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.
 
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.
 
void addIgnore (const std::string &exp)
 Add an ignore rule to the list of regex expressions to ignore on input.
 
template<typename T >
void add (const std::string &collectionName, T &obj)
 Adds an object to the event bus.
 
template<typename T >
const T & getObject (const std::string &collectionName, const std::string &passName) const
 Get an general object from the event bus.
 
template<typename ContentType >
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.
 
template<typename KeyType , typename ValType >
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.
 
void setInputTree (TTree *tree)
 Set the input data tree.
 
void setOutputTree (TTree *tree)
 Set the output data tree.
 
TTree * createTree ()
 Create the output data tree.
 
const std::vector< ProductTag > & getProducts () const
 Get a list of the data products in the event.
 
bool nextEvent ()
 Go to the next event by retrieving the event header.
 
void beforeFill ()
 Action to be executed before the tree is filled.
 
void clear ()
 Clear this object's data (including passengers).
 
void onEndOfEvent ()
 Perform end of event action (doesn't do anything right now).
 
void onEndOfFile ()
 Perform end of file action.
 
std::string getPassName ()
 Get the current/default pass name.
 
int getElectronCount () const
 
void setElectronCount (const int &electronCount)
 Set the beam electron count.
 

Private Member Functions

bool shouldDrop (const std::string &collName) const
 Check if collection should be dropped.
 
bool shouldIgnore (const std::string &branchName) const
 Check if a branch from the input tree should be ignored.
 
std::string makeBranchName (const std::string &collectionName, const std::string &passName) const
 Make a branch name from a collection and pass name.
 
std::string makeBranchName (const std::string &collectionName) const
 Make a branch name from a collection and the default(current) pass name.
 

Private Attributes

ldmx::EventHeader event_header_
 The event header object.
 
std::string pass_name_
 The default pass name.
 
TTree * output_tree_ {nullptr}
 The output tree for writing a new file.
 
TTree * input_tree_ {nullptr}
 The input tree for reading existing data.
 
int electron_count_ {1}
 The total number of electrons in the event.
 
framework::Bus bus_
 The Bus.
 
std::set< std::string > branches_filled_
 Names of branches filled during this event.
 
std::vector< regex_t > regex_drop_collections_
 Regex of collection names to not store in event.
 
std::vector< regex_t > regex_ignore_collections_
 Regex of branch names to not even read from the input tree.
 
std::map< std::string, std::string > known_lookups_
 Efficiency cache for empty pass name lookups.
 
std::vector< ProductTagproducts_
 List of all the event products.
 

Detailed Description

Implements an event buffer system for storing event data.

Event data is stored in ROOT trees and branches for persistency. For the buffering, we use a multi-layered inheritance tree that is wrapped inside of the Bus class.

See also
framework::Bus for this buffering tool

Definition at line 42 of file Event.h.

Constructor & Destructor Documentation

◆ Event()

framework::Event::Event ( const std::string & passName)

Class constructor.

Parameters
passNameThe default pass name for adding event data.

Definition at line 7 of file Event.cxx.

7: pass_name_(thePassName) {}
std::string pass_name_
The default pass name.
Definition Event.h:555

◆ ~Event()

framework::Event::~Event ( )

Class destructor.

Definition at line 9 of file Event.cxx.

9 {
10 for (regex_t& reg : regex_drop_collections_) {
11 regfree(&reg);
12 }
13 for (regex_t& reg : regex_ignore_collections_) {
14 regfree(&reg);
15 }
16}
std::vector< regex_t > regex_ignore_collections_
Regex of branch names to not even read from the input tree.
Definition Event.h:598
std::vector< regex_t > regex_drop_collections_
Regex of collection names to not store in event.
Definition Event.h:593

References regex_drop_collections_, and regex_ignore_collections_.

Member Function Documentation

◆ add()

template<typename T >
void framework::Event::add ( const std::string & collectionName,
T & obj )
inline

Adds an object to the event bus.

Exceptions
Exceptionif there is an underscore in the collection name.
Exceptionif there already has been a branch filled with the constructed name.
Exceptionif the type we are putting in mis-matches the type in the bus under the input name.
See also
makeBranchName The branch name is constructed from the collection name using the current pass name.
Bus::board
Bus::attach If the branch is not on the bus yet, we board the bus and check if we need to attach the object to a tree.
Bus::update We always update the contents of the bus object with the input object.
Parameters
collectionName
objin ROOT dictionary to add

Definition at line 195 of file Event.h.

195 {
196 if (collectionName.find('_') != std::string::npos) {
197 EXCEPTION_RAISE("IllegalName",
198 "The product name '" + collectionName +
199 "' is illegal as it contains an underscore.");
200 }
201
202 // determine the branch name
203 std::string branch_name;
204 if (collectionName == ldmx::EventHeader::BRANCH)
205 branch_name = collectionName;
206 else
207 branch_name = makeBranchName(collectionName);
208
209 if (branches_filled_.find(branch_name) != branches_filled_.end()) {
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).");
214 }
215 branches_filled_.insert(branch_name);
216 // MEMORY add is leaking memory when given a vector (possible upon
217 // destruction of Event?) MEMORY add is 'conditional jump or move depends on
218 // uninitialised values' for all types of objects
219 // TTree::BranchImpRef or TTree::BronchExec
220 if (not bus_.isOnBoard(branch_name)) {
221 // create a new branch for this collection
222
223 // have type T board bus under name 'branchName'
224 bus_.board<T>(branch_name);
225
226 // type name (want to use branch element if possible)
227 std::string tname = typeid(obj).name();
228
229 if (output_tree_ and not shouldDrop(branch_name)) {
230 // we are writing this branch to an output file, so let's
231 // attach this passenger to the output tree
232 TBranch *out_branch = bus_.attach(output_tree_, branch_name, true);
233 // get type name from branch if possible,
234 // otherwise use compiler level type name (above)
235 std::string class_name{out_branch->GetClassName()};
236 if (not class_name.empty()) tname = class_name;
237 } // output tree exists or not
238
239 // check for cache entry to remove
240 auto it_known{known_lookups_.find(collectionName)};
241 if (it_known != known_lookups_.end()) known_lookups_.erase(it_known);
242
243 // add us to list of products
244 products_.emplace_back(collectionName, pass_name_, tname);
245 }
246
247 // copy input contents into bus passenger
248 try {
249 bus_.update(branch_name, obj);
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.");
255 }
256
257 return;
258 }
void update(const std::string &name, const BaggageType &obj)
Update the object a passenger is carrying.
Definition Bus.h:83
bool isOnBoard(const std::string &name)
Check if a passenger is on the bus.
Definition Bus.h:117
TBranch * attach(TTree *tree, const std::string &name, bool can_create)
Attach the input tree to the object a passenger is carrying.
Definition Bus.h:107
void board(const std::string &name)
Board a new passenger onto the bus.
Definition Bus.h:65
std::vector< ProductTag > products_
List of all the event products.
Definition Event.h:608
std::string makeBranchName(const std::string &collectionName, const std::string &passName) const
Make a branch name from a collection and pass name.
Definition Event.h:533
framework::Bus bus_
The Bus.
Definition Event.h:578
std::set< std::string > branches_filled_
Names of branches filled during this event.
Definition Event.h:588
bool shouldDrop(const std::string &collName) const
Check if collection should be dropped.
Definition Event.cxx:195
TTree * output_tree_
The output tree for writing a new file.
Definition Event.h:560
std::map< std::string, std::string > known_lookups_
Efficiency cache for empty pass name lookups.
Definition Event.h:603
static const std::string BRANCH
Name of EventHeader branch.
Definition EventHeader.h:49

References framework::Bus::attach(), framework::Bus::board(), ldmx::EventHeader::BRANCH, branches_filled_, bus_, framework::Bus::isOnBoard(), known_lookups_, makeBranchName(), output_tree_, pass_name_, products_, shouldDrop(), and framework::Bus::update().

Referenced by beforeFill(), packing::rawdatafile::File::nextEvent(), and trigscint::ZCCMDecoder::produce().

◆ addDrop()

void framework::Event::addDrop ( const std::string & exp)

Add a drop rule to the list of regex expressions to drop.

If a collection name matches one of the stored regex expressions, it will be stored as a passenger but not added to output tree.

Parameters
expregex to match

Definition at line 24 of file Event.cxx.

24 {
25 regex_t reg;
26 if (!regcomp(&reg, exp.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB)) {
27 regex_drop_collections_.push_back(reg);
28 } else {
29 EXCEPTION_RAISE("InvalidRegex", "The passed drop rule regex '" + exp +
30 "' is not a valid regex.");
31 }
32}

References regex_drop_collections_.

Referenced by framework::EventFile::addDrop().

◆ addIgnore()

void framework::Event::addIgnore ( const std::string & exp)

Add an ignore rule to the list of regex expressions to ignore on input.

If a branch name matches one of the stored regex expressions, it will not be added to the list of known products when reading the input tree. This prevents processors from accessing these collections at all.

Parameters
expregex to match

Definition at line 34 of file Event.cxx.

34 {
35 regex_t reg;
36 if (!regcomp(&reg, exp.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB)) {
37 regex_ignore_collections_.push_back(reg);
38 } else {
39 EXCEPTION_RAISE("InvalidRegex", "The passed ignore rule regex '" + exp +
40 "' is not a valid regex.");
41 }
42}

References regex_ignore_collections_.

Referenced by framework::EventFile::addDrop().

◆ beforeFill()

void framework::Event::beforeFill ( )

Action to be executed before the tree is filled.

Definition at line 170 of file Event.cxx.

170 {
172 branches_filled_.end()) {
173 // Event Header not copied from input and hasn't been added yet, need to put
174 // it in
176 }
177}
TTree * input_tree_
The input tree for reading existing data.
Definition Event.h:565
ldmx::EventHeader event_header_
The event header object.
Definition Event.h:550
void add(const std::string &collectionName, T &obj)
Adds an object to the event bus.
Definition Event.h:195

References add(), ldmx::EventHeader::BRANCH, branches_filled_, event_header_, and input_tree_.

Referenced by framework::EventFile::nextEvent().

◆ clear()

void framework::Event::clear ( )

Clear this object's data (including passengers).

Definition at line 179 of file Event.cxx.

179 {
180 branches_filled_.clear(); // forget names of branches we filled
181 bus_.clear(); // clear the event objects individually but leave them on bus
182}
void clear()
Reset the objects carried by the passengers.
Definition Bus.h:126

References branches_filled_, bus_, and framework::Bus::clear().

Referenced by framework::EventFile::nextEvent().

◆ createTree()

TTree * framework::Event::createTree ( )

Create the output data tree.

Returns
The output data tree.

Definition at line 115 of file Event.cxx.

115 {
116 output_tree_ = new TTree("LDMX_Events", "LDMX Events");
117
118 return output_tree_;
119}

References output_tree_.

Referenced by framework::EventFile::setupEvent().

◆ exists()

bool framework::Event::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.

This function just uses the searchProducts function while requiring the input name and pass to match the full string.

See also
searchProducts for a more flexible method for existence checking. If you have any situation more complicated than simply checking if a collection with exactly the input name, it is recommended to use the searchProducts function directly. Within a processor, one can access and print the products from a search relatively easily.
auto matches{event.searchProducts("MyCollection","","")};
std::cout << matches.size() << " event objects match pattern" << std::endl;
for (const auto& match : matches) { std::cout << match << std::endl; }
searchProducts returns a list of ProductTag objects that store the name, pass, and type of the objects matching the search.
Parameters
nameName (label, not class name) given to the object when it was put into the event.
passNameThe process pass label which was in use when this object was put into the event, such as "sim" or "rerecov2".
uniquetrue if requiring one and only one matching object, false if allowing for one or more matching objects
Returns
True if the object or collection exists in the event.

Definition at line 105 of file Event.cxx.

106 {
107 static const bool require_full_string_match = true;
108 auto matches = searchProducts(name, passName, "", require_full_string_match);
109 if (unique)
110 return (matches.size() == 1);
111 else
112 return (matches.size() > 0);
113}
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.
Definition Event.cxx:79

References searchProducts().

Referenced by dqm::EcalDigiVerifier::analyze(), dqm::TrigScintClusterDQM::analyze(), dqm::VisiblesCutflow::analyze(), dqm::VisiblesFeatureProducer::analyze(), tracking::dqm::StraightTracksDQM::analyze(), tracking::dqm::TrackerDigiDQM::analyze(), tracking::dqm::TrackingRecoDQM::analyze(), trigger::DumpFileWriter::analyze(), trigscint::TestBeamClusterAnalyzer::analyze(), packing::rawdatafile::File::nextEvent(), ecal::EcalPnetVetoProcessor::produce(), ecal::EcalRecProducer::produce(), ecal::EcalVetoProcessor::produce(), ecal::EcalWABRecProcessor::produce(), hcal::HcalRecProducer::produce(), hcal::VisiblesVetoProcessor::produce(), recon::BeamElectronLocator::produce(), recon::ElectronCounter::produce(), recon::MyProcessor::produce(), recon::ParticleFlow::produce(), recon::PFEcalClusterProducer::produce(), recon::PFHcalClusterProducer::produce(), recon::PFTrackProducer::produce(), recon::PFTruthProducer::produce(), recon::PileupFinder::produce(), recon::TrackDeDxMassEstimator::produce(), tracking::reco::CKFProcessor::produce(), tracking::reco::GreedyAmbiguitySolver::produce(), tracking::reco::GSFProcessor::produce(), tracking::reco::LinearSeedFinder::produce(), tracking::reco::SeedFinderProcessor::produce(), trigger::EcalTPSelector::produce(), trigger::HcalTPSelector::produce(), trigger::NtupleWriter::produce(), trigger::PropagationMapWriter::produce(), trigger::TrigEcalClusterProducer::produce(), trigger::TrigEcalEnergySum::produce(), trigger::TrigElectronProducer::produce(), trigger::TrigHcalEnergySum::produce(), trigger::TrigMipReco::produce(), trigscint::TrigScintTrackProducer::produce(), and trigscint::TruthHitProducer::produce().

◆ getCollection()

template<typename ContentType >
const std::vector< ContentType > & framework::Event::getCollection ( const std::string & collectionName,
const std::string & passName ) const
inline

Get a collection (std::vector) of objects from the event bus.

See also
getObject for actual implementation
Template Parameters

in,out] ContentType type of object stored in the vector

Parameters
[in]collectionNamename of collection that we want
[in]passNamename of specific pass we want, optional
Returns
const reference to collection of objects on the bus

Definition at line 411 of file Event.h.

412 {
413 return getObject<std::vector<ContentType> >(collectionName, passName);
414 }
const T & getObject(const std::string &collectionName, const std::string &passName) const
Get an general object from the event bus.
Definition Event.h:299

References getObject().

Referenced by dqm::SampleValidation::analyze(), packing::rawdatafile::File::nextEvent(), hcal::HcalRawDecoder::produce(), and recon::OverlayProducer::produce().

◆ getElectronCount()

int framework::Event::getElectronCount ( ) const
inline
Returns
The beam electron count.

Definition at line 497 of file Event.h.

497{ return electron_count_; }
int electron_count_
The total number of electrons in the event.
Definition Event.h:568

References electron_count_.

◆ getEventHeader() [1/2]

ldmx::EventHeader & framework::Event::getEventHeader ( )
inline

◆ getEventHeader() [2/2]

const ldmx::EventHeader & framework::Event::getEventHeader ( ) const
inline

Get the event header.

Returns
A constant reference to the event header.

Definition at line 65 of file Event.h.

65{ return event_header_; }

References event_header_.

◆ getEventHeaderPtr()

const ldmx::EventHeader * framework::Event::getEventHeaderPtr ( )
inline

Get the event header as a pointer.

Note
This is only helpful for the internal workings of the framework and should not be used by processors. Use getEventHeader instead.
Returns
A const pointer to the event header.

Definition at line 75 of file Event.h.

75{ return &event_header_; }

References event_header_.

Referenced by framework::Process::run().

◆ getEventNumber()

int framework::Event::getEventNumber ( ) const
inline

Get the event number.

Returns
the event index_/number

Definition at line 81 of file Event.h.

81{ return event_header_.getEventNumber(); }
int getEventNumber() const
Return the event number.
Definition EventHeader.h:78

References event_header_, and ldmx::EventHeader::getEventNumber().

Referenced by Standalone::analyze(), packing::rawdatafile::File::nextEvent(), and framework::Process::run().

◆ getEventWeight()

double framework::Event::getEventWeight ( ) const
inline

Get the event weight.

Returns
weight from the EventHeader

Definition at line 87 of file Event.h.

87{ return event_header_.getWeight(); }
double getWeight() const
Get the event weight (default of 1.0).
Definition EventHeader.h:98

References event_header_, and ldmx::EventHeader::getWeight().

◆ getMap()

template<typename KeyType , typename ValType >
const std::map< KeyType, ValType > & framework::Event::getMap ( const std::string & collectionName,
const std::string & passName ) const
inline

Get a map (std::map) of objects from the event bus.

See also
getObject for actual implementation
Template Parameters

in,out] KeyType type of object used as the key in the map

Template Parameters

in,out] ValType type of object used as the value in the map

Parameters
[in]collectionNamename of collection that we want
[in]passNamename of specific pass we want, optional
Returns
const reference to collection of objects on the bus

Definition at line 428 of file Event.h.

429 {
430 return getObject<std::map<KeyType, ValType> >(collectionName, passName);
431 }

References getObject().

Referenced by recon::OverlayProducer::produce().

◆ getObject()

template<typename T >
const T & framework::Event::getObject ( const std::string & collectionName,
const std::string & passName ) const
inline

Get an general object from the event bus.

First we determine the branch name. If the collection is the EventHeader or if the passName is given, this is easy. But if the pass name is empty, we try to find a matching collection under the list of branch names. We will throw an exception if we don't find a unique branch corresponding to the collection. We also employ a rudimentary caching system for mapping collection names to branches (if no pass name is given) so this looping only needs to happen once.

See also
EventHeader::BRANCH for the name of the event header branch
makeBranchName for how we make branch names from object/pass names
Exceptions
Exceptionif unable to uniquely determine the branch name from the collection name alone.

If the object we are asking for is already on the bus, we simply make sure the branch corresponding to it is on the correct entry.

If the object we are asking for is not on the bus and there is an input tree, we look for a branch on the input tree corresponding to the branch name and then we load the current entry of that branch.

Exceptions
Exceptionif can't find a corresponding branch name on the input tree or in the bus
Exceptionif we are trying to load a new branch and the input tree has negative read entry (i.e. it is uninitialized)
See also
Bus::board
Bus::attach

Finally, we return a const reference to the object on the bus.

Exceptions
Exceptionif mismatching type
See also
Bus::get
Template Parameters
Ttype of object we should be getting
Parameters
collectionNamename of collection you want
passNamename of pass you want
Returns
const reference to requested object

Load in the current entry This is necessary because getObject is called after EventFile::nextEvent loads the current entry of the inputTree. Many branches are turned "off" (status == 0), so they aren't loaded when the entire TTree is updated to a specific entry.

We shouldn't end up here before inputTree's read entry is unset, but we check anyways because ROOT will just seg-fault like a chump.

Definition at line 299 of file Event.h.

300 {
301 // get branch name
302 std::string branch_name;
303 if (collectionName == ldmx::EventHeader::BRANCH) {
304 branch_name = collectionName;
305 } else if (passName.empty()) {
306 // if no passName, then find branchName by looking over known products
307 if (known_lookups_.find(collectionName) == known_lookups_.end()) {
308 // this collectionName hasn't been found before
309 // this collection name is the whole name and not a partial name
310 // so we search products with a full-string match required
311 auto matches = searchProducts(collectionName, "", "", true);
312 if (matches.empty()) {
313 // no matches found
314 EXCEPTION_RAISE("ProductNotFound",
315 "No product found for name '" + collectionName + "'");
316 } else if (matches.size() > 1) {
317 // more than one branch found
318 std::stringstream names;
319 for (auto strs : matches) {
320 names << "\n" << strs;
321 }
322 EXCEPTION_RAISE("ProductAmbiguous",
323 "Multiple products found for name '" +
324 collectionName +
325 "' without specified pass name :" + names.str());
326 } else {
327 // exactly one branch found -> cache for later
328 known_lookups_[collectionName] =
329 makeBranchName(collectionName, matches.at(0).passname());
330 } // different options for number of possible branch matches
331 } // collection not in known lookups
332 branch_name = known_lookups_.at(collectionName);
333 } else {
334 branch_name = makeBranchName(collectionName, passName);
335 }
336
337 // now we have determined the unique branch name to look for
338 // so we can start looking on the bus and the input tree
339 // (if it exists) for it
340 bool already_on_board{bus_.isOnBoard(branch_name)};
341 if (not already_on_board and input_tree_) {
342 // branch is not on the bus but there is an input tree
343 // -> let's look for a new branch to load
344
345 // default construct a new passenger
346 bus_.board<T>(branch_name);
347
348 // attempt to attach the new passenger to the input tree
349 TBranch *branch = bus_.attach(input_tree_, branch_name, false);
350 if (branch == 0) {
351 // inputTree doesn't have that branch
352 EXCEPTION_RAISE(
353 "ProductNotFound",
354 "No product found for branch '" + branch_name + "' on input tree.");
355 }
356 // ooh, new branch!
357 branch->SetStatus(1); // overrides any 'ignore' rules
368 long long int ientry{input_tree_->GetReadEntry()};
369 if (ientry < 0) {
370 // reached getObject without initializing inputTree's read entry
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 + "'.");
375 }
376 branch->GetEntry(ientry);
377 } else if (not already_on_board) {
378 // not found in loaded branches and there is no inputTree,
379 // so no hope of finding an unloaded object
380 EXCEPTION_RAISE("ProductNotFound", "No product found for name '" +
381 collectionName + "' and pass '" +
382 pass_name_ + "'");
383 }
384
385 // we've made sure the passenger is on the bus
386 // and the branch we are reading from (if we are reading)
387 // has been updated
388 // let's return the object that the passenger is carrying
389 try {
390 const T &obj = bus_.get<T>(branch_name);
391 return obj;
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());
396 }
397 } // getObject
const BaggageType & get(const std::string &name)
Get the baggage carried by the passenger with the passed name.
Definition Bus.h:43

References framework::Bus::attach(), framework::Bus::board(), ldmx::EventHeader::BRANCH, bus_, framework::Bus::get(), input_tree_, framework::Bus::isOnBoard(), known_lookups_, makeBranchName(), pass_name_, and searchProducts().

Referenced by eventdisplay::Display::draw(), getCollection(), getMap(), and nextEvent().

◆ getPassName()

std::string framework::Event::getPassName ( )
inline

Get the current/default pass name.

Returns
The current/default pass name.

Definition at line 494 of file Event.h.

494{ return pass_name_; }

References pass_name_.

◆ getProducts()

const std::vector< ProductTag > & framework::Event::getProducts ( ) const
inline

Get a list of the data products in the event.

Definition at line 453 of file Event.h.

453{ return products_; }

References products_.

Referenced by print(), and searchProducts().

◆ makeBranchName() [1/2]

std::string framework::Event::makeBranchName ( const std::string & collectionName) const
inlineprivate

Make a branch name from a collection and the default(current) pass name.

Parameters
collectionNameThe collection name.

Definition at line 542 of file Event.h.

542 {
543 return makeBranchName(collectionName, pass_name_);
544 }

References makeBranchName(), and pass_name_.

◆ makeBranchName() [2/2]

std::string framework::Event::makeBranchName ( const std::string & collectionName,
const std::string & passName ) const
inlineprivate

Make a branch name from a collection and pass name.

Parameters
collectionNameThe collection name.
passNameThe pass name.

Definition at line 533 of file Event.h.

534 {
535 return collectionName + "_" + passName;
536 }

Referenced by add(), getObject(), and makeBranchName().

◆ nextEvent()

bool framework::Event::nextEvent ( )

Go to the next event by retrieving the event header.

We deep-copy the event header into our own member object. This is so we can modify the event header during the processing of this event and then re-add the event header at the end of the event. This is a pretty lame way to handle the event header, but it works.

Returns
Hard-coded to return true.

Definition at line 165 of file Event.cxx.

165 {
167 return true;
168}

References ldmx::EventHeader::BRANCH, event_header_, and getObject().

Referenced by framework::EventFile::nextEvent().

◆ onEndOfEvent()

void framework::Event::onEndOfEvent ( )

Perform end of event action (doesn't do anything right now).

Definition at line 184 of file Event.cxx.

184{}

Referenced by framework::EventFile::nextEvent().

◆ onEndOfFile()

void framework::Event::onEndOfFile ( )

Perform end of file action.

Clears buffer objects and resets output branch addresses. This prepares the event bus for a new input file (with new addresses).

Definition at line 186 of file Event.cxx.

186 {
187 if (output_tree_)
188 output_tree_->ResetBranchAddresses(); // reset addresses for output branch
189 if (input_tree_)
190 input_tree_ = nullptr; // detach old input_tree (owned by EventFile)
191 known_lookups_.clear(); // reset caching of empty pass requests
192 bus_.everybodyOff(); // delete buffer objects
193}
void everybodyOff()
Kicks all of the passengers off the bus and therefore destroys any objects they are carrying.
Definition Bus.h:140

References bus_, framework::Bus::everybodyOff(), input_tree_, known_lookups_, and output_tree_.

Referenced by framework::Process::run().

◆ print()

void framework::Event::print ( ) const

Print event bus.

Prints the list of products using the current stored product tags.

Definition at line 18 of file Event.cxx.

18 {
19 for (const ProductTag& tag : getProducts()) {
20 std::cout << tag << std::endl;
21 }
22}
const std::vector< ProductTag > & getProducts() const
Get a list of the data products in the event.
Definition Event.h:453

References getProducts().

◆ searchProducts()

std::vector< ProductTag > framework::Event::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.

An empty argument is interpreted as ".*", which matches everything.

By default (with full_string_match = false), the pattern can match the full string or any substring within it. One can require the pattern to match the full string by changing that parameter.

Parameters
namematchRegular expression to compare with the product name
passmatchRegular expression to compare with the pass name
typematchRegular expression to compare with the type name
full_string_matchrequire all non-empty regular expressions to match the full string and not a sub-string

Definition at line 79 of file Event.cxx.

82 {
83 std::vector<ProductTag> retval;
84 regex_t reg_name{constructRegex(namematch, full_string_match)},
85 reg_pass{constructRegex(passmatch, full_string_match)},
86 reg_type{constructRegex(typematch, full_string_match)};
87
88 // all passed expressions are valid regular expressions
89 const std::vector<ProductTag>& products = getProducts();
90 for (std::vector<ProductTag>::const_iterator i = products.begin();
91 i != products.end(); i++) {
92 if (!regexec(&reg_name, i->name().c_str(), 0, 0, 0) &&
93 !regexec(&reg_pass, i->passname().c_str(), 0, 0, 0) &&
94 !regexec(&reg_type, i->type().c_str(), 0, 0, 0))
95 retval.push_back(*i);
96 }
97
98 regfree(&reg_type);
99 regfree(&reg_pass);
100 regfree(&reg_name);
101
102 return retval;
103}
static regex_t constructRegex(const std::string &pattern, bool full_string_match)
Construct an actual regex from the pass pattern (and full-string flag)
Definition Event.cxx:60

References framework::constructRegex(), and getProducts().

Referenced by exists(), and getObject().

◆ setElectronCount()

void framework::Event::setElectronCount ( const int & electronCount)
inline

Set the beam electron count.

Parameters
electronCountThe beam electron count.

Definition at line 504 of file Event.h.

504 {
505 electron_count_ = electronCount;
506 }

References electron_count_.

◆ setInputTree()

void framework::Event::setInputTree ( TTree * tree)

Set the input data tree.

Parameters
treeThe input data tree.

Definition at line 123 of file Event.cxx.

123 {
124 input_tree_ = tree;
125
126 // in some cases, setInputTree is called more than once,
127 // so reset branch listing before starting
128 products_.clear();
129 known_lookups_.clear(); // reset caching of empty pass requests
131
132 // put in EventHeader (only one without pass name)
133 products_.emplace_back(ldmx::EventHeader::BRANCH, "", "ldmx::EventHeader");
134
135 // find the names of all the existing branches
136 TObjArray* branches = input_tree_->GetListOfBranches();
137 if (!branches) {
138 EXCEPTION_RAISE(
139 "BadInputFile",
140 "Input tree doesn't have a list of branches but still made it to this "
141 "point. This is bad and has never been seen before!");
142 return;
143 }
144 for (int i = 0; i < branches->GetEntriesFast(); i++) {
145 std::string brname;
146 if (branches->At(i)) {
147 brname = branches->At(i)->GetName();
148 }
149 if (brname != ldmx::EventHeader::BRANCH) {
150 if (shouldIgnore(brname)) continue;
151 size_t j = brname.find("_");
152 auto br = dynamic_cast<TBranchElement*>(branches->At(i));
153 // can't determine type if branch isn't
154 // the higher-level TBranchElement type
155 // Only occurs if the type on the bus is one of:
156 // bool, short, int, long, float, double (BSILFD)
157 products_.emplace_back(
158 brname.substr(0, j), // collection name is before '_'
159 brname.substr(j + 1), // pass name is after
160 br ? br->GetClassName() : "BSILFD");
161 }
162 }
163}
bool shouldIgnore(const std::string &branchName) const
Check if a branch from the input tree should be ignored.
Definition Event.cxx:202

References ldmx::EventHeader::BRANCH, bus_, framework::Bus::everybodyOff(), input_tree_, known_lookups_, products_, and shouldIgnore().

Referenced by framework::EventFile::nextEvent(), and framework::EventFile::setupEvent().

◆ setOutputTree()

void framework::Event::setOutputTree ( TTree * tree)

Set the output data tree.

Parameters
treeThe output data tree.

Definition at line 121 of file Event.cxx.

121{ output_tree_ = tree; }

References output_tree_.

Referenced by framework::EventFile::nextEvent(), and framework::EventFile::setupEvent().

◆ shouldDrop()

bool framework::Event::shouldDrop ( const std::string & collName) const
private

Check if collection should be dropped.

Parameters
collNamename of collection
Returns
true if the collection should be dropped (i.e. NOT saved)

Definition at line 195 of file Event.cxx.

195 {
196 for (const regex_t& exp : regex_drop_collections_) {
197 if (!regexec(&exp, branch_name.c_str(), 0, 0, 0)) return true;
198 }
199 return false;
200}

References regex_drop_collections_.

Referenced by add().

◆ shouldIgnore()

bool framework::Event::shouldIgnore ( const std::string & branchName) const
private

Check if a branch from the input tree should be ignored.

Ignored branches are not added to the products list and are therefore inaccessible to processors.

Parameters
branchNamename of branch
Returns
true if the branch should be ignored (i.e. NOT loaded)

Definition at line 202 of file Event.cxx.

202 {
203 for (const regex_t& exp : regex_ignore_collections_) {
204 if (!regexec(&exp, branch_name.c_str(), 0, 0, 0)) return true;
205 }
206 return false;
207}

References regex_ignore_collections_.

Referenced by setInputTree().

Member Data Documentation

◆ branches_filled_

std::set<std::string> framework::Event::branches_filled_
private

Names of branches filled during this event.

This is used to make sure the same passenger isn't modified more than once in one event and to make sure the event header is updated if it wasn't updated manually.

Definition at line 588 of file Event.h.

Referenced by add(), beforeFill(), and clear().

◆ bus_

framework::Bus framework::Event::bus_
mutableprivate

The Bus.

We buffer the event bus objects by having passengers on the bus carry them.

See also
framework::Bus for how this buffering works

Definition at line 578 of file Event.h.

Referenced by add(), clear(), getObject(), onEndOfFile(), and setInputTree().

◆ electron_count_

int framework::Event::electron_count_ {1}
private

The total number of electrons in the event.

Definition at line 568 of file Event.h.

568{1};

Referenced by getElectronCount(), and setElectronCount().

◆ event_header_

ldmx::EventHeader framework::Event::event_header_
private

The event header object.

Definition at line 550 of file Event.h.

Referenced by beforeFill(), getEventHeader(), getEventHeader(), getEventHeaderPtr(), getEventNumber(), getEventWeight(), and nextEvent().

◆ input_tree_

TTree* framework::Event::input_tree_ {nullptr}
private

The input tree for reading existing data.

Definition at line 565 of file Event.h.

565{nullptr};

Referenced by beforeFill(), getObject(), onEndOfFile(), and setInputTree().

◆ known_lookups_

std::map<std::string, std::string> framework::Event::known_lookups_
mutableprivate

Efficiency cache for empty pass name lookups.

Definition at line 603 of file Event.h.

Referenced by add(), getObject(), onEndOfFile(), and setInputTree().

◆ output_tree_

TTree* framework::Event::output_tree_ {nullptr}
private

The output tree for writing a new file.

Definition at line 560 of file Event.h.

560{nullptr};

Referenced by add(), createTree(), onEndOfFile(), and setOutputTree().

◆ pass_name_

std::string framework::Event::pass_name_
private

The default pass name.

Definition at line 555 of file Event.h.

Referenced by add(), getObject(), getPassName(), and makeBranchName().

◆ products_

std::vector<ProductTag> framework::Event::products_
private

List of all the event products.

Definition at line 608 of file Event.h.

Referenced by add(), getProducts(), and setInputTree().

◆ regex_drop_collections_

std::vector<regex_t> framework::Event::regex_drop_collections_
private

Regex of collection names to not store in event.

Definition at line 593 of file Event.h.

Referenced by addDrop(), shouldDrop(), and ~Event().

◆ regex_ignore_collections_

std::vector<regex_t> framework::Event::regex_ignore_collections_
private

Regex of branch names to not even read from the input tree.

Definition at line 598 of file Event.h.

Referenced by addIgnore(), shouldIgnore(), and ~Event().


The documentation for this class was generated from the following files: