-
Notifications
You must be signed in to change notification settings - Fork 10
/
process_pickler.py
54 lines (44 loc) · 1.77 KB
/
process_pickler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pickle
import optparse
import imp
import traceback
def pickler(input_file, output_file):
print('input {}'.format(input_file))
print('output {}'.format(output_file))
handle = open(input_file, 'r')
cfo = imp.load_source("pycfg", input_file, handle)
cmsProcess = cfo.process
handle.close()
pklFile_name = '{}.pkl'.format(output_file.split('.')[0])
pklFile = open(pklFile_name, "wb")
psetFile = open(output_file, "w")
try:
pickle.dump(cmsProcess, pklFile)
psetFile.write("import FWCore.ParameterSet.Config as cms\n")
psetFile.write("import pickle\n")
psetFile.write("handle = open('{}', 'rb')\n".format(pklFile_name))
psetFile.write("process = pickle.load(handle)\n")
psetFile.write("handle.close()\n")
psetFile.close()
except Exception as ex:
print("Error writing out PSet:")
print(traceback.format_exc())
raise ex
finally:
psetFile.close()
pklFile.close()
def main():
usage = ('usage: %prog [options]\n'
+ '%prog -h for help')
parser = optparse.OptionParser(usage)
# parser.add_option('-f', '--file', dest='CONFIGFILE', help='specify the ini configuration file')
# parser.add_option("--create", action="store_true", dest="CREATE", default=False, help="create the job configuration")
# parser.add_option("--submit", action="store_true", dest="SUBMIT", default=False, help="submit the jobs to condor")
# parser.add_option("--status", action="store_true", dest="STATUS", default=False, help="check the status of the condor tasks")
global opt, args
(opt, args) = parser.parse_args()
input_file = args[0]
output_file = args[1]
pickler(input_file, output_file)
if __name__ == "__main__":
main()