CMS 3D CMS Logo

TreeToEdges.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # go to the tree file and pick out all the paths that have hits greater
00004 # than the cutoff and convert the entries to edge definitions.
00005 
00006 import sys
00007 
00008 class Int:
00009     def __init__(self,num):
00010         self.value = num
00011 
00012     def inc(self,num):
00013         self.value+=num
00014 
00015     def __repr__(self):
00016         return str(self.value)
00017 
00018 def runme(infile,outfile,cutoff):
00019     fin = open(infile,'r')
00020     fout = open(outfile,'w')
00021     tree = {}
00022     count = 0
00023     
00024     for line in fin.xreadlines():
00025 
00026         a = line.split()
00027         id = int(a.pop(0))
00028         tot = int(a.pop(0))
00029         if tot < cutoff: break
00030         head = int(a.pop(0))
00031         
00032         for node in a:
00033             val = int(node)
00034             key = (head,val)
00035                 
00036             n = tree.get(key)
00037             if n == None:
00038                 tree[key] = Int(tot)
00039             else:
00040                 n.inc(tot)
00041             head = val
00042             
00043         count += 1
00044 
00045     for node in tree.items():
00046         # print node
00047         print >>fout, node[1], ' ', node[0][0], ' ', node[0][1]
00048             
00049 if __name__ == "__main__":
00050     if len(sys.argv) < 4:
00051         print "usage: ", sys.argv[0], " in_tree_file out_edge_file cutoff"
00052         sys.exit(1)
00053         
00054     infile = sys.argv[1]
00055     outfile = sys.argv[2]
00056     cutoff = int(sys.argv[3])
00057     print "cutoff=",cutoff
00058     # if cutoff == 0: cutoff = 1000000000
00059     runme(infile, outfile, cutoff)

Generated on Tue Jun 9 17:36:39 2009 for CMSSW by  doxygen 1.5.4