File indexing completed on 2024-11-26 02:34:20
0001
0002
0003
0004 import sys,string,time,os
0005
0006
0007 istart=0
0008 NJOBS=41
0009
0010
0011
0012 INPUTSTARTSWITH="INPUTFILE="
0013 searchInput="xxx"
0014
0015 OUTPUTSTARTSWITH=" OUTPUTFILE="
0016
0017 searchOutput=".root"
0018
0019
0020
0021 def usage():
0022 """ Usage: CreateCFGS <cmsCFGFile> <outputDir>
0023 """
0024 pass
0025
0026 def OpenFile(file_in,iodir):
0027 """ file_in -- Input file name
0028 iodir -- 'r' readonly 'r+' read+write """
0029 try:
0030 ifile=open(file_in, iodir)
0031
0032 except:
0033 print("Could not open file: ",file_in)
0034 sys.exit(1)
0035 return ifile
0036
0037 def CloseFile(ifile):
0038 ifile.close()
0039
0040 def createCFGFiles(i,orgFile,basename,dir):
0041
0042 newFile=basename + "_" + str(i) + ".py"
0043 newFile=os.path.join(dir,newFile)
0044 print(newFile)
0045 outFile = open(newFile,'w')
0046
0047 for iline in orgFile:
0048 indx=string.find(iline,INPUTSTARTSWITH)
0049 if (indx == 0):
0050 indx2=string.find(iline,searchInput)
0051 if (indx2 < 0):
0052 print("Problem")
0053 sys.exit(1)
0054 else:
0055 iline=string.replace(iline,searchInput,str(i))
0056
0057 indx=string.find(iline,OUTPUTSTARTSWITH)
0058 if (indx == 0):
0059 indx2=string.find(iline,searchOutput)
0060 if (indx2 < 0):
0061 print("Problem")
0062 sys.exit(1)
0063 else:
0064 replString="_" + str(i) + searchOutput
0065 iline=string.replace(iline,searchOutput,replString)
0066
0067 outFile.write(iline + "\n")
0068 CloseFile(outFile)
0069
0070 return newFile
0071
0072 def createLSFScript(cfgfile):
0073
0074 file=os.path.basename(cfgfile)
0075 absDir=os.path.abspath(os.path.dirname(cfgfile))
0076
0077
0078 outScript="runlsf_" + string.replace(file,".py",".csh")
0079 outLog="runlsf_" + string.replace(file,".py",".log")
0080
0081 inScript=os.path.join(file)
0082 outScript=os.path.join(absDir,outScript)
0083 outLog=os.path.join(absDir,outLog)
0084
0085 oFile = open(outScript,'w')
0086 oFile.write("#!/bin/csh" + "\n")
0087
0088 oFile.write("cd " + absDir + "\n")
0089 oFile.write("eval `scram runtime -csh`" + "\n")
0090
0091 oFile.write("cmsRun " + inScript + "\n")
0092
0093
0094 oFile.close()
0095
0096 return
0097
0098 def ReadFile(file):
0099
0100 infile=OpenFile(file,'r')
0101 iline=0
0102
0103 x = infile.readline()
0104
0105 file=[]
0106 while x != "":
0107 iline+=1
0108 xx=string.rstrip(x)
0109 file.append(xx)
0110 x = infile.readline()
0111
0112 CloseFile(infile)
0113
0114 return file
0115
0116
0117 if __name__ == '__main__':
0118
0119
0120 narg=len(sys.argv)
0121 if narg < 3 :
0122 print(usage.__doc__)
0123 sys.exit(1)
0124
0125
0126 InputFile=sys.argv[1]
0127 basename=string.replace(InputFile,".py","")
0128
0129 OutputDir=sys.argv[2]
0130 if not os.path.exists(OutputDir):
0131 os.mkdir(OutputDir)
0132
0133 infile=ReadFile(InputFile)
0134
0135
0136 cfglist=[]
0137 for i in range(istart,istart+NJOBS):
0138
0139 file=createCFGFiles(i,infile,basename,OutputDir)
0140 cfglist.append(file)
0141
0142
0143 for cfgfile in cfglist:
0144 createLSFScript(cfgfile)
0145
0146
0147
0148
0149
0150