diff --git a/MagneticField/Engine/test/queryField.cc b/MagneticField/Engine/test/queryField.cc index c39d4bbcc6495..21e22ab04210f 100644 --- a/MagneticField/Engine/test/queryField.cc +++ b/MagneticField/Engine/test/queryField.cc @@ -5,7 +5,7 @@ */ #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" @@ -29,19 +29,16 @@ using namespace edm; using namespace Geom; using namespace std; -class queryField : public edm::EDAnalyzer { +class queryField : public edm::one::EDAnalyzer<> { public: - queryField(const edm::ParameterSet& pset) {} + queryField(const edm::ParameterSet&) : m_fieldToken(esConsumes()) {} - ~queryField() {} + ~queryField() final {} - virtual void analyze(const edm::Event& event, const edm::EventSetup& setup) { - ESHandle magfield; - setup.get().get(magfield); + void analyze(const edm::Event& event, const edm::EventSetup& setup) final { + auto const& field = setup.getData(m_fieldToken); - field = magfield.product(); - - cout << "Field Nominal Value: " << field->nominalValue() << endl; + cout << "Field Nominal Value: " << field.nominalValue() << endl; double x, y, z; @@ -53,12 +50,12 @@ class queryField : public edm::EDAnalyzer { GlobalPoint g(x, y, z); - cout << "At R=" << g.perp() << " phi=" << g.phi() << " B=" << field->inTesla(g) << endl; + cout << "At R=" << g.perp() << " phi=" << g.phi() << " B=" << field.inTesla(g) << endl; } } private: - const MagneticField* field; + const edm::ESGetToken m_fieldToken; }; DEFINE_FWK_MODULE(queryField); diff --git a/MagneticField/Engine/test/testMagneticField.cc b/MagneticField/Engine/test/testMagneticField.cc index 88bde438d9550..a4ab570999cd0 100644 --- a/MagneticField/Engine/test/testMagneticField.cc +++ b/MagneticField/Engine/test/testMagneticField.cc @@ -19,7 +19,7 @@ #include #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" @@ -52,9 +52,9 @@ using namespace edm; using namespace Geom; using namespace std; -class testMagneticField : public edm::EDAnalyzer { +class testMagneticField : public edm::one::EDAnalyzer<> { public: - testMagneticField(const edm::ParameterSet& pset) { + testMagneticField(const edm::ParameterSet& pset) : fieldToken(esConsumes()) { // verbose::debugOut = true; outputFile = pset.getUntrackedParameter("outputTable", ""); inputFile = pset.getUntrackedParameter("inputTable", ""); @@ -72,15 +72,12 @@ class testMagneticField : public edm::EDAnalyzer { maxZ = pset.getUntrackedParameter("maxZ", 2400); } - ~testMagneticField() {} + ~testMagneticField() final {} void go(GlobalPoint g) { std::cout << "At: " << g << " phi=" << g.phi() << " B= " << field->inTesla(g) << std::endl; } - virtual void analyze(const edm::Event& event, const edm::EventSetup& setup) { - ESHandle magfield; - setup.get().get(magfield); - - field = magfield.product(); + void analyze(const edm::Event& event, const edm::EventSetup& setup) final { + field = &setup.getData(fieldToken); std::cout << "Nominal Field " << field->nominalValue() << "\n" << std::endl; @@ -131,6 +128,7 @@ class testMagneticField : public edm::EDAnalyzer { void compareSectorTables(string file); private: + const edm::ESGetToken fieldToken; const MagneticField* field; string inputFile; string inputFileType;