Skip to content

Commit

Permalink
Migrate from legacy to global module type
Browse files Browse the repository at this point in the history
TestPRegisterModule1
TestPRegisterModule2
RandomFilter
  • Loading branch information
wddgit committed Sep 27, 2022
1 parent 185fd98 commit 90b7d1b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 144 deletions.
2 changes: 1 addition & 1 deletion FWCore/Framework/test/BuildFile.xml
Expand Up @@ -155,7 +155,7 @@
<use name="FWCore/Utilities"/>
</library>

<library file="stubs/TestPRegisterModule2.cc,stubs/TestPRegisterModule1.cc,stubs/TestPRegisterModules.cc" name="FWCoreFrameworkTestPRegisterModules">
<library file="stubs/TestPRegisterModule2.cc,stubs/TestPRegisterModule1.cc" name="FWCoreFrameworkTestPRegisterModules">
<flags EDM_PLUGIN="1"/>
<use name="DataFormats/Common"/>
<use name="FWCore/Framework"/>
Expand Down
39 changes: 29 additions & 10 deletions FWCore/Framework/test/stubs/TestPRegisterModule1.cc
@@ -1,25 +1,44 @@
/**
\file
Test Modules for testProductRegistry
// -*- C++ -*-
//
// Package: FWCore/Framework
// Class : TestPRegisterModule1
//
/**\class TestPRegisterModule1
\author Stefano ARGIRO
Description:
Usage:
\author Stefano ARGIRO, Chris Jones
\date 19 May 2005
*/

#include "DataFormats/TestObjects/interface/ToyProducts.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/FrameworkfwdMostUsed.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DataFormats/TestObjects/interface/ToyProducts.h"
#include "FWCore/Framework/test/stubs/TestPRegisterModule1.h"
#include <memory>
#include <string>

using namespace edm;
class TestPRegisterModule1 : public edm::global::EDProducer<> {
public:
explicit TestPRegisterModule1(edm::ParameterSet const&);
void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;

private:
edm::ParameterSet pset_;
};

TestPRegisterModule1::TestPRegisterModule1(edm::ParameterSet const& p) : pset_(p) {
TestPRegisterModule1::TestPRegisterModule1(edm::ParameterSet const& pset) : pset_(pset) {
produces<edmtest::StringProduct>();
}

void TestPRegisterModule1::produce(Event& e, EventSetup const&) {
void TestPRegisterModule1::produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const {
std::string myname = pset_.getParameter<std::string>("@module_label");
e.put(std::make_unique<edmtest::StringProduct>(myname));
event.put(std::make_unique<edmtest::StringProduct>(myname));
}

DEFINE_FWK_MODULE(TestPRegisterModule1);
38 changes: 0 additions & 38 deletions FWCore/Framework/test/stubs/TestPRegisterModule1.h

This file was deleted.

49 changes: 33 additions & 16 deletions FWCore/Framework/test/stubs/TestPRegisterModule2.cc
@@ -1,32 +1,47 @@
/**
\file
Test Module for testProductRegistry
// -*- C++ -*-
//
// Package: FWCore/Framework
// Class : TestPRegisterModule2
//
/**\class TestPRegisterModule2
\author Stefano ARGIRO
Description:
Usage:
\author Stefano ARGIRO, Chris Jones
\date 19 May 2005
*/

#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"

#include "FWCore/Framework/test/stubs/TestPRegisterModule2.h"
#include "DataFormats/Provenance/interface/StableProvenance.h"
#include "DataFormats/TestObjects/interface/ToyProducts.h"
#include "FWCore/Version/interface/GetReleaseVersion.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/FrameworkfwdMostUsed.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/TypeID.h"

#include "cppunit/extensions/HelperMacros.h"
#include <cassert>

#include <memory>
#include <string>
#include <vector>

using namespace edm;
class TestPRegisterModule2 : public edm::global::EDProducer<> {
public:
explicit TestPRegisterModule2(edm::ParameterSet const&);
void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
};

TestPRegisterModule2::TestPRegisterModule2(edm::ParameterSet const&) {
produces<edmtest::DoubleProduct>();
consumes<edmtest::StringProduct>(edm::InputTag{"m2"});
}

void TestPRegisterModule2::produce(Event& e, EventSetup const&) {
void TestPRegisterModule2::produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const {
std::vector<edm::StableProvenance const*> plist;
e.getAllStableProvenance(plist);
event.getAllStableProvenance(plist);

std::vector<edm::StableProvenance const*>::const_iterator pd = plist.begin();

Expand All @@ -50,9 +65,11 @@ void TestPRegisterModule2::produce(Event& e, EventSetup const&) {
CPPUNIT_ASSERT(dID.friendlyClassName() == (*pd)->friendlyClassName());
CPPUNIT_ASSERT((*pd)->moduleLabel() == "m2");

Handle<edmtest::StringProduct> stringp;
e.getByLabel("m2", stringp);
edm::Handle<edmtest::StringProduct> stringp;
event.getByLabel("m2", stringp);
CPPUNIT_ASSERT(stringp->name_ == "m1");

e.put(std::make_unique<edmtest::DoubleProduct>());
event.put(std::make_unique<edmtest::DoubleProduct>());
}

DEFINE_FWK_MODULE(TestPRegisterModule2);
43 changes: 0 additions & 43 deletions FWCore/Framework/test/stubs/TestPRegisterModule2.h

This file was deleted.

21 changes: 0 additions & 21 deletions FWCore/Framework/test/stubs/TestPRegisterModules.cc

This file was deleted.

7 changes: 3 additions & 4 deletions IOMC/RandomEngine/src/RandomFilter.cc
Expand Up @@ -6,6 +6,7 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
#include "FWCore/Utilities/interface/StreamID.h"

#include "CLHEP/Random/RandomEngine.h"

Expand All @@ -21,11 +22,9 @@ RandomFilter::RandomFilter(edm::ParameterSet const& ps) : acceptRate_(ps.getUntr
}
}

RandomFilter::~RandomFilter() {}

bool RandomFilter::filter(edm::Event& event, edm::EventSetup const&) {
bool RandomFilter::filter(edm::StreamID streamID, edm::Event&, edm::EventSetup const&) const {
Service<RandomNumberGenerator> rng;
CLHEP::HepRandomEngine& engine = rng->getEngine(event.streamID());
CLHEP::HepRandomEngine& engine = rng->getEngine(streamID);
if (engine.flat() < acceptRate_)
return true;
return false;
Expand Down
18 changes: 7 additions & 11 deletions IOMC/RandomEngine/src/RandomFilter.h
@@ -1,9 +1,9 @@
// -*- C++ -*-
//
// Package: RandomEngine
// Package: IOMC/RandomEngine
// Class: RandomFilter
//
/**\class RandomFilter RandomFilter.h IOMC/RandomEngine/src/RandomFilter.h
/**\class edm::RandomFilter
Description: The output of this module is used for test purposes.
It is a filter module that makes a filter decision based on a
Expand All @@ -18,19 +18,15 @@ type and name is "untracked double acceptRate".
// Created: 26 March 2007
//

#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/FrameworkfwdMostUsed.h"
#include "FWCore/Framework/interface/global/EDFilter.h"

namespace edm {
class ParameterSet;
class Event;
class EventSetup;

class RandomFilter : public edm::EDFilter {
class RandomFilter : public edm::global::EDFilter<> {
public:
explicit RandomFilter(edm::ParameterSet const& ps);
~RandomFilter() override;

bool filter(edm::Event& e, edm::EventSetup const& c) override;
explicit RandomFilter(edm::ParameterSet const&);
bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;

private:
// value between 0 and 1
Expand Down

0 comments on commit 90b7d1b

Please sign in to comment.