LDMX Software
|
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 * | 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. | |
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< ProductTag > | products_ |
List of all the event products. | |
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.
framework::Event::Event | ( | const std::string & | passName | ) |
framework::Event::~Event | ( | ) |
Class destructor.
Definition at line 9 of file Event.cxx.
References regexDropCollections_.
|
inline |
Adds an object to the event bus.
Exception | if there is an underscore in the collection name. |
Exception | if there already has been a branch filled with the constructed name. |
Exception | if the type we are putting in mis-matches the type in the bus under the input name. |
collectionName | |
obj | in ROOT dictionary to add |
Definition at line 173 of file Event.h.
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().
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.
exp | regex to match |
Definition at line 21 of file Event.cxx.
References regexDropCollections_.
Referenced by framework::EventFile::addDrop().
void framework::Event::beforeFill | ( | ) |
Action to be executed before the tree is filled.
Definition at line 156 of file Event.cxx.
References add(), ldmx::EventHeader::BRANCH, branchesFilled_, eventHeader_, and inputTree_.
Referenced by framework::EventFile::nextEvent().
void framework::Event::Clear | ( | ) |
Clear this object's data (including passengers).
Definition at line 165 of file Event.cxx.
References branchesFilled_, bus_, and framework::Bus::clear().
Referenced by framework::EventFile::nextEvent().
TTree * framework::Event::createTree | ( | ) |
Create the output data tree.
Definition at line 102 of file Event.cxx.
References outputTree_.
Referenced by framework::EventFile::setupEvent().
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.
name | Name (label, not class name) given to the object when it was put into the event. |
passName | The process pass label which was in use when this object was put into the event, such as "sim" or "rerecov2". |
unique | true if requiring one and only one matching object, false if allowing for one or more matching objects |
Definition at line 92 of file Event.cxx.
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().
|
inline |
Get a collection (std::vector) of objects from the event bus.
in,out] ContentType type of object stored in the vector
[in] | collectionName | name of collection that we want |
[in] | passName | name of specific pass we want, optional |
Definition at line 386 of file Event.h.
Referenced by dqm::SampleValidation::analyze(), tracking::dqm::TrackingRecoDQM::analyze(), packing::rawdatafile::File::nextEvent(), hcal::HcalRawDecoder::produce(), and recon::OverlayProducer::produce().
|
inline |
Definition at line 475 of file Event.h.
References electronCount_.
|
inline |
Get the event header.
Definition at line 58 of file Event.h.
References eventHeader_.
Referenced by packing::rawdatafile::File::nextEvent(), recon::OverlayProducer::onNewRun(), dqm::DarkBremInteraction::produce(), recon::OverlayProducer::produce(), simcore::Simulator::produce(), trigscint::QIEDecoder::produce(), framework::Process::run(), and simcore::ReSimulator::skip().
|
inline |
Get the event header as a pointer.
Definition at line 64 of file Event.h.
References eventHeader_.
Referenced by framework::Process::run().
|
inline |
Get the event number.
Definition at line 70 of file Event.h.
References eventHeader_, and ldmx::EventHeader::getEventNumber().
Referenced by packing::rawdatafile::File::nextEvent(), and framework::Process::run().
|
inline |
Get the event weight.
Definition at line 76 of file Event.h.
References eventHeader_, and ldmx::EventHeader::getWeight().
|
inline |
Get a map (std::map) of objects from the event bus.
in,out] KeyType type of object used as the key in the map
in,out] ValType type of object used as the value in the map
[in] | collectionName | name of collection that we want |
[in] | passName | name of specific pass we want, optional |
Definition at line 404 of file Event.h.
|
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.
Exception | if 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.
Exception | if can't find a corresponding branch name on the input tree or in the bus |
Exception | if we are trying to load a new branch and the input tree has negative read entry (i.e. it is uninitialized) |
Finally, we return a const reference to the object on the bus.
Exception | if mismatching type |
T | type of object we should be getting |
collectionName | name of collection you want |
passName | name of pass you want |
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.
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().
|
inline |
|
inline |
|
inlineprivate |
Make a branch name from a collection and the default(current) pass name.
collectionName | The collection name. |
Definition at line 509 of file Event.h.
References makeBranchName(), and passName_.
|
inlineprivate |
Make a branch name from a collection and pass name.
collectionName | The collection name. |
passName | The pass name. |
Definition at line 500 of file Event.h.
Referenced by add(), getObject(), and makeBranchName().
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.
Definition at line 151 of file Event.cxx.
References ldmx::EventHeader::BRANCH, and eventHeader_.
Referenced by framework::EventFile::nextEvent().
void framework::Event::onEndOfEvent | ( | ) |
Perform end of event action (doesn't do anything right now).
Definition at line 170 of file Event.cxx.
Referenced by framework::EventFile::nextEvent().
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.
References bus_, framework::Bus::everybodyOff(), inputTree_, knownLookups_, and outputTree_.
Referenced by framework::Process::run().
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.
References getProducts().
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.
namematch | Regular expression to compare with the product name |
passmatch | Regular expression to compare with the pass name |
typematch | Regular expression to compare with the type name |
full_string_match | require all non-empty regular expressions to match the full string and not a sub-string |
Definition at line 66 of file Event.cxx.
References framework::construct_regex(), and getProducts().
Referenced by exists(), and getObject().
|
inline |
Set the beam electron count.
electronCount | The beam electron count. |
Definition at line 482 of file Event.h.
References electronCount_.
void framework::Event::setInputTree | ( | TTree * | tree | ) |
Set the input data tree.
tree | The input data tree. |
Definition at line 110 of file Event.cxx.
References ldmx::EventHeader::BRANCH, bus_, framework::Bus::everybodyOff(), inputTree_, knownLookups_, and products_.
Referenced by framework::EventFile::nextEvent(), and framework::EventFile::setupEvent().
void framework::Event::setOutputTree | ( | TTree * | tree | ) |
Set the output data tree.
tree | The output data tree. |
Definition at line 108 of file Event.cxx.
References outputTree_.
Referenced by framework::EventFile::nextEvent(), and framework::EventFile::setupEvent().
|
private |
Check if collection should be dropped.
collName | name of collection |
Definition at line 181 of file Event.cxx.
References regexDropCollections_.
Referenced by add().
|
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().
|
mutableprivate |
The Bus.
We buffer the event bus objects by having passengers on the bus carry them.
Definition at line 545 of file Event.h.
Referenced by add(), Clear(), getObject(), onEndOfFile(), and setInputTree().
|
private |
The total number of electrons in the event.
Definition at line 535 of file Event.h.
Referenced by getElectronCount(), and setElectronCount().
|
private |
The event header object.
Definition at line 517 of file Event.h.
Referenced by beforeFill(), getEventHeader(), getEventHeaderPtr(), getEventNumber(), getEventWeight(), and nextEvent().
|
private |
The input tree for reading existing data.
Definition at line 532 of file Event.h.
Referenced by beforeFill(), getObject(), onEndOfFile(), and setInputTree().
|
mutableprivate |
Efficiency cache for empty pass name lookups.
Definition at line 565 of file Event.h.
Referenced by add(), getObject(), onEndOfFile(), and setInputTree().
|
private |
The output tree for writing a new file.
Definition at line 527 of file Event.h.
Referenced by add(), createTree(), onEndOfFile(), and setOutputTree().
|
private |
The default pass name.
Definition at line 522 of file Event.h.
Referenced by add(), getObject(), getPassName(), and makeBranchName().
|
private |
List of all the event products.
Definition at line 570 of file Event.h.
Referenced by add(), getProducts(), and setInputTree().
|
private |
Regex of collection names to not store in event.
Definition at line 560 of file Event.h.
Referenced by addDrop(), shouldDrop(), and ~Event().