1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// -*- C++ -*-
//
// Package: TestModuleChangeLooper
// Class: TestModuleChangeLooper
//
/**\class TestModuleChangeLooper TestModuleChangeLooper.h FWCore/TestModuleChangeLooper/interface/TestModuleChangeLooper.h
Description: <one line class summary>
Implementation:
<Notes on implementation>
*/
//
// Original Author: Valentin Kuznetsov
// Created: Tue Jul 18 10:17:05 EDT 2006
//
// user include files
#include "DataFormats/TestObjects/interface/ToyProducts.h"
#include "FWCore/Framework/interface/EDLooper.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/LooperFactory.h"
#include "FWCore/Framework/interface/ModuleChanger.h"
#include "FWCore/Framework/interface/ScheduleInfo.h"
// system include files
#include <memory>
//
// class decleration
//
class TestModuleChangeLooper : public edm::EDLooper {
public:
TestModuleChangeLooper(edm::ParameterSet const&);
~TestModuleChangeLooper();
void startingNewLoop(unsigned int) {}
Status duringLoop(edm::Event const& iEvent, edm::EventSetup const&) {
auto const& product = iEvent.get(m_token);
if (product.value != m_expectedValue) {
throw cms::Exception("WrongValue") << "expected value " << m_expectedValue << " but got " << product.value;
}
return kContinue;
}
Status endOfLoop(edm::EventSetup const&, unsigned int iCount) {
//modify the module
Labels labels;
labelsForToken(m_token, labels);
std::string const moduleLabel{labels.module};
edm::ParameterSet const* pset = scheduleInfo()->parametersForModule(moduleLabel);
assert(0 != pset);
edm::ParameterSet newPSet(*pset);
newPSet.addParameter<int>("ivalue", ++m_expectedValue);
auto success = moduleChanger()->changeModule(moduleLabel, newPSet);
assert(success && "moduleChanger()->changeModule(m_tag.label(), newPSet)");
return iCount == 2 ? kStop : kContinue;
}
private:
// ----------member data ---------------------------
int m_expectedValue;
edm::EDGetTokenT<edmtest::IntProduct> m_token;
};
//
// constants, enums and typedefs
//
//
// static data member definitions
//
//
// constructors and destructor
//
TestModuleChangeLooper::TestModuleChangeLooper(edm::ParameterSet const& iConfig)
: m_expectedValue(iConfig.getUntrackedParameter<int>("startingValue")),
m_token(consumes(iConfig.getUntrackedParameter<edm::InputTag>("tag"))) {
//now do what ever other initialization is needed
}
TestModuleChangeLooper::~TestModuleChangeLooper() {
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
}
//
// member functions
//
// ------------ method called to produce the data ------------
//define this as a plug-in
DEFINE_FWK_LOOPER(TestModuleChangeLooper);
|