diff --git a/RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.cc b/RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.cc index 8258af4f4538a..43201ba50995e 100644 --- a/RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.cc +++ b/RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.cc @@ -9,8 +9,6 @@ #include #include -#include - #include #include #include @@ -19,9 +17,12 @@ #include #include -GEMCSCSegmentProducer::GEMCSCSegmentProducer(const edm::ParameterSet& pas) : iev(0) { - csc_token = consumes(pas.getParameter("inputObjectsCSC")); - gem_token = consumes(pas.getParameter("inputObjectsGEM")); +GEMCSCSegmentProducer::GEMCSCSegmentProducer(const edm::ParameterSet& pas) + : kCSCGeometryToken_(esConsumes()), + kGEMGeometryToken_(esConsumes()), + kCSCSegmentCollectionToken_(consumes(pas.getParameter("inputObjectsCSC"))), + kGEMRecHitCollectionToken_(consumes(pas.getParameter("inputObjectsGEM"))), + iev(0) { segmentBuilder_ = new GEMCSCSegmentBuilder(pas); // pass on the parameterset // register what this produces @@ -37,12 +38,18 @@ void GEMCSCSegmentProducer::produce(edm::Event& ev, const edm::EventSetup& setup LogDebug("GEMCSCSegment") << "start producing segments for " << ++iev << "th event w/ gem and csc data"; // find the geometry (& conditions?) for this event & cache it in the builder - edm::ESHandle cscg; - setup.get().get(cscg); + const auto cscg = setup.getHandle(kCSCGeometryToken_); + if (not cscg.isValid()) { + edm::LogError("GEMCSCSegment") << "invalid CSCGeometry"; + return; + } const CSCGeometry* cgeom = &*cscg; - edm::ESHandle gemg; - setup.get().get(gemg); + const auto gemg = setup.getHandle(kGEMGeometryToken_); + if (not gemg.isValid()) { + edm::LogError("GEMCSCSegment") << "invalid GEMGeometry"; + return; + } const GEMGeometry* ggeom = &*gemg; // cache the geometry in the builder @@ -52,10 +59,17 @@ void GEMCSCSegmentProducer::produce(edm::Event& ev, const edm::EventSetup& setup segmentBuilder_->LinkGEMRollsToCSCChamberIndex(ggeom, cgeom); // get the collection of CSCSegment and GEMRecHits - edm::Handle cscSegment; - ev.getByToken(csc_token, cscSegment); - edm::Handle gemRecHits; - ev.getByToken(gem_token, gemRecHits); + const auto cscSegment = ev.getHandle(kCSCSegmentCollectionToken_); + if (not cscSegment.isValid()) { + edm::LogError("GEMCSCSegment") << "invalid CSCSegmentCollection"; + return; + } + + const auto gemRecHits = ev.getHandle(kGEMRecHitCollectionToken_); + if (not gemRecHits.isValid()) { + edm::LogError("GEMCSCSegment") << "invalid GEMRecHitCollection"; + return; + } // create empty collection of GEMCSC Segments auto oc = std::make_unique(); diff --git a/RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.h b/RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.h index c4d1c60a2e5b2..49ce0c336874d 100644 --- a/RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.h +++ b/RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.h @@ -12,12 +12,17 @@ #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Utilities/interface/InputTag.h" #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h" #include "DataFormats/GEMRecHit/interface/GEMRecHitCollection.h" +#include +#include "Geometry/CSCGeometry/interface/CSCGeometry.h" +#include "Geometry/GEMGeometry/interface/GEMGeometry.h" + class GEMCSCSegmentBuilder; class GEMCSCSegmentProducer : public edm::stream::EDProducer<> { @@ -30,10 +35,13 @@ class GEMCSCSegmentProducer : public edm::stream::EDProducer<> { void produce(edm::Event&, const edm::EventSetup&) override; private: + const edm::ESGetToken kCSCGeometryToken_; + const edm::ESGetToken kGEMGeometryToken_; + const edm::EDGetTokenT kCSCSegmentCollectionToken_; + const edm::EDGetTokenT kGEMRecHitCollectionToken_; + int iev; // events through GEMCSCSegmentBuilder* segmentBuilder_; - edm::EDGetTokenT csc_token; - edm::EDGetTokenT gem_token; }; #endif diff --git a/RecoLocalMuon/GEMCSCSegment/test/TestGEMCSCSegmentAnalyzer.cc b/RecoLocalMuon/GEMCSCSegment/test/TestGEMCSCSegmentAnalyzer.cc index 36933a49403ce..47e2ef9790f7b 100644 --- a/RecoLocalMuon/GEMCSCSegment/test/TestGEMCSCSegmentAnalyzer.cc +++ b/RecoLocalMuon/GEMCSCSegment/test/TestGEMCSCSegmentAnalyzer.cc @@ -30,7 +30,7 @@ // user include files #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/MakerMacros.h" @@ -64,7 +64,7 @@ using namespace std; using namespace edm; -class TestGEMCSCSegmentAnalyzer : public edm::EDAnalyzer { +class TestGEMCSCSegmentAnalyzer : public edm::one::EDAnalyzer<> { public: explicit TestGEMCSCSegmentAnalyzer(const edm::ParameterSet&); ~TestGEMCSCSegmentAnalyzer(); @@ -90,6 +90,8 @@ class TestGEMCSCSegmentAnalyzer : public edm::EDAnalyzer { bool debug; std::string rootFileName; + const edm::ESGetToken kCSCGeometryToken_; + const edm::ESGetToken kGEMGeometryToken_; edm::EDGetTokenT SimTrack_Token; edm::EDGetTokenT CSCSegment_Token; edm::EDGetTokenT GEMCSCSegment_Token; @@ -346,14 +348,15 @@ class TestGEMCSCSegmentAnalyzer : public edm::EDAnalyzer { // constructors and destructor // TestGEMCSCSegmentAnalyzer::TestGEMCSCSegmentAnalyzer(const edm::ParameterSet& iConfig) - -{ + : kCSCGeometryToken_(esConsumes()), + kGEMGeometryToken_(esConsumes()) { //now do what ever initialization is needed debug = iConfig.getUntrackedParameter("Debug"); rootFileName = iConfig.getUntrackedParameter("RootFileName"); // outputfile = new TFile(rootFileName.c_str(), "RECREATE" ); - outputfile.reset(TFile::Open(rootFileName.c_str())); + outputfile.reset(TFile::Open(rootFileName.c_str(), "CREATE")); + outputfile->cd(); SimTrack_Token = consumes(edm::InputTag("g4SimHits")); CSCSegment_Token = consumes(edm::InputTag("cscSegments")); @@ -973,8 +976,17 @@ TestGEMCSCSegmentAnalyzer::~TestGEMCSCSegmentAnalyzer() { // ------------ method called for each event ------------ void TestGEMCSCSegmentAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { - iSetup.get().get(gemGeom); - iSetup.get().get(cscGeom); + const auto gemGeom = iSetup.getHandle(kGEMGeometryToken_); + if (not gemGeom.isValid()) { + edm::LogError("GEMCSCSegment") << "invalid GEMGeometry"; + return; + } + + const auto cscGeom = iSetup.getHandle(kCSCGeometryToken_); + if (not cscGeom.isValid()) { + edm::LogError("GEMCSCSegment") << "invalid CSCGeometry"; + return; + } const CSCGeometry* cscGeom_ = &*cscGeom; // ================