Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:37:22

0001 // -*- C++ -*-
0002 //
0003 // Package:    PatAlgos
0004 // Class:      pat::PATTriggerObjectStandAloneUnpacker
0005 //
0006 //
0007 /**
0008   \class    pat::PATTriggerObjectStandAloneUnpacker PATTriggerObjectStandAloneUnpacker.h "PhysicsTools/PatAlgos/plugins/PATTriggerObjectStandAloneUnpacker.cc"
0009   \brief    Unpacks a pat::TriggerObjectStandAloneCollection with packed path names.
0010 
0011   The producer will throw, if a pat::TriggerObjectStandAloneCollection with unpacked path names is used as input.
0012 
0013   \author   Volker Adler
0014 */
0015 
0016 #include "FWCore/Framework/interface/global/EDProducer.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/Utilities/interface/InputTag.h"
0021 
0022 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
0023 #include "DataFormats/Common/interface/TriggerResults.h"
0024 
0025 namespace pat {
0026 
0027   class PATTriggerObjectStandAloneUnpacker : public edm::global::EDProducer<> {
0028   public:
0029     explicit PATTriggerObjectStandAloneUnpacker(const edm::ParameterSet& iConfig);
0030     ~PATTriggerObjectStandAloneUnpacker() override {}
0031 
0032   private:
0033     void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0034 
0035     const edm::EDGetTokenT<TriggerObjectStandAloneCollection> patTriggerObjectsStandAloneToken_;
0036     const edm::EDGetTokenT<edm::TriggerResults> triggerResultsToken_;
0037     bool unpackFilterLabels_;
0038     const edm::EDGetTokenT<std::vector<std::string> > filterLabelsToken_;
0039   };
0040 
0041 }  // namespace pat
0042 
0043 using namespace pat;
0044 
0045 PATTriggerObjectStandAloneUnpacker::PATTriggerObjectStandAloneUnpacker(const edm::ParameterSet& iConfig)
0046     : patTriggerObjectsStandAloneToken_(consumes<TriggerObjectStandAloneCollection>(
0047           iConfig.getParameter<edm::InputTag>("patTriggerObjectsStandAlone"))),
0048       triggerResultsToken_(consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("triggerResults"))),
0049       unpackFilterLabels_(iConfig.getParameter<bool>("unpackFilterLabels")) {
0050   produces<TriggerObjectStandAloneCollection>();
0051 }
0052 
0053 void PATTriggerObjectStandAloneUnpacker::produce(edm::StreamID,
0054                                                  edm::Event& iEvent,
0055                                                  const edm::EventSetup& iSetup) const {
0056   edm::Handle<TriggerObjectStandAloneCollection> patTriggerObjectsStandAlone;
0057   iEvent.getByToken(patTriggerObjectsStandAloneToken_, patTriggerObjectsStandAlone);
0058   edm::Handle<edm::TriggerResults> triggerResults;
0059   iEvent.getByToken(triggerResultsToken_, triggerResults);
0060 
0061   auto patTriggerObjectsStandAloneUnpacked = std::make_unique<TriggerObjectStandAloneCollection>();
0062 
0063   for (size_t iTrigObj = 0; iTrigObj < patTriggerObjectsStandAlone->size(); ++iTrigObj) {
0064     TriggerObjectStandAlone patTriggerObjectStandAloneUnpacked(patTriggerObjectsStandAlone->at(iTrigObj));
0065     const edm::TriggerNames& names = iEvent.triggerNames(*triggerResults);
0066     patTriggerObjectStandAloneUnpacked.unpackPathNames(names);
0067     if (unpackFilterLabels_)
0068       patTriggerObjectStandAloneUnpacked.unpackFilterLabels(iEvent, *triggerResults);
0069     patTriggerObjectsStandAloneUnpacked->push_back(patTriggerObjectStandAloneUnpacked);
0070   }
0071 
0072   iEvent.put(std::move(patTriggerObjectsStandAloneUnpacked));
0073 }
0074 
0075 #include "FWCore/Framework/interface/MakerMacros.h"
0076 DEFINE_FWK_MODULE(PATTriggerObjectStandAloneUnpacker);