ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/input.py
Revision: 1.4
Committed: Mon Sep 19 21:45:41 2011 UTC (13 years, 7 months ago) by paus
Content type: text/x-python
Branch: MAIN
CVS Tags: Mit_025, Mit_025pre2
Changes since 1.3: +13 -7 lines
Log Message:
Reinstate the bin and python areas.

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.4 if dbs == 'none':
64     cmd = 'dascli.py --query="block=' + dataset + '*" --limit=999999 --format=blocks'
65     elif dbs == '':
66     cmd = 'dbs search --query=\"find block where dataset=' + dataset + '\"'
67 paus 1.3 else:
68 paus 1.4 cmd = 'dbs search --url=' + dbs + ' --query="find block where dataset=' + dataset + '"'
69     #print "CMD " + cmd
70 paus 1.2 cmd += "| grep \# | sort"
71 paus 1.3 # never print #print "cmd: " + cmd
72    
73 paus 1.2 blocks = []
74     iJob = 1
75     if option == 'xml':
76     print '<arguments>'
77     for line in os.popen(cmd).readlines():
78     line = line[:-1]
79     blocks.append(line)
80     for block in blocks:
81 paus 1.4 if dbs == 'none':
82     cmd = 'dascli.py --query="file block=' + block + '" --limit=999999 --format=files'
83     elif dbs == '':
84     cmd = 'dbs search --query="find file,file.numevents where block=' + block + '"'
85 paus 1.3 else:
86 paus 1.4 cmd = 'dbs search --url=' + dbs + \
87     ' --query="find file,file.numevents where block=' + block + '"'
88     #print "CMD " + cmd
89 paus 1.2 cmd += "| grep store | sort"
90     for line in os.popen(cmd).readlines():
91     line = line[:-1]
92     f = line.split()
93     lfn = f[0]
94     nEvents = int(f[1])
95     f = lfn.split("/")
96     file = f[-1]
97     if nEvents != 0:
98     printLine(option,nEvents,block,lfn,iJob)
99     iJob = iJob + 1
100     if option == 'xml':
101     print '</arguments>'
102    
103     if db:
104     cmd = 'cat ' + db
105    
106     iJob = 1
107     if option == 'xml':
108     print '<arguments>'
109     for line in os.popen(cmd).readlines():
110     line = line[:-1]
111    
112     f = line.split()
113     block = f[0]
114     lfn = f[1]
115     nEvents = int(f[2])
116    
117     f = lfn.split("/")
118     file = f[-1]
119    
120     if nEvents != 0:
121     printLine(option,nEvents,block,lfn,iJob)
122     iJob = iJob + 1
123    
124     if option == 'xml':
125     print '</arguments>'