ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/mjarvis/createPSet.py
Revision: 1.1
Committed: Thu Jul 22 08:54:28 2010 UTC (14 years, 9 months ago) by mjarvis
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Log Message:
first commit.

File Contents

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