Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:02:52

0001 #include "DataFormats/Provenance/interface/EventID.h"
0002 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/global/EDProducer.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 
0012 #include <memory>
0013 
0014 namespace edmtest {
0015 
0016   namespace {
0017     struct Cache {};
0018   }  // namespace
0019 
0020   class ExceptionThrowingProducer
0021       : public edm::global::EDProducer<edm::StreamCache<Cache>, edm::RunCache<Cache>, edm::LuminosityBlockCache<Cache>> {
0022   public:
0023     explicit ExceptionThrowingProducer(edm::ParameterSet const&);
0024 
0025     ~ExceptionThrowingProducer() override;
0026 
0027     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0028 
0029     std::shared_ptr<Cache> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override;
0030     void globalEndRun(edm::Run const&, edm::EventSetup const&) const override;
0031     std::shared_ptr<Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0032                                                       edm::EventSetup const&) const override;
0033     void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const override;
0034 
0035     std::unique_ptr<Cache> beginStream(edm::StreamID) const override;
0036     void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const override;
0037     void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const&, edm::EventSetup const&) const override;
0038     void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const&, edm::EventSetup const&) const override;
0039     void streamEndRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const override;
0040 
0041     static void fillDescriptions(edm::ConfigurationDescriptions&);
0042 
0043   private:
0044     edm::EventID eventIDThrowOnEvent_;
0045     edm::EventID eventIDThrowOnGlobalBeginRun_;
0046     edm::EventID eventIDThrowOnGlobalBeginLumi_;
0047     edm::EventID eventIDThrowOnGlobalEndRun_;
0048     edm::EventID eventIDThrowOnGlobalEndLumi_;
0049     edm::EventID eventIDThrowOnStreamBeginRun_;
0050     edm::EventID eventIDThrowOnStreamBeginLumi_;
0051     edm::EventID eventIDThrowOnStreamEndRun_;
0052     edm::EventID eventIDThrowOnStreamEndLumi_;
0053   };
0054 
0055   ExceptionThrowingProducer::ExceptionThrowingProducer(edm::ParameterSet const& pset)
0056       : eventIDThrowOnEvent_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnEvent")),
0057         eventIDThrowOnGlobalBeginRun_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnGlobalBeginRun")),
0058         eventIDThrowOnGlobalBeginLumi_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnGlobalBeginLumi")),
0059         eventIDThrowOnGlobalEndRun_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnGlobalEndRun")),
0060         eventIDThrowOnGlobalEndLumi_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnGlobalEndLumi")),
0061         eventIDThrowOnStreamBeginRun_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnStreamBeginRun")),
0062         eventIDThrowOnStreamBeginLumi_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnStreamBeginLumi")),
0063         eventIDThrowOnStreamEndRun_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnStreamEndRun")),
0064         eventIDThrowOnStreamEndLumi_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnStreamEndLumi")) {}
0065 
0066   ExceptionThrowingProducer::~ExceptionThrowingProducer() {}
0067 
0068   void ExceptionThrowingProducer::produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const {
0069     if (event.id() == eventIDThrowOnEvent_) {
0070       throw cms::Exception("IntentionalTestException")
0071           << "ExceptionThrowingProducer::produce, module configured to throw on: " << eventIDThrowOnEvent_;
0072     }
0073   }
0074 
0075   std::shared_ptr<Cache> ExceptionThrowingProducer::globalBeginRun(edm::Run const& run, edm::EventSetup const&) const {
0076     if (edm::EventID(run.id().run(), edm::invalidLuminosityBlockNumber, edm::invalidEventNumber) ==
0077         eventIDThrowOnGlobalBeginRun_) {
0078       throw cms::Exception("IntentionalTestException")
0079           << "ExceptionThrowingProducer::globalBeginRun, module configured to throw on: "
0080           << eventIDThrowOnGlobalBeginRun_;
0081     }
0082     return std::make_shared<Cache>();
0083   }
0084 
0085   void ExceptionThrowingProducer::globalEndRun(edm::Run const& run, edm::EventSetup const&) const {
0086     if (edm::EventID(run.id().run(), edm::invalidLuminosityBlockNumber, edm::invalidEventNumber) ==
0087         eventIDThrowOnGlobalEndRun_) {
0088       throw cms::Exception("IntentionalTestException")
0089           << "ExceptionThrowingProducer::globalEndRun, module configured to throw on: " << eventIDThrowOnGlobalEndRun_;
0090     }
0091   }
0092 
0093   std::shared_ptr<Cache> ExceptionThrowingProducer::globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi,
0094                                                                                edm::EventSetup const&) const {
0095     if (edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) ==
0096         eventIDThrowOnGlobalBeginLumi_) {
0097       throw cms::Exception("IntentionalTestException")
0098           << "ExceptionThrowingProducer::globalBeginLuminosityBlock, module configured to throw on: "
0099           << eventIDThrowOnGlobalBeginLumi_;
0100     }
0101     return std::make_shared<Cache>();
0102   }
0103 
0104   void ExceptionThrowingProducer::globalEndLuminosityBlock(edm::LuminosityBlock const& lumi,
0105                                                            edm::EventSetup const&) const {
0106     if (edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) ==
0107         eventIDThrowOnGlobalEndLumi_) {
0108       throw cms::Exception("IntentionalTestException")
0109           << "ExceptionThrowingProducer::globalEndLuminosityBlock, module configured to throw on: "
0110           << eventIDThrowOnGlobalEndLumi_;
0111     }
0112   }
0113 
0114   std::unique_ptr<Cache> ExceptionThrowingProducer::beginStream(edm::StreamID) const {
0115     return std::make_unique<Cache>();
0116   }
0117 
0118   void ExceptionThrowingProducer::streamBeginRun(edm::StreamID iStream,
0119                                                  edm::Run const& run,
0120                                                  edm::EventSetup const&) const {
0121     if (iStream.value() == 0 &&
0122         edm::EventID(run.id().run(), edm::invalidLuminosityBlockNumber, edm::invalidEventNumber) ==
0123             eventIDThrowOnStreamBeginRun_) {
0124       throw cms::Exception("IntentionalTestException")
0125           << "ExceptionThrowingProducer::streamBeginRun, module configured to throw on: "
0126           << eventIDThrowOnStreamBeginRun_;
0127     }
0128   }
0129 
0130   void ExceptionThrowingProducer::streamBeginLuminosityBlock(edm::StreamID iStream,
0131                                                              edm::LuminosityBlock const& lumi,
0132                                                              edm::EventSetup const&) const {
0133     if (iStream.value() == 0 && edm::EventID(lumi.run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) ==
0134                                     eventIDThrowOnStreamBeginLumi_) {
0135       throw cms::Exception("IntentionalTestException")
0136           << "ExceptionThrowingProducer::streamBeginLuminosityBlock, module configured to throw on: "
0137           << eventIDThrowOnStreamBeginLumi_;
0138     }
0139   }
0140 
0141   void ExceptionThrowingProducer::streamEndLuminosityBlock(edm::StreamID iStream,
0142                                                            edm::LuminosityBlock const& lumi,
0143                                                            edm::EventSetup const&) const {
0144     if (iStream.value() == 0 && edm::EventID(lumi.run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) ==
0145                                     eventIDThrowOnStreamEndLumi_) {
0146       throw cms::Exception("IntentionalTestException")
0147           << "ExceptionThrowingProducer::streamEndLuminosityBlock, module configured to throw on: "
0148           << eventIDThrowOnStreamEndLumi_;
0149     }
0150   }
0151 
0152   void ExceptionThrowingProducer::streamEndRun(edm::StreamID iStream,
0153                                                edm::Run const& run,
0154                                                edm::EventSetup const&) const {
0155     if (iStream.value() == 0 &&
0156         edm::EventID(run.id().run(), edm::invalidLuminosityBlockNumber, edm::invalidEventNumber) ==
0157             eventIDThrowOnStreamEndRun_) {
0158       throw cms::Exception("IntentionalTestException")
0159           << "ExceptionThrowingProducer::streamEndRun, module configured to throw on: " << eventIDThrowOnStreamEndRun_;
0160     }
0161   }
0162 
0163   void ExceptionThrowingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0164     edm::ParameterSetDescription desc;
0165     edm::EventID invalidEventID;
0166     desc.addUntracked<edm::EventID>("eventIDThrowOnEvent", invalidEventID);
0167     desc.addUntracked<edm::EventID>("eventIDThrowOnGlobalBeginRun", invalidEventID);
0168     desc.addUntracked<edm::EventID>("eventIDThrowOnGlobalBeginLumi", invalidEventID);
0169     desc.addUntracked<edm::EventID>("eventIDThrowOnGlobalEndRun", invalidEventID);
0170     desc.addUntracked<edm::EventID>("eventIDThrowOnGlobalEndLumi", invalidEventID);
0171     desc.addUntracked<edm::EventID>("eventIDThrowOnStreamBeginRun", invalidEventID);
0172     desc.addUntracked<edm::EventID>("eventIDThrowOnStreamBeginLumi", invalidEventID);
0173     desc.addUntracked<edm::EventID>("eventIDThrowOnStreamEndRun", invalidEventID);
0174     desc.addUntracked<edm::EventID>("eventIDThrowOnStreamEndLumi", invalidEventID);
0175     descriptions.addDefault(desc);
0176   }
0177 
0178 }  // namespace edmtest
0179 using edmtest::ExceptionThrowingProducer;
0180 DEFINE_FWK_MODULE(ExceptionThrowingProducer);