diff --git a/GeneratorInterface/Core/interface/GeneratorFilter.h b/GeneratorInterface/Core/interface/GeneratorFilter.h index 7deb56b80485b..17ceaf94b6d99 100644 --- a/GeneratorInterface/Core/interface/GeneratorFilter.h +++ b/GeneratorInterface/Core/interface/GeneratorFilter.h @@ -67,6 +67,7 @@ namespace edm Decayer* decayer_; unsigned int nEventsInLumiBlock_; unsigned int nThreads_{1}; + bool initialized_ = false; }; //------------------------------------------------------------------------ @@ -222,9 +223,11 @@ namespace edm // the contained hadronizer that would report the integrated // luminosity. - hadronizer_.statistics(); + if(initialized_) { + hadronizer_.statistics(); - if ( decayer_ ) decayer_->statistics(); + if ( decayer_ ) decayer_->statistics(); + } std::unique_ptr griproduct(new GenRunInfoProduct(hadronizer_.getGenRunInfo())); r.put(std::move(griproduct)); @@ -274,7 +277,7 @@ namespace edm std::unique_ptr genLumiInfoHeader(hadronizer_.getGenLumiInfoHeader()); lumi.put(std::move(genLumiInfoHeader)); - + initialized_ = true; } template diff --git a/GeneratorInterface/Pythia8Interface/test/BuildFile.xml b/GeneratorInterface/Pythia8Interface/test/BuildFile.xml index 0a302c56e7e22..643d169882572 100755 --- a/GeneratorInterface/Pythia8Interface/test/BuildFile.xml +++ b/GeneratorInterface/Pythia8Interface/test/BuildFile.xml @@ -12,3 +12,8 @@ + + + + + diff --git a/GeneratorInterface/Pythia8Interface/test/test_catch2_Pythia8GeneratorFilter.cc b/GeneratorInterface/Pythia8Interface/test/test_catch2_Pythia8GeneratorFilter.cc new file mode 100644 index 0000000000000..1395e38dc19b3 --- /dev/null +++ b/GeneratorInterface/Pythia8Interface/test/test_catch2_Pythia8GeneratorFilter.cc @@ -0,0 +1,56 @@ +#include "catch.hpp" +#include "FWCore/TestProcessor/interface/TestProcessor.h" +#include "FWCore/Utilities/interface/Exception.h" + +static constexpr auto s_tag = "[Pythia8GeneratorFilter]"; + +TEST_CASE("Standard checks of Pythia8GeneratorFilter", s_tag) { + const std::string baseConfig{ +R"_(from FWCore.TestProcessor.TestProcess import * +process = TestProcess() +process.load("Configuration.StandardSequences.SimulationRandomNumberGeneratorSeeds_cff") +process.RandomNumberGeneratorService.toTest = process.RandomNumberGeneratorService.generator.clone() +process.toTest = cms.EDFilter("Pythia8GeneratorFilter", + comEnergy = cms.double(7000.), + PythiaParameters = cms.PSet( + pythia8_example02 = cms.vstring('HardQCD:all = on', + 'PhaseSpace:pTHatMin = 20.'), + parameterSets = cms.vstring('pythia8_example02') + ) +) +process.moduleToTest(process.toTest) +)_" + }; + + edm::test::TestProcessor::Config config{ baseConfig }; + SECTION("base configuration is OK") { + REQUIRE_NOTHROW(edm::test::TestProcessor(config)); + } + + SECTION("No event data") { + edm::test::TestProcessor tester(config); + + REQUIRE_NOTHROW(tester.test()); + } + + SECTION("beginJob and endJob only") { + edm::test::TestProcessor tester(config); + + REQUIRE_NOTHROW(tester.testBeginAndEndJobOnly()); + } + + SECTION("Run with no LuminosityBlocks") { + edm::test::TestProcessor tester(config); + + REQUIRE_NOTHROW(tester.testRunWithNoLuminosityBlocks()); + } + + SECTION("LuminosityBlock with no Events") { + edm::test::TestProcessor tester(config); + + REQUIRE_NOTHROW(tester.testLuminosityBlockWithNoEvents()); + } + +} + +//Add additional TEST_CASEs to exercise the modules capabilities diff --git a/GeneratorInterface/Pythia8Interface/test/test_catch2_main.cc b/GeneratorInterface/Pythia8Interface/test/test_catch2_main.cc new file mode 100644 index 0000000000000..0c7c351f437f5 --- /dev/null +++ b/GeneratorInterface/Pythia8Interface/test/test_catch2_main.cc @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN +#include "catch.hpp"