Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-19 02:16: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 ModuleTypeResolver and Ref')
0007 parser.add_argument("--enableOther", action="store_true", help="Enable other accelerator. Also sets Lumi to 2")
0008 args = parser.parse_args()
0009 
0010 class ModuleTypeResolverTest:
0011     def __init__(self, accelerators):
0012         self._variants = []
0013         if "other" in accelerators:
0014             self._variants.append("other")
0015         if "cpu" in accelerators:
0016             self._variants.append("cpu")
0017         if len(self._variants) == 0:
0018             raise cms.EDMException(cms.edm.errors.UnavailableAccelerator, "No 'cpu' or 'other' accelerator available")
0019 
0020     def plugin(self):
0021         return "edm::test::ConfigurableTestTypeResolverMaker"
0022 
0023     def setModuleVariant(self, module):
0024         if module.type_().startswith("generic::"):
0025             if hasattr(module, "variant"):
0026                 if module.variant.value() not in self._variants:
0027                     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()))
0028             else:
0029                 module.variant = cms.untracked.string(self._variants[0])
0030 
0031 class ProcessAcceleratorTest(cms.ProcessAccelerator):
0032     def __init__(self):
0033         super(ProcessAcceleratorTest,self).__init__()
0034         self._labels = ["other"]
0035         self._enabled = []
0036         if args.enableOther:
0037             self._enabled.append("other")
0038     def labels(self):
0039         return self._labels
0040     def enabledLabels(self):
0041         return self._enabled
0042     def moduleTypeResolver(self, accelerators):
0043         return ModuleTypeResolverTest(accelerators)
0044 
0045 process = cms.Process("PROD1")
0046 process.add_(ProcessAcceleratorTest())
0047 
0048 process.source = cms.Source("EmptySource",
0049     firstEvent = cms.untracked.uint32(10 if args.enableOther else 1),
0050 )
0051 process.maxEvents.input = 3
0052 
0053 process.intprod = cms.EDProducer("generic::IntTransformer", valueCpu = cms.int32(1), valueOther = cms.int32(2))
0054 
0055 process.thing = cms.EDProducer("ThingProducer")
0056 
0057 process.otherThing = cms.EDProducer("OtherThingProducer",
0058                                    thingTag=cms.InputTag("thing"))
0059 
0060 process.t = cms.Task(
0061     process.intprod,
0062     process.thing,
0063     process.otherThing
0064 )
0065 process.p = cms.Path(process.t)
0066 
0067 fname = "refconsistency_{}".format(process.source.firstEvent.value())
0068 process.out = cms.OutputModule("EventStreamFileWriter",
0069     fileName = cms.untracked.string(fname+".dat"),
0070 )
0071 
0072 process.ep = cms.EndPath(process.out)