-
Notifications
You must be signed in to change notification settings - Fork 95
Allow filtering by trigger bits, add accessor #1670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| #include "canvas/Persistency/Common/TriggerResults.h" | ||
|
|
||
| #include <map> | ||
| #include <unordered_map> | ||
| #include <string> | ||
| #include <vector> | ||
| #include <ostream> | ||
|
|
@@ -24,28 +25,27 @@ namespace mu2e { | |
| return _trigPathsNames.size(); | ||
| } | ||
|
|
||
| std::vector<std::string> const& getTrigPaths () const { return _trigPathsNames; } | ||
| std::string const& getTrigPath (unsigned int const i) const { return _trigPathsNames.at(i); } | ||
| std::string const getTrigPathName(unsigned int const i) const; | ||
| size_t getTrigBit (unsigned int const pathID) const; | ||
| size_t findTrigPath(std::string const& name) const; | ||
| size_t find(std::map<std::string, unsigned int> const& posmap, std::string const& name) const; | ||
| size_t findTrigPathID(std::string const& name) const; | ||
| std::vector<std::string> const& getTrigPaths() const { return _trigPathsNames; } | ||
| std::string const& getTrigPathByIndex(unsigned int const index) const { return _trigPathsNames.at(index); } | ||
| std::string const& getTrigPathNameByIndex(unsigned int const i) const; | ||
| std::string const& getTrigPathNameByBit(unsigned int const bit) const; | ||
| size_t getTrigBitByIndex(unsigned int const pathID) const; | ||
| size_t getTrigBitByName(const std::string& name) const; | ||
| size_t getTrigPathIndex(std::string const& name) const; | ||
| size_t getTrigPathIndex(const size_t bit) const; | ||
|
|
||
| bool validPath(std::string const& name) const { | ||
| size_t path_index = findTrigPath(name); | ||
| return path_index < _trigPathsNames.size(); | ||
| return _trigMap.contains(name); | ||
| } | ||
|
|
||
| size_t getTrigBit(std::string const& name) const { | ||
| if(!validPath(name)) | ||
| throw cet::exception("TRIGGER") << "TriggerResultsNavigator: Path name " << name << " not found"; | ||
| return findTrigPathID(name); | ||
| bool validPath(const unsigned int bit) { | ||
| return _bitToPathName.contains(bit); | ||
| } | ||
|
|
||
| // Has ith path accepted the event? | ||
| // Did the path pass the event | ||
| bool accepted(std::string const& name) const; | ||
| bool accepted(unsigned int const bit) const; | ||
|
|
||
| // Was the path run in the event | ||
| bool wasrun(std::string const& name) const; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that the trigger navigators relies a lot on strings, which is slow. IS there a way to improve this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added unordered maps so we can avoid more string comparisons. Users may ask about the bit, the string name, or the index, so all of these interfaces need to be maintained. I think this version should be clearer though. |
||
|
|
||
| //NOTE: the following three functions can be used only within the same job that runs the | ||
|
|
@@ -58,10 +58,15 @@ namespace mu2e { | |
| void print() const; | ||
|
|
||
| private: | ||
| const art::TriggerResults* _trigResults; | ||
| std::vector<std::string> _trigPathsNames; // vector of trigger path names | ||
| std::map<std::string, unsigned int> _trigMap; // map of trigger path name to index in TriggerResults | ||
| std::map<std::string, unsigned int> _trigPathMap; // map of trigger path name to path ID (bit) | ||
| const art::TriggerResults* _trigResults; // trigger results info | ||
| std::vector<std::string> _trigPathsNames; // vector of trigger path names | ||
| std::unordered_map<std::string, unsigned int> _trigMap; // map of trigger path name to index in the art::TriggerResults | ||
| std::unordered_map<std::string, unsigned int> _trigPathMap; // map of trigger path name to path ID (bit) | ||
| std::unordered_map<unsigned int, std::string> _indexToPathName; // trigger path index -> name map | ||
| std::unordered_map<unsigned int, std::string> _bitToPathName; // trigger path bit -> name map | ||
| std::unordered_map<unsigned int, unsigned int> _bitToIndex; // trigger path bit -> index map | ||
|
|
||
| static constexpr size_t NOTFOUND = -1; // special bit/index value for no trigger was found | ||
| }; | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, it would be nice if you could align the different fields, this makes the code easier to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to better align these