test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
circuitry Namespace Reference

Functions

def plotModuleInputs
 
def plotSequences
 

Variables

 _dot
 
 _seq
 
 _stack
 

Function Documentation

def circuitry.plotModuleInputs (   seq,
  filename,
  printOuter = True,
  printLinkNames = True 
)

Definition at line 36 of file circuitry.py.

36 
37 def plotModuleInputs(seq,filename,printOuter=True,printLinkNames=True):
38  from sys import stderr, argv
39  from os import popen
40  from os.path import basename
41  from re import sub;
42  import FWCore.ParameterSet.Config as cms
43  stderr.write("Writing plot to %s\n" % (filename,))
44  dot = popen("dot -Tpng > %s" % (filename,), "w")
45  #dot = open("%s.dot" % (filename,), "w")
46  dot.write("digraph G { \n rankdir=\"LR\" \n")
47  deps = {}; alls = {}
48  modules = []
49  class visitor(object):
50  def enter(self,v):
51  if isinstance(v, (cms.EDProducer, cms.EDFilter, cms.EDAnalyzer)):
52  modules.append(v)
53  def leave(self,v):
54  pass
55  def greptags(ps,basename=""):
56  ret = []
57  for pn, pv in ps.parameters_().items():
58  type = pv.configTypeName()
59  if type == 'InputTag' : ret.append( (basename+pn, pv.configValue()) )
60  elif type == 'VInputTag' : ret += [ ("%s%s[%d]"%(basename,pn,i+1),v.configValue()) for i,v in enumerate(pv.value()) ]
61  elif type == 'PSet' : ret += greptags(pv, basename+pn+'.')
62  elif type == 'VPset' :
63  for r1 in [greptags(pvi, basename+pn+'.') for pvi in pv.value()]: ret += r1
64  return ret
65  def escapeParValue(name): return sub(r":.*","", name)
66  seq.visit(visitor())
67  for m in modules:
68  dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (m.label(),'green',m.label()) + "\n")
69  tags = greptags(m)
70  #stderr.write("Tags for %s: %s\n" % (m.label(), tags))
71  deps[m.label()] = tags;
72  if m.label() not in alls: alls[m.label()]=True
73  for (tn,tv) in tags:
74  tve = escapeParValue(tv)
75  if tve not in alls: alls[tve]=True
76  names = deps.keys();
77  if printOuter: names = alls.keys()
78  done = {}
79  for n in names:
80  ne = escapeParValue(n)
81  if ne not in deps:
82  dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (ne,'yellow',ne) + "\n")
83  else:
84  for tn,tv in deps[ne]:
85  tve = escapeParValue(tv)
86  if printOuter or tve in deps:
87  style = ""
88  if printLinkNames: style = " [label=\"%s\" ]" %(tn,)
89  dot.write( "%s -> %s%s\n"%(tve,ne,style))
90  dot.write("}\n")
91  dot.close()
92 
93 
def plotModuleInputs
Definition: circuitry.py:36
def circuitry.plotSequences (   seq,
  filename 
)

Definition at line 1 of file circuitry.py.

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 
def plotSequences
Definition: circuitry.py:1

Variable Documentation

circuitry._dot

Definition at line 12 of file circuitry.py.

circuitry._seq

Definition at line 14 of file circuitry.py.

circuitry._stack

Definition at line 13 of file circuitry.py.