Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-11 22:43:50

0001 // -*- C++ -*-
0002 //
0003 // Package:    TestModuleChangeLooper
0004 // Class:      TestModuleChangeLooper
0005 //
0006 /**\class TestModuleChangeLooper TestModuleChangeLooper.h FWCore/TestModuleChangeLooper/interface/TestModuleChangeLooper.h
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Valentin Kuznetsov
0015 //         Created:  Tue Jul 18 10:17:05 EDT 2006
0016 //
0017 
0018 // user include files
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 // system include files
0027 #include <memory>
0028 
0029 //
0030 // class decleration
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     //modify the module
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   // ----------member data ---------------------------
0065   int m_expectedValue;
0066   edm::EDGetTokenT<edmtest::IntProduct> m_token;
0067 };
0068 
0069 //
0070 // constants, enums and typedefs
0071 //
0072 
0073 //
0074 // static data member definitions
0075 //
0076 
0077 //
0078 // constructors and destructor
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   //now do what ever other initialization is needed
0084 }
0085 
0086 TestModuleChangeLooper::~TestModuleChangeLooper() {
0087   // do anything here that needs to be done at desctruction time
0088   // (e.g. close files, deallocate resources etc.)
0089 }
0090 
0091 //
0092 // member functions
0093 //
0094 
0095 // ------------ method called to produce the data  ------------
0096 
0097 //define this as a plug-in
0098 DEFINE_FWK_LOOPER(TestModuleChangeLooper);