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.
 
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.
 
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::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:533

◆ ~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}
std::vector< regex_t > regex_drop_collections_
Regex of collection names to not store in event.
Definition Event.h:571

References regex_drop_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 184 of file Event.h.

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

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

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

References regex_drop_collections_.

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

◆ beforeFill()

void framework::Event::beforeFill ( )

Action to be executed before the tree is filled.

Definition at line 156 of file Event.cxx.

156 {
158 branches_filled_.end()) {
159 // Event Header not copied from input and hasn't been added yet, need to put
160 // it in
162 }
163}
TTree * input_tree_
The input tree for reading existing data.
Definition Event.h:543
ldmx::EventHeader event_header_
The event header object.
Definition Event.h:528
void add(const std::string &collectionName, T &obj)
Adds an object to the event bus.
Definition Event.h:184

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

165 {
166 branches_filled_.clear(); // forget names of branches we filled
167 bus_.clear(); // clear the event objects individually but leave them on bus
168}
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 102 of file Event.cxx.

102 {
103 output_tree_ = new TTree("LDMX_Events", "LDMX Events");
104
105 return output_tree_;
106}

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

93 {
94 static const bool require_full_string_match = true;
95 auto matches = searchProducts(name, passName, "", require_full_string_match);
96 if (unique)
97 return (matches.size() == 1);
98 else
99 return (matches.size() > 0);
100}
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:66

References searchProducts().

Referenced by 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::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 400 of file Event.h.

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

References getObject().

Referenced by dqm::SampleValidation::analyze(), tracking::dqm::TrackingRecoDQM::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 486 of file Event.h.

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

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

418 {
419 return getObject<std::map<KeyType, ValType> >(collectionName, passName);
420 }

References getObject().

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

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

483{ 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 442 of file Event.h.

442{ 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 520 of file Event.h.

520 {
521 return makeBranchName(collectionName, pass_name_);
522 }

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

512 {
513 return collectionName + "_" + passName;
514 }

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

151 {
153 return true;
154}

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

170{}

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

172 {
173 if (output_tree_)
174 output_tree_->ResetBranchAddresses(); // reset addresses for output branch
175 if (input_tree_)
176 input_tree_ = nullptr; // detach old input_tree (owned by EventFile)
177 known_lookups_.clear(); // reset caching of empty pass requests
178 bus_.everybodyOff(); // delete buffer objects
179}
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 15 of file Event.cxx.

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

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

69 {
70 std::vector<ProductTag> retval;
71 regex_t reg_name{constructRegex(namematch, full_string_match)},
72 reg_pass{constructRegex(passmatch, full_string_match)},
73 reg_type{constructRegex(typematch, full_string_match)};
74
75 // all passed expressions are valid regular expressions
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(&reg_name, i->name().c_str(), 0, 0, 0) &&
80 !regexec(&reg_pass, i->passname().c_str(), 0, 0, 0) &&
81 !regexec(&reg_type, i->type().c_str(), 0, 0, 0))
82 retval.push_back(*i);
83 }
84
85 regfree(&reg_type);
86 regfree(&reg_pass);
87 regfree(&reg_name);
88
89 return retval;
90}
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:47

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

493 {
494 electron_count_ = electronCount;
495 }

References electron_count_.

◆ setInputTree()

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

Set the input data tree.

Parameters
treeThe input data tree.

Definition at line 110 of file Event.cxx.

110 {
111 input_tree_ = tree;
112
113 // in some cases, setInputTree is called more than once,
114 // so reset branch listing before starting
115 products_.clear();
116 known_lookups_.clear(); // reset caching of empty pass requests
118
119 // put in EventHeader (only one without pass name)
120 products_.emplace_back(ldmx::EventHeader::BRANCH, "", "ldmx::EventHeader");
121
122 // find the names of all the existing branches
123 TObjArray* branches = input_tree_->GetListOfBranches();
124 if (!branches) {
125 EXCEPTION_RAISE(
126 "BadInputFile",
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!");
129 return;
130 }
131 for (int i = 0; i < branches->GetEntriesFast(); i++) {
132 std::string brname;
133 if (branches->At(i)) {
134 brname = branches->At(i)->GetName();
135 }
136 if (brname != ldmx::EventHeader::BRANCH) {
137 size_t j = brname.find("_");
138 auto br = dynamic_cast<TBranchElement*>(branches->At(i));
139 // can't determine type if branch isn't
140 // the higher-level TBranchElement type
141 // Only occurs if the type on the bus is one of:
142 // bool, short, int, long, float, double (BSILFD)
143 products_.emplace_back(
144 brname.substr(0, j), // collection name is before '_'
145 brname.substr(j + 1), // pass name is after
146 br ? br->GetClassName() : "BSILFD");
147 }
148 }
149}

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

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

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

181 {
182 for (const regex_t& exp : regex_drop_collections_) {
183 if (!regexec(&exp, branch_name.c_str(), 0, 0, 0)) return true;
184 }
185 return false;
186}

References regex_drop_collections_.

Referenced by add().

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 566 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 556 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 546 of file Event.h.

546{1};

Referenced by getElectronCount(), and setElectronCount().

◆ event_header_

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

The event header object.

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

543{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 576 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 538 of file Event.h.

538{nullptr};

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

◆ pass_name_

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

The default pass name.

Definition at line 533 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 581 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 571 of file Event.h.

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


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