Skip to content

Commit

Permalink
Moving to emplace & reserving size
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianoDee committed Jul 16, 2021
1 parent 54b2997 commit 680cb1f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions PhysicsTools/PatUtils/plugins/LUTPackedCandidatesProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LUTPackedCandidatesProducer : public edm::global::EDProducer<> {

private:
const edm::EDGetTokenT<pat::PackedCandidateCollection> inputCandidates_;

edm::EDPutTokenT<pat::PackedCandidateCollection> outputCandidates_;
const unsigned int covSchema_;
const unsigned int covVersion_;
const unsigned int nHits_;
Expand All @@ -36,7 +36,8 @@ LUTPackedCandidatesProducer::LUTPackedCandidatesProducer(const edm::ParameterSet
covVersion_(iConfig.getParameter<unsigned int>("covVersion")),
nHits_(iConfig.getParameter<unsigned int>("nHits")),
nPixelHits_(iConfig.getParameter<unsigned int>("nPixelHits")) {
produces<pat::PackedCandidateCollection>("");

outputCandidates_ = produces<pat::PackedCandidateCollection>("");
}

LUTPackedCandidatesProducer::~LUTPackedCandidatesProducer() {}
Expand All @@ -45,17 +46,17 @@ void LUTPackedCandidatesProducer::produce(edm::StreamID, edm::Event &iEvent, con
edm::Handle<pat::PackedCandidateCollection> packedCandidates;
iEvent.getByToken(inputCandidates_, packedCandidates);

auto output = std::make_unique<pat::PackedCandidateCollection>();

pat::PackedCandidateCollection output;
output.reserve(packedCandidates->size());
for (unsigned int ic = 0, nc = packedCandidates->size(); ic < nc; ++ic) {
const pat::PackedCandidate &cand = (*packedCandidates)[ic];
output->push_back(pat::PackedCandidate(cand));
output.push_back(pat::PackedCandidate(cand));

if (!output->back().hasTrackDetails() && output->back().covarianceVersion() == int(covVersion_))
output->back().setTrackPropertiesLite(covSchema_, covVersion_, nHits_, nPixelHits_);
if (!output.back().hasTrackDetails() && output.back().covarianceVersion() == int(covVersion_))
output.back().setTrackPropertiesLite(covSchema_, covVersion_, nHits_, nPixelHits_);
}

iEvent.put(std::move(output));
iEvent.emplace(outputCandidates_,std::move(output));
};

void LUTPackedCandidatesProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
Expand Down

0 comments on commit 680cb1f

Please sign in to comment.