LDMX Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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::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 eventHeader_
 The event header object.
 
std::string passName_
 The default pass name.
 
TTree * outputTree_ {nullptr}
 The output tree for writing a new file.
 
TTree * inputTree_ {nullptr}
 The input tree for reading existing data.
 
int electronCount_ {1}
 The total number of electrons in the event.
 
framework::Bus bus_
 The Bus.
 
std::set< std::string > branchesFilled_
 Names of branches filled during this event.
 
std::vector< regex_t > regexDropCollections_
 Regex of collection names to not store in event.
 
std::map< std::string, std::string > knownLookups_
 Efficiency cache for empty pass name lookups.
 
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 41 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: passName_(thePassName) {}
std::string passName_
The default pass name.
Definition Event.h:522

◆ ~Event()

framework::Event::~Event ( )

Class destructor.

Definition at line 9 of file Event.cxx.

9 {
10 for (regex_t& reg : regexDropCollections_) {
11 regfree(&reg);
12 }
13}
std::vector< regex_t > regexDropCollections_
Regex of collection names to not store in event.
Definition Event.h:560

References regexDropCollections_.

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

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

References framework::Bus::attach(), framework::Bus::board(), ldmx::EventHeader::BRANCH, branchesFilled_, bus_, framework::Bus::isOnBoard(), knownLookups_, makeBranchName(), outputTree_, passName_, 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 regexDropCollections_.push_back(reg);
25 } else {
26 EXCEPTION_RAISE("InvalidRegex", "The passed drop rule regex '" + exp +
27 "' is not a valid regex.");
28 }
29}

References regexDropCollections_.

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 branchesFilled_.end()) {
159 // Event Header not copied from input and hasn't been added yet, need to put
160 // it in
162 }
163}
TTree * inputTree_
The input tree for reading existing data.
Definition Event.h:532
ldmx::EventHeader eventHeader_
The event header object.
Definition Event.h:517
void add(const std::string &collectionName, T &obj)
Adds an object to the event bus.
Definition Event.h:173

References add(), ldmx::EventHeader::BRANCH, branchesFilled_, eventHeader_, and inputTree_.

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 branchesFilled_.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 branchesFilled_, 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 outputTree_ = new TTree("LDMX_Events", "LDMX Events");
104
105 return outputTree_;
106}

References outputTree_.

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(), trigger::DumpFileWriter::analyze(), dqm::RecoilTrackerDQM::analyze(), tracking::dqm::TrackerDigiDQM::analyze(), tracking::dqm::TrackingRecoDQM::analyze(), trigscint::TestBeamClusterAnalyzer::analyze(), packing::rawdatafile::File::nextEvent(), ecal::EcalRecProducer::produce(), recon::ParticleFlow::produce(), recon::PFEcalClusterProducer::produce(), recon::PFHcalClusterProducer::produce(), recon::PFTrackProducer::produce(), recon::PFTruthProducer::produce(), trigger::EcalTPSelector::produce(), trigger::NtupleWriter::produce(), trigger::PropagationMapWriter::produce(), trigger::TrigEcalClusterProducer::produce(), trigger::TrigEcalEnergySum::produce(), trigger::TrigElectronProducer::produce(), trigger::TrigHcalEnergySum::produce(), ecal::EcalVetoProcessor::produce(), hcal::HcalRecProducer::produce(), recon::BeamElectronLocator::produce(), recon::ElectronCounter::produce(), recon::MyProcessor::produce(), tracking::reco::CKFProcessor::produce(), tracking::reco::GSFProcessor::produce(), tracking::reco::SeedFinderProcessor::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 386 of file Event.h.

388 {
389 return getObject<std::vector<ContentType> >(collectionName, passName);
390 }

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

475{ return electronCount_; }
int electronCount_
The total number of electrons in the event.
Definition Event.h:535

References electronCount_.

◆ getEventHeader()

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

◆ getEventHeaderPtr()

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

Get the event header as a pointer.

Returns
A const pointer to the event header.

Definition at line 64 of file Event.h.

64{ return &eventHeader_; }

References eventHeader_.

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

◆ getEventNumber()

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

Get the event number.

Returns
the event index/number

Definition at line 70 of file Event.h.

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

References eventHeader_, 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 76 of file Event.h.

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

References eventHeader_, 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 404 of file Event.h.

406 {
407 return getObject<std::map<KeyType, ValType> >(collectionName, passName);
408 }

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

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

Referenced by eventdisplay::Display::draw().

◆ getPassName()

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

Get the current/default pass name.

Returns
The current/default pass name.

Definition at line 472 of file Event.h.

472{ return passName_; }

References passName_.

◆ getProducts()

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

Get a list of the data products in the event.

Definition at line 431 of file Event.h.

431{ 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 509 of file Event.h.

509 {
510 return makeBranchName(collectionName, passName_);
511 }

References makeBranchName(), and passName_.

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

501 {
502 return collectionName + "_" + passName;
503 }

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 {
152 eventHeader_ = getObject<ldmx::EventHeader>(ldmx::EventHeader::BRANCH);
153 return true;
154}

References ldmx::EventHeader::BRANCH, and eventHeader_.

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 (outputTree_)
174 outputTree_->ResetBranchAddresses(); // reset addresses for output branch
175 if (inputTree_)
176 inputTree_ = nullptr; // detach old inputTree (owned by EventFile)
177 knownLookups_.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(), inputTree_, knownLookups_, and outputTree_.

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:431

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{construct_regex(namematch, full_string_match)},
72 reg_pass{construct_regex(passmatch, full_string_match)},
73 reg_type{construct_regex(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 construct_regex(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::construct_regex(), 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 482 of file Event.h.

482 {
483 electronCount_ = electronCount;
484 }

References electronCount_.

◆ 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 inputTree_ = tree;
112
113 // in some cases, setInputTree is called more than once,
114 // so reset branch listing before starting
115 products_.clear();
116 knownLookups_.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 = inputTree_->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(), inputTree_, knownLookups_, 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{ outputTree_ = tree; }

References outputTree_.

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 : regexDropCollections_) {
183 if (!regexec(&exp, branchName.c_str(), 0, 0, 0)) return true;
184 }
185 return false;
186}

References regexDropCollections_.

Referenced by add().

Member Data Documentation

◆ branchesFilled_

std::set<std::string> framework::Event::branchesFilled_
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 555 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 545 of file Event.h.

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

◆ electronCount_

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

The total number of electrons in the event.

Definition at line 535 of file Event.h.

535{1};

Referenced by getElectronCount(), and setElectronCount().

◆ eventHeader_

ldmx::EventHeader framework::Event::eventHeader_
private

The event header object.

Definition at line 517 of file Event.h.

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

◆ inputTree_

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

The input tree for reading existing data.

Definition at line 532 of file Event.h.

532{nullptr};

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

◆ knownLookups_

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

Efficiency cache for empty pass name lookups.

Definition at line 565 of file Event.h.

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

◆ outputTree_

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

The output tree for writing a new file.

Definition at line 527 of file Event.h.

527{nullptr};

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

◆ passName_

std::string framework::Event::passName_
private

The default pass name.

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

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

◆ regexDropCollections_

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

Regex of collection names to not store in event.

Definition at line 560 of file Event.h.

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


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