ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/input.py
Revision: 1.3
Committed: Sat Mar 19 01:49:13 2011 UTC (14 years, 1 month ago) by paus
Content type: text/x-python
Branch: MAIN
CVS Tags: Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020
Changes since 1.2: +16 -3 lines
Log Message:
Small updates here and there.

File Contents

# User Rev Content
1 paus 1.2 #!/usr/bin/env python
2     #---------------------------------------------------------------------------------------------------
3     # Simple interface to command line DBS to prepare my crabTask input files.
4     #---------------------------------------------------------------------------------------------------
5     import os,sys,types,string,getopt
6    
7     # Define string to explain usage of the script
8     usage = "Usage: input.py --dataset=<name>\n"
9     usage += " --option=[ lfn, xml ]\n"
10 paus 1.3 usage += " [ --dbs= ]\n"
11 paus 1.2 usage += " --help\n"
12    
13     def printLine(option,nEvents,block,lfn,iJob):
14     if option == 'xml':
15     print ' <Job MaxEvents="%d'%nEvents + '" InputFiles="' + lfn \
16     + '" SkipEvents="0" JobID="%d'%iJob + '" > </Job>'
17     else:
18     print "%s %s %d"%(block,lfn,nEvents)
19    
20    
21     # Define the valid options which can be specified and check out the command line
22 paus 1.3 valid = ['db=','dbs=','dataset=','option=','help']
23 paus 1.2 try:
24     opts, args = getopt.getopt(sys.argv[1:], "", valid)
25     except getopt.GetoptError, ex:
26     print usage
27     print str(ex)
28     sys.exit(1)
29    
30     # --------------------------------------------------------------------------------------------------
31     # Get all parameters for the production
32     # --------------------------------------------------------------------------------------------------
33     # Set defaults for each option
34     db = None
35 paus 1.3 dbs = None
36 paus 1.2 dataset = None
37     option = 'lfn'
38    
39     # Read new values from the command line
40     for opt, arg in opts:
41     if opt == "--help":
42     print usage
43     sys.exit(0)
44     if opt == "--db":
45     db = arg
46 paus 1.3 if opt == "--dbs":
47     dbs = arg
48 paus 1.2 if opt == "--dataset":
49     dataset = arg
50     if opt == "--option":
51     option = arg
52    
53     # Deal with obvious problems
54     if dataset == None:
55     cmd = "--dataset= required parameter not provided."
56     raise RuntimeError, cmd
57    
58     #---------------------------------------------------------------------------------------------------
59     # main
60     #---------------------------------------------------------------------------------------------------
61     if not db:
62     # find relevant blocks
63 paus 1.3 if dbs != '':
64     cmd = "dbs search --url=" + dbs + " --query=\"find block where dataset=" + dataset + "\""
65     else:
66     cmd = "dbs search --query=\"find block where dataset=" + dataset + "\""
67 paus 1.2 cmd += "| grep \# | sort"
68 paus 1.3 # never print #print "cmd: " + cmd
69    
70 paus 1.2 blocks = []
71     iJob = 1
72     if option == 'xml':
73     print '<arguments>'
74     for line in os.popen(cmd).readlines():
75     line = line[:-1]
76     blocks.append(line)
77     for block in blocks:
78 paus 1.3 if dbs != '':
79     cmd = "dbs search --url=" + dbs + \
80     " --query=\"find file,file.numevents where block=" + block + "\""
81     else:
82     cmd = "dbs search --query=\"find file,file.numevents where block=" + block + "\""
83 paus 1.2 cmd += "| grep store | sort"
84     for line in os.popen(cmd).readlines():
85     line = line[:-1]
86     f = line.split()
87     lfn = f[0]
88     nEvents = int(f[1])
89     f = lfn.split("/")
90     file = f[-1]
91     if nEvents != 0:
92     printLine(option,nEvents,block,lfn,iJob)
93     iJob = iJob + 1
94     if option == 'xml':
95     print '</arguments>'
96    
97     if db:
98     cmd = 'cat ' + db
99    
100     iJob = 1
101     if option == 'xml':
102     print '<arguments>'
103     for line in os.popen(cmd).readlines():
104     line = line[:-1]
105    
106     f = line.split()
107     block = f[0]
108     lfn = f[1]
109     nEvents = int(f[2])
110    
111     f = lfn.split("/")
112     file = f[-1]
113    
114     if nEvents != 0:
115     printLine(option,nEvents,block,lfn,iJob)
116     iJob = iJob + 1
117    
118     if option == 'xml':
119     print '</arguments>'