Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:56

0001 def plotSequences(seq,filename):
0002     from sys import stderr, argv
0003     from os import popen
0004     from os.path import basename
0005     from re import sub;
0006     import FWCore.ParameterSet.Config as cms
0007     stderr.write("Writing plot to %s\n" % (filename,))
0008     dot = popen("dot -Tpng > %s" % (filename,), "w")
0009     dot.write("digraph G { \n rankdir=\"LR\" \n")
0010     class visitor(object):
0011         def __init__(self,seq,dot):
0012             self._dot = dot
0013             self._stack = []
0014             self._seq = seq.label()
0015             self._dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (self._seq,'orange',self._seq) + "\n" )
0016         def seq(self, seq):
0017             self._stack.append(self._seq)
0018             self._seq = seq.label()
0019         def enter(self,v):
0020             if isinstance(v, cms.Sequence):
0021                 self._dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (v.label(),'orange',v.label()) + "\n" )
0022                 self.dep(v)
0023                 self.seq(v)
0024             if isinstance(v, (cms.EDProducer, cms.EDFilter, cms.EDAnalyzer)):
0025                 self._dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (v.label(),'green',v.label()) + "\n" ) 
0026                 self.dep(v)
0027         def leave(self,v):
0028             if isinstance(v, cms.Sequence):
0029                 self._seq = self._stack.pop()
0030         def dep(self,v):
0031             self._dot.write("%s -> %s" %(v.label(), self._seq) +"\n")
0032     seq.visit(visitor(seq,dot))
0033     dot.write("}\n")
0034     dot.close()
0035 
0036 def plotModuleInputs(seq,filename,printOuter=True,printLinkNames=True):
0037     from sys import stderr, argv
0038     from os import popen
0039     from os.path import basename
0040     from re import sub;
0041     import FWCore.ParameterSet.Config as cms
0042     stderr.write("Writing plot to %s\n" % (filename,))
0043     dot = popen("dot -Tpng > %s" % (filename,), "w")
0044     #dot = open("%s.dot" % (filename,), "w")
0045     dot.write("digraph G { \n rankdir=\"LR\" \n")
0046     deps = {}; alls = {}
0047     modules = []
0048     class visitor(object):
0049         def enter(self,v):
0050             if isinstance(v, (cms.EDProducer, cms.EDFilter, cms.EDAnalyzer)):
0051                 modules.append(v)
0052         def leave(self,v):
0053             pass
0054     def greptags(ps,basename=""):
0055         ret = []
0056         for pn, pv in ps.parameters_().items():
0057             type = pv.configTypeName()
0058             if type == 'InputTag'    : ret.append( (basename+pn, pv.configValue()) )
0059             elif type == 'VInputTag' : ret += [ ("%s%s[%d]"%(basename,pn,i+1),v.configValue()) for i,v in enumerate(pv.value()) ]
0060             elif type == 'PSet'      : ret += greptags(pv, basename+pn+'.')
0061             elif type == 'VPset'     : 
0062                 for r1 in [greptags(pvi, basename+pn+'.') for pvi in pv.value()]: ret += r1
0063         return ret
0064     def escapeParValue(name): return sub(r":.*","", name)
0065     seq.visit(visitor())
0066     for m in modules:
0067         dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (m.label(),'green',m.label()) + "\n")
0068         tags = greptags(m)
0069         #stderr.write("Tags for %s: %s\n" % (m.label(), tags))
0070         deps[m.label()] = tags;
0071         if m.label() not in alls: alls[m.label()]=True
0072         for (tn,tv) in tags:
0073             tve = escapeParValue(tv)
0074             if tve not in alls: alls[tve]=True
0075     names = deps.keys();
0076     if printOuter: names = alls.keys()
0077     done = {}
0078     for n in names:
0079         ne = escapeParValue(n)
0080         if ne not in deps:
0081             dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (ne,'yellow',ne) + "\n")
0082         else:
0083             for tn,tv in deps[ne]:
0084                 tve = escapeParValue(tv)
0085                 if printOuter or tve in deps:
0086                     style = ""
0087                     if printLinkNames: style = " [label=\"%s\" ]" %(tn,)
0088                     dot.write(  "%s -> %s%s\n"%(tve,ne,style))
0089     dot.write("}\n")
0090     dot.close()
0091 
0092