File indexing completed on 2024-04-06 12:15:49
0001 #ifndef HLTCollectionProducer_h
0002 #define HLTCollectionProducer_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <string>
0019 #include <vector>
0020
0021
0022 #include "FWCore/Framework/interface/global/EDProducer.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0026 #include "FWCore/Utilities/interface/InputTag.h"
0027 #include "DataFormats/Common/interface/RefVector.h"
0028 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0029 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0030
0031
0032
0033
0034
0035 template <typename T>
0036 class HLTCollectionProducer : public edm::global::EDProducer<> {
0037 public:
0038 explicit HLTCollectionProducer(const edm::ParameterSet&);
0039 ~HLTCollectionProducer() override;
0040 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0041 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0042
0043 private:
0044 const edm::InputTag hltObjectTag_;
0045 const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> hltObjectToken_;
0046 const std::vector<int> triggerTypes_;
0047 };
0048
0049
0050
0051
0052 template <typename T>
0053 HLTCollectionProducer<T>::HLTCollectionProducer(const edm::ParameterSet& iConfig)
0054 : hltObjectTag_(iConfig.getParameter<edm::InputTag>("HLTObject")),
0055 hltObjectToken_(consumes<trigger::TriggerFilterObjectWithRefs>(hltObjectTag_)),
0056 triggerTypes_(iConfig.getParameter<std::vector<int>>("TriggerTypes")) {
0057 produces<std::vector<T>>();
0058 }
0059
0060 template <typename T>
0061 HLTCollectionProducer<T>::~HLTCollectionProducer() {}
0062
0063 template <typename T>
0064 void HLTCollectionProducer<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0065 edm::ParameterSetDescription desc;
0066 desc.add<edm::InputTag>("HLTObject", edm::InputTag("TriggerFilterObjectWithRefs"));
0067 std::vector<int> triggerTypes;
0068 desc.add<std::vector<int>>("TriggerTypes", triggerTypes);
0069 descriptions.add(defaultModuleLabel<HLTCollectionProducer<T>>(), desc);
0070 }
0071
0072
0073
0074
0075
0076
0077 template <typename T>
0078 void HLTCollectionProducer<T>::produce(edm::StreamID iStreamID,
0079 edm::Event& iEvent,
0080 const edm::EventSetup& iSetup) const {
0081 std::unique_ptr<std::vector<T>> collection(new std::vector<T>());
0082
0083
0084 edm::Handle<trigger::TriggerFilterObjectWithRefs> hltObject;
0085 iEvent.getByToken(hltObjectToken_, hltObject);
0086 std::vector<edm::Ref<std::vector<T>>> objectRefs;
0087
0088 for (size_t t = 0; t < triggerTypes_.size(); ++t) {
0089 objectRefs.clear();
0090 hltObject->getObjects(triggerTypes_[t], objectRefs);
0091 for (size_t i = 0; i < objectRefs.size(); ++i) {
0092 collection->push_back(*objectRefs[i]);
0093 }
0094 }
0095
0096 iEvent.put(std::move(collection));
0097 }
0098
0099 #endif