ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/mjarvis/makePSet.py
Revision: 1.2
Committed: Thu Jul 22 09:38:07 2010 UTC (14 years, 9 months ago) by mjarvis
Content type: text/x-python
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
Actually changed it this time.

File Contents

# Content
1 #!/usr/bin/env python
2
3 #Generates psets
4 #Uses 'lcg-ls' which requires grid to be sourced and a valid grid proxy (voms-proxy-init)
5
6
7 import commands
8
9 import configuration_SCBooks as conf,sys,os,readline,getpass,string,fileinput,socket,datetime,re
10
11 user = getpass.getuser()
12 db = conf.lockedDB()
13 db.connect()
14
15 paths=[]
16 shortNames=[]
17 xsecs=[]
18
19 rows = db.execute('''select job.rowid,state,path,dataset,rpath,node
20 from job join tag on tag.rowid=job.tagid join dset on dset.rowid=job.dsetid
21 where user="'''+user+'''" order by state,path''').fetchall()
22 for row in rows:
23 print ('\t'.join([str(item) for item in row]))[0:90]+"..."
24 jobnumber = raw_input("\n\n\tWhich job? ")
25
26 for row in rows:
27 if jobnumber == str(row['rowid']):
28 datasets = (row['dataset']).split(',')
29 if len(datasets) > 1 :
30 for dset in datasets :
31 path = (row['rpath'])+string.replace(dset[1:], '/', '.')
32 paths.append(path)
33 shortName = (string.split(dset, '/'))[1] + "_" + (string.split(dset, '/'))[2]
34 shortNames.append(shortName)
35 xsecs.append(0.0)
36 #Would be nice if this information was in the database.
37 else :
38 dset = datasets[0]
39 path = (row['rpath'])
40 paths.append(path)
41 shortName = (string.split(dset, '/'))[1] + "_" + (string.split(dset, '/'))[2]
42 shortNames.append(shortName)
43 xsecs.append(0.0)
44 break
45 db.disconnect()
46
47 for path, shortName, xsec in zip(paths, shortNames, xsecs) :
48 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
49 print "Generating " + shortName + '_pset.py'
50 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
51 print "Path is " + path
52
53 prefix = '\n' + '\t' + "\"dcap://gfe02.grid.hep.ph.ic.ac.uk:22128/" + path[22:]
54 suffix = '.root\" ,'
55
56 temp = commands.getstatusoutput("lcg-ls srm://gfe02.grid.hep.ph.ic.ac.uk:8443/srm/managerv2?SFN=" + path + "/ | grep -E SusyCAF_Tree_[0-9]\{1\}[0-9]\{0,1\}[0-9]\{0,1\}_[0-9] -o")
57
58 if temp[0] != 0 :
59 print "\tError occured:"
60 print temp
61 break
62
63 infile = temp[1].split('\n')
64 infile.sort()
65
66 toRemove = []
67 for i,line1 in enumerate(infile[:-1]) :
68 for line2 in infile[i+1:] :
69 if line1[:-1] == line2[:-1] :
70 print "\tDuplicates exist: " + line1 + " and " + line2
71 print "\t\tIgnoring " + line1
72 toRemove.append(i)
73 break
74 toRemove.sort()
75 toRemove.reverse()
76 for i in toRemove :
77 del infile[i]
78
79 outfile = open(shortName+'_pset.py','w')
80
81 filenames = []
82 for line in infile :
83 line = line.rstrip()
84 line = prefix + line + suffix
85 filenames.append(line)
86
87 #header
88 header = '\n'.join([
89 'from icf.core import PSet',
90 '',
91 '%s=PSet(' % shortName,
92 '\tName=\"%s\",' % shortName,
93 '\tFormat=(\"ICF\",2),',
94 '\tFile=['
95 ])
96 outfile.write(header)
97
98 #body
99 for line in filenames :
100 outfile.write(line)
101
102 #footer
103 footer = '\n'.join([
104 '',
105 '\t],',
106 '\tCrossSection=%d,' % xsec,
107 ')'
108 ])
109 outfile.write(footer)