Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:04

0001 #!/usr/bin/env python3
0002 from __future__ import print_function
0003 from builtins import range
0004 import sys,os,re
0005 from CommonMethods import *
0006 def main():
0007 #    sourcePath = "/castor/cern.ch/cms/store/caf/user/uplegger/Workflows/Repro_2011Feb24/"
0008     sourcePath = "LatestRuns/"
0009 #    sourcePath = "Files/"
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     #for n in range(0,3):
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         #if len(copiedFiles) != len(fileList):
0040         #    error = "ERROR: I couldn't copy all files"
0041         #    exit(error)
0042 #        exit("ok")
0043         for fileName in copiedFiles:
0044             #regExp = re.search('(\D+)(\d+)_(\d+)_.txt',fileName)
0045             regExp = re.search('(\D+)(\d+)_(\d+)_[a-zA-Z0-9]+.txt',fileName)
0046             #if regExp:
0047                 #print regExp.group(1) + regExp.group(2) + "_" + str(1) + "_" + regExp.group(3) + ".txt" 
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                                 #aCmd = "cp " + destDir + fileName + " " + finalDir + newFileName
0066                                 #print aCmd
0067                                 #output =  subprocess.getstatusoutput(aCmd)
0068                                 #if output[0] != 0:
0069                                     #print output[1]
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()