2 from FWCore.ParameterSet.ModulesProxy
import _ModuleProxy
3 from FWCore.ParameterSet.Types
import _ProxyParameter, _RequiredParameter, _OptionalParameter
4 import FWCore.ParameterSet.Config
as cms
7 cms.int32.dummyDefault = 999
8 cms.uint32.dummyDefault = 999
9 cms.int64.dummyDefault = 999
10 cms.uint64.dummyDefault = 999
11 cms.string.dummyDefault=
"__default__" 12 cms.double.dummyDefault = 9999
13 cms.vdouble.dummyDefault = []
14 cms.vint32.dummyDefault = []
15 cms.vuint32.dummyDefault = []
16 cms.vint64.dummyDefault = []
17 cms.vuint64.dummyDefault=[]
18 cms.vstring.dummyDefault=[]
19 cms.bool.dummyDefault =
False 20 cms.PSet.dummyDefault = cms.PSet()
21 cms.VPSet.dummyDefault = cms.VPSet()
22 cms.InputTag.dummyDefault =
"__dummy__" 23 cms.VInputTag.dummyDefault = []
24 cms.ESInputTag.dummyDefault=
":__dummy__" 25 cms.VESInputTag.dummyValue = []
26 cms.EventID.dummyDefault=
"0:0:0" 27 cms.VEventID.dummyDefault =[]
28 cms.LuminosityBlockID.dummyDefault =
"0:0" 29 cms.VLuminosityBlockID.dummyDefault=[]
30 cms.EventRange.dummyDefault=
"0:0" 31 cms.VEventRange.dummyDefault=[]
32 cms.LuminosityBlockRange.dummyDefault=
"0:0" 33 cms.VLuminosityBlockID.dummyDefault=[]
34 cms.FileInPath.dummyDefault=
"__dummy__" 39 modules = importlib.import_module(modName+
".modules")
40 for (n,m)
in (x
for x
in modules.__dict__.items()
if isinstance(x[1], _ModuleProxy)):
42 write_cfi(modName+
'.'+n, writeRequired, writeOptional)
44 def write_cfi(pythonModuleName, writeRequired, writeOptional):
45 parts = pythonModuleName.split(
'.')
46 filename = parts[-1][0].lower()+parts[-1][1:]
47 f = open(filename+
"_cfi.py",
'x')
48 f.writelines([
"import FWCore.ParameterSet.DummyCfis as dc\n",
50 "dc.create_module('{}', sys.modules[__name__], {}, {})\n".
format(pythonModuleName, writeRequired, writeOptional)])
54 for n
in pset.parameterNames_():
57 def setADefault(obj, paramName, writeRequired, writeOptional):
58 p = getattr(obj, paramName)
60 if (isinstance(p, _RequiredParameter)
and writeRequired)
or (isinstance(p, _OptionalParameter)
and writeOptional):
61 p.setValue(p._ProxyParameter__type.dummyDefault)
62 if isinstance(p, cms.PSet):
64 if isinstance(p, cms.VPSet):
69 for n
in mod.parameterNames_():
73 def create_module(pythonModuleName: str, localPythonModule, writeRequired, writeOptional ):
74 parts = pythonModuleName.split(
'.')
75 pmod = importlib.import_module(pythonModuleName)
76 setattr(localPythonModule, parts[-1][0].lower()+parts[-1][1:],
setDefaultsInModule(getattr(pmod, parts[-1])(), writeRequired, writeOptional ) )
81 if __name__ ==
'__main__':
82 import FWCore.ParameterSet.Config
as cms
83 test = cms.EDAnalyzer(
"Foo",
84 a = cms.optional.int32,
85 b = cms.optional.string,
86 c = cms.optional.PSet,
87 d = cms.untracked.PSet(a=cms.int32(1), b= cms.optional.untracked.PSet),
88 e = cms.required.EventID,
89 f = cms.optional.LuminosityBlockID,
90 g = cms.optional.EventRange,
91 h = cms.optional.LuminosityBlockRange,
92 j = cms.optional.InputTag,
93 k = cms.optional.ESInputTag,
94 l = cms.optional.FileInPath
96 print(test.dumpPython())
98 print(test.dumpPython())
def setDefaultsInModule(mod, writeRequired, writeOptional)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def setADefault(obj, paramName, writeRequired, writeOptional)
def write_cfi(pythonModuleName, writeRequired, writeOptional)