Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-21 01:39:48

0001 // -*- C++ -*-
0002 //
0003 // Package:     GeneratorInterface/Core
0004 // Class  :     FailingGeneratorFilter
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Christopher Jones
0010 //         Created:  Wed, 08 Sep 2021 15:58:11 GMT
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "GeneratorInterface/Core/interface/BaseHadronizer.h"
0017 #include "GeneratorInterface/Core/interface/GeneratorFilter.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/Utilities/interface/Exception.h"
0020 
0021 #include <csignal>
0022 namespace test {
0023   class FailingHad {
0024   public:
0025     FailingHad(const edm::ParameterSet& iPSet)
0026         : failAt_(iPSet.getParameter<int>("failAt")), failureType_(iPSet.getParameter<int>("failureType")) {}
0027 
0028     std::vector<std::string> sharedResources() const {
0029       if (failAt_ == 0) {
0030         fail("Constructor");
0031       }
0032       return {};
0033     }
0034 
0035     void setEDMEvent(edm::Event&) { event_ = std::make_unique<HepMC::GenEvent>(); }
0036 
0037     bool generatePartonsAndHadronize() const {
0038       if (failAt_ == 2) {
0039         fail("Event");
0040       }
0041       return true;
0042     }
0043     bool decay() const { return true; }
0044 
0045     unsigned int getVHepMC() { return ivhepmc; }
0046     std::unique_ptr<HepMC::GenEvent> getGenEvent() { return std::move(event_); }
0047     std::unique_ptr<HepMC3::GenEvent> getGenEvent3() { return std::move(event3_); }
0048 
0049     bool select(HepMC::GenEvent*) const { return true; }
0050     void resetEvent(std::unique_ptr<HepMC::GenEvent> iEvent) { event_ = std::move(iEvent); }
0051     void resetEvent3(std::unique_ptr<HepMC3::GenEvent> iEvent) { event3_ = std::move(iEvent); }
0052     bool residualDecay() const { return true; }
0053     void finalizeEvent() const {}
0054     std::unique_ptr<GenEventInfoProduct> getGenEventInfo() const { return std::make_unique<GenEventInfoProduct>(); }
0055     std::unique_ptr<GenEventInfoProduct3> getGenEventInfo3() const { return std::make_unique<GenEventInfoProduct3>(); }
0056 
0057     //caled at endRunProduce, endLumiProduce
0058     void statistics() const {}
0059     GenRunInfoProduct getGenRunInfo() const { return GenRunInfoProduct(); }
0060 
0061     //called begin Lumi Produce
0062     template <typename T>
0063     void randomizeIndex(edm::LuminosityBlock const&, T&&) const {
0064       if (failAt_ == 1) {
0065         fail("BeginLumi");
0066       }
0067     }
0068     template <typename T>
0069     void generateLHE(edm::LuminosityBlock const&, T, unsigned int) const {}
0070 
0071     bool readSettings(int) const { return true; }
0072     std::string classname() const { return ""; }
0073     template <typename T>
0074     bool declareStableParticles(T&&) const {
0075       return true;
0076     }
0077     template <typename T>
0078     bool declareSpecialSettings(T&&) const {
0079       return true;
0080     }
0081     bool initializeForInternalPartons() const { return true; }
0082     std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader() const { return std::make_unique<GenLumiInfoHeader>(); }
0083 
0084     //called end lumi
0085     void cleanLHE() const {};
0086 
0087     template <typename T>
0088     void setRandomEngine(T&&) const {}
0089 
0090   private:
0091     void fail(std::string const& iName) const {
0092       switch (failureType_) {
0093         case 0: {
0094           throw cms::Exception(iName);
0095         }
0096         case 1: {
0097           std::raise(SIGSEGV);
0098           break;
0099         }
0100         case 2: {
0101           std::terminate();
0102           break;
0103         }
0104         default: {
0105           std::exit(-1);
0106         }
0107       }
0108     }
0109     std::unique_ptr<HepMC::GenEvent> event_;
0110     std::unique_ptr<HepMC3::GenEvent> event3_;
0111     int failAt_;
0112     int failureType_;
0113     unsigned int ivhepmc = 2;
0114   };
0115 
0116   class DummyDec {
0117   public:
0118     DummyDec(const edm::ParameterSet&, edm::ConsumesCollector) {}
0119     std::vector<std::string> sharedResources() const { return {}; }
0120 
0121     HepMC::GenEvent* decay(HepMC::GenEvent const*) { return nullptr; }
0122     HepMC3::GenEvent* decay(HepMC3::GenEvent const*) { return nullptr; }
0123     void statistics() const {}
0124 
0125     void init(const edm::EventSetup&) const {}
0126     bool operatesOnParticles() const { return false; }
0127     bool specialSettings() const { return false; }
0128 
0129     template <typename T>
0130     void setRandomEngine(T&&) const {}
0131   };
0132 }  // namespace test
0133 
0134 using FailingGeneratorFilter = edm::GeneratorFilter<test::FailingHad, test::DummyDec>;
0135 
0136 DEFINE_FWK_MODULE(FailingGeneratorFilter);