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