Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:41

0001 #ifndef HLTReco_TriggerEvent_h
0002 #define HLTReco_TriggerEvent_h
0003 
0004 /** \class trigger::TriggerEvent
0005  *
0006  *  The single EDProduct to be saved for each event (AOD case)
0007  *  describing the (HLT) trigger table
0008  *
0009  *
0010  *  \author Martin Grunewald
0011  *
0012  */
0013 
0014 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0015 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0016 #include "FWCore/Utilities/interface/InputTag.h"
0017 #include "DataFormats/Common/interface/traits.h"
0018 #include <string>
0019 #include <vector>
0020 #include <cassert>
0021 
0022 namespace trigger {
0023 
0024   /// The single EDProduct to be saved for each event (AOD case)
0025   class TriggerEvent : public edm::DoNotRecordParents {
0026   public:
0027     /// Helper class: recording trigger objects firing a single filter
0028     class TriggerFilterObject {
0029     public:
0030       /// encoded InputTag of filter product
0031       std::string filterTag_;
0032       /// physics object type as per filter
0033       Vids filterIds_;
0034       /// indices pointing into collection of unique TriggerObjects
0035       Keys filterKeys_;
0036       /// constructors
0037       TriggerFilterObject() : filterTag_(), filterIds_(), filterKeys_() { filterTag_ = edm::InputTag().encode(); }
0038       TriggerFilterObject(const edm::InputTag& filterTag)
0039           : filterTag_(filterTag.encode()), filterIds_(), filterKeys_() {}
0040       TriggerFilterObject(const edm::InputTag& filterTag, const Vids& filterIds, const Keys& filterKeys)
0041           : filterTag_(filterTag.encode()), filterIds_(filterIds), filterKeys_(filterKeys) {}
0042     };
0043 
0044     /// data members
0045   private:
0046     /// processName used to select products packed up
0047     std::string usedProcessName_;
0048     /// Input tags of packed up collections
0049     std::vector<std::string> collectionTags_;
0050     /// 1-past-end indices into linearised vector
0051     Keys collectionKeys_;
0052     /// collection of all unique physics objects (linearised vector)
0053     TriggerObjectCollection triggerObjects_;
0054     /// collection of all TriggerFilterObjects
0055     std::vector<TriggerFilterObject> triggerFilters_;
0056 
0057     ///methods
0058   public:
0059     /// constructors
0060     TriggerEvent() : usedProcessName_(), collectionTags_(), collectionKeys_(), triggerObjects_(), triggerFilters_() {}
0061     TriggerEvent(const std::string& usedProcessName, trigger::size_type nc, trigger::size_type no, trigger::size_type nf)
0062         : usedProcessName_(usedProcessName),
0063           collectionTags_(),
0064           collectionKeys_(),
0065           triggerObjects_(),
0066           triggerFilters_() {
0067       collectionTags_.reserve(nc);
0068       collectionKeys_.reserve(nc);
0069       triggerObjects_.reserve(no);
0070       triggerFilters_.reserve(nf);
0071     }
0072 
0073     /// setters
0074     void addObjects(const TriggerObjectCollection& triggerObjects) {
0075       triggerObjects_.insert(triggerObjects_.end(), triggerObjects.begin(), triggerObjects.end());
0076     }
0077 
0078     void addCollections(const std::vector<edm::InputTag>& collectionTags, const Keys& collectionKeys) {
0079       assert(collectionTags.size() == collectionKeys.size());
0080       const trigger::size_type n(collectionTags.size());
0081       for (trigger::size_type i = 0; i != n; ++i) {
0082         collectionTags_.push_back(collectionTags[i].encode());
0083       }
0084       collectionKeys_.insert(collectionKeys_.end(), collectionKeys.begin(), collectionKeys.end());
0085     }
0086 
0087     void addCollections(const std::vector<std::string>& collectionTags, const Keys& collectionKeys) {
0088       assert(collectionTags.size() == collectionKeys.size());
0089       collectionTags_.insert(collectionTags_.end(), collectionTags.begin(), collectionTags.end());
0090       collectionKeys_.insert(collectionKeys_.end(), collectionKeys.begin(), collectionKeys.end());
0091     }
0092 
0093     void addFilter(const edm::InputTag& filterTag, const Vids& filterIds, const Keys& filterKeys) {
0094       triggerFilters_.push_back(TriggerFilterObject(filterTag, filterIds, filterKeys));
0095     }
0096 
0097     /// getters
0098     const std::string& usedProcessName() const { return usedProcessName_; }
0099     const std::vector<std::string>& collectionTags() const { return collectionTags_; }
0100     const Keys& collectionKeys() const { return collectionKeys_; }
0101     const TriggerObjectCollection& getObjects() const { return triggerObjects_; }
0102 
0103     const edm::InputTag collectionTag(trigger::size_type index) const {
0104       return edm::InputTag(collectionTags_.at(index));
0105     }
0106     const std::string& collectionTagEncoded(trigger::size_type index) const { return collectionTags_.at(index); }
0107     trigger::size_type collectionKey(trigger::size_type index) const { return collectionKeys_.at(index); }
0108     const edm::InputTag filterTag(trigger::size_type index) const {
0109       return edm::InputTag(triggerFilters_.at(index).filterTag_);
0110     }
0111     const std::string& filterTagEncoded(trigger::size_type index) const { return triggerFilters_.at(index).filterTag_; }
0112     std::string filterLabel(trigger::size_type index) const {
0113       const std::string& tag = triggerFilters_.at(index).filterTag_;
0114       std::string::size_type idx = tag.find(':');
0115       return (idx == std::string::npos ? tag : tag.substr(0, idx));
0116     }
0117     const Vids& filterIds(trigger::size_type index) const { return triggerFilters_.at(index).filterIds_; }
0118     const Keys& filterKeys(trigger::size_type index) const { return triggerFilters_.at(index).filterKeys_; }
0119 
0120     /// find index of collection from collection tag
0121     trigger::size_type collectionIndex(const edm::InputTag& collectionTag) const {
0122       const std::string encodedCollectionTag(collectionTag.encode());
0123       const trigger::size_type n(collectionTags_.size());
0124       for (trigger::size_type i = 0; i != n; ++i) {
0125         if (encodedCollectionTag == collectionTags_[i]) {
0126           return i;
0127         }
0128       }
0129       return n;
0130     }
0131     /// find index of filter in data-member vector from filter tag
0132     trigger::size_type filterIndex(const edm::InputTag& filterTag) const {
0133       const std::string encodedFilterTag(filterTag.encode());
0134       const trigger::size_type n(triggerFilters_.size());
0135       for (trigger::size_type i = 0; i != n; ++i) {
0136         if (encodedFilterTag == triggerFilters_[i].filterTag_) {
0137           return i;
0138         }
0139       }
0140       return n;
0141     }
0142 
0143     /// other
0144     trigger::size_type sizeCollections() const { return collectionTags_.size(); }
0145     trigger::size_type sizeObjects() const { return triggerObjects_.size(); }
0146     trigger::size_type sizeFilters() const { return triggerFilters_.size(); }
0147   };
0148 
0149 }  // namespace trigger
0150 
0151 #endif