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