Skip to content

Commit

Permalink
Migrate from getByLabel to getByToken
Browse files Browse the repository at this point in the history
  • Loading branch information
wmtan committed Feb 27, 2015
1 parent e8753ad commit 7b4dc1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Expand Up @@ -6,6 +6,7 @@
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
#include "FWCore/Utilities/interface/EDGetToken.h"

#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
Expand All @@ -26,7 +27,7 @@ class SimHitTPAssociationProducer : public edm::EDProducer
private:
virtual void produce(edm::Event&, const edm::EventSetup&) override;

std::vector<edm::InputTag> _simHitSrc;
edm::InputTag _trackingParticleSrc;
std::vector<edm::EDGetToken> _simHitSrc;
edm::EDGetToken _trackingParticleSrc;
};
#endif
Expand Up @@ -15,13 +15,14 @@
#include "SimGeneral/TrackingAnalysis/interface/SimHitTPAssociationProducer.h"

SimHitTPAssociationProducer::SimHitTPAssociationProducer(const edm::ParameterSet & cfg)
: _simHitSrc(cfg.getParameter<std::vector<edm::InputTag> >("simHitSrc")),
_trackingParticleSrc(cfg.getParameter<edm::InputTag>("trackingParticleSrc"))
: _simHitSrc(),
_trackingParticleSrc(consumes<TrackingParticleCollection>(cfg.getParameter<edm::InputTag>("trackingParticleSrc")))
{
produces<SimHitTPAssociationList>();
consumes<TrackingParticleCollection>(_trackingParticleSrc);
for(auto const& psit : _simHitSrc) {
consumes<edm::PSimHitContainer>(psit);
std::vector<edm::InputTag> tags = cfg.getParameter<std::vector<edm::InputTag> >("simHitSrc");
_simHitSrc.reserve(tags.size());
for(auto const& tag : tags) {
_simHitSrc.emplace_back(consumes<edm::PSimHitContainer>(tag));
}
}

Expand All @@ -33,7 +34,7 @@ void SimHitTPAssociationProducer::produce(edm::Event& iEvent, const edm::EventSe

// TrackingParticle
edm::Handle<TrackingParticleCollection> TPCollectionH;
iEvent.getByLabel(_trackingParticleSrc, TPCollectionH);
iEvent.getByToken(_trackingParticleSrc, TPCollectionH);

// prepare temporary map between SimTrackId and TrackingParticle index
std::map<std::pair<size_t, EncodedEventId>, TrackingParticleRef> mapping;
Expand All @@ -50,7 +51,7 @@ void SimHitTPAssociationProducer::produce(edm::Event& iEvent, const edm::EventSe
// PSimHits
for (auto const& psit : _simHitSrc ) {
edm::Handle<edm::PSimHitContainer> PSimHitCollectionH;
iEvent.getByLabel(psit, PSimHitCollectionH);
iEvent.getByToken(psit, PSimHitCollectionH);
for (unsigned int psimHit = 0;psimHit != PSimHitCollectionH->size();++psimHit) {
TrackPSimHitRef pSimHitRef(PSimHitCollectionH,psimHit);
std::pair<uint32_t, EncodedEventId> simTkIds(pSimHitRef->trackId(),pSimHitRef->eventId());
Expand Down

0 comments on commit 7b4dc1f

Please sign in to comment.