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::EventHeader & getEventHeader ()
 Get the event header.
 
const ldmx::EventHeader & getEventHeader () const
 Get the event header.
 
const ldmx::EventHeader * getEventHeaderPtr ()
 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< 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.
 
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< ProductTag > products_
 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 40 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 9 of file Event.cxx.

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

◆ ~Event()

framework::Event::~Event ( )

Class destructor.

Definition at line 11 of file Event.cxx.

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

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 193 of file Event.h.

193 {
194 if (collectionName.find('_') != std::string::npos) {
195 EXCEPTION_RAISE("IllegalName",
196 "The product name '" + collectionName +
197 "' is illegal as it contains an underscore.");
198 }
199
200 // determine the branch name
201 std::string branch_name;
202 if (collectionName == ldmx::EventHeader::BRANCH)
203 branch_name = collectionName;
204 else
205 branch_name = makeBranchName(collectionName);
206
207 if (branches_filled_.find(branch_name) != branches_filled_.end()) {
208 EXCEPTION_RAISE("ProductExists",
209 "A product named '" + collectionName +
210 "' already exists in the event (has been loaded by a "
211 "previous producer in this process).");
212 }
213 branches_filled_.insert(branch_name);
214 // MEMORY add is leaking memory when given a vector (possible upon
215 // destruction of Event?) MEMORY add is 'conditional jump or move depends on
216 // uninitialised values' for all types of objects
217 // TTree::BranchImpRef or TTree::BronchExec
218 if (not bus_.isOnBoard(branch_name)) {
219 // create a new branch for this collection
220
221 // have type T board bus under name 'branchName'
222 bus_.board<T>(branch_name);
223
224 // type name (want to use branch element if possible)
225 std::string tname = typeid(obj).name();
226
227 if (output_tree_ and not shouldDrop(branch_name)) {
228 // we are writing this branch to an output file, so let's
229 // attach this passenger to the output tree
230 TBranch* out_branch = bus_.attach(output_tree_, branch_name, true);
231 // get type name from branch if possible,
232 // otherwise use compiler level type name (above)
233 std::string class_name{out_branch->GetClassName()};
234 if (not class_name.empty()) tname = class_name;
235 } // output tree exists or not
236
237 // check for cache entry to remove
238 auto it_known{known_lookups_.find(collectionName)};
239 if (it_known != known_lookups_.end()) known_lookups_.erase(it_known);
240
241 // add us to list of products
242 products_.emplace_back(collectionName, pass_name_, tname);
243 }
244
245 // copy input contents into bus passenger
246 try {
247 bus_.update(branch_name, obj);
248 } catch (const std::bad_cast&) {
249 EXCEPTION_RAISE("TypeMismatch",
250 "Attempting to add an object whose type '" +
251 std::string(typeid(obj).name()) +
252 "' doesn't match the type stored in the collection.");
253 }
254
255 return;
256 }
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:606
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:531
framework::Bus bus_
The Bus.
Definition Event.h:576
std::set< std::string > branches_filled_
Names of branches filled during this event.
Definition Event.h:586
bool shouldDrop(const std::string &collName) const
Check if collection should be dropped.
Definition Event.cxx:197
TTree * output_tree_
The output tree for writing a new file.
Definition Event.h:558
std::map< std::string, std::string > known_lookups_
Efficiency cache for empty pass name lookups.
Definition Event.h:601
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 26 of file Event.cxx.

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

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 36 of file Event.cxx.

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

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 172 of file Event.cxx.

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

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 181 of file Event.cxx.

181 {
182 branches_filled_.clear(); // forget names of branches we filled
183 bus_.clear(); // clear the event objects individually but leave them on bus
184}
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 117 of file Event.cxx.

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

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 107 of file Event.cxx.

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

References searchProducts().

Referenced by dqm::CascadeHistoryDQM::analyze(), dqm::EcalDigiVerifier::analyze(), dqm::EcalSPTrackCompare::analyze(), dqm::EcalTrackAnalyzer::analyze(), dqm::TrigScintClusterDQM::analyze(), dqm::TrigScintTrackDQM::analyze(), dqm::VisiblesCutflow::analyze(), dqm::VisiblesFeatureProducer::analyze(), tracking::dqm::DigiDQM::analyze(), tracking::dqm::RawSiStripDQM::analyze(), tracking::dqm::StraightTracksDQM::analyze(), tracking::dqm::TrackerDigiDQM::analyze(), tracking::dqm::TrackingRecoDQM::analyze(), trigger::DumpFileWriter::analyze(), trigscint::TestBeamClusterAnalyzer::analyze(), dqm::PhotoNuclearDQM::analyzeInteractionDetails(), packing::rawdatafile::File::nextEvent(), dqm::EcalSPElectronKinematics::produce(), ecal::EcalPnetVetoProcessor::produce(), ecal::EcalRecProducer::produce(), ecal::EcalTrackFinderProcessor::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(), simcore::GenieReweightProducer::produce(), tracking::reco::CKFProcessor::produce(), tracking::reco::GreedyAmbiguitySolver::produce(), tracking::reco::GSFProcessor::produce(), tracking::reco::LinearSeedFinder::produce(), tracking::reco::SeedFinderProcessor::produce(), tracking::reco::TrigScintMeasurementProducer::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::TrigScintQIEDigiProducer::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 409 of file Event.h.

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

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 495 of file Event.h.

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

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 63 of file Event.h.

63{ 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 73 of file Event.h.

73{ 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 79 of file Event.h.

79{ 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 85 of file Event.h.

85{ 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 426 of file Event.h.

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

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 297 of file Event.h.

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

492{ return pass_name_; }

References pass_name_.

Referenced by tracking::reco::SeedFinderProcessor::produce().

◆ getProducts()

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

Get a list of the data products in the event.

Definition at line 451 of file Event.h.

451{ 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 540 of file Event.h.

540 {
541 return makeBranchName(collectionName, pass_name_);
542 }

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 531 of file Event.h.

532 {
533 return collectionName + "_" + passName;
534 }

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 167 of file Event.cxx.

167 {
169 return true;
170}

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 186 of file Event.cxx.

186{}

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 188 of file Event.cxx.

188 {
189 if (output_tree_)
190 output_tree_->ResetBranchAddresses(); // reset addresses for output branch
191 if (input_tree_)
192 input_tree_ = nullptr; // detach old input_tree (owned by EventFile)
193 known_lookups_.clear(); // reset caching of empty pass requests
194 bus_.everybodyOff(); // delete buffer objects
195}
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 20 of file Event.cxx.

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

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 81 of file Event.cxx.

84 {
85 std::vector<ProductTag> retval;
86 regex_t reg_name{constructRegex(namematch, full_string_match)},
87 reg_pass{constructRegex(passmatch, full_string_match)},
88 reg_type{constructRegex(typematch, full_string_match)};
89
90 // all passed expressions are valid regular expressions
91 const std::vector<ProductTag>& products = getProducts();
92 for (std::vector<ProductTag>::const_iterator i = products.begin();
93 i != products.end(); i++) {
94 if (!regexec(&reg_name, i->name().c_str(), 0, 0, 0) &&
95 !regexec(&reg_pass, i->passname().c_str(), 0, 0, 0) &&
96 !regexec(&reg_type, i->type().c_str(), 0, 0, 0))
97 retval.push_back(*i);
98 }
99
100 regfree(&reg_type);
101 regfree(&reg_pass);
102 regfree(&reg_name);
103
104 return retval;
105}
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:62

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 502 of file Event.h.

502 {
503 electron_count_ = electronCount;
504 }

References electron_count_.

◆ setInputTree()

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

Set the input data tree.

Parameters
treeThe input data tree.

Definition at line 125 of file Event.cxx.

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

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 123 of file Event.cxx.

123{ 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 197 of file Event.cxx.

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

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 204 of file Event.cxx.

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

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 586 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 576 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 566 of file Event.h.

566{1};

Referenced by getElectronCount(), and setElectronCount().

◆ event_header_

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

The event header object.

Definition at line 548 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 563 of file Event.h.

563{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 601 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 558 of file Event.h.

558{nullptr};

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

◆ pass_name_

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

The default pass name.

Definition at line 553 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 606 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 591 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 596 of file Event.h.

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


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