CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/PhysicsTools/PatAlgos/python/tools/circuitry.py

Go to the documentation of this file.
00001 def plotSequences(seq,filename):
00002     from sys import stderr, argv
00003     from os import popen
00004     from os.path import basename
00005     from re import sub;
00006     import FWCore.ParameterSet.Config as cms
00007     stderr.write("Writing plot to %s\n" % (filename,))
00008     dot = popen("dot -Tpng > %s" % (filename,), "w")
00009     dot.write("digraph G { \n rankdir=\"LR\" \n")
00010     class visitor(object):
00011         def __init__(self,seq,dot):
00012             self._dot = dot
00013             self._stack = []
00014             self._seq = seq.label()
00015             self._dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (self._seq,'orange',self._seq) + "\n" )
00016         def seq(self, seq):
00017             self._stack.append(self._seq)
00018             self._seq = seq.label()
00019         def enter(self,v):
00020             if isinstance(v, cms.Sequence):
00021                 self._dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (v.label(),'orange',v.label()) + "\n" )
00022                 self.dep(v)
00023                 self.seq(v)
00024             if isinstance(v, (cms.EDProducer, cms.EDFilter, cms.EDAnalyzer)):
00025                 self._dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (v.label(),'green',v.label()) + "\n" ) 
00026                 self.dep(v)
00027         def leave(self,v):
00028             if isinstance(v, cms.Sequence):
00029                 self._seq = self._stack.pop()
00030         def dep(self,v):
00031             self._dot.write("%s -> %s" %(v.label(), self._seq) +"\n")
00032     seq.visit(visitor(seq,dot))
00033     dot.write("}\n")
00034     dot.close()
00035 
00036 def plotModuleInputs(seq,filename,printOuter=True,printLinkNames=True):
00037     from sys import stderr, argv
00038     from os import popen
00039     from os.path import basename
00040     from re import sub;
00041     import FWCore.ParameterSet.Config as cms
00042     stderr.write("Writing plot to %s\n" % (filename,))
00043     dot = popen("dot -Tpng > %s" % (filename,), "w")
00044     #dot = open("%s.dot" % (filename,), "w")
00045     dot.write("digraph G { \n rankdir=\"LR\" \n")
00046     deps = {}; alls = {}
00047     modules = []
00048     class visitor(object):
00049         def enter(self,v):
00050             if isinstance(v, (cms.EDProducer, cms.EDFilter, cms.EDAnalyzer)):
00051                 modules.append(v)
00052         def leave(self,v):
00053             pass
00054     def greptags(ps,basename=""):
00055         ret = []
00056         for pn, pv in ps.parameters_().items():
00057             type = pv.configTypeName()
00058             if type == 'InputTag'    : ret.append( (basename+pn, pv.configValue()) )
00059             elif type == 'VInputTag' : ret += [ ("%s%s[%d]"%(basename,pn,i+1),v.configValue()) for i,v in enumerate(pv.value()) ]
00060             elif type == 'PSet'      : ret += greptags(pv, basename+pn+'.')
00061             elif type == 'VPset'     : 
00062                 for r1 in [greptags(pvi, basename+pn+'.') for pvi in pv.value()]: ret += r1
00063         return ret
00064     def escapeParValue(name): return sub(r":.*","", name)
00065     seq.visit(visitor())
00066     for m in modules:
00067         dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (m.label(),'green',m.label()) + "\n")
00068         tags = greptags(m)
00069         #stderr.write("Tags for %s: %s\n" % (m.label(), tags))
00070         deps[m.label()] = tags;
00071         if not alls.has_key(m.label()): alls[m.label()]=True
00072         for (tn,tv) in tags:
00073             tve = escapeParValue(tv)
00074             if not alls.has_key(tve): alls[tve]=True
00075     names = deps.keys();
00076     if printOuter: names = alls.keys()
00077     done = {}
00078     for n in names:
00079         ne = escapeParValue(n)
00080         if not deps.has_key(ne):
00081             dot.write( "%s [  shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (ne,'yellow',ne) + "\n")
00082         else:
00083             for tn,tv in deps[ne]:
00084                 tve = escapeParValue(tv)
00085                 if printOuter or deps.has_key(tve):
00086                     style = ""
00087                     if printLinkNames: style = " [label=\"%s\" ]" %(tn,)
00088                     dot.write(  "%s -> %s%s\n"%(tve,ne,style))
00089     dot.write("}\n")
00090     dot.close()
00091 
00092