-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateBatchCFGs.py
More file actions
109 lines (81 loc) · 2.54 KB
/
CreateBatchCFGs.py
File metadata and controls
109 lines (81 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/python
#
# Create Config files suitable for multiple job submission to the CERN LSF batch queue
import sys,string,time,os
istart=0
# NFILES=81
NFILES=23
INPUTSTARTSWITH="INPUTFILELIST="
COMMENTLINE="#"
searchInput="xxx"
OUTPUTSTARTSWITH="OUTPUTHIST="
searchOutput=".root"
def usage():
""" Usage: CreateCFGS <cmsCFGFile> <outputDir>
"""
pass
def OpenFile(file_in,iodir):
""" file_in -- Input file name
iodir -- 'r' readonly 'r+' read+write """
try:
ifile=open(file_in, iodir)
# print "Opened file: ",file_in," iodir ",iodir
except:
print "Could not open file: ",file_in
sys.exit(1)
return ifile
def CloseFile(ifile):
ifile.close()
def createNewFile(i,orgFile,basename,dir):
newFile=basename + "_" + str(i) + ".py"
newFile=os.path.join(dir,newFile)
print newFile
outFile = open(newFile,'w')
for iline in orgFile:
if len(iline)>0 and iline[0]!=COMMENTLINE:
indx=string.find(iline,INPUTSTARTSWITH)
if (indx == 0):
indx2=string.find(iline,searchInput)
if (indx2 < 0):
print "Problem finding line beginning with: ", INPUTSTARTSWITH
sys.exit(1)
else:
iline=string.replace(iline,searchInput,str(i))
# indx=string.find(iline,OUTPUTSTARTSWITH)
# if (indx == 0):
# indx2=string.find(iline,searchOutput)
# if (indx2 < 0):
# print "Problem"
# sys.exit(1)
# else:
# replString="_" + str(i) + searchOutput
# iline=string.replace(iline,searchOutput,replString)
outFile.write(iline + "\n")
CloseFile(outFile)
return
def ReadFile(file):
infile=OpenFile(file,'r')
iline=0
x = infile.readline()
file=[]
while x != "":
iline+=1
xx=string.rstrip(x)
file.append(xx)
x = infile.readline()
CloseFile(infile)
return file
if __name__ == '__main__':
narg=len(sys.argv)
if narg < 3 :
print usage.__doc__
sys.exit(1)
InputFile=sys.argv[1]
basename=string.replace(InputFile,".py","")
OutputDir=sys.argv[2]
if not os.path.exists(OutputDir):
os.mkdir(OutputDir)
infile=ReadFile(InputFile)
for i in range(istart,istart+NFILES):
# print i
createNewFile(i,infile,basename,OutputDir)