From 8c720fe4fca1ab2961a85cb12283e0637e7beaea Mon Sep 17 00:00:00 2001 From: wmtan Date: Fri, 3 Apr 2015 23:36:12 +0200 Subject: [PATCH] add consumes interface, and fix memory leaks --- .../Muons/plugins/FastTSGFromPropagation.cc | 52 +++++++------------ .../Muons/plugins/FastTSGFromPropagation.h | 29 +++++------ 2 files changed, 33 insertions(+), 48 deletions(-) diff --git a/FastSimulation/Muons/plugins/FastTSGFromPropagation.cc b/FastSimulation/Muons/plugins/FastTSGFromPropagation.cc index e3009ab1c907f..0ea9d9087adb3 100644 --- a/FastSimulation/Muons/plugins/FastTSGFromPropagation.cc +++ b/FastSimulation/Muons/plugins/FastTSGFromPropagation.cc @@ -44,30 +44,20 @@ using namespace std; - -FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet & iConfig,edm::ConsumesCollector& iC) :theTkLayerMeasurements(), theTracker(0), theNavigation(0), theService(0), theEstimator(0), theSigmaZ(0), theConfig (iConfig), - beamSpot_(iConfig.getParameter("beamSpot")) -{ - theCategory = "FastSimulation|Muons||FastTSGFromPropagation"; - theMeasurementTrackerEventTag = iConfig.getParameter("MeasurementTrackerEvent"); +FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet& iConfig,edm::ConsumesCollector& iC) : FastTSGFromPropagation(iConfig, nullptr, iC) { } -FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet & iConfig, const MuonServiceProxy* service,edm::ConsumesCollector& iC) : theTkLayerMeasurements(), theTracker(0), theNavigation(0), theService(service),theUpdator(0), theEstimator(0), theSigmaZ(0), theConfig (iConfig), - beamSpot_(iConfig.getParameter("beamSpot")) -{ - theCategory = "FastSimulation|Muons|FastTSGFromPropagation"; - theMeasurementTrackerEventTag = iConfig.getParameter("MeasurementTrackerEvent"); +FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet& iConfig, const MuonServiceProxy* service, edm::ConsumesCollector& iC) : + theCategory("FastSimulation|Muons|FastTSGFromPropagation"), + theTkLayerMeasurements(), theTracker(), theNavigation(), theService(service), theUpdator(), theEstimator(), theSigmaZ(0.0), theConfig (iConfig), + theSimTrackCollectionToken_(iC.consumes(theConfig.getParameter("SimTrackCollectionLabel"))), + theHitProducer(iC.consumes(theConfig.getParameter("HitProducer"))), + beamSpot_(iC.consumes(iConfig.getParameter("beamSpot"))), + theMeasurementTrackerEventToken_(iC.consumes(iConfig.getParameter("MeasurementTrackerEvent"))) { } -FastTSGFromPropagation::~FastTSGFromPropagation() -{ - +FastTSGFromPropagation::~FastTSGFromPropagation() { LogTrace(theCategory) << " FastTSGFromPropagation dtor called "; - if ( theNavigation ) delete theNavigation; - if ( theUpdator ) delete theUpdator; - if ( theEstimator ) delete theEstimator; - if ( theErrorMatrixAdjuster ) delete theErrorMatrixAdjuster; - } void FastTSGFromPropagation::trackerSeeds(const TrackCand& staMuon, const TrackingRegion& region, @@ -309,7 +299,7 @@ void FastTSGFromPropagation::init(const MuonServiceProxy* service) { theResetMethod = "discrete"; } - theEstimator = new Chi2MeasurementEstimator(theMaxChi2); + theEstimator.reset( new Chi2MeasurementEstimator(theMaxChi2)); theCacheId_MT = 0; @@ -325,24 +315,21 @@ void FastTSGFromPropagation::init(const MuonServiceProxy* service) { theSelectStateFlag = theConfig.getParameter("SelectState"); - theSimTrackCollectionLabel = theConfig.getParameter("SimTrackCollectionLabel"); - theHitProducer = theConfig.getParameter("HitProducer"); - - theUpdator = new KFUpdator(); + theUpdator.reset(new KFUpdator()); theSigmaZ = theConfig.getParameter("SigmaZ"); edm::ParameterSet errorMatrixPset = theConfig.getParameter("errorMatrixPset"); if ( theResetMethod == "matrix" && !errorMatrixPset.empty()){ theAdjustAtIp = errorMatrixPset.getParameter("atIP"); - theErrorMatrixAdjuster = new MuonErrorMatrix(errorMatrixPset); + theErrorMatrixAdjuster.reset(new MuonErrorMatrix(errorMatrixPset)); } else { theAdjustAtIp =false; - theErrorMatrixAdjuster=0; + theErrorMatrixAdjuster.reset(); } theService->eventSetup().get().get(theTracker); - theNavigation = new DirectTrackerNavigation(theTracker); + theNavigation.reset(new DirectTrackerNavigation(theTracker)); edm::ESHandle geometry; theService->eventSetup().get().get(geometry); @@ -354,11 +341,11 @@ void FastTSGFromPropagation::init(const MuonServiceProxy* service) { void FastTSGFromPropagation::setEvent(const edm::Event& iEvent) { - iEvent.getByLabel(beamSpot_, theBeamSpot); + iEvent.getByToken(beamSpot_, theBeamSpot); // retrieve the MC truth (SimTracks) - iEvent.getByLabel(theSimTrackCollectionLabel, theSimTracks); - iEvent.getByLabel(theHitProducer, theGSRecHits); + iEvent.getByToken(theSimTrackCollectionToken_, theSimTracks); + iEvent.getByToken(theHitProducer, theGSRecHits); unsigned long long newCacheId_MT = theService->eventSetup().get().cacheIdentifier(); @@ -370,7 +357,7 @@ void FastTSGFromPropagation::setEvent(const edm::Event& iEvent) { } if ( theUpdateStateFlag ) { - iEvent.getByLabel(theMeasurementTrackerEventTag, theMeasTrackerEvent); + iEvent.getByToken(theMeasurementTrackerEventToken_, theMeasTrackerEvent); theTkLayerMeasurements = LayerMeasurements(*theMeasTracker,*theMeasTrackerEvent); } @@ -386,8 +373,7 @@ void FastTSGFromPropagation::setEvent(const edm::Event& iEvent) { } if ( trackerGeomChanged && (&*theTracker) ) { - if ( theNavigation ) delete theNavigation; - theNavigation = new DirectTrackerNavigation(theTracker); + theNavigation.reset(new DirectTrackerNavigation(theTracker)); } } diff --git a/FastSimulation/Muons/plugins/FastTSGFromPropagation.h b/FastSimulation/Muons/plugins/FastTSGFromPropagation.h index 3ad2c6a721b81..a7126fea5292a 100644 --- a/FastSimulation/Muons/plugins/FastTSGFromPropagation.h +++ b/FastSimulation/Muons/plugins/FastTSGFromPropagation.h @@ -12,7 +12,7 @@ #include "RecoMuon/TrackerSeedGenerator/interface/TrackerSeedGenerator.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/Utilities/interface/EDGetToken.h" #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h" #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h" #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h" @@ -30,6 +30,7 @@ #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h" #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h" #include "FWCore/Framework/interface/ConsumesCollector.h" +#include class LayerMeasurements; @@ -76,9 +77,9 @@ class FastTSGFromPropagation : public TrackerSeedGenerator { const LayerMeasurements* tkLayerMeasurements() const { return &theTkLayerMeasurements; } - const TrajectoryStateUpdator* updator() const {return theUpdator;} + const TrajectoryStateUpdator* updator() const {return theUpdator.get();} - const Chi2MeasurementEstimator* estimator() const { return theEstimator; } + const Chi2MeasurementEstimator* estimator() const { return theEstimator.get(); } edm::ESHandle propagator() const {return theService->propagator(thePropagatorName); } @@ -136,16 +137,15 @@ class FastTSGFromPropagation : public TrackerSeedGenerator { edm::ESHandle theMeasTracker; - const DirectTrackerNavigation* theNavigation; + std::unique_ptr theNavigation; + const TrackerGeometry* theGeometry; const MuonServiceProxy* theService; - const TrajectoryStateUpdator* theUpdator; - - const Chi2MeasurementEstimator* theEstimator; + std::unique_ptr theUpdator; - TrajectoryStateTransform* theTSTransformer; + std::unique_ptr theEstimator; double theMaxChi2; @@ -157,24 +157,23 @@ class FastTSGFromPropagation : public TrackerSeedGenerator { bool theUpdateStateFlag; - edm::InputTag theSimTrackCollectionLabel; - edm::InputTag theHitProducer; - std::string theResetMethod; bool theSelectStateFlag; std::string thePropagatorName; - MuonErrorMatrix * theErrorMatrixAdjuster; + std::unique_ptr theErrorMatrixAdjuster; bool theAdjustAtIp; double theSigmaZ; - edm::ParameterSet theConfig; - edm::InputTag beamSpot_; - edm::InputTag theMeasurementTrackerEventTag; + const edm::ParameterSet theConfig; + edm::EDGetTokenT theSimTrackCollectionToken_; + edm::EDGetTokenT theHitProducer; + edm::EDGetTokenT beamSpot_; + edm::EDGetTokenT theMeasurementTrackerEventToken_; edm::Handle theBeamSpot; edm::Handle theSimTracks;