Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:47:29

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