File indexing completed on 2024-11-27 03:18:06
0001
0002 from builtins import range
0003 import sys,os,re
0004 from CommonMethods import *
0005 def main():
0006
0007 sourcePath = "LatestRuns/"
0008
0009 sourceDirList = [sourcePath+"2010A",sourcePath+"2010B",sourcePath+"Commissioning10"]
0010 destDirList = ["2010A","2010B","Commissioning10"]
0011 path = "LatestRuns/"
0012 finalDir = path + "Results/"
0013
0014 if not os.path.isdir(path):
0015 error = "WARNING: path directory doesn't exist! Creating it..."
0016 print(error)
0017 os.mkdir(path)
0018
0019 if not os.path.isdir(finalDir):
0020 error = "WARNING: final dir directory doesn't exist! Creating it..."
0021 print(error)
0022 os.mkdir(finalDir)
0023
0024
0025 for n in range(0,len(sourceDirList)):
0026 sourceDir = sourceDirList[n] + '/'
0027 destDir = path + destDirList[n] + '/'
0028 if not dirExists(sourceDir):
0029 print(sourceDir + " doesn't exist!")
0030 continue
0031 fileList = ls(sourceDir)
0032 if not os.path.isdir(destDir):
0033 error = "WARNING: destination directory doesn't exist! Creating it..."
0034 print(error)
0035 os.mkdir(destDir)
0036 copiedFiles = cp(sourceDir,destDir,fileList,False,False)
0037
0038
0039
0040
0041
0042 for fileName in copiedFiles:
0043
0044 regExp = re.search('(\D+)(\d+)_(\d+)_[a-zA-Z0-9]+.txt',fileName)
0045
0046
0047
0048 fullFileName = destDir + fileName
0049 print(fullFileName)
0050 runNumber = -1
0051 with open(fullFileName,'r') as file:
0052 allTxt = ''
0053 for line in file:
0054 if line.find("Runnumber") != -1:
0055 tmpRun = int(line.split(' ')[1])
0056 if runNumber != -1 and tmpRun != runNumber:
0057 error = "This file (" + fileName + ") contains more than 1 run number!"
0058 if regExp:
0059 newFileName = regExp.group(1) + regExp.group(2) + "_" + str(runNumber) + "_1.txt"
0060 with open(finalDir+newFileName,'a') as outFile:
0061 outFile.writelines(allTxt)
0062 outFile.close()
0063 allTxt = ''
0064
0065
0066
0067
0068
0069 else:
0070 print("WARNING: I can't match the regular espression for file: " + fileName)
0071 runNumber = int(line.split(' ')[1])
0072 allTxt += line
0073 file.close()
0074 if regExp:
0075 newFileName = regExp.group(1) + regExp.group(2) + "_" + str(runNumber) + "_" + regExp.group(3) + ".txt"
0076 with open(finalDir+newFileName,'a') as outFile:
0077 outFile.writelines(allTxt)
0078 outFile.close()
0079
0080
0081
0082
0083
0084 if __name__ == "__main__":
0085 main()