ATLAS Offline Software
Loading...
Searching...
No Matches
CreateTrfArgs.py
Go to the documentation of this file.
1# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2
3import pickle, os.path, sys, os
4def fileExists(fp):
5 #caveats : http://stackoverflow.com/questions/82831/how-do-i-check-if-a-file-exists-using-python
6 return os.path.isfile(fp)
7
8def getPickle(fp):
9 f=open(fp,'r')
10 d=pickle.load(f)
11 return d
12
13def correctPath(myPickle):
14 thisPath=os.getcwd()
15 #find the variable which gives the SCTCalibConfig path
16 SCTCalibConfigFile=myPickle['SCTCalibConfig']
17 fileName='SCTCalibConfig.py'
18 dissectedPath=thisPath.split('/')
19 dissectedPath[-1]='share'
20 sharePath='/'.join(dissectedPath)
21 newFileName=sharePath+'/'+fileName
22 myPickle['SCTcalibConfig']=newFileName
23
24def writeNewPickle(newPickleName, data):
25 pickleFile=open(newPickleName,'w')
26 pickle.dump(data, pickleFile)
27
28def swapFiles(originalFile,newFile):
29 os.remove(originalFile)
30 os.rename(newFile,originalFile)
31
32
33
34def main():
35 existingPickleFilename='./newargdict.gpickle'
36 newPickleFileName='mynewpickle.gpickle'
37 data=getPickle(existingPickleFilename)
38 correctPath(data)
39 writeNewPickle(newPickleFileName,data)
40 swapFiles(existingPickleFilename,newPickleFileName)
41
42
43if __name__=="__main__":
44 sys.exit(main())
writeNewPickle(newPickleName, data)
correctPath(myPickle)
swapFiles(originalFile, newFile)