Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 import argparse
0004 import sys
0005 
0006 parser = argparse.ArgumentParser(prog=sys.argv[0], description='Test SwitchProducer in Task.')
0007 parser.add_argument("--disableTest2", help="Disable test2 SwitchProducer case", action="store_true")
0008 parser.add_argument("--input", help="Read input file from a previous step of this same configuration", action="store_true")
0009 parser.add_argument("--conditionalTask", help="Use ConditionalTask instead of Task", action="store_true")
0010 
0011 args = parser.parse_args()
0012 
0013 enableTest2 = not args.disableTest2
0014 class SwitchProducerTest(cms.SwitchProducer):
0015     def __init__(self, **kargs):
0016         super(SwitchProducerTest,self).__init__(
0017             dict(
0018                 test1 = lambda accelerators: (True, -10),
0019                 test2 = lambda accelerators: (enableTest2, -9)
0020             ), **kargs)
0021 
0022 process = cms.Process("PROD2" if args.input else "PROD1")
0023 
0024 if args.input:
0025      # Test that having SwitchProducers with same labels as products from
0026     # earlier processes works
0027     process.source = cms.Source("PoolSource",
0028         fileNames = cms.untracked.vstring("file:testSwitchProducer{}Task{}.root".format(
0029             "Conditional" if args.conditionalTask else "",
0030             1 if enableTest2 else 2,
0031         ))
0032     )
0033     process.maxEvents.input = -1
0034 else:
0035     process.source = cms.Source("EmptySource")
0036     process.maxEvents.input = 3
0037     if enableTest2:
0038         process.source.firstLuminosityBlock = cms.untracked.uint32(2)
0039 
0040 process.out = cms.OutputModule("PoolOutputModule",
0041     fileName = cms.untracked.string('testSwitchProducer{}Task{}{}.root'.format(
0042         "Conditional" if args.conditionalTask else "",
0043         "Input" if args.input else "",
0044         1 if enableTest2 else 2,
0045     )),
0046     outputCommands = cms.untracked.vstring(
0047         'keep *_intProducer_*_*',
0048         'keep *_intProducerOther_*_*',
0049         'keep *_intProducerAlias_*_*',
0050         'keep *_intProducerAlias2_other_*',
0051         'keep *_intProducerDep1_*_*',
0052         'keep *_intProducerDep2_*_*',
0053         'keep *_intProducerDep3_*_*',
0054     )
0055 )
0056 
0057 process.intProducer1 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(1))
0058 process.intProducer2 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(2))
0059 process.intProducer3 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(2), values = cms.VPSet(cms.PSet(instance=cms.string("foo"),value=cms.int32(2))))
0060 process.intProducer4 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(42), throw = cms.untracked.bool(True))
0061 process.intProducer5 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(3), values = cms.VPSet(cms.PSet(instance=cms.string("foo"),value=cms.int32(3))))
0062 if enableTest2:
0063     process.intProducer1.throw = cms.untracked.bool(True)
0064 else:
0065     process.intProducer2.throw = cms.untracked.bool(True)
0066     process.intProducer3.throw = cms.untracked.bool(True)
0067     process.intProducer5.throw = cms.untracked.bool(True)
0068 
0069 process.intProducer = SwitchProducerTest(
0070     test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")),
0071     test2 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer2"))
0072 )
0073 # Test also existence of another SwitchProducer here
0074 process.intProducerOther = SwitchProducerTest(
0075     test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")),
0076     test2 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer2"))
0077 )
0078 # SwitchProducer with an alias
0079 process.intProducerAlias = SwitchProducerTest(
0080     test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")),
0081     test2 = cms.EDAlias(intProducer3 = cms.VPSet(cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string(""), toProductInstance = cms.string("")),
0082                                                  cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string("foo"), toProductInstance = cms.string("other"))))
0083 )
0084 
0085 process.intProducerAlias2 = SwitchProducerTest(
0086     test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")),
0087     test2 = cms.EDAlias(intProducer4 = cms.VPSet(cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string(""), toProductInstance = cms.string(""))),
0088                         intProducer5 = cms.VPSet(cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string("foo"), toProductInstance = cms.string("other"))))
0089 )
0090 
0091 # Test multiple consumers of a SwitchProducer
0092 process.intProducerDep1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer"))
0093 process.intProducerDep2 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer"))
0094 process.intProducerDep3 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer"))
0095 
0096 if args.conditionalTask:
0097     process.ct = cms.ConditionalTask(process.intProducer, process.intProducerOther, process.intProducerAlias, process.intProducerAlias2,
0098                                      process.intProducer1, process.intProducer2, process.intProducer3, process.intProducer4, process.intProducer5)
0099     process.p = cms.Path(process.intProducerDep1+process.intProducerDep2+process.intProducerDep3, process.ct)
0100 else:
0101     process.t = cms.Task(process.intProducer, process.intProducerOther, process.intProducerAlias, process.intProducerAlias2,
0102                          process.intProducerDep1, process.intProducerDep2, process.intProducerDep3,
0103                          process.intProducer1, process.intProducer2, process.intProducer3, process.intProducer4, process.intProducer5)
0104     process.p = cms.Path(process.t)
0105 
0106 process.e = cms.EndPath(process.out)