8 import FWCore.ParameterSet.Modules
as mod
9 import FWCore.ParameterSet.Types
as typ
13 from FWCore.GuiBrowsers.FileExportPlugin
import FileExportPlugin
17 plugin_name=
'JSON Export'
18 file_types=(
'html',
'json')
20 FileExportPlugin.__init__(self)
27 for k,v
in pdict.items():
28 if v.pythonTypeName()==
'cms.PSet' or v.pythonTypeName()==
'cms.untracked.PSet':
29 result.append([k,v.pythonTypeName(),
'pset',pset(v.parameters_())])
30 elif v.pythonTypeName()==
'cms.VPSet' or v.pythonTypeName()==
'cms.untracked.VPSet':
31 result.append([k,v.pythonTypeName(),
'vpset',[pset(a.parameters_())
for a
in v]])
32 elif v.pythonTypeName().lower().startswith(
'cms.v')
or v.pythonTypeName().lower().startswith(
'cms.untracked.v'):
33 result.append([k,v.pythonTypeName(),
'list',[repr(a)
for a
in v]])
35 result.append([k,v.pythonTypeName(),
'single',repr(v.pythonValue())])
41 def moduledict(mod,prefix,links=False):
43 result[
'label']=data.label(mod)
44 result[
'class']=data.classname(mod)
45 result[
'file']=data.pypath(mod)
46 result[
'line']=data.lineNumber(mod)
47 result[
'package']=data.pypackage(mod)
48 result[
'pset']=pset(mod.parameters_())
49 result[
'type']=data.type(mod)
51 result[
'uses']=[data.uses(mod)]
52 result[
'usedby']=[data.usedBy(mod)]
53 result[
'id']=
'%s_%s'%(prefix,data.label(mod))
57 for tlo
in data.topLevelObjects():
58 children=data.children(tlo)
60 all[tlo._label]=children
62 process = {
'name':data.process().name_(),
'src':data._filename}
73 source[
'class']=data.classname(s)
74 source[
'pset']=pset(s.parameters_())
77 if 'essources' in all:
78 for e
in all[
'essources']:
79 essources.append(moduledict(e,
'essource'))
81 if 'esproducers' in all:
82 for e
in all[
'esproducers']:
83 essources.append(moduledict(e,
'esproducer'))
85 if 'esprefers' in all:
86 for e
in all[
'esprefers']:
87 essources.append(moduledict(e,
'esprefers'))
90 for s
in all[
'services']:
91 services.append({
'class':data.classname(s),
'pset':pset(s.parameters_())})
94 def jsonPathRecursive(p,prefix):
96 children = data.children(p)
98 children = [jsonPathRecursive(c,prefix)
for c
in children]
99 return {
'type':
'Sequence',
'label':
'Sequence %s'%(data.label(p)),
'id':
'seq_%s' % data.label(p),
'children':children}
101 return moduledict(p,prefix,
True)
106 for p
in all[
'paths']:
107 path=jsonPathRecursive(p,data.label(p))
109 if not type(path)==type([]):
110 if path[
'type']==
'Sequence':
111 path = path[
'children']
116 paths.append({
'label':data.label(p),
'path':path})
118 if 'endpaths' in all:
119 for p
in all[
'endpaths']:
120 path=jsonPathRecursive(p,data.label(p))
122 if not type(path)==type([]):
123 if path[
'type']==
'Sequence':
124 path = path[
'children']
129 endpaths.append({
'label':data.label(p),
'path':path})
132 json={
'process':process,
'source':source,
'essources':essources,
'esproducers':esproducers,
'esprefers':esprefers,
'services':services,
'paths':paths,
'endpaths':endpaths}
137 if not data.process():
138 raise "JSONExport requires a cms.Process object"
143 jsonfile = open(filename,
'w')