39 |
|
""" |
40 |
|
writeCfg |
41 |
|
|
42 |
< |
- Read in existing, user supplied cfg or pickled pycfg file |
42 |
> |
- Read in existing, user supplied pycfg 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 |
44 |
> |
- Write out pickled pycfg file |
45 |
|
|
46 |
|
required parameters: none |
47 |
|
|
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 |
124 |
> |
# Read Input python config file |
125 |
|
|
126 |
< |
if fileName.endswith('py'): |
127 |
< |
handle = open(fileName, 'r') |
127 |
< |
try: # Nested form for Python < 2.5 |
128 |
< |
try: |
129 |
< |
print "Importing .py file" |
130 |
< |
cfo = imp.load_source("pycfg", fileName, handle) |
131 |
< |
cmsProcess = cfo.process |
132 |
< |
except Exception, ex: |
133 |
< |
msg = "Your pycfg file is not valid python: %s" % str(ex) |
134 |
< |
raise ConfigException(msg) |
135 |
< |
finally: |
136 |
< |
handle.close() |
137 |
< |
else: |
126 |
> |
handle = open(fileName, 'r') |
127 |
> |
try: # Nested form for Python < 2.5 |
128 |
|
try: |
129 |
< |
print "Importing .cfg file" |
130 |
< |
cfo = include(fileName) |
131 |
< |
cmsProcess = cfo |
129 |
> |
print "Importing .py file" |
130 |
> |
cfo = imp.load_source("pycfg", fileName, handle) |
131 |
> |
cmsProcess = cfo.process |
132 |
|
except Exception, ex: |
133 |
< |
msg = "The cfg file is not valid, %s\n" % str(ex) |
133 |
> |
msg = "Your pycfg file is not valid python: %s" % str(ex) |
134 |
|
raise ConfigException(msg) |
135 |
+ |
finally: |
136 |
+ |
handle.close() |
137 |
|
|
138 |
|
cfg = CfgInterface(cmsProcess) |
139 |
|
|
150 |
|
if generator == 'comphep': |
151 |
|
cmsProcess.source.CompHEPFirstEvent = CfgTypes.int32(firstEvent) |
152 |
|
elif generator == 'lhe': |
153 |
< |
cmsProcess.LHESource.skipEvents = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) |
153 |
> |
cmsProcess.source.skipEvents = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) |
154 |
> |
cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent+1)) |
155 |
|
elif firstEvent != -1: # (Old? Madgraph) |
156 |
|
cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) |
157 |
|
|
164 |
|
parentFileNames = parentFiles.split(',') |
165 |
|
inModule.setSecondaryFileNames(*parentFileNames) |
166 |
|
|
167 |
+ |
if lumis: |
168 |
+ |
if CMSSW_major < 3: # FUTURE: Can remove this check |
169 |
+ |
print "Cannot skip lumis for CMSSW 2_x" |
170 |
+ |
else: |
171 |
+ |
lumiRanges = lumis.split(',') |
172 |
+ |
inModule.setLumisToProcess(*lumiRanges) |
173 |
+ |
|
174 |
|
# Pythia parameters |
175 |
|
if (firstRun): |
176 |
|
inModule.setFirstRun(firstRun) |
177 |
|
|
178 |
< |
incrementSeedList = [] |
179 |
< |
preserveSeedList = [] |
180 |
< |
|
181 |
< |
if incrementSeeds: |
182 |
< |
incrementSeedList = incrementSeeds.split(',') |
183 |
< |
if preserveSeeds: |
184 |
< |
preserveSeedList = preserveSeeds.split(',') |
185 |
< |
|
186 |
< |
# FUTURE: This function tests the CMSSW version and presence of old-style seed specification. |
187 |
< |
# Reduce when we drop support for old versions |
188 |
< |
if cfg.data.services.has_key('RandomNumberGeneratorService'): # There are random #'s to deal with |
178 |
> |
# Check if there are random #'s to deal with |
179 |
> |
if cfg.data.services.has_key('RandomNumberGeneratorService'): |
180 |
|
print "RandomNumberGeneratorService found, will attempt to change seeds" |
181 |
+ |
from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper |
182 |
|
ranGenerator = cfg.data.services['RandomNumberGeneratorService'] |
183 |
< |
ranModules = getattr(ranGenerator, "moduleSeeds", None) |
192 |
< |
oldSource = getattr(ranGenerator, "sourceSeed", None) |
193 |
< |
if ranModules != None or oldSource != None: # Old format present, no matter the CMSSW version |
194 |
< |
print "Old-style random number seeds found, will be changed." |
195 |
< |
if oldSource != None: |
196 |
< |
sourceSeed = int(ranGenerator.sourceSeed.value()) |
197 |
< |
if ('sourceSeed' in preserveSeedList) or ('theSource' in preserveSeedList): |
198 |
< |
pass |
199 |
< |
elif ('sourceSeed' in incrementSeedList) or ('theSource' in incrementSeedList): |
200 |
< |
ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(sourceSeed+nJob)) |
201 |
< |
else: |
202 |
< |
ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(MyRandom.randint(1, _MAXINT))) |
203 |
< |
|
204 |
< |
for seed in incrementSeedList: |
205 |
< |
curSeed = getattr(ranGenerator.moduleSeeds, seed, None) |
206 |
< |
if curSeed: |
207 |
< |
curValue = int(curSeed.value()) |
208 |
< |
setattr(ranGenerator.moduleSeeds, seed, CfgTypes.untracked(CfgTypes.uint32(curValue+nJob))) |
209 |
< |
preserveSeedList.append(seed) |
210 |
< |
|
211 |
< |
if ranModules != None: |
212 |
< |
for seed in ranGenerator.moduleSeeds.parameterNames_(): |
213 |
< |
if seed not in preserveSeedList: |
214 |
< |
curSeed = getattr(ranGenerator.moduleSeeds, seed, None) |
215 |
< |
if curSeed: |
216 |
< |
curValue = int(curSeed.value()) |
217 |
< |
setattr(ranGenerator.moduleSeeds, seed, |
218 |
< |
CfgTypes.untracked(CfgTypes.uint32(MyRandom.randint(1,_MAXINT)))) |
219 |
< |
elif CMSSW_major > 2 or (CMSSW_major == 2 and CMSSW_minor >= 1): # Treatment for seeds, CMSSW 2_1_x and later |
220 |
< |
print "New-style random number seeds found, will be changed." |
221 |
< |
from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper |
222 |
< |
randSvc = RandomNumberServiceHelper(ranGenerator) |
223 |
< |
|
224 |
< |
# Increment requested seed sets |
225 |
< |
for seedName in incrementSeedList: |
226 |
< |
curSeeds = randSvc.getNamedSeed(seedName) |
227 |
< |
newSeeds = [x+nJob for x in curSeeds] |
228 |
< |
randSvc.setNamedSeed(seedName, *newSeeds) |
229 |
< |
preserveSeedList.append(seedName) |
183 |
> |
randSvc = RandomNumberServiceHelper(ranGenerator) |
184 |
|
|
185 |
< |
# Randomize remaining seeds |
186 |
< |
randSvc.populate(*preserveSeedList) |
187 |
< |
else: |
188 |
< |
print "Neither old nor new seed format found!" |
185 |
> |
incrementSeedList = [] |
186 |
> |
preserveSeedList = [] |
187 |
> |
|
188 |
> |
if incrementSeeds: |
189 |
> |
incrementSeedList = incrementSeeds.split(',') |
190 |
> |
if preserveSeeds: |
191 |
> |
preserveSeedList = preserveSeeds.split(',') |
192 |
> |
|
193 |
> |
# Increment requested seed sets |
194 |
> |
for seedName in incrementSeedList: |
195 |
> |
curSeeds = randSvc.getNamedSeed(seedName) |
196 |
> |
newSeeds = [x+nJob for x in curSeeds] |
197 |
> |
randSvc.setNamedSeed(seedName, *newSeeds) |
198 |
> |
preserveSeedList.append(seedName) |
199 |
|
|
200 |
< |
# End version specific code |
200 |
> |
# Randomize remaining seeds |
201 |
> |
randSvc.populate(*preserveSeedList) |
202 |
|
|
203 |
< |
# Write out new config file in one format or the other, FUTURE: Get rid of cfg mode |
203 |
> |
# Write out new config file |
204 |
|
outFile = open(outFileName,"w") |
205 |
< |
if outFileName.endswith('py'): |
206 |
< |
outFile.write("import FWCore.ParameterSet.Config as cms\n") |
207 |
< |
outFile.write("import pickle\n") |
208 |
< |
outFile.write("pickledCfg=\"\"\"%s\"\"\"\n" % pickle.dumps(cmsProcess)) |
244 |
< |
outFile.write("process = pickle.loads(pickledCfg)\n") |
245 |
< |
if (debug): |
246 |
< |
print "writeCfg output (May not be exact):" |
247 |
< |
print "import FWCore.ParameterSet.Config as cms" |
248 |
< |
print cmsProcess.dumpPython() |
249 |
< |
else: |
250 |
< |
outFile.write(cfg.data.dumpConfig()) |
251 |
< |
if (debug): |
252 |
< |
print "writeCfg output:" |
253 |
< |
print str(cfg.data.dumpConfig()) |
205 |
> |
outFile.write("import FWCore.ParameterSet.Config as cms\n") |
206 |
> |
outFile.write("import pickle\n") |
207 |
> |
outFile.write("pickledCfg=\"\"\"%s\"\"\"\n" % pickle.dumps(cmsProcess)) |
208 |
> |
outFile.write("process = pickle.loads(pickledCfg)\n") |
209 |
|
outFile.close() |
210 |
+ |
if (debug): |
211 |
+ |
print "writeCfg output (May not be exact):" |
212 |
+ |
print "import FWCore.ParameterSet.Config as cms" |
213 |
+ |
print cmsProcess.dumpPython() |
214 |
|
|
215 |
|
|
216 |
|
if __name__ == '__main__' : |