File indexing completed on 2024-04-06 12:12:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0020 #include "FWCore/Framework/interface/EDLooper.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/LooperFactory.h"
0023 #include "FWCore/Framework/interface/ModuleChanger.h"
0024 #include "FWCore/Framework/interface/ScheduleInfo.h"
0025
0026
0027 #include <memory>
0028
0029
0030
0031
0032
0033 class TestModuleChangeLooper : public edm::EDLooper {
0034 public:
0035 TestModuleChangeLooper(edm::ParameterSet const&);
0036 ~TestModuleChangeLooper();
0037
0038 void startingNewLoop(unsigned int) {}
0039 Status duringLoop(edm::Event const& iEvent, edm::EventSetup const&) {
0040 auto const& product = iEvent.get(m_token);
0041 if (product.value != m_expectedValue) {
0042 throw cms::Exception("WrongValue") << "expected value " << m_expectedValue << " but got " << product.value;
0043 }
0044 return kContinue;
0045 }
0046 Status endOfLoop(edm::EventSetup const&, unsigned int iCount) {
0047
0048 Labels labels;
0049 labelsForToken(m_token, labels);
0050 std::string const moduleLabel{labels.module};
0051
0052 edm::ParameterSet const* pset = scheduleInfo()->parametersForModule(moduleLabel);
0053 assert(0 != pset);
0054
0055 edm::ParameterSet newPSet(*pset);
0056 newPSet.addParameter<int>("ivalue", ++m_expectedValue);
0057 auto success = moduleChanger()->changeModule(moduleLabel, newPSet);
0058 assert(success && "moduleChanger()->changeModule(m_tag.label(), newPSet)");
0059
0060 return iCount == 2 ? kStop : kContinue;
0061 }
0062
0063 private:
0064
0065 int m_expectedValue;
0066 edm::EDGetTokenT<edmtest::IntProduct> m_token;
0067 };
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 TestModuleChangeLooper::TestModuleChangeLooper(edm::ParameterSet const& iConfig)
0081 : m_expectedValue(iConfig.getUntrackedParameter<int>("startingValue")),
0082 m_token(consumes(iConfig.getUntrackedParameter<edm::InputTag>("tag"))) {
0083
0084 }
0085
0086 TestModuleChangeLooper::~TestModuleChangeLooper() {
0087
0088
0089 }
0090
0091
0092
0093
0094
0095
0096
0097
0098 DEFINE_FWK_LOOPER(TestModuleChangeLooper);