Skip to content

Commit

Permalink
Merge pull request cms-sw#32858 from mmusich/moreESConsmumeMigration_1
Browse files Browse the repository at this point in the history
More esConsumes migration in the Alignment area
  • Loading branch information
cmsbuild authored Feb 11, 2021
2 parents a09e085 + 3bebeda commit 3220826
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 47 deletions.
13 changes: 7 additions & 6 deletions Alignment/CommonAlignment/plugins/APVModeFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/Exception.h"
Expand Down Expand Up @@ -74,6 +73,9 @@ class APVModeFilter : public edm::stream::EDFilter<> {

// ----------member data ---------------------------

// esConsumes
const edm::ESGetToken<SiStripLatency, SiStripLatencyRcd> latencyToken_;

/// bits of interest for the APV mode
static constexpr std::array<size_t, 2> bits_ = {{1, 3}};
static constexpr BitMask deco_ = BitMask(0); /// deco mode bit mask (0000)
Expand All @@ -96,7 +98,8 @@ constexpr APVModeFilter::BitMask APVModeFilter::multi_;
// constructors and destructor
//
APVModeFilter::APVModeFilter(const edm::ParameterSet& iConfig)
: mode_(convertMode(iConfig.getUntrackedParameter<std::string>("apvMode"))) {
: latencyToken_(esConsumes<edm::Transition::BeginRun>()),
mode_(convertMode(iConfig.getUntrackedParameter<std::string>("apvMode"))) {
edm::LogInfo("Alignment") << "@SUB=APVModeFilter::APVModeFilter"
<< "Selecting events with APV mode '"
<< iConfig.getUntrackedParameter<std::string>("apvMode") << "'.";
Expand All @@ -111,10 +114,8 @@ bool APVModeFilter::filter(edm::Event&, const edm::EventSetup&) { return mode_ =

// ------------ method called when starting to processes a run ------------
void APVModeFilter::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
edm::ESHandle<SiStripLatency> siStripLatency;
iSetup.get<SiStripLatencyRcd>().get(siStripLatency);
auto product = siStripLatency.product();
modeCurrentRun_ = convertMode(product->singleMode());
const auto& siStripLatency = &iSetup.getData(latencyToken_);
modeCurrentRun_ = convertMode(siStripLatency->singleMode());
}

APVModeFilter::BitMask APVModeFilter::convertMode(const std::string& mode) const {
Expand Down
13 changes: 8 additions & 5 deletions Alignment/CommonAlignment/plugins/MagneticFieldFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "CondFormats/RunInfo/interface/RunInfo.h"
Expand All @@ -52,6 +51,10 @@ class MagneticFieldFilter : public edm::stream::EDFilter<> {
float currentToField(const float& current) const;

// ----------member data ---------------------------

// esConsumes
const edm::ESGetToken<RunInfo, RunInfoRcd> runInfoToken_;

/// see: https://hypernews.cern.ch/HyperNews/CMS/get/magnetic-field/63/1/1/1.html
static constexpr float linearCoeffCurrentToField_ = 2.084287e-04;
/// see: https://hypernews.cern.ch/HyperNews/CMS/get/magnetic-field/63/1/1/1.html
Expand All @@ -71,7 +74,9 @@ constexpr float MagneticFieldFilter::constantTermCurrentToField_;
// constructor
//
MagneticFieldFilter::MagneticFieldFilter(const edm::ParameterSet& iConfig)
: magneticField_(iConfig.getUntrackedParameter<int>("magneticField")), magneticFieldCurrentRun_(-10000) {}
: runInfoToken_(esConsumes<edm::Transition::BeginRun>()),
magneticField_(iConfig.getUntrackedParameter<int>("magneticField")),
magneticFieldCurrentRun_(-10000) {}

//
// member functions
Expand All @@ -85,9 +90,7 @@ bool MagneticFieldFilter::filter(edm::Event&, const edm::EventSetup&) {
// ------------ method called when starting to processes a run ------------

void MagneticFieldFilter::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
edm::ESHandle<RunInfo> sum;
iSetup.get<RunInfoRcd>().get(sum);
auto summary = sum.product();
const auto& summary = &iSetup.getData(runInfoToken_);
// convert from Tesla to kGauss (multiply with 10) and
// round off to whole kGauss (add 0.5 and cast to int) as is done in
// 'MagneticField::computeNominalValue()':
Expand Down
5 changes: 2 additions & 3 deletions Alignment/HIPAlignmentAlgorithm/interface/LhcTrackAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#define LhcTrackAnalyzer_h

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand Down Expand Up @@ -51,7 +50,7 @@
// class decleration
//

class LhcTrackAnalyzer : public edm::EDAnalyzer {
class LhcTrackAnalyzer : public edm::one::EDAnalyzer<> {
public:
explicit LhcTrackAnalyzer(const edm::ParameterSet&);
~LhcTrackAnalyzer() override;
Expand Down
28 changes: 16 additions & 12 deletions Alignment/HIPAlignmentAlgorithm/plugins/HIPTwoBodyDecayAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand All @@ -29,7 +29,7 @@
#include "RecoVertex/KalmanVertexFit/interface/KalmanVertexFitter.h"
#include "RecoVertex/VertexPrimitives/interface/ConvertToFromReco.h"

class HIPTwoBodyDecayAnalyzer : public edm::EDAnalyzer {
class HIPTwoBodyDecayAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit HIPTwoBodyDecayAnalyzer(const edm::ParameterSet&);
~HIPTwoBodyDecayAnalyzer() override;
Expand All @@ -47,6 +47,9 @@ class HIPTwoBodyDecayAnalyzer : public edm::EDAnalyzer {
std::vector<std::pair<std::string, short*>> shortBranches;

private:
// es consumes
const edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> ttkbuilderToken_;

enum BranchType { BranchType_short_t, BranchType_int_t, BranchType_float_t, BranchType_unknown_t };

void beginJob() override;
Expand Down Expand Up @@ -77,15 +80,18 @@ class HIPTwoBodyDecayAnalyzer : public edm::EDAnalyzer {
bool actuateBranches();

void analyzeTrackCollection(std::string strTrackType,
edm::ESHandle<TransientTrackBuilder>& theTTBuilder,
const TransientTrackBuilder& theTTBuilder,
edm::Handle<reco::TrackCollection>& hTrackColl,
bool verbose = false);
reco::Vertex fitDimuonVertex(edm::ESHandle<TransientTrackBuilder>& theTTBuilder,
reco::Vertex fitDimuonVertex(const TransientTrackBuilder& theTTBuilder,
edm::Handle<reco::TrackCollection>& hTrackColl,
bool& fitOk);
};

HIPTwoBodyDecayAnalyzer::HIPTwoBodyDecayAnalyzer(const edm::ParameterSet& iConfig) {
HIPTwoBodyDecayAnalyzer::HIPTwoBodyDecayAnalyzer(const edm::ParameterSet& iConfig)
: ttkbuilderToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))) {
usesResource(TFileService::kSharedResource);

alcareco_trackCollToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("alcarecotracks"));
refit1_trackCollToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("refit1tracks"));
ctf_trackCollToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("refit2tracks"));
Expand Down Expand Up @@ -265,9 +271,7 @@ void HIPTwoBodyDecayAnalyzer::analyze(const edm::Event& iEvent, const edm::Event
edm::Handle<reco::TrackCollection> finaltracks;
iEvent.getByToken(final_trackCollToken_, finaltracks);

edm::ESHandle<TransientTrackBuilder> theTTBuilder;
iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", theTTBuilder);

const auto& theTTBuilder = iSetup.getData(ttkbuilderToken_);
initializeBranches();

analyzeTrackCollection("alcareco", theTTBuilder, alcarecotracks);
Expand All @@ -288,7 +292,7 @@ void HIPTwoBodyDecayAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& d
}

void HIPTwoBodyDecayAnalyzer::analyzeTrackCollection(std::string strTrackType,
edm::ESHandle<TransientTrackBuilder>& theTTBuilder,
const TransientTrackBuilder& theTTBuilder,
edm::Handle<reco::TrackCollection>& hTrackColl,
bool verbose) {
if (verbose)
Expand Down Expand Up @@ -357,7 +361,7 @@ void HIPTwoBodyDecayAnalyzer::analyzeTrackCollection(std::string strTrackType,
// Recalculate track momenta with this vertex as reference
j = 0;
for (reco::TrackCollection::const_iterator track = hTrackColl->begin(); track != hTrackColl->end(); ++track) {
TransientTrack t_track = theTTBuilder->build(&(*track));
TransientTrack t_track = theTTBuilder.build(&(*track));
AnalyticalImpactPointExtrapolator extrapolator(t_track.field());
TrajectoryStateOnSurface closestIn3DSpaceState =
extrapolator.extrapolate(t_track.impactPointState(), RecoVertex::convertPos(ZVtx.position()));
Expand Down Expand Up @@ -404,15 +408,15 @@ void HIPTwoBodyDecayAnalyzer::analyzeTrackCollection(std::string strTrackType,
}
}

reco::Vertex HIPTwoBodyDecayAnalyzer::fitDimuonVertex(edm::ESHandle<TransientTrackBuilder>& theTTBuilder,
reco::Vertex HIPTwoBodyDecayAnalyzer::fitDimuonVertex(const TransientTrackBuilder& theTTBuilder,
edm::Handle<reco::TrackCollection>& hTrackColl,
bool& fitOk) {
using namespace edm;
using namespace reco;

std::vector<TransientTrack> t_tks;
for (TrackCollection::const_iterator track = hTrackColl->begin(); track != hTrackColl->end(); ++track) {
TransientTrack tt = theTTBuilder->build(&(*track));
TransientTrack tt = theTTBuilder.build(&(*track));
t_tks.push_back(tt);
}

Expand Down
32 changes: 11 additions & 21 deletions Alignment/MillePedeAlignmentAlgorithm/plugins/MillePedeDQMModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,24 @@
#include "TH1F.h"

/*** Core framework functionality ***/
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

/*** Geometry ***/
#include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"

/*** Alignment ***/
#include "Alignment/MillePedeAlignmentAlgorithm/interface/PedeLabelerBase.h"
#include "Alignment/MillePedeAlignmentAlgorithm/interface/PedeLabelerPluginFactory.h"
#include "Alignment/TrackerAlignment/interface/AlignableTracker.h"

/*** Thresholds from DB ***/
#include "CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h"

/*** Necessary Framework infrastructure ***/
#include "FWCore/Framework/interface/ProcessBlock.h"
#include "DataFormats/Alignment/interface/AlignmentToken.h"

MillePedeDQMModule ::MillePedeDQMModule(const edm::ParameterSet& config)
: mpReaderConfig_(config.getParameter<edm::ParameterSet>("MillePedeFileReader")) {
: tTopoToken_(esConsumes<edm::Transition::BeginRun>()),
gDetToken_(esConsumes<edm::Transition::BeginRun>()),
ptpToken_(esConsumes<edm::Transition::BeginRun>()),
aliThrToken_(esConsumes<edm::Transition::BeginRun>()),
mpReaderConfig_(config.getParameter<edm::ParameterSet>("MillePedeFileReader")) {
consumes<AlignmentToken, edm::InProcess>(config.getParameter<edm::InputTag>("alignmentTokenSrc"));
}

Expand Down Expand Up @@ -89,25 +84,20 @@ void MillePedeDQMModule ::beginRun(const edm::Run&, const edm::EventSetup& setup
if (!setupChanged(setup))
return;

edm::ESHandle<TrackerTopology> tTopo;
setup.get<TrackerTopologyRcd>().get(tTopo);
edm::ESHandle<GeometricDet> geometricDet;
setup.get<IdealGeometryRecord>().get(geometricDet);
edm::ESHandle<PTrackerParameters> ptp;
setup.get<PTrackerParametersRcd>().get(ptp);
const TrackerTopology* const tTopo = &setup.getData(tTopoToken_);
const GeometricDet* geometricDet = &setup.getData(gDetToken_);
const PTrackerParameters* ptp = &setup.getData(ptpToken_);

// take the thresholds from DB
edm::ESHandle<AlignPCLThresholds> thresholdHandle;
setup.get<AlignPCLThresholdsRcd>().get(thresholdHandle);
auto thresholds_ = thresholdHandle.product();
const auto& thresholds_ = &setup.getData(aliThrToken_);

auto myThresholds = std::make_shared<AlignPCLThresholds>();
myThresholds->setAlignPCLThresholds(thresholds_->getNrecords(), thresholds_->getThreshold_Map());

TrackerGeomBuilderFromGeometricDet builder;

const auto trackerGeometry = builder.build(&(*geometricDet), *ptp, &(*tTopo));
tracker_ = std::make_unique<AlignableTracker>(trackerGeometry, &(*tTopo));
const auto trackerGeometry = builder.build(geometricDet, *ptp, tTopo);
tracker_ = std::make_unique<AlignableTracker>(trackerGeometry, tTopo);

const std::string labelerPlugin{"PedeLabeler"};
edm::ParameterSet labelerConfig{};
Expand Down
14 changes: 14 additions & 0 deletions Alignment/MillePedeAlignmentAlgorithm/plugins/MillePedeDQMModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

/*** Geometry ***/
#include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"

/*** Thresholds from DB ***/
#include "CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h"

/*** DQM ***/
#include "DQMServices/Core/interface/DQMEDHarvester.h"
#include "DQMServices/Core/interface/DQMStore.h"
Expand Down Expand Up @@ -68,6 +76,12 @@ class MillePedeDQMModule : public DQMEDHarvester {
//========================== PRIVATE DATA ====================================
//============================================================================

// esConsumes
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
const edm::ESGetToken<GeometricDet, IdealGeometryRecord> gDetToken_;
const edm::ESGetToken<PTrackerParameters, PTrackerParametersRcd> ptpToken_;
const edm::ESGetToken<AlignPCLThresholds, AlignPCLThresholdsRcd> aliThrToken_;

const edm::ParameterSet mpReaderConfig_;
std::unique_ptr<AlignableTracker> tracker_;
std::unique_ptr<MillePedeFileReader> mpReader_;
Expand Down

0 comments on commit 3220826

Please sign in to comment.