Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:03

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("--enableOther", action="store_true", help="Enable other accelerator")
0009 parser.add_argument("--setInResolver", type=str, default="", help="Set the default variant in module type resolver")
0010 parser.add_argument("--setInModule", type=str, default="", help="Set the default variant in module itself")
0011 parser.add_argument("--accelerators", type=str, help="Comma-separated string for accelerators to enable")
0012 parser.add_argument("--expectOther", action="store_true", help="Set this if the 'other' variant is expected to get run")
0013 
0014 argv = sys.argv[:]
0015 if '--' in argv:
0016     argv.remove("--")
0017 args, unknown = parser.parse_known_args(argv)
0018 
0019 class ModuleTypeResolverTest:
0020     def __init__(self, accelerators):
0021         self._variants = []
0022         if "other" in accelerators:
0023             self._variants.append("other")
0024         if "cpu" in accelerators:
0025             self._variants.append("cpu")
0026         if args.setInResolver != "":
0027             if args.setInResolver not in self._variants:
0028                 raise cms.EDMException(cms.edm.errors.UnavailableAccelerator, "Trying to set variant globally in ModuleTypeResolverTest to {}, but a corresponding accelerator is not available".format(args.setInResolver))
0029             self._variants.remove(args.setInResolver)
0030             self._variants.insert(0, args.setInResolver)
0031         if len(self._variants) == 0:
0032             raise cms.EDMException(cms.edm.errors.UnavailableAccelerator, "No 'cpu' or 'other' accelerator available")
0033 
0034     def plugin(self):
0035         return "edm::test::ConfigurableTestTypeResolverMaker"
0036 
0037     def setModuleVariant(self, module):
0038         if module.type_().startswith("generic::"):
0039             if hasattr(module, "variant"):
0040                 if module.variant.value() not in self._variants:
0041                     raise cms.EDMException(cms.edm.errors.UnavailableAccelerator, "Module {} has the Test variant set explicitly to {}, but its accelerator is not available for the job".format(module.label_(), module.variant.value()))
0042             else:
0043                 module.variant = cms.untracked.string(self._variants[0])
0044 
0045 class ProcessAcceleratorTest(cms.ProcessAccelerator):
0046     def __init__(self):
0047         super(ProcessAcceleratorTest,self).__init__()
0048         self._labels = ["other"]
0049         self._enabled = []
0050         if args.enableOther:
0051             self._enabled.append("other")
0052     def labels(self):
0053         return self._labels
0054     def enabledLabels(self):
0055         return self._enabled
0056     def moduleTypeResolver(self, accelerators):
0057         return ModuleTypeResolverTest(accelerators)
0058 
0059 process = cms.Process("PROD1")
0060 
0061 process.add_(ProcessAcceleratorTest())
0062 
0063 process.source = cms.Source("EmptySource",
0064     firstRun = cms.untracked.uint32(1),
0065     firstLuminosityBlock = cms.untracked.uint32(1),
0066     firstEvent = cms.untracked.uint32(1),
0067     numberEventsInLuminosityBlock = cms.untracked.uint32(1),
0068     numberEventsInRun = cms.untracked.uint32(1)
0069 )
0070 process.maxEvents.input = 3
0071 if args.accelerators is not None:
0072     process.options.accelerators = args.accelerators.split(",")
0073 
0074 # EventSetup
0075 process.emptyESSourceA = cms.ESSource("EmptyESSource",
0076     recordName = cms.string("ESTestRecordA"),
0077     firstValid = cms.vuint32(1,2,3),
0078     iovIsRunNotTime = cms.bool(True)
0079 )
0080 
0081 process.esTestProducerA = cms.ESProducer("generic::ESTestProducerA", valueCpu = cms.int32(10), valueOther = cms.int32(20))
0082 
0083 process.esTestAnalyzerA = cms.EDAnalyzer("ESTestAnalyzerA",
0084     runsToGetDataFor = cms.vint32(1,2,3),
0085     expectedValues=cms.untracked.vint32(11,12,13)
0086 )
0087 
0088 # Event
0089 process.intProducer = cms.EDProducer("generic::IntProducer", valueCpu = cms.int32(1), valueOther = cms.int32(2))
0090 
0091 process.intConsumer = cms.EDAnalyzer("IntTestAnalyzer",
0092     moduleLabel = cms.untracked.InputTag("intProducer"),
0093     valueMustMatch = cms.untracked.int32(1)
0094 )
0095 
0096 if args.setInModule != "":
0097     process.esTestProducerA.variant = cms.untracked.string(args.setInModule)
0098     process.intProducer.variant = cms.untracked.string(args.setInModule)
0099 
0100 if args.expectOther:
0101     process.esTestAnalyzerA.expectedValues = [21, 22, 23]
0102     process.intConsumer.valueMustMatch = 2
0103 
0104 process.t = cms.Task(
0105     process.intProducer
0106 )
0107 process.p = cms.Path(
0108     process.intConsumer + process.esTestAnalyzerA,
0109     process.t
0110 )