Skip to content

Commit

Permalink
Merge pull request #44063 from wddgit/removeOwnVectorTrackingRegion
Browse files Browse the repository at this point in the history
Migrate away from ```OwnVector<TrackingRegion>```
  • Loading branch information
cmsbuild authored Feb 29, 2024
2 parents 2d3751c + f2ac2b8 commit 596d17b
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 66 deletions.
2 changes: 1 addition & 1 deletion DQM/TrackingMonitor/interface/TrackBuildingAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TrackBuildingAnalyzer {
const std::vector<const MVACollection*>& mvaCollections,
const std::vector<const QualityMaskCollection*>& qualityMaskCollections);
void analyze(const reco::CandidateView& regionCandidates);
void analyze(const edm::OwnVector<TrackingRegion>& regions);
void analyze(const std::vector<std::unique_ptr<TrackingRegion>>& regions);
void analyze(const TrackingRegionsSeedingLayerSets& regions);

private:
Expand Down
21 changes: 11 additions & 10 deletions DQM/TrackingMonitor/interface/TrackingMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Monitoring source for general quantities related to tracks.

#include <memory>
#include <fstream>
#include <vector>

#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
Expand Down Expand Up @@ -41,7 +43,6 @@ Monitoring source for general quantities related to tracks.
#include "DataFormats/Scalers/interface/LumiScalers.h"
#include "DataFormats/OnlineMetaData/interface/OnlineLuminosityRecord.h"

#include "DataFormats/Common/interface/OwnVector.h"
#include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
#include "RecoTracker/TkTrackingRegions/interface/TrackingRegionsSeedingLayerSets.h"

Expand Down Expand Up @@ -93,12 +94,12 @@ class TrackingMonitor : public DQMEDAnalyzer {
edm::EDGetTokenT<reco::BeamSpot> bsSrcToken_;
edm::EDGetTokenT<reco::VertexCollection> pvSrcToken_;

edm::EDGetTokenT<edm::View<reco::Track> > allTrackToken_;
edm::EDGetTokenT<edm::View<reco::Track> > trackToken_;
edm::EDGetTokenT<edm::View<reco::Track>> allTrackToken_;
edm::EDGetTokenT<edm::View<reco::Track>> trackToken_;
edm::EDGetTokenT<TrackCandidateCollection> trackCandidateToken_;
edm::EDGetTokenT<edm::View<TrajectorySeed> > seedToken_;
edm::EDGetTokenT<std::vector<SeedStopInfo> > seedStopInfoToken_;
edm::EDGetTokenT<edm::OwnVector<TrackingRegion> > regionToken_;
edm::EDGetTokenT<edm::View<TrajectorySeed>> seedToken_;
edm::EDGetTokenT<std::vector<SeedStopInfo>> seedStopInfoToken_;
edm::EDGetTokenT<std::vector<std::unique_ptr<TrackingRegion>>> regionToken_;
edm::EDGetTokenT<TrackingRegionsSeedingLayerSets> regionLayerSetsToken_;
edm::EDGetTokenT<reco::CandidateView> regionCandidateToken_;

Expand All @@ -107,11 +108,11 @@ class TrackingMonitor : public DQMEDAnalyzer {

edm::InputTag stripClusterInputTag_;
edm::InputTag pixelClusterInputTag_;
edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > stripClustersToken_;
edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster> > pixelClustersToken_;
edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster>> stripClustersToken_;
edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster>> pixelClustersToken_;

std::vector<std::tuple<edm::EDGetTokenT<MVACollection>, edm::EDGetTokenT<QualityMaskCollection> > > mvaQualityTokens_;
edm::EDGetTokenT<edm::View<reco::Track> > mvaTrackToken_;
std::vector<std::tuple<edm::EDGetTokenT<MVACollection>, edm::EDGetTokenT<QualityMaskCollection>>> mvaQualityTokens_;
edm::EDGetTokenT<edm::View<reco::Track>> mvaTrackToken_;

edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> transientTrackingRecHitBuilderToken_;
Expand Down
8 changes: 5 additions & 3 deletions DQM/TrackingMonitor/src/TrackBuildingAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void TrackBuildingAnalyzer::initHisto(DQMStore::IBooker& ibooker, const edm::Par

edm::InputTag seedProducer = iConfig.getParameter<edm::InputTag>("SeedProducer");
edm::InputTag tcProducer = iConfig.getParameter<edm::InputTag>("TCProducer");
std::vector<std::string> mvaProducers = iConfig.getParameter<std::vector<std::string> >("MVAProducers");
std::vector<std::string> mvaProducers = iConfig.getParameter<std::vector<std::string>>("MVAProducers");
edm::InputTag regionProducer = iConfig.getParameter<edm::InputTag>("RegionProducer");

// if (doAllPlots){doAllSeedPlots=true; doTCPlots=true;}
Expand Down Expand Up @@ -715,11 +715,13 @@ void TrackBuildingAnalyzer::analyze(const reco::CandidateView& regionCandidates)
}
}

void TrackBuildingAnalyzer::analyze(const edm::OwnVector<TrackingRegion>& regions) { analyzeRegions(regions); }
void TrackBuildingAnalyzer::analyze(const std::vector<std::unique_ptr<TrackingRegion>>& regions) {
analyzeRegions(regions);
}
void TrackBuildingAnalyzer::analyze(const TrackingRegionsSeedingLayerSets& regions) { analyzeRegions(regions); }

namespace {
const TrackingRegion* regionPtr(const TrackingRegion& region) { return &region; }
const TrackingRegion* regionPtr(const std::unique_ptr<TrackingRegion>& region) { return region.get(); }
const TrackingRegion* regionPtr(const TrackingRegionsSeedingLayerSets::RegionLayers& regionLayers) {
return &(regionLayers.region());
}
Expand Down
5 changes: 2 additions & 3 deletions DQM/TrackingMonitor/src/TrackingMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TrackingMonitor::TrackingMonitor(const edm::ParameterSet& iConfig)
if (doRegionPlots) {
const auto& regionTag = iConfig.getParameter<edm::InputTag>("RegionProducer");
if (!regionTag.label().empty()) {
regionToken_ = consumes<edm::OwnVector<TrackingRegion> >(regionTag);
regionToken_ = consumes(regionTag);
}
const auto& regionLayersTag = iConfig.getParameter<edm::InputTag>("RegionSeedingLayersProducer");
if (!regionLayersTag.label().empty()) {
Expand Down Expand Up @@ -993,8 +993,7 @@ void TrackingMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& i
// plots for tracking regions
if (doRegionPlots) {
if (!regionToken_.isUninitialized()) {
edm::Handle<edm::OwnVector<TrackingRegion> > hregions = iEvent.getHandle(regionToken_);
const auto& regions = *hregions;
auto const& regions = iEvent.get(regionToken_);
NumberOfTrackingRegions->Fill(regions.size());

theTrackBuildingAnalyzer->analyze(regions);
Expand Down
12 changes: 5 additions & 7 deletions FastSimulation/Tracking/plugins/TrajectorySeedProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TrajectorySeedProducer : public edm::stream::EDProducer<> {

edm::EDGetTokenT<FastTrackerRecHitCombinationCollection> recHitCombinationsToken;
edm::EDGetTokenT<std::vector<bool>> hitMasksToken;
edm::EDGetTokenT<edm::OwnVector<TrackingRegion>> trackingRegionToken;
edm::EDGetTokenT<std::vector<std::unique_ptr<TrackingRegion>>> trackingRegionToken;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> trackerTopologyESToken_;

// other data members
Expand Down Expand Up @@ -128,7 +128,7 @@ TrajectorySeedProducer::TrajectorySeedProducer(const edm::ParameterSet& conf) :
}

/// regions
trackingRegionToken = consumes<edm::OwnVector<TrackingRegion>>(conf.getParameter<edm::InputTag>("trackingRegions"));
trackingRegionToken = consumes(conf.getParameter<edm::InputTag>("trackingRegions"));

// seed creator
const edm::ParameterSet& seedCreatorPSet = conf.getParameter<edm::ParameterSet>("SeedCreatorPSet");
Expand All @@ -154,9 +154,7 @@ void TrajectorySeedProducer::produce(edm::Event& e, const edm::EventSetup& es) {
std::unique_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection());

// read the regions;
edm::Handle<edm::OwnVector<TrackingRegion>> hregions;
e.getByToken(trackingRegionToken, hregions);
const auto& regions = *hregions;
auto const& regions = e.get(trackingRegionToken);
// and make sure there is at least one region
if (regions.empty()) {
e.put(std::move(output));
Expand Down Expand Up @@ -187,7 +185,7 @@ void TrajectorySeedProducer::produce(edm::Event& e, const edm::EventSetup& es) {
for (const auto& region : regions) {
// set the region used in the selector
if (seedFinderSelector) {
seedFinderSelector->setTrackingRegion(&region);
seedFinderSelector->setTrackingRegion(region.get());
}

// find hits compatible with the seed requirements
Expand All @@ -204,7 +202,7 @@ void TrajectorySeedProducer::produce(edm::Event& e, const edm::EventSetup& es) {
fastTrackingUtilities::setRecHitCombinationIndex(seedHits, icomb);

// create the seed
seedCreator->init(region, es, nullptr);
seedCreator->init(*region, es, nullptr);
seedCreator->makeSeed(*output,
SeedingHitSet(&seedHits[0],
&seedHits[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/Common/interface/OwnVector.h"
#include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"

#include <vector>
Expand All @@ -20,7 +19,7 @@ class TrackSelectorByRegion final : public edm::global::EDProducer<> {
: produceCollection_(conf.getParameter<bool>("produceTrackCollection")),
produceMask_(conf.getParameter<bool>("produceMask")),
tracksToken_(consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("tracks"))),
inputTrkRegionToken_(consumes<edm::OwnVector<TrackingRegion>>(conf.getParameter<edm::InputTag>("regions"))),
inputTrkRegionToken_(consumes(conf.getParameter<edm::InputTag>("regions"))),
outputTracksToken_(produceCollection_ ? produces<reco::TrackCollection>()
: edm::EDPutTokenT<reco::TrackCollection>{}),
outputMaskToken_(produceMask_ ? produces<std::vector<bool>>() : edm::EDPutTokenT<std::vector<bool>>{}) {}
Expand All @@ -46,7 +45,7 @@ class TrackSelectorByRegion final : public edm::global::EDProducer<> {
MaskCollection mask(tracks.size(), false); // output mask

for (auto const& region : regions) {
region.checkTracks(tracks, mask);
region->checkTracks(tracks, mask);
}

if (produceCollection_) {
Expand All @@ -71,7 +70,7 @@ class TrackSelectorByRegion final : public edm::global::EDProducer<> {
const bool produceCollection_;
const bool produceMask_;
const edm::EDGetTokenT<reco::TrackCollection> tracksToken_;
const edm::EDGetTokenT<edm::OwnVector<TrackingRegion>> inputTrkRegionToken_;
const edm::EDGetTokenT<std::vector<std::unique_ptr<TrackingRegion>>> inputTrkRegionToken_;
const edm::EDPutTokenT<reco::TrackCollection> outputTracksToken_;
const edm::EDPutTokenT<std::vector<bool>> outputMaskToken_;
};
Expand Down
22 changes: 11 additions & 11 deletions RecoTracker/TkHitPairs/plugins/HitPairEDProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
#include "FWCore/Utilities/interface/RunningAverage.h"

#include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
#include "DataFormats/Common/interface/OwnVector.h"
#include "TrackingTools/TransientTrackingRecHit/interface/SeedingLayerSetsHits.h"
#include "RecoTracker/TkTrackingRegions/interface/TrackingRegionsSeedingLayerSets.h"
#include "RecoTracker/TkHitPairs/interface/LayerHitMapCache.h"
#include "RecoTracker/TkHitPairs/interface/HitPairGeneratorFromLayerPair.h"
#include "RecoTracker/TkHitPairs/interface/IntermediateHitDoublets.h"
#include "RecoTracker/TkHitPairs/interface/RegionsSeedingHitSets.h"

#include <memory>
#include <vector>

namespace {
class ImplBase;
}
Expand Down Expand Up @@ -260,15 +262,15 @@ namespace {
public:
class const_iterator {
public:
using internal_iterator_type = edm::OwnVector<TrackingRegion>::const_iterator;
using internal_iterator_type = std::vector<std::unique_ptr<TrackingRegion>>::const_iterator;
using value_type = RegionLayers;
using difference_type = internal_iterator_type::difference_type;

const_iterator(internal_iterator_type iter,
const std::vector<SeedingLayerSetsHits::SeedingLayerSet>* layerPairs)
: iter_(iter), layerPairs_(layerPairs) {}

value_type operator*() const { return value_type(&(*iter_), layerPairs_); }
value_type operator*() const { return value_type(&(**iter_), layerPairs_); }

const_iterator& operator++() {
++iter_;
Expand All @@ -289,7 +291,7 @@ namespace {
};

EventTmp(const SeedingLayerSetsHits* seedingLayerSetsHits,
const edm::OwnVector<TrackingRegion>* regions,
const std::vector<std::unique_ptr<TrackingRegion>>* regions,
const std::vector<unsigned>& layerPairBegins)
: seedingLayerSetsHits_(seedingLayerSetsHits), regions_(regions) {
// construct the pairs from the sets
Expand Down Expand Up @@ -349,7 +351,7 @@ namespace {

private:
const SeedingLayerSetsHits* seedingLayerSetsHits_;
const edm::OwnVector<TrackingRegion>* regions_;
const std::vector<std::unique_ptr<TrackingRegion>>* regions_;
std::vector<SeedingLayerSetsHits::SeedingLayerSet> layerPairs;
};

Expand All @@ -359,7 +361,7 @@ namespace {
edm::ConsumesCollector iC)
: layerPairBegins_(layerPairBegins),
seedingLayerToken_(iC.consumes<SeedingLayerSetsHits>(seedingLayerTag)),
regionToken_(iC.consumes<edm::OwnVector<TrackingRegion>>(regionTag)) {}
regionToken_(iC.consumes(regionTag)) {}

EventTmp beginEvent(const edm::Event& iEvent) const {
edm::Handle<SeedingLayerSetsHits> hlayers;
Expand All @@ -370,16 +372,14 @@ namespace {
<< "HitPairEDProducer expects SeedingLayerSetsHits::numberOfLayersInSet() to be >= 2, got "
<< layers->numberOfLayersInSet()
<< ". This is likely caused by a configuration error of this module, or SeedingLayersEDProducer.";
edm::Handle<edm::OwnVector<TrackingRegion>> hregions;
iEvent.getByToken(regionToken_, hregions);

return EventTmp(layers, hregions.product(), *layerPairBegins_);
auto const& regions = iEvent.get(regionToken_);
return EventTmp(layers, &regions, *layerPairBegins_);
}

private:
const std::vector<unsigned>* layerPairBegins_;
edm::EDGetTokenT<SeedingLayerSetsHits> seedingLayerToken_;
edm::EDGetTokenT<edm::OwnVector<TrackingRegion>> regionToken_;
edm::EDGetTokenT<std::vector<std::unique_ptr<TrackingRegion>>> regionToken_;
};

/////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/EDPutToken.h"

#include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
#include "DataFormats/Common/interface/OwnVector.h"

#include <memory>
#include <vector>

template <typename T_TrackingRegionProducer>
class TrackingRegionEDProducerT : public edm::stream::EDProducer<> {
public:
// using OwnVector as vector<shared_ptr> and vector<unique_ptr> cause problems
// I can't get dictionary compiled with unique_ptr
// shared_ptr fails with runtime error "Class name 'TrackingRegionstdshared_ptrs' contains an underscore ('_'), which is illegal in the name of a product."
using ProductType = edm::OwnVector<TrackingRegion>;

TrackingRegionEDProducerT(const edm::ParameterSet& iConfig) : regionProducer_(iConfig, consumesCollector()) {
produces<ProductType>();
}
TrackingRegionEDProducerT(const edm::ParameterSet& iConfig)
: regionsPutToken_{produces()}, regionProducer_(iConfig, consumesCollector()) {}

~TrackingRegionEDProducerT() override = default;

Expand All @@ -28,16 +25,11 @@ class TrackingRegionEDProducerT : public edm::stream::EDProducer<> {

void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
auto regions = regionProducer_.regions(iEvent, iSetup);
auto ret = std::make_unique<ProductType>();
ret->reserve(regions.size());
for (auto& regionPtr : regions) {
ret->push_back(regionPtr.release());
}

iEvent.put(std::move(ret));
iEvent.emplace(regionsPutToken_, std::move(regions));
}

private:
edm::EDPutTokenT<std::vector<std::unique_ptr<TrackingRegion>>> regionsPutToken_;
T_TrackingRegionProducer regionProducer_;
};

Expand Down
11 changes: 2 additions & 9 deletions RecoTracker/TkTrackingRegions/src/classes.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
#include "RecoTracker/TkTrackingRegions/interface/TrackingRegionsSeedingLayerSets.h"
#include "DataFormats/Common/interface/OwnVector.h"
#include "DataFormats/Common/interface/Wrapper.h"

namespace RecoTracker_TkTrackingRegions {
struct dictionary {
edm::OwnVector<TrackingRegion> ovtr;
edm::Wrapper<edm::OwnVector<TrackingRegion> > wovtr;

edm::Wrapper<TrackingRegionsSeedingLayerSets> wtrsls;
};
} // namespace RecoTracker_TkTrackingRegions
#include <memory>
#include <vector>
4 changes: 2 additions & 2 deletions RecoTracker/TkTrackingRegions/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<lcgdict>
<class name="TrackingRegion" persistent="false"/>
<class name="edm::OwnVector<TrackingRegion>" persistent="false"/>
<class name="edm::Wrapper<edm::OwnVector<TrackingRegion> >" persistent="false"/>
<class name="std::vector<std::unique_ptr<TrackingRegion>>" persistent="false"/>
<class name="edm::Wrapper<std::vector<std::unique_ptr<TrackingRegion>>>" persistent="false"/>

<class name="TrackingRegionsSeedingLayerSets" persistent="false"/>
<class name="edm::Wrapper<TrackingRegionsSeedingLayerSets>" persistent="false"/>
Expand Down

0 comments on commit 596d17b

Please sign in to comment.