Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get rid of more UB in TrackListMerger #37384

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 44 additions & 31 deletions RecoTracker/FinalTrackSelectors/plugins/TrackListMerger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class dso_hidden TrackListMerger : public edm::stream::EDProducer<> {
void produce(edm::Event& e, const edm::EventSetup& c) override;

private:
void returnEmptyCollections(edm::Event& e);

using MVACollection = std::vector<float>;
using QualityMaskCollection = std::vector<unsigned char>;

Expand Down Expand Up @@ -333,38 +335,9 @@ void TrackListMerger::produce(edm::Event& e, const edm::EventSetup& es) {
}
}

// output empty collections and early return
if (trackColls.empty()) {
if (trkQualMod_) {
auto vm = std::make_unique<edm::ValueMap<int>>();
e.put(std::move(vm));
auto quals = std::make_unique<QualityMaskCollection>();
e.put(std::move(quals), "QualityMasks");
} else {
auto outputTrks = std::make_unique<reco::TrackCollection>();
e.put(std::move(outputTrks));

if (makeReKeyedSeeds_) {
auto outputSeeds = std::make_unique<TrajectorySeedCollection>();
e.put(std::move(outputSeeds));
}

if (copyExtras_) {
auto outputTrkExtras = std::make_unique<reco::TrackExtraCollection>();
auto outputTrkHits = std::make_unique<TrackingRecHitCollection>();
e.put(std::move(outputTrkExtras));
e.put(std::move(outputTrkHits));
}

auto outputTrajs = std::make_unique<std::vector<Trajectory>>();
outputTTAss = std::make_unique<TrajTrackAssociationCollection>();
e.put(std::move(outputTrajs));
e.put(std::move(outputTTAss));
}
auto vmMVA = std::make_unique<edm::ValueMap<float>>();
e.put(std::move(vmMVA), "MVAVals");
auto mvas = std::make_unique<MVACollection>();
e.put(std::move(mvas), "MVAValues");
// output empty collections and early return
this->returnEmptyCollections(e);
return;
}

Expand All @@ -378,6 +351,12 @@ void TrackListMerger::produce(edm::Event& e, const edm::EventSetup& es) {
rSize += trackCollSizes[i];
}

if (rSize == 0) {
// output empty collections and early return
this->returnEmptyCollections(e);
return;
}

statCount.begin(rSize);

//
Expand Down Expand Up @@ -906,6 +885,40 @@ void TrackListMerger::produce(edm::Event& e, const edm::EventSetup& es) {

} //end produce

void TrackListMerger::returnEmptyCollections(edm::Event& e) {
if (trkQualMod_) {
auto vm = std::make_unique<edm::ValueMap<int>>();
e.put(std::move(vm));
auto quals = std::make_unique<QualityMaskCollection>();
e.put(std::move(quals), "QualityMasks");
} else {
auto outputTrks = std::make_unique<reco::TrackCollection>();
e.put(std::move(outputTrks));

if (makeReKeyedSeeds_) {
auto outputSeeds = std::make_unique<TrajectorySeedCollection>();
e.put(std::move(outputSeeds));
}

if (copyExtras_) {
auto outputTrkExtras = std::make_unique<reco::TrackExtraCollection>();
auto outputTrkHits = std::make_unique<TrackingRecHitCollection>();
e.put(std::move(outputTrkExtras));
e.put(std::move(outputTrkHits));
}

auto outputTrajs = std::make_unique<std::vector<Trajectory>>();
outputTTAss = std::make_unique<TrajTrackAssociationCollection>();
e.put(std::move(outputTrajs));
e.put(std::move(outputTTAss));
}
auto vmMVA = std::make_unique<edm::ValueMap<float>>();
e.put(std::move(vmMVA), "MVAVals");
auto mvas = std::make_unique<MVACollection>();
e.put(std::move(mvas), "MVAValues");
return;
}

#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/MakerMacros.h"

Expand Down