ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/mjarvis/makeICFPSet.py
Revision: 1.1
Committed: Thu Jul 22 13:21:32 2010 UTC (14 years, 9 months ago) by mjarvis
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 mjarvis 1.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     #Does not add the correct crosssections, this will need to be done by hand.
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     shortName = string.replace(shortName,'-','_')
35     shortNames.append(shortName)
36     xsecs.append(0.0)
37     #Would be nice if this information was in the database.
38     else :
39     dset = datasets[0]
40     path = (row['rpath'])
41     paths.append(path)
42     shortName = (string.split(dset, '/'))[1] + "_" + (string.split(dset, '/'))[2]
43     shortName = string.replace(shortName,'-','_')
44     shortNames.append(shortName)
45     xsecs.append(0.0)
46     break
47     db.disconnect()
48    
49     for path, shortName, xsec in zip(paths, shortNames, xsecs) :
50     # print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
51     print "Generating " + shortName + '.py'
52     # print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
53     # print "\tPath: " + path
54    
55     prefix = '\n' + '\t' + "\"dcap://gfe02.grid.hep.ph.ic.ac.uk:22128/"# + path + '/'
56     suffix = '\" ,'
57    
58     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")
59    
60     if temp[0] != 0 :
61     print "\tError occured:"
62     print temp
63     break
64    
65     infile = temp[1].split('\n')
66     infile.sort()
67    
68     toRemove = []
69     for i,line1 in enumerate(infile[:-1]) :
70     if (((line1.split('/'))[-1]).split('_'))[2] == (((infile[i+1].split('/'))[-1]).split('_'))[2] :
71     #print "\tDuplicates: " + line1
72     toRemove.append(i)
73     # for line2 in infile[i+1:] :
74     # if line1[:-1] == line2[:-1] :
75    
76    
77     toRemove.sort()
78     toRemove.reverse()
79     for i in toRemove :
80     del infile[i]
81    
82     outfile = open(shortName+'.py','w')
83    
84     filenames = []
85     for line in infile :
86     line = line.rstrip()
87     line = prefix + line + suffix
88     filenames.append(line)
89    
90     #header
91     header = '\n'.join([
92     'from icf.core import PSet',
93     '',
94     '%s=PSet(' % shortName,
95     '\tName=\"%s\",' % shortName,
96     '\tFormat=(\"ICF\",2),',
97     '\tFile=['
98     ])
99     outfile.write(header)
100    
101     #body
102     for line in filenames :
103     outfile.write(line)
104    
105     #footer
106     footer = '\n'.join([
107     '',
108     '\t],',
109     '\tCrossSection=%d,' % xsec,
110     ')'
111     ])
112     outfile.write(footer)