4 |
|
Re-write config file and optionally convert to python |
5 |
|
""" |
6 |
|
|
7 |
< |
import sys, getopt |
7 |
> |
__revision__ = "$Id$" |
8 |
> |
__version__ = "$Revision$" |
9 |
> |
|
10 |
> |
import getopt |
11 |
|
import imp |
12 |
|
import os |
13 |
+ |
import pickle |
14 |
+ |
import sys |
15 |
+ |
import xml.dom.minidom |
16 |
+ |
|
17 |
|
from random import SystemRandom |
18 |
|
|
19 |
|
from ProdCommon.CMSConfigTools.ConfigAPI.CfgInterface import CfgInterface |
39 |
|
""" |
40 |
|
writeCfg |
41 |
|
|
42 |
< |
- Read in existing, user supplied cfg or pycfg file |
43 |
< |
- Modify job specific parameters based on environment variables |
44 |
< |
- Write out modified cfg or pycfg file |
42 |
> |
- Read in existing, user supplied cfg or pickled pycfg file |
43 |
> |
- Modify job specific parameters based on environment variables and arguments.xml |
44 |
> |
- Write out modified cfg or pickled pycfg file |
45 |
|
|
46 |
|
required parameters: none |
47 |
|
|
89 |
|
print main.__doc__ |
90 |
|
sys.exit() |
91 |
|
|
92 |
< |
# Optional Parameters |
92 |
> |
# Read in Environment, XML and get optional Parameters |
93 |
|
|
87 |
– |
maxEvents = int(os.environ.get('MaxEvents', '0')) |
88 |
– |
skipEvents = int(os.environ.get('SkipEvents','0')) |
89 |
– |
firstRun = int(os.environ.get('FirstRun', '0')) |
94 |
|
nJob = int(os.environ.get('NJob', '0')) |
91 |
– |
|
92 |
– |
inputFiles = os.environ.get('InputFiles','') |
93 |
– |
parentFiles = os.environ.get('ParentFiles','') |
95 |
|
preserveSeeds = os.environ.get('PreserveSeeds','') |
96 |
|
incrementSeeds = os.environ.get('IncrementSeeds','') |
97 |
|
|
98 |
+ |
# Defaults |
99 |
+ |
|
100 |
+ |
maxEvents = 0 |
101 |
+ |
skipEvents = 0 |
102 |
+ |
firstEvent = -1 |
103 |
+ |
compHEPFirstEvent = 0 |
104 |
+ |
firstRun = 0 |
105 |
+ |
|
106 |
+ |
dom = xml.dom.minidom.parse(os.environ['RUNTIME_AREA']+'/arguments.xml') |
107 |
+ |
|
108 |
+ |
for elem in dom.getElementsByTagName("Job"): |
109 |
+ |
if nJob == int(elem.getAttribute("JobID")): |
110 |
+ |
if elem.getAttribute("MaxEvents"): |
111 |
+ |
maxEvents = int(elem.getAttribute("MaxEvents")) |
112 |
+ |
if elem.getAttribute("SkipEvents"): |
113 |
+ |
skipEvents = int(elem.getAttribute("SkipEvents")) |
114 |
+ |
if elem.getAttribute("FirstEvent"): |
115 |
+ |
firstEvent = int(elem.getAttribute("FirstEvent")) |
116 |
+ |
if elem.getAttribute("FirstRun"): |
117 |
+ |
firstRun = int(elem.getAttribute("FirstRun")) |
118 |
+ |
|
119 |
+ |
generator = str(elem.getAttribute('Generator')) |
120 |
+ |
inputFiles = str(elem.getAttribute('InputFiles')) |
121 |
+ |
parentFiles = str(elem.getAttribute('ParentFiles')) |
122 |
+ |
lumis = str(elem.getAttribute('Lumis')) |
123 |
+ |
|
124 |
|
# Read Input cfg or python cfg file, FUTURE: Get rid cfg mode |
125 |
|
|
126 |
|
if fileName.endswith('py'): |
155 |
|
if skipEvents: |
156 |
|
inModule.setSkipEvents(skipEvents) |
157 |
|
|
158 |
+ |
# Set "skip events" for various generators |
159 |
+ |
if generator == 'comphep': |
160 |
+ |
cmsProcess.source.CompHEPFirstEvent = CfgTypes.int32(firstEvent) |
161 |
+ |
elif generator == 'lhe': |
162 |
+ |
cmsProcess.source.skipEvents = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) |
163 |
+ |
cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent+1)) |
164 |
+ |
elif firstEvent != -1: # (Old? Madgraph) |
165 |
+ |
cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) |
166 |
+ |
|
167 |
|
if inputFiles: |
132 |
– |
inputFiles = inputFiles.replace('\\','') |
133 |
– |
inputFiles = inputFiles.replace('"','') |
168 |
|
inputFileNames = inputFiles.split(',') |
169 |
|
inModule.setFileNames(*inputFileNames) |
170 |
|
|
171 |
|
# handle parent files if needed |
172 |
|
if parentFiles: |
139 |
– |
parentFiles = parentFiles.replace('\\','') |
140 |
– |
parentFiles = parentFiles.replace('"','') |
173 |
|
parentFileNames = parentFiles.split(',') |
174 |
|
inModule.setSecondaryFileNames(*parentFileNames) |
175 |
|
|
176 |
+ |
if lumis: |
177 |
+ |
lumiRanges = lumis.split(',') |
178 |
+ |
inModule.setLumisToProcess(*lumiRanges) |
179 |
+ |
|
180 |
|
# Pythia parameters |
181 |
|
if (firstRun): |
182 |
|
inModule.setFirstRun(firstRun) |
245 |
|
outFile = open(outFileName,"w") |
246 |
|
if outFileName.endswith('py'): |
247 |
|
outFile.write("import FWCore.ParameterSet.Config as cms\n") |
248 |
< |
outFile.write(cmsProcess.dumpPython()) |
248 |
> |
outFile.write("import pickle\n") |
249 |
> |
outFile.write("pickledCfg=\"\"\"%s\"\"\"\n" % pickle.dumps(cmsProcess)) |
250 |
> |
outFile.write("process = pickle.loads(pickledCfg)\n") |
251 |
|
if (debug): |
252 |
< |
print "writeCfg output:" |
252 |
> |
print "writeCfg output (May not be exact):" |
253 |
|
print "import FWCore.ParameterSet.Config as cms" |
254 |
|
print cmsProcess.dumpPython() |
255 |
|
else: |
256 |
< |
outFile.write(str(cfg)) |
256 |
> |
outFile.write(cfg.data.dumpConfig()) |
257 |
|
if (debug): |
258 |
|
print "writeCfg output:" |
259 |
< |
print str(cfg) |
259 |
> |
print str(cfg.data.dumpConfig()) |
260 |
|
outFile.close() |
261 |
|
|
262 |
|
|