File indexing completed on 2024-04-06 12:12:39
0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003
0004 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/TestProcessor/interface/TestProcessor.h"
0007
0008 static constexpr auto s_tag = "[RandomIntProducer]";
0009
0010 TEST_CASE("Direct", s_tag) {
0011 const std::string baseConfig{
0012 R"_(from FWCore.TestProcessor.TestProcess import *
0013 import FWCore.ParameterSet.Config as cms
0014
0015 process = TestProcess()
0016 process.test = cms.EDProducer('RandomIntProducer')
0017 process.add_(cms.Service("RandomNumberGeneratorService",
0018 test = cms.PSet(initialSeed = cms.untracked.uint32(12345))
0019 ))
0020 process.moduleToTest(process.test)
0021 )_"};
0022
0023 edm::test::TestProcessor::Config config{baseConfig};
0024
0025 SECTION("Base configuration is OK") { REQUIRE_NOTHROW(edm::test::TestProcessor(config)); }
0026
0027 SECTION("transitions") {
0028 edm::test::TestProcessor tester(config);
0029 {
0030 auto lumi = tester.testBeginLuminosityBlock(1).get<edmtest::IntProduct>("lumi");
0031 REQUIRE(lumi->value == 1);
0032 }
0033 {
0034 auto event = tester.test().get<edmtest::IntProduct>();
0035 REQUIRE(event->value == 6);
0036 }
0037 {
0038 auto event = tester.test().get<edmtest::IntProduct>();
0039 REQUIRE(event->value == 4);
0040 }
0041 {
0042 auto lumi = tester.testBeginLuminosityBlock(2).get<edmtest::IntProduct>("lumi");
0043 REQUIRE(lumi->value == 1);
0044 }
0045 }
0046 }
0047
0048 TEST_CASE("External", s_tag) {
0049 const std::string baseConfig{
0050 R"_(from FWCore.TestProcessor.TestProcess import *
0051 import FWCore.ParameterSet.Config as cms
0052
0053 class RandomIntExternalProcessProducer(cms.EDProducer):
0054 def __init__(self, prod):
0055 self.__dict__['_prod'] = prod
0056 super(cms.EDProducer,self).__init__('TestInterProcessRandomProd')
0057 def __setattr__(self, name, value):
0058 setattr(self._prod, name, value)
0059 def __getattr__(self, name):
0060 if name =='_prod':
0061 return self.__dict__['_prod']
0062 return getattr(self._prod, name)
0063 def clone(self, **params):
0064 returnValue = RandomIntExternalProcessProducer.__new__(type(self))
0065 returnValue.__init__(self._prod.clone())
0066 return returnValue
0067 def insertInto(self, parameterSet, myname):
0068 newpset = parameterSet.newPSet()
0069 newpset.addString(True, "@module_label", self.moduleLabel_(myname))
0070 newpset.addString(True, "@module_type", self.type_())
0071 newpset.addString(True, "@module_edm_type", cms.EDProducer.__name__)
0072 newpset.addString(True, "@external_type", self._prod.type_())
0073 newpset.addString(False,"@python_config", self._prod.dumpPython())
0074 self._prod.insertContentsInto(newpset)
0075 parameterSet.addPSet(True, self.nameInProcessDesc_(myname), newpset)
0076
0077 process = TestProcess()
0078 _generator = cms.EDProducer('RandomIntProducer')
0079 process.test = RandomIntExternalProcessProducer(_generator)
0080 process.add_(cms.Service("RandomNumberGeneratorService",
0081 test = cms.PSet(initialSeed = cms.untracked.uint32(12345))
0082 ))
0083 process.moduleToTest(process.test)
0084 )_"};
0085
0086 edm::test::TestProcessor::Config config{baseConfig};
0087
0088 SECTION("Base configuration is OK") { REQUIRE_NOTHROW(edm::test::TestProcessor(config)); }
0089
0090 SECTION("transitions") {
0091 edm::test::TestProcessor tester(config);
0092 {
0093 auto lumi = tester.testBeginLuminosityBlock(1).get<edmtest::IntProduct>("lumi");
0094 REQUIRE(lumi->value == 1);
0095 }
0096 {
0097 auto event = tester.test().get<edmtest::IntProduct>();
0098 REQUIRE(event->value == 6);
0099 }
0100 {
0101 auto event = tester.test().get<edmtest::IntProduct>();
0102 REQUIRE(event->value == 4);
0103 }
0104 {
0105 auto lumi = tester.testBeginLuminosityBlock(2).get<edmtest::IntProduct>("lumi");
0106 REQUIRE(lumi->value == 1);
0107 }
0108 }
0109 }