test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
circuitry.py
Go to the documentation of this file.
1 def plotSequences(seq,filename):
2  from sys import stderr, argv
3  from os import popen
4  from os.path import basename
5  from re import sub;
6  import FWCore.ParameterSet.Config as cms
7  stderr.write("Writing plot to %s\n" % (filename,))
8  dot = popen("dot -Tpng > %s" % (filename,), "w")
9  dot.write("digraph G { \n rankdir=\"LR\" \n")
10  class visitor(object):
11  def __init__(self,seq,dot):
12  self._dot = dot
13  self._stack = []
14  self._seq = seq.label()
15  self._dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (self._seq,'orange',self._seq) + "\n" )
16  def seq(self, seq):
17  self._stack.append(self._seq)
18  self._seq = seq.label()
19  def enter(self,v):
20  if isinstance(v, cms.Sequence):
21  self._dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (v.label(),'orange',v.label()) + "\n" )
22  self.dep(v)
23  self.seq(v)
24  if isinstance(v, (cms.EDProducer, cms.EDFilter, cms.EDAnalyzer)):
25  self._dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (v.label(),'green',v.label()) + "\n" )
26  self.dep(v)
27  def leave(self,v):
28  if isinstance(v, cms.Sequence):
29  self._seq = self._stack.pop()
30  def dep(self,v):
31  self._dot.write("%s -> %s" %(v.label(), self._seq) +"\n")
32  seq.visit(visitor(seq,dot))
33  dot.write("}\n")
34  dot.close()
35 
36 def plotModuleInputs(seq,filename,printOuter=True,printLinkNames=True):
37  from sys import stderr, argv
38  from os import popen
39  from os.path import basename
40  from re import sub;
41  import FWCore.ParameterSet.Config as cms
42  stderr.write("Writing plot to %s\n" % (filename,))
43  dot = popen("dot -Tpng > %s" % (filename,), "w")
44  #dot = open("%s.dot" % (filename,), "w")
45  dot.write("digraph G { \n rankdir=\"LR\" \n")
46  deps = {}; alls = {}
47  modules = []
48  class visitor(object):
49  def enter(self,v):
50  if isinstance(v, (cms.EDProducer, cms.EDFilter, cms.EDAnalyzer)):
51  modules.append(v)
52  def leave(self,v):
53  pass
54  def greptags(ps,basename=""):
55  ret = []
56  for pn, pv in ps.parameters_().items():
57  type = pv.configTypeName()
58  if type == 'InputTag' : ret.append( (basename+pn, pv.configValue()) )
59  elif type == 'VInputTag' : ret += [ ("%s%s[%d]"%(basename,pn,i+1),v.configValue()) for i,v in enumerate(pv.value()) ]
60  elif type == 'PSet' : ret += greptags(pv, basename+pn+'.')
61  elif type == 'VPset' :
62  for r1 in [greptags(pvi, basename+pn+'.') for pvi in pv.value()]: ret += r1
63  return ret
64  def escapeParValue(name): return sub(r":.*","", name)
65  seq.visit(visitor())
66  for m in modules:
67  dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (m.label(),'green',m.label()) + "\n")
68  tags = greptags(m)
69  #stderr.write("Tags for %s: %s\n" % (m.label(), tags))
70  deps[m.label()] = tags;
71  if not alls.has_key(m.label()): alls[m.label()]=True
72  for (tn,tv) in tags:
73  tve = escapeParValue(tv)
74  if not alls.has_key(tve): alls[tve]=True
75  names = deps.keys();
76  if printOuter: names = alls.keys()
77  done = {}
78  for n in names:
79  ne = escapeParValue(n)
80  if not deps.has_key(ne):
81  dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (ne,'yellow',ne) + "\n")
82  else:
83  for tn,tv in deps[ne]:
84  tve = escapeParValue(tv)
85  if printOuter or deps.has_key(tve):
86  style = ""
87  if printLinkNames: style = " [label=\"%s\" ]" %(tn,)
88  dot.write( "%s -> %s%s\n"%(tve,ne,style))
89  dot.write("}\n")
90  dot.close()
91 
92 
def plotSequences
Definition: circuitry.py:1
def plotModuleInputs
Definition: circuitry.py:36
list object
Definition: dbtoconf.py:77