Skip to content

Commit

Permalink
Removed CMS deprecation warnings from MagneticField/Engine
Browse files Browse the repository at this point in the history
- converted legacy modules to one::
- added needed esConsumes calls
  • Loading branch information
Dr15Jones committed Oct 14, 2021
1 parent 1adfdc9 commit 36383b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
21 changes: 9 additions & 12 deletions MagneticField/Engine/test/queryField.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<MagneticField> magfield;
setup.get<IdealMagneticFieldRecord>().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;

Expand All @@ -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<MagneticField, IdealMagneticFieldRecord> m_fieldToken;
};

DEFINE_FWK_MODULE(queryField);
16 changes: 7 additions & 9 deletions MagneticField/Engine/test/testMagneticField.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <memory>

#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 Down Expand Up @@ -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<string>("outputTable", "");
inputFile = pset.getUntrackedParameter<string>("inputTable", "");
Expand All @@ -72,15 +72,12 @@ class testMagneticField : public edm::EDAnalyzer {
maxZ = pset.getUntrackedParameter<double>("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<MagneticField> magfield;
setup.get<IdealMagneticFieldRecord>().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;

Expand Down Expand Up @@ -131,6 +128,7 @@ class testMagneticField : public edm::EDAnalyzer {
void compareSectorTables(string file);

private:
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> fieldToken;
const MagneticField* field;
string inputFile;
string inputFileType;
Expand Down

0 comments on commit 36383b7

Please sign in to comment.