ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/mjarvis/makePSet.py
Revision: 1.4
Committed: Thu Jul 22 11:52:06 2010 UTC (14 years, 9 months ago) by mjarvis
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +3 -3 lines
Log Message:
Fixed problem with output file.

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 mjarvis 1.3 #Does not add the correct crosssections, this will need to be done by hand.
6 mjarvis 1.1
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 mjarvis 1.4 path = (row['rpath'])+'/'+string.replace(dset[1:], '/', '.')
32 mjarvis 1.1 paths.append(path)
33     shortName = (string.split(dset, '/'))[1] + "_" + (string.split(dset, '/'))[2]
34 mjarvis 1.3 shortName = string.replace(shortName,'-','_')
35 mjarvis 1.1 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 mjarvis 1.2 shortName = (string.split(dset, '/'))[1] + "_" + (string.split(dset, '/'))[2]
43 mjarvis 1.3 shortName = string.replace(shortName,'-','_')
44 mjarvis 1.1 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 mjarvis 1.3 # print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
51     print "Generating " + shortName + '.py'
52     # print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
53     # print "\tPath: " + path
54 mjarvis 1.1
55 mjarvis 1.4 prefix = '\n' + '\t' + "\"dcap://gfe02.grid.hep.ph.ic.ac.uk:22128/" + path + '/'
56 mjarvis 1.1 suffix = '.root\" ,'
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     for line2 in infile[i+1:] :
71     if line1[:-1] == line2[:-1] :
72 mjarvis 1.3 # print "\tDuplicates: " + line1 + " and " + line2
73     # print "\t\tIgnoring: " + line1
74 mjarvis 1.1 toRemove.append(i)
75     break
76     toRemove.sort()
77     toRemove.reverse()
78     for i in toRemove :
79     del infile[i]
80 mjarvis 1.4
81 mjarvis 1.3 outfile = open(shortName+'.py','w')
82 mjarvis 1.1
83     filenames = []
84     for line in infile :
85     line = line.rstrip()
86     line = prefix + line + suffix
87     filenames.append(line)
88    
89     #header
90     header = '\n'.join([
91     'from icf.core import PSet',
92     '',
93     '%s=PSet(' % shortName,
94     '\tName=\"%s\",' % shortName,
95     '\tFormat=(\"ICF\",2),',
96     '\tFile=['
97     ])
98     outfile.write(header)
99    
100     #body
101     for line in filenames :
102     outfile.write(line)
103    
104     #footer
105     footer = '\n'.join([
106     '',
107     '\t],',
108     '\tCrossSection=%d,' % xsec,
109     ')'
110     ])
111     outfile.write(footer)