1 |
ewv |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
|
3 |
|
|
import sys, getopt, string
|
4 |
|
|
import imp
|
5 |
|
|
import os
|
6 |
|
|
|
7 |
|
|
from ProdCommon.CMSConfigTools.ConfigAPI.CfgInterface import CfgInterface
|
8 |
|
|
from FWCore.ParameterSet.DictTypes import SortedKeysDict
|
9 |
|
|
from FWCore.ParameterSet.Modules import Service
|
10 |
|
|
from FWCore.ParameterSet.Types import *
|
11 |
|
|
from FWCore.ParameterSet.Config import include
|
12 |
|
|
|
13 |
|
|
import FWCore.ParameterSet.Types as CfgTypes
|
14 |
|
|
import FWCore.ParameterSet.Modules as CfgModules
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
def main(argv) :
|
18 |
|
|
"""
|
19 |
|
|
writeCfg
|
20 |
|
|
|
21 |
|
|
- Read in existing, user supplied cfg or pycfg file
|
22 |
|
|
- Modify job specific parameters based on environment variables
|
23 |
|
|
- Write out modified cfg or pycfg file
|
24 |
|
|
|
25 |
|
|
required parameters: none
|
26 |
|
|
|
27 |
|
|
optional parameters:
|
28 |
|
|
--help : help
|
29 |
|
|
--debug : debug statements
|
30 |
|
|
|
31 |
|
|
"""
|
32 |
|
|
|
33 |
|
|
# defaults
|
34 |
|
|
maxEvents = 0
|
35 |
|
|
skipEvents = 0
|
36 |
|
|
inputFileNames = None
|
37 |
|
|
debug = False
|
38 |
|
|
|
39 |
|
|
try:
|
40 |
|
|
opts, args = getopt.getopt(argv, "", ["debug", "help","inputFiles=","maxEvents=","skipEvents="])
|
41 |
|
|
except getopt.GetoptError:
|
42 |
|
|
print main.__doc__
|
43 |
|
|
sys.exit(2)
|
44 |
|
|
|
45 |
|
|
# Parse command line parameters
|
46 |
|
|
for opt, arg in opts :
|
47 |
|
|
if opt == "--help" :
|
48 |
|
|
print main.__doc__
|
49 |
|
|
sys.exit()
|
50 |
|
|
elif opt == "--debug" :
|
51 |
|
|
debug = True
|
52 |
|
|
elif opt == "--maxEvents":
|
53 |
|
|
maxEvents = int(arg)
|
54 |
|
|
elif opt == "--skipEvents":
|
55 |
|
|
skipEvents = int(arg)
|
56 |
|
|
elif opt == "--inputFiles":
|
57 |
|
|
inputFiles = arg
|
58 |
|
|
inputFiles = inputFiles.replace('\\','')
|
59 |
|
|
inputFiles = inputFiles.replace('"','')
|
60 |
|
|
inputFileNames = inputFiles.split(',')
|
61 |
|
|
|
62 |
|
|
# Parse remaining parameters
|
63 |
|
|
|
64 |
|
|
fileName = args[0];
|
65 |
|
|
outFileName = args[1];
|
66 |
|
|
|
67 |
|
|
# Input cfg or python cfg file
|
68 |
|
|
|
69 |
|
|
if (fileName.endswith('py') or fileName.endswith('pycfg') ):
|
70 |
|
|
handle = open(fileName, 'r')
|
71 |
|
|
try: # Nested form for Python < 2.5
|
72 |
|
|
try:
|
73 |
|
|
cfo = imp.load_source("pycfg", fileName, handle)
|
74 |
|
|
except Exception, ex:
|
75 |
|
|
msg = "Your pycfg file is not valid python: %s" % str(ex)
|
76 |
|
|
raise "Error: ",msg
|
77 |
|
|
finally:
|
78 |
|
|
handle.close()
|
79 |
|
|
cfg = CfgInterface(cfo.process)
|
80 |
|
|
else:
|
81 |
|
|
try:
|
82 |
|
|
cfo = include(fileName)
|
83 |
|
|
cfg = CfgInterface(cfo)
|
84 |
|
|
except Exception, ex:
|
85 |
|
|
msg = "The cfg file is not valid, %s\n" % str(ex)
|
86 |
|
|
raise "Error: ",msg
|
87 |
|
|
|
88 |
|
|
# Set parameters for job
|
89 |
|
|
|
90 |
|
|
inModule = cfg.inputSource
|
91 |
|
|
|
92 |
|
|
cfg.maxEvents.setMaxEventsInput(maxEvents)
|
93 |
|
|
|
94 |
|
|
inModule.setSkipEvents(skipEvents)
|
95 |
|
|
if (inputFileNames):
|
96 |
|
|
inModule.setFileNames(*inputFileNames)
|
97 |
|
|
|
98 |
|
|
# Write out new config file
|
99 |
|
|
|
100 |
|
|
outFile = open(outFileName,"w")
|
101 |
|
|
outFile.write("import FWCore.ParameterSet.Config as cms\n")
|
102 |
|
|
outFile.write(cfo.dumpPython())
|
103 |
|
|
outFile.close()
|
104 |
|
|
|
105 |
|
|
if (debug):
|
106 |
|
|
print "writeCfg output:"
|
107 |
|
|
print "import FWCore.ParameterSet.Config as cms"
|
108 |
|
|
print cfo.dumpPython()
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
if __name__ == '__main__' :
|
112 |
|
|
exit_status = main(sys.argv[1:])
|
113 |
|
|
sys.exit(exit_status)
|
114 |
|
|
|