Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-24 02:12:42

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 ProcessAccelerator.')
0007 
0008 parser.add_argument("--enableTest2", help="Enable test2 accelerator", action="store_true")
0009 parser.add_argument("--accelerators", type=str, help="Comma-separated string for accelerators to enable")
0010 
0011 argv = sys.argv[:]
0012 if '--' in argv:
0013     argv.remove("--")
0014 args, unknown = parser.parse_known_args(argv)
0015 
0016 class ProcessAcceleratorTest(cms.ProcessAccelerator):
0017     def __init__(self):
0018         super(ProcessAcceleratorTest,self).__init__()
0019         self._labels = ["test1", "test2"]
0020         self._enabled = ["test1"]
0021         if args.enableTest2:
0022             self._enabled.append("test2")
0023     def labels(self):
0024         return self._labels
0025     def enabledLabels(self):
0026         return self._enabled
0027 
0028 class SwitchProducerTest(cms.SwitchProducer):
0029     def __init__(self, **kargs):
0030         super(SwitchProducerTest,self).__init__(
0031             dict(
0032                 cpu = cms.SwitchProducer.getCpu(),
0033                 test1 = lambda accelerators: ("test1" in accelerators, 2),
0034                 test2 = lambda accelerators: ("test2" in accelerators, 3),
0035             ), **kargs)
0036 
0037 process = cms.Process("PROD1")
0038 
0039 process.add_(ProcessAcceleratorTest())
0040 
0041 process.source = cms.Source("EmptySource")
0042 process.maxEvents.input = 3
0043 if args.accelerators is not None:
0044     process.options.accelerators = args.accelerators.split(",")
0045 
0046 process.intProducer1 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(1))
0047 process.intProducer2 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(2))
0048 process.failIntProducer = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(-1), throw = cms.untracked.bool(True))
0049 
0050 if args.enableTest2 and ("test2" in process.options.accelerators or "*" in process.options.accelerators):
0051     process.intProducer1.throw = cms.untracked.bool(True)
0052 else:
0053     process.intProducer2.throw = cms.untracked.bool(True)
0054 
0055 process.intProducer = SwitchProducerTest(
0056     cpu = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("failIntProducer")),
0057     test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")),
0058     test2 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer2"))
0059 )
0060 
0061 process.intConsumer = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer"))
0062 
0063 process.t = cms.Task(
0064     process.failIntProducer,
0065     process.intProducer1,
0066     process.intProducer2,
0067     process.intProducer,
0068 )
0069 process.p = cms.Path(
0070     process.intConsumer,
0071     process.t
0072 )