Skip to content

Commit 52b2549

Browse files
committed
use range whereever possible
1 parent 8c97130 commit 52b2549

File tree

6 files changed

+19
-32
lines changed

6 files changed

+19
-32
lines changed

PhysicsTools/PatAlgos/plugins/PATElectronCandidatesRekeyer.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,17 @@ void PATElectronCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup c
5555
auto outPtrP = std::make_unique<std::vector<pat::Electron>>();
5656
outPtrP->reserve(src->size());
5757

58-
for (size_t i = 0; i < src->size(); ++i) {
58+
for (const auto &obj : *src){
5959
// copy original pat object and append to vector
60-
outPtrP->emplace_back((*src)[i]);
60+
outPtrP->emplace_back(obj);
6161

6262
std::vector<unsigned int> keys;
6363
for (const edm::Ref<pat::PackedCandidateCollection> &ref : outPtrP->back().associatedPackedPFCandidates()) {
6464
keys.push_back(ref.key());
6565
};
6666
outPtrP->back().setAssociatedPackedPFCandidates(
6767
edm::RefProd<pat::PackedCandidateCollection>(pcNewHandle), keys.begin(), keys.end());
68-
if (keys.size() == 1) {
69-
outPtrP->back().refToOrig_ = outPtrP->back().sourceCandidatePtr(0);
70-
} else {
71-
outPtrP->back().refToOrig_ = reco::CandidatePtr(pcNewHandle.id());
72-
}
68+
outPtrP->back().refToOrig_ = (keys.size() == 1) ? outPtrP->back().sourceCandidatePtr(0) : reco::CandidatePtr(pcNewHandle.id());
7369
}
7470
iEvent.put(std::move(outPtrP));
7571
}

PhysicsTools/PatAlgos/plugins/PATJetCandidatesRekeyer.cc

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,9 @@ void PATJetCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup const
6161
//
6262
//
6363
//
64-
for (std::vector<pat::Jet>::const_iterator ibegin = (*src).begin(), iend = (*src).end(), ijet = ibegin; ijet != iend;
65-
++ijet) {
66-
for (TagInfoFwdPtrCollection::const_iterator iinfoBegin = ijet->tagInfosFwdPtr().begin(),
67-
iinfoEnd = ijet->tagInfosFwdPtr().end(),
68-
iinfo = iinfoBegin;
69-
iinfo != iinfoEnd;
70-
++iinfo) {
71-
tagInfosOut->push_back(**iinfo);
64+
for (const auto & jet : *src){
65+
for (const auto & info : jet.tagInfosFwdPtr()){
66+
tagInfosOut->push_back(*info);
7267
}
7368
}
7469

@@ -79,9 +74,9 @@ void PATJetCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup const
7974
//
8075
unsigned int tagInfoIndex = 0;
8176

82-
for (size_t i = 0; i < src->size(); ++i) {
77+
for (const auto & obj : *src){
8378
// copy original pat object and append to vector
84-
outPtrP->emplace_back((*src)[i]);
79+
outPtrP->emplace_back(obj);
8580

8681
reco::CompositePtrCandidate::daughters old = outPtrP->back().daughterPtrVector();
8782
outPtrP->back().clearDaughters();
@@ -91,7 +86,7 @@ void PATJetCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup const
9186

9287
// Copy the tag infos
9388
for (TagInfoFwdPtrCollection::const_iterator iinfoBegin = outPtrP->back().tagInfosFwdPtr().begin(),
94-
iinfoEnd = outPtrP->back().tagInfosFwdPtr().end(),
89+
iinfoEnd = outPtrP->back().tagInfosFwdPtr().end(),
9590
iinfo = iinfoBegin;
9691
iinfo != iinfoEnd;
9792
++iinfo) {

PhysicsTools/PatAlgos/plugins/PATMuonCandidatesRekeyer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ void PATMuonCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup const
5353
auto outPtrP = std::make_unique<std::vector<pat::Muon>>();
5454
outPtrP->reserve(src->size());
5555

56-
for (size_t i = 0; i < src->size(); ++i) {
56+
for (const auto & obj : *src){
5757
// copy original pat object and append to vector
58-
outPtrP->emplace_back((*src)[i]);
58+
outPtrP->emplace_back(obj);
5959

6060
//
6161
std::vector<unsigned int> keys;

PhysicsTools/PatAlgos/plugins/PATPhotonCandidatesRekeyer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ void PATPhotonCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup con
5353
auto outPtrP = std::make_unique<std::vector<pat::Photon>>();
5454
outPtrP->reserve(src->size());
5555

56-
for (size_t i = 0; i < src->size(); ++i) {
56+
for (const auto & obj : *src){
5757
// copy original pat object and append to vector
58-
outPtrP->emplace_back((*src)[i]);
58+
outPtrP->emplace_back(obj);
5959

6060
std::vector<unsigned int> keys;
6161
for (const edm::Ref<pat::PackedCandidateCollection> &ref : outPtrP->back().associatedPackedPFCandidates()) {

PhysicsTools/PatAlgos/plugins/PATTauCandidatesRekeyer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ void PATTauCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup const
5353
auto outPtrP = std::make_unique<std::vector<pat::Tau>>();
5454
outPtrP->reserve(src->size());
5555

56-
for (size_t i = 0; i < src->size(); ++i) {
56+
for (const auto & obj : *src){
5757
// copy original pat object and append to vector
58-
outPtrP->emplace_back((*src)[i]);
58+
outPtrP->emplace_back(obj);
5959

6060
reco::CandidatePtrVector signalChHPtrs;
6161
for (const reco::CandidatePtr &p : outPtrP->back().signalChargedHadrCands()) {

PhysicsTools/PatAlgos/plugins/VertexCompositeCandidateDaughtersRekeyer.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ void VertexCompositeCandidateDaughtersRekeyer::produce(edm::Event &iEvent, edm::
5656
auto outPtrP = std::make_unique<reco::VertexCompositePtrCandidateCollection>();
5757
outPtrP->reserve(src->size());
5858

59-
for (size_t i = 0; i < src->size(); ++i) {
59+
for (const auto & obj : *src){
6060
// copy original object and append to vector
61-
outPtrP->emplace_back((*src)[i]);
61+
outPtrP->emplace_back(obj);
6262

6363
std::vector<reco::CandidatePtr> daughters = outPtrP->back().daughterPtrVector();
6464
outPtrP->back().clearDaughters();
@@ -68,15 +68,11 @@ void VertexCompositeCandidateDaughtersRekeyer::produce(edm::Event &iEvent, edm::
6868
// We check if this CandidatePtr points to a candidate in the original packedPFCandidates collection
6969
// This is needed because the CandidatePtr can point to a candidate in lostTracks collection
7070
//
71-
if (dau.id() == pcOriHandle.id()) {
72-
outPtrP->back().addDaughter(edm::Ptr<reco::Candidate>(pcNewHandle, dau.key()));
73-
} else {
74-
outPtrP->back().addDaughter(dau);
75-
}
71+
outPtrP->back().addDaughter( (dau.id() == pcOriHandle.id()) ? edm::Ptr<reco::Candidate>(pcNewHandle, dau.key()) : dau);
7672
}
7773
}
7874
iEvent.put(std::move(outPtrP));
7975
}
8076

8177
#include "FWCore/Framework/interface/MakerMacros.h"
82-
DEFINE_FWK_MODULE(VertexCompositeCandidateDaughtersRekeyer);
78+
DEFINE_FWK_MODULE(VertexCompositeCandidateDaughtersRekeyer);

0 commit comments

Comments
 (0)