CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/FWCore/Services/bin/NewTree.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 import re
00008 import Parameters
00009 import operator
00010 import string
00011 
00012 def runme2(fid,infile,outfile):
00013     fin = open(infile,'r')
00014     fout = open(outfile,'w')
00015     sub = ' ' + fid + '[ $]'
00016     r = re.compile(sub)
00017     
00018     for line in fin.xreadlines():
00019         i = line.index(' ')+1
00020         s = r.search(line[i:])
00021         if s != None:
00022             print >>fout,line[0:i+s.end()-1]
00023 
00024 def runme(fid,infile,outfile):
00025     fin = open(infile,'r')
00026     fout = open(outfile,'w')
00027     tot_up = Parameters.parameters['view']['levels_up']
00028     tot_down = Parameters.parameters['view']['levels_down']
00029     print "up=",tot_up," down=",tot_down
00030     # trigger too difficult for now
00031     trigger = Parameters.parameters['find']['immediate_children_threshold']
00032     
00033     for line in fin.xreadlines():
00034         a=line.split()
00035         b=a[2:]
00036         # find fid in a
00037         try:
00038             i=operator.indexOf(b,fid)
00039             # write out stuff according to tot_up and tot_down
00040             if i < tot_up: c = i
00041             else: c = tot_up
00042             print >>fout,"%s %s %s"%(a[0],a[1],string.join(b[i-c:i+1+tot_down]))
00043         except ValueError:
00044             pass
00045 
00046 if __name__ == "__main__":
00047     if len(sys.argv) < 3:
00048         print "usage: ", sys.argv[0], " function_id input_file_prefix"
00049         sys.exit(1)
00050         
00051     fid = sys.argv[1]
00052     infile = sys.argv[2]
00053     outfile = fid + Parameters.parameters['view']['out_file_suffix']
00054     runme(fid, infile, outfile)
00055