Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:17

0001 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0002 #include "FWCore/Framework/interface/ESProducerLooper.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/LooperFactory.h"
0006 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "FWCore/Utilities/interface/transform.h"
0011 
0012 #include "FWCore/Framework/test/DummyData.h"
0013 #include "FWCore/Framework/test/DummyRecord.h"
0014 
0015 namespace edmtest {
0016   class IntTestLooper : public edm::ESProducerLooper {
0017   public:
0018     IntTestLooper(edm::ParameterSet const& iPSet)
0019         : tokensBeginRun_(edm::vector_transform(
0020               iPSet.getUntrackedParameter<std::vector<edm::InputTag>>("srcBeginRun"),
0021               [this](edm::InputTag const& tag) { return this->consumes<IntProduct, edm::InRun>(tag); })),
0022           tokensBeginLumi_(edm::vector_transform(
0023               iPSet.getUntrackedParameter<std::vector<edm::InputTag>>("srcBeginLumi"),
0024               [this](edm::InputTag const& tag) { return this->consumes<IntProduct, edm::InLumi>(tag); })),
0025           tokensEvent_(
0026               edm::vector_transform(iPSet.getUntrackedParameter<std::vector<edm::InputTag>>("srcEvent"),
0027                                     [this](edm::InputTag const& tag) { return this->consumes<IntProduct>(tag); })),
0028           tokensEndLumi_(edm::vector_transform(
0029               iPSet.getUntrackedParameter<std::vector<edm::InputTag>>("srcEndLumi"),
0030               [this](edm::InputTag const& tag) { return this->consumes<IntProduct, edm::InLumi>(tag); })),
0031           tokensEndRun_(edm::vector_transform(
0032               iPSet.getUntrackedParameter<std::vector<edm::InputTag>>("srcEndRun"),
0033               [this](edm::InputTag const& tag) { return this->consumes<IntProduct, edm::InRun>(tag); })),
0034           esTokenBeginRun_(esConsumes<edm::Transition::BeginRun>()),
0035           esToken_(esConsumes()),
0036           valuesBeginRun_(iPSet.getUntrackedParameter<std::vector<int>>("expectBeginRunValues")),
0037           valuesBeginLumi_(iPSet.getUntrackedParameter<std::vector<int>>("expectBeginLumiValues")),
0038           valuesEvent_(iPSet.getUntrackedParameter<std::vector<int>>("expectEventValues")),
0039           valuesEndLumi_(iPSet.getUntrackedParameter<std::vector<int>>("expectEndLumiValues")),
0040           valuesEndRun_(iPSet.getUntrackedParameter<std::vector<int>>("expectEndRunValues")),
0041           valueES_(iPSet.getUntrackedParameter<int>("expectESValue")) {}
0042 
0043     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0044       edm::ParameterSetDescription desc;
0045       desc.setComment(
0046           "This test EDLooper can consume arbitrary number of IntProduct's at Run, Lumi, and Event transitions. It "
0047           "always consumes DummyData EventSetup product in beginRun and Event transitions. For all the consumed "
0048           "products it requires the value of the product to correspond the value in configuratoin. It stops looping "
0049           "after 3rd time.");
0050       desc.addUntracked<std::vector<edm::InputTag>>("srcBeginRun", std::vector<edm::InputTag>{});
0051       desc.addUntracked<std::vector<edm::InputTag>>("srcBeginLumi", std::vector<edm::InputTag>{});
0052       desc.addUntracked<std::vector<edm::InputTag>>("srcEvent", std::vector<edm::InputTag>{});
0053       desc.addUntracked<std::vector<edm::InputTag>>("srcEndLumi", std::vector<edm::InputTag>{});
0054       desc.addUntracked<std::vector<edm::InputTag>>("srcEndRun", std::vector<edm::InputTag>{});
0055       desc.addUntracked<std::vector<int>>("expectBeginRunValues", std::vector<int>{});
0056       desc.addUntracked<std::vector<int>>("expectBeginLumiValues", std::vector<int>{});
0057       desc.addUntracked<std::vector<int>>("expectEventValues", std::vector<int>{});
0058       desc.addUntracked<std::vector<int>>("expectEndLumiValues", std::vector<int>{});
0059       desc.addUntracked<std::vector<int>>("expectEndRunValues", std::vector<int>{});
0060       desc.addUntracked<int>("expectESValue");
0061       descriptions.addDefault(desc);
0062     }
0063 
0064     void beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) override {
0065       for (size_t i = 0; i < tokensBeginRun_.size(); ++i) {
0066         int const expectedValue = valuesBeginRun_[i];
0067         int const value = iRun.get(tokensBeginRun_[i]).value;
0068         if (expectedValue != value) {
0069           throw cms::Exception("WrongValue")
0070               << "expected value " << expectedValue << " but got " << value << " for beginRun product " << i;
0071         }
0072       }
0073 
0074       auto const& data = iSetup.getData(esTokenBeginRun_);
0075       if (data.value_ != valueES_) {
0076         throw cms::Exception("WrongValue")
0077             << " expected value " << valueES_ << " but got " << data.value_ << " for EventSetup product in beginRun";
0078       }
0079     }
0080 
0081     void beginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) override {
0082       for (size_t i = 0; i < tokensBeginLumi_.size(); ++i) {
0083         int const expectedValue = valuesBeginLumi_[i];
0084         int const value = iLumi.get(tokensBeginLumi_[i]).value;
0085         if (expectedValue != value) {
0086           throw cms::Exception("WrongValue")
0087               << "expected value " << expectedValue << " but got " << value << " for beginLumi product " << i;
0088         }
0089       }
0090     }
0091 
0092     void endLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) override {
0093       for (size_t i = 0; i < tokensEndLumi_.size(); ++i) {
0094         int const expectedValue = valuesEndLumi_[i];
0095         int const value = iLumi.get(tokensEndLumi_[i]).value;
0096         if (expectedValue != value) {
0097           throw cms::Exception("WrongValue")
0098               << "expected value " << expectedValue << " but got " << value << " for endLumi product " << i;
0099         }
0100       }
0101     }
0102 
0103     void endRun(edm::Run const& iRun, edm::EventSetup const&) override {
0104       for (size_t i = 0; i < tokensEndRun_.size(); ++i) {
0105         int const expectedValue = valuesEndRun_[i];
0106         int const value = iRun.get(tokensEndRun_[i]).value;
0107         if (expectedValue != value) {
0108           throw cms::Exception("WrongValue")
0109               << "expected value " << expectedValue << " but got " << value << " for endRun product " << i;
0110         }
0111       }
0112     }
0113 
0114     void startingNewLoop(unsigned int) override {}
0115 
0116     Status duringLoop(edm::Event const& iEvent, edm::EventSetup const& iSetup) override {
0117       for (size_t i = 0; i < tokensEvent_.size(); ++i) {
0118         int const expectedValue = valuesEvent_[i];
0119         int const value = iEvent.get(tokensEvent_[i]).value;
0120         if (expectedValue != value) {
0121           throw cms::Exception("WrongValue")
0122               << "expected value " << expectedValue << " but got " << value << " for Event product " << i;
0123         }
0124       }
0125 
0126       auto const& data = iSetup.getData(esToken_);
0127       if (data.value_ != valueES_) {
0128         throw cms::Exception("WrongValue")
0129             << " expected value " << valueES_ << " but got " << data.value_ << " for EventSetup product in duringLoop";
0130       }
0131 
0132       return kContinue;
0133     }
0134 
0135     Status endOfLoop(edm::EventSetup const&, unsigned int iCount) override { return iCount == 2 ? kStop : kContinue; }
0136 
0137   private:
0138     const std::vector<edm::EDGetTokenT<IntProduct>> tokensBeginRun_;
0139     const std::vector<edm::EDGetTokenT<IntProduct>> tokensBeginLumi_;
0140     const std::vector<edm::EDGetTokenT<IntProduct>> tokensEvent_;
0141     const std::vector<edm::EDGetTokenT<IntProduct>> tokensEndLumi_;
0142     const std::vector<edm::EDGetTokenT<IntProduct>> tokensEndRun_;
0143     edm::ESGetToken<edm::eventsetup::test::DummyData, edm::DefaultRecord> const esTokenBeginRun_;
0144     edm::ESGetToken<edm::eventsetup::test::DummyData, edm::DefaultRecord> const esToken_;
0145     const std::vector<int> valuesBeginRun_;
0146     const std::vector<int> valuesBeginLumi_;
0147     const std::vector<int> valuesEvent_;
0148     const std::vector<int> valuesEndLumi_;
0149     const std::vector<int> valuesEndRun_;
0150     const int valueES_;
0151   };
0152 }  // namespace edmtest
0153 
0154 using IntTestLooper = edmtest::IntTestLooper;
0155 DEFINE_FWK_LOOPER(IntTestLooper);