CMS 3D CMS Logo

DummyCfis.py
Go to the documentation of this file.
1 import importlib
2 from FWCore.ParameterSet.ModulesProxy import _ModuleProxy
3 from FWCore.ParameterSet.Types import _ProxyParameter, _RequiredParameter, _OptionalParameter
4 import FWCore.ParameterSet.Config as cms
5 
6 #setup defaults for each type
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__"
35 
36 
37 
38 def create_cfis(modName: str, writeRequired, writeOptional):
39  modules = importlib.import_module(modName+".modules")
40  for (n,m) in (x for x in modules.__dict__.items() if isinstance(x[1], _ModuleProxy)):
41  print(modName +'.'+n)
42  write_cfi(modName+'.'+n, writeRequired, writeOptional)
43 
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",
49  "import sys\n",
50  "dc.create_module('{}', sys.modules[__name__], {}, {})\n".format(pythonModuleName, writeRequired, writeOptional)])
51  f.close()
52 
53 def setDefaultInPSet(pset: cms.PSet, writeRequired, writeOptional):
54  for n in pset.parameterNames_():
55  setADefault(pset, n, writeRequired, writeOptional)
56 
57 def setADefault(obj, paramName, writeRequired, writeOptional):
58  p = getattr(obj, paramName)
59  #print(p)
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):
63  setDefaultInPSet(p, writeRequired, writeOptional)
64  if isinstance(p, cms.VPSet):
65  for pset in p:
66  setDefaultInPSet(pset, writeRequired, writeOptional)
67 
68 def setDefaultsInModule(mod, writeRequired, writeOptional):
69  for n in mod.parameterNames_():
70  setADefault(mod, n, writeRequired, writeOptional)
71  return mod
72 
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 ) )
77 
78 
79 #create_cfis("FWCore.Integration")
80 
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
95  )
96  print(test.dumpPython())
97  setDefaultsInModule(test, True, False)
98  print(test.dumpPython())
99 
def create_module
Definition: DummyCfis.py:73
def setDefaultsInModule(mod, writeRequired, writeOptional)
Definition: DummyCfis.py:68
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def setADefault(obj, paramName, writeRequired, writeOptional)
Definition: DummyCfis.py:57
def setDefaultInPSet
Definition: DummyCfis.py:53
def write_cfi(pythonModuleName, writeRequired, writeOptional)
Definition: DummyCfis.py:44
def create_cfis
Definition: DummyCfis.py:38