1 from __future__
import absolute_import
8 import FWCore.ParameterSet.Config
as cms
9 import FWCore.ParameterSet.Modules
as mod
10 import FWCore.ParameterSet.Types
as typ
14 from FWCore.GuiBrowsers.FileExportPlugin
import FileExportPlugin
18 plugin_name=
'JSON Export' 19 file_types=(
'html',
'json')
21 FileExportPlugin.__init__(self)
28 for k,v
in pdict.items():
29 if v.pythonTypeName()==
'cms.PSet' or v.pythonTypeName()==
'cms.untracked.PSet':
30 result.append([k,v.pythonTypeName(),
'pset',
pset(v.parameters_())])
31 elif v.pythonTypeName()==
'cms.VPSet' or v.pythonTypeName()==
'cms.untracked.VPSet':
32 result.append([k,v.pythonTypeName(),
'vpset',[
pset(a.parameters_())
for a
in v]])
33 elif v.pythonTypeName().lower().startswith(
'cms.v')
or v.pythonTypeName().lower().startswith(
'cms.untracked.v'):
34 result.append([k,v.pythonTypeName(),
'list',[repr(a)
for a
in v]])
36 result.append([k,v.pythonTypeName(),
'single',repr(v.pythonValue())])
42 def moduledict(mod,prefix,links=False):
44 result[
'label']=data.label(mod)
45 result[
'class']=data.classname(mod)
46 result[
'file']=data.pypath(mod)
47 result[
'line']=data.lineNumber(mod)
48 result[
'package']=data.pypackage(mod)
49 result[
'pset']=
pset(mod.parameters_())
50 result[
'type']=data.type(mod)
52 result[
'uses']=[data.uses(mod)]
53 result[
'usedby']=[data.usedBy(mod)]
54 result[
'id']=
'%s_%s'%(prefix,data.label(mod))
58 for tlo
in data.topLevelObjects():
59 children=data.children(tlo)
61 all[tlo._label]=children
63 process = {
'name':data.process().name_(),
'src':data._filename}
74 source[
'class']=data.classname(s)
75 source[
'pset']=
pset(s.parameters_())
78 if 'essources' in all:
79 for e
in all[
'essources']:
80 essources.append(moduledict(e,
'essource'))
82 if 'esproducers' in all:
83 for e
in all[
'esproducers']:
84 essources.append(moduledict(e,
'esproducer'))
86 if 'esprefers' in all:
87 for e
in all[
'esprefers']:
88 essources.append(moduledict(e,
'esprefers'))
91 for s
in all[
'services']:
92 services.append({
'class':data.classname(s),
'pset':
pset(s.parameters_())})
95 def jsonPathRecursive(p,prefix):
97 children = data.children(p)
99 children = [jsonPathRecursive(c,prefix)
for c
in children]
100 return {
'type':
'Sequence',
'label':
'Sequence %s'%(data.label(p)),
'id':
'seq_%s' % data.label(p),
'children':children}
102 return moduledict(p,prefix,
True)
107 for p
in all[
'paths']:
108 path=jsonPathRecursive(p,data.label(p))
110 if not isinstance(path, type([])):
111 if path[
'type']==
'Sequence':
112 path = path[
'children']
117 paths.append({
'label':data.label(p),
'path':path})
119 if 'endpaths' in all:
120 for p
in all[
'endpaths']:
121 path=jsonPathRecursive(p,data.label(p))
123 if not isinstance(path, type([])):
124 if path[
'type']==
'Sequence':
125 path = path[
'children']
130 endpaths.append({
'label':data.label(p),
'path':path})
133 json={
'process':process,
'source':source,
'essources':essources,
'esproducers':esproducers,
'esprefers':esprefers,
'services':services,
'paths':paths,
'endpaths':endpaths}
138 if not data.process():
139 raise "JSONExport requires a cms.Process object" 144 jsonfile = open(filename,
'w')
def export(self, data, filename, filetype)