ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/input.py
Revision: 1.6
Committed: Sun May 6 12:45:04 2012 UTC (13 years ago) by paus
Content type: text/x-python
Branch: MAIN
CVS Tags: Mit_031, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_028, Mit_027a, Mit_027
Changes since 1.5: +2 -2 lines
Log Message:
Small fixes.

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 paus 1.5 import os,sys,types,string,re,getopt
6 paus 1.2
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 paus 1.6 cmd = 'dbs search --query=\"find block where dataset=*' + dataset + '\"'
67 paus 1.5 elif re.search('http://',dbs):
68 paus 1.6 cmd = 'dbs search --url=' + dbs + ' --query="find block where dataset=*' + dataset + '"'
69 paus 1.3 else:
70 paus 1.5 cmd = 'echo ' + dataset + '#00000000-0000-0000-0000-000000000000'
71    
72 paus 1.4 #print "CMD " + cmd
73 paus 1.2 cmd += "| grep \# | sort"
74 paus 1.3 # never print #print "cmd: " + cmd
75    
76 paus 1.2 blocks = []
77     iJob = 1
78     if option == 'xml':
79     print '<arguments>'
80     for line in os.popen(cmd).readlines():
81     line = line[:-1]
82     blocks.append(line)
83     for block in blocks:
84 paus 1.5 #print ' BLOCK: ' + block
85    
86 paus 1.4 if dbs == 'none':
87     cmd = 'dascli.py --query="file block=' + block + '" --limit=999999 --format=files'
88     elif dbs == '':
89     cmd = 'dbs search --query="find file,file.numevents where block=' + block + '"'
90 paus 1.5 elif re.search('http://',dbs):
91 paus 1.4 cmd = 'dbs search --url=' + dbs + \
92     ' --query="find file,file.numevents where block=' + block + '"'
93 paus 1.5 else:
94     cmd = 'cat /home/cmsprod/catalog/t2mit/private/' + dbs + dataset \
95     + '/Files | sed \'s@XX-CATALOG-XX@@\' | sed \'s@root://xrootd1.cmsaf.mit.edu/@@\''
96    
97 paus 1.4 #print "CMD " + cmd
98 paus 1.2 cmd += "| grep store | sort"
99     for line in os.popen(cmd).readlines():
100 paus 1.5 #print "LINE >" + line
101 paus 1.2 line = line[:-1]
102     f = line.split()
103     lfn = f[0]
104     nEvents = int(f[1])
105     f = lfn.split("/")
106     file = f[-1]
107     if nEvents != 0:
108     printLine(option,nEvents,block,lfn,iJob)
109     iJob = iJob + 1
110     if option == 'xml':
111     print '</arguments>'
112    
113     if db:
114     cmd = 'cat ' + db
115    
116     iJob = 1
117     if option == 'xml':
118     print '<arguments>'
119     for line in os.popen(cmd).readlines():
120     line = line[:-1]
121    
122     f = line.split()
123     block = f[0]
124     lfn = f[1]
125     nEvents = int(f[2])
126    
127     f = lfn.split("/")
128     file = f[-1]
129    
130     if nEvents != 0:
131     printLine(option,nEvents,block,lfn,iJob)
132     iJob = iJob + 1
133    
134     if option == 'xml':
135     print '</arguments>'