Skip to content

Commit

Permalink
Merge pull request #35526 from Dr15Jones/fixDeprecatedFramework
Browse files Browse the repository at this point in the history
Remove use of legacy module classes from framework tests
  • Loading branch information
cmsbuild authored Oct 7, 2021
2 parents aff49a5 + 277322d commit 8c64ddc
Show file tree
Hide file tree
Showing 52 changed files with 210 additions and 370 deletions.
18 changes: 10 additions & 8 deletions FWCore/Framework/test/stubs/DeleteEarlyModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

// user include files
#include "DataFormats/TestObjects/interface/DeleteEarly.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/global/EDAnalyzer.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/Exception.h"
Expand All @@ -26,16 +26,18 @@
#include "FWCore/Framework/interface/Event.h"

namespace edmtest {
class DeleteEarlyProducer : public edm::EDProducer {
class DeleteEarlyProducer : public edm::global::EDProducer<> {
public:
DeleteEarlyProducer(edm::ParameterSet const& pset) { produces<DeleteEarly>(); }
explicit DeleteEarlyProducer(edm::ParameterSet const& pset) { produces<DeleteEarly>(); }

virtual void beginJob() {
void beginJob() override {
// Needed because DeleteEarly objects may be allocated and deleted in initialization
edmtest::DeleteEarly::resetDeleteCount();
}

virtual void produce(edm::Event& e, edm::EventSetup const&) { e.put(std::make_unique<DeleteEarly>()); }
void produce(edm::StreamID, edm::Event& e, edm::EventSetup const&) const override {
e.put(std::make_unique<DeleteEarly>());
}
};

class DeleteEarlyReader : public edm::global::EDAnalyzer<> {
Expand All @@ -60,12 +62,12 @@ namespace edmtest {
private:
};

class DeleteEarlyCheckDeleteAnalyzer : public edm::EDAnalyzer {
class DeleteEarlyCheckDeleteAnalyzer : public edm::one::EDAnalyzer<> {
public:
DeleteEarlyCheckDeleteAnalyzer(edm::ParameterSet const& pset)
: m_expectedValues(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedValues")), m_index(0) {}

virtual void analyze(edm::Event const&, edm::EventSetup const&) {
void analyze(edm::Event const&, edm::EventSetup const&) override {
if (DeleteEarly::nDeletes() != m_expectedValues.at(m_index)) {
throw cms::Exception("DeleteEarlyError")
<< "On index " << m_index << " we expected " << m_expectedValues[m_index] << " deletes but we see "
Expand Down
4 changes: 2 additions & 2 deletions FWCore/Framework/test/stubs/HistoryAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
----------------------------------------------------------------------*/

#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "DataFormats/Provenance/interface/EventSelectionID.h"
#include "FWCore/Framework/interface/Event.h"
Expand All @@ -27,7 +27,7 @@ namespace edm {

namespace edmtest {

class HistoryAnalyzer : public edm::EDAnalyzer {
class HistoryAnalyzer : public edm::one::EDAnalyzer<> {
public:
explicit HistoryAnalyzer(edm::ParameterSet const& params);
void analyze(edm::Event const& event, edm::EventSetup const&);
Expand Down
4 changes: 2 additions & 2 deletions FWCore/Framework/test/stubs/RunLumiEventAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define Integration_RunLumiEventAnalyzer_h

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/propagate_const.h"

Expand All @@ -14,7 +14,7 @@ namespace edm {

namespace edmtest {

class RunLumiEventAnalyzer : public edm::EDAnalyzer {
class RunLumiEventAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
public:
explicit RunLumiEventAnalyzer(edm::ParameterSet const& pset);

Expand Down
87 changes: 22 additions & 65 deletions FWCore/Framework/test/stubs/TestMergeResults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "DataFormats/TestObjects/interface/ThingWithIsEqual.h"
#include "DataFormats/TestObjects/interface/ThingWithMerge.h"
#include "FWCore/Framework/interface/ConstProductRegistry.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/FileBlock.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
Expand All @@ -41,19 +41,16 @@ namespace edm {

namespace edmtest {

class TestMergeResults : public edm::EDAnalyzer {
class TestMergeResults : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
public:
explicit TestMergeResults(edm::ParameterSet const&);
virtual ~TestMergeResults();

virtual void analyze(edm::Event const& e, edm::EventSetup const& c);
virtual void beginRun(edm::Run const&, edm::EventSetup const&);
virtual void endRun(edm::Run const&, edm::EventSetup const&);
virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
virtual void respondToOpenInputFile(edm::FileBlock const& fb);
virtual void respondToCloseInputFile(edm::FileBlock const& fb);
void endJob();
void analyze(edm::Event const& e, edm::EventSetup const& c) override;
void beginRun(edm::Run const&, edm::EventSetup const&) override;
void endRun(edm::Run const&, edm::EventSetup const&) override;
void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
void endJob() override;

private:
void checkExpectedLumiProducts(unsigned int index,
Expand Down Expand Up @@ -99,20 +96,15 @@ namespace edmtest {

std::vector<int> expectedDroppedEvent_;
std::vector<int> expectedDroppedEvent1_;

int nRespondToOpenInputFile_;
int nRespondToCloseInputFile_;
int expectedRespondToOpenInputFile_;
int expectedRespondToCloseInputFile_;

std::vector<std::string> expectedInputFileNames_;
std::vector<int> expectedDroppedEvent1NEvents_;

bool verbose_;

unsigned int indexRun_;
unsigned int indexLumi_;
unsigned int parentIndex_;
unsigned int droppedIndex1_;
int droppedIndex1EventCount_;
unsigned int processHistoryIndex_;

edm::Handle<edmtest::Thing> h_thing;
Expand Down Expand Up @@ -148,21 +140,16 @@ namespace edmtest {

expectedDroppedEvent_(ps.getUntrackedParameter<std::vector<int> >("expectedDroppedEvent", default_)),
expectedDroppedEvent1_(ps.getUntrackedParameter<std::vector<int> >("expectedDroppedEvent1", default_)),

nRespondToOpenInputFile_(0),
nRespondToCloseInputFile_(0),
expectedRespondToOpenInputFile_(ps.getUntrackedParameter<int>("expectedRespondToOpenInputFile", -1)),
expectedRespondToCloseInputFile_(ps.getUntrackedParameter<int>("expectedRespondToCloseInputFile", -1)),

expectedInputFileNames_(
ps.getUntrackedParameter<std::vector<std::string> >("expectedInputFileNames", defaultvstring_)),
expectedDroppedEvent1NEvents_(
ps.getUntrackedParameter<std::vector<int> >("expectedDroppedEvent1NEvents", default_)),

verbose_(ps.getUntrackedParameter<bool>("verbose", false)),

indexRun_(0),
indexLumi_(0),
parentIndex_(0),
droppedIndex1_(0),
droppedIndex1EventCount_(0),
processHistoryIndex_(0),
testAlias_(ps.getUntrackedParameter<bool>("testAlias", false)) {
auto ap_thing = std::make_unique<edmtest::Thing>();
Expand Down Expand Up @@ -193,6 +180,7 @@ namespace edmtest {
mayConsume<edmtest::Thing>(edm::InputTag{parent, "event", "PROD"});
}
if (expectedDroppedEvent1_.size() > droppedIndex1_) {
assert(expectedDroppedEvent1_.size() == expectedDroppedEvent1NEvents_.size());
consumes<edmtest::ThingWithIsEqual>(edm::InputTag{"makeThingToBeDropped1", "event", "PROD"});
}
consumes<edmtest::Thing>(edm::InputTag{"thingWithMergeProducer", "event", "PROD"});
Expand Down Expand Up @@ -289,10 +277,6 @@ namespace edmtest {

// -----------------------------------------------------------------

TestMergeResults::~TestMergeResults() {}

// -----------------------------------------------------------------

void TestMergeResults::analyze(edm::Event const& e, edm::EventSetup const&) {
assert(e.processHistory().id() == e.processHistoryID());

Expand All @@ -311,6 +295,14 @@ namespace edmtest {
// This one is used to test the merging step when a specific product
// has been dropped or not created in some of the input files.
if (expectedDroppedEvent1_.size() > droppedIndex1_) {
++droppedIndex1EventCount_;
if (droppedIndex1EventCount_ > expectedDroppedEvent1NEvents_[droppedIndex1_]) {
++droppedIndex1_;
std::cout << "advance " << droppedIndex1_ << std::endl;
droppedIndex1EventCount_ = 1;
}
assert(droppedIndex1_ < expectedDroppedEvent1_.size());

edm::InputTag tag("makeThingToBeDropped1", "event", "PROD");
e.getByLabel(tag, h_thingWithIsEqual);
if (expectedDroppedEvent1_[droppedIndex1_] == -1) {
Expand Down Expand Up @@ -510,44 +502,9 @@ namespace edmtest {
indexLumi_ += 3;
}

void TestMergeResults::respondToOpenInputFile(edm::FileBlock const& fb) {
if (verbose_)
edm::LogInfo("TestMergeResults") << "respondToOpenInputFile";

if (!expectedInputFileNames_.empty()) {
if (expectedInputFileNames_.size() <= static_cast<unsigned>(nRespondToOpenInputFile_) ||
expectedInputFileNames_[nRespondToOpenInputFile_] != fb.fileName()) {
std::cerr << "Error while testing merging of run/lumi products in TestMergeResults.cc\n"
<< "Unexpected input filename, expected name = " << expectedInputFileNames_[nRespondToOpenInputFile_]
<< " actual name = " << fb.fileName() << std::endl;
abort();
}
}
++nRespondToOpenInputFile_;
}

void TestMergeResults::respondToCloseInputFile(edm::FileBlock const&) {
if (verbose_)
edm::LogInfo("TestMergeResults") << "respondToCloseInputFile";
++nRespondToCloseInputFile_;
++droppedIndex1_;
}

void TestMergeResults::endJob() {
if (verbose_)
edm::LogInfo("TestMergeResults") << "endJob";

if (expectedRespondToOpenInputFile_ > -1 && nRespondToOpenInputFile_ != expectedRespondToOpenInputFile_) {
std::cerr << "Error while testing merging of run/lumi products in TestMergeResults.cc\n"
<< "Unexpected number of calls to the function respondToOpenInputFile" << std::endl;
abort();
}

if (expectedRespondToCloseInputFile_ > -1 && nRespondToCloseInputFile_ != expectedRespondToCloseInputFile_) {
std::cerr << "Error while testing merging of run/lumi products in TestMergeResults.cc\n"
<< "Unexpected number of calls to the function respondToCloseInputFile" << std::endl;
abort();
}
}

void TestMergeResults::checkExpectedRunProducts(unsigned int index,
Expand Down
8 changes: 4 additions & 4 deletions FWCore/Framework/test/stubs/TestMod.cc
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

#include <iostream>

#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

using namespace edm;

class TestMod : public EDProducer {
class TestMod : public global::EDProducer<> {
public:
explicit TestMod(ParameterSet const& p);

void produce(Event& e, EventSetup const&);
void produce(StreamID, Event& e, EventSetup const&) const final;
};

TestMod::TestMod(ParameterSet const& p) {
Expand All @@ -21,7 +21,7 @@ TestMod::TestMod(ParameterSet const& p) {
// << std::endl;
}

void TestMod::produce(Event&, EventSetup const&) {
void TestMod::produce(StreamID, Event&, EventSetup const&) const {
//std::cerr << "Hi" << std::endl;
}

Expand Down
8 changes: 4 additions & 4 deletions FWCore/Framework/test/stubs/TestSchedulerModule1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
\date 19 May 2005
*/

#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

Expand All @@ -17,17 +17,17 @@

using namespace edm;

class TestSchedulerModule1 : public EDProducer {
class TestSchedulerModule1 : public global::EDProducer<> {
public:
explicit TestSchedulerModule1(ParameterSet const& p) : pset_(p) { produces<edmtest::StringProduct>(); }

void produce(Event& e, EventSetup const&);
void produce(StreamID, Event& e, EventSetup const&) const final;

private:
ParameterSet pset_;
};

void TestSchedulerModule1::produce(Event& e, EventSetup const&) {
void TestSchedulerModule1::produce(StreamID, Event& e, EventSetup const&) const {
std::string myname = pset_.getParameter<std::string>("module_name");
e.put(std::make_unique<edmtest::StringProduct>(myname));
}
Expand Down
8 changes: 4 additions & 4 deletions FWCore/Framework/test/stubs/TestSchedulerModule2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
\date 19 May 2005
*/

#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

Expand All @@ -17,17 +17,17 @@

namespace edm {

class TestSchedulerModule2 : public EDProducer {
class TestSchedulerModule2 : public global::EDProducer<> {
public:
explicit TestSchedulerModule2(ParameterSet const& p) : pset_(p) { produces<edmtest::StringProduct>(); }

void produce(Event& e, EventSetup const&);
void produce(StreamID, Event& e, EventSetup const&) const final;

private:
ParameterSet pset_;
};

void TestSchedulerModule2::produce(Event& e, EventSetup const&) {
void TestSchedulerModule2::produce(StreamID, Event& e, EventSetup const&) const {
std::string myname = pset_.getParameter<std::string>("module_name");
e.put(std::make_unique<edmtest::StringProduct>(myname));
}
Expand Down
Loading

0 comments on commit 8c64ddc

Please sign in to comment.