3 |
|
import os |
4 |
|
import common |
5 |
|
import imp |
6 |
+ |
|
7 |
|
from crab_util import * |
8 |
|
from crab_exceptions import * |
9 |
|
from crab_logger import Logger |
26 |
|
#convert Pset |
27 |
|
from FWCore.ParameterSet.Config import include |
28 |
|
common.logger.debug(3,"PsetManipulator::__init__: PSet file = "+self.pset) |
29 |
< |
if (self.pset.endswith('py') or self.pset.endswith('pycfg') ): |
30 |
< |
handle = open(self.pset, 'r') |
31 |
< |
try: # Nested form for Python < 2.5 |
29 |
> |
if self.pset.endswith('py'): |
30 |
> |
handle = open(self.pset, 'r') |
31 |
> |
try: # Nested form for Python < 2.5 |
32 |
> |
try: |
33 |
> |
self.cfo = imp.load_source("pycfg", self.pset, handle) |
34 |
> |
self.cmsProcess = self.cfo.process |
35 |
> |
except Exception, ex: |
36 |
> |
msg = "Your config file is not valid python: %s" % str(ex) |
37 |
> |
raise CrabException(msg) |
38 |
> |
finally: |
39 |
> |
handle.close() |
40 |
> |
else: |
41 |
|
try: |
42 |
< |
self.cfo = imp.load_source("pycfg", self.pset, handle) |
42 |
> |
self.cfo = include(self.pset) |
43 |
> |
self.cmsProcess = self.cfo |
44 |
|
except Exception, ex: |
45 |
< |
msg = "Your pycfg file is not valid python: %s" % str(ex) |
46 |
< |
raise CrabException(msg) |
47 |
< |
finally: |
48 |
< |
handle.close() |
49 |
< |
self.cfg = CfgInterface(self.cfo.process) |
39 |
< |
else: |
40 |
< |
try: |
41 |
< |
self.cfo = include(self.pset) |
42 |
< |
self.cfg = CfgInterface(self.cfo) |
43 |
< |
except Exception, ex: |
44 |
< |
msg = "Your cfg file is not valid, %s\n" % str(ex) |
45 |
< |
msg += " https://twiki.cern.ch/twiki/bin/view/CMS/CrabFaq#Problem_with_ParameterSet_parsin\n" |
46 |
< |
msg += " may help you understand the problem." |
47 |
< |
raise CrabException(msg) |
48 |
< |
def inputModule(self, source): |
49 |
< |
""" |
50 |
< |
Set vString Filenames key |
51 |
< |
""" |
52 |
< |
# set input module |
53 |
< |
inModule = self.cfg.inputSource |
54 |
< |
inModule.setFileNames(source) |
55 |
< |
return |
56 |
< |
|
57 |
< |
def pythiaSeed(self,seed): |
58 |
< |
""" |
59 |
< |
Set pythia seed key |
60 |
< |
""" |
61 |
< |
ranGenerator = self.cfg.data.services['RandomNumberGeneratorService'] |
62 |
< |
ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(seed)) |
63 |
< |
return |
64 |
< |
|
65 |
< |
def vtxSeed(self,vtxSeed): |
66 |
< |
""" |
67 |
< |
Set vtx seed key |
68 |
< |
""" |
69 |
< |
ranGenerator = self.cfg.data.services['RandomNumberGeneratorService'] |
70 |
< |
ranModules = ranGenerator.moduleSeeds |
71 |
< |
# set seed |
72 |
< |
ranModules.VtxSmeared = CfgTypes.untracked(CfgTypes.uint32(vtxSeed)) |
73 |
< |
return |
74 |
< |
|
75 |
< |
def g4Seed(self,g4Seed): |
76 |
< |
""" |
77 |
< |
Set g4 seed key |
78 |
< |
""" |
79 |
< |
ranGenerator = self.cfg.data.services['RandomNumberGeneratorService'] |
80 |
< |
ranModules = ranGenerator.moduleSeeds |
81 |
< |
# set seed |
82 |
< |
ranModules.g4SimHits = CfgTypes.untracked(CfgTypes.uint32(g4Seed)) |
83 |
< |
return |
84 |
< |
|
85 |
< |
def mixSeed(self,mixSeed): |
86 |
< |
""" |
87 |
< |
Set mix seed key |
88 |
< |
""" |
89 |
< |
ranGenerator = self.cfg.data.services['RandomNumberGeneratorService'] |
90 |
< |
ranModules = ranGenerator.moduleSeeds |
91 |
< |
ranModules.mix = CfgTypes.untracked(CfgTypes.uint32(mixSeed)) |
92 |
< |
return |
93 |
< |
|
94 |
< |
def pythiaFirstRun(self, firstrun): |
95 |
< |
""" |
96 |
< |
Set firstRun |
97 |
< |
""" |
98 |
< |
inModule = self.cfg.inputSource |
99 |
< |
inModule.setFirstRun(firstrun) ## Add Daniele |
100 |
< |
return |
45 |
> |
msg = "Your cfg file is not valid, %s\n" % str(ex) |
46 |
> |
msg += " https://twiki.cern.ch/twiki/bin/view/CMS/CrabFaq#Problem_with_ParameterSet_parsin\n" |
47 |
> |
msg += " may help you understand the problem." |
48 |
> |
raise CrabException(msg) |
49 |
> |
self.cfg = CfgInterface(self.cmsProcess) |
50 |
|
|
51 |
|
def maxEvent(self, maxEv): |
52 |
|
""" |
55 |
|
self.cfg.maxEvents.setMaxEventsInput(maxEv) |
56 |
|
return |
57 |
|
|
109 |
– |
def skipEvent(self, skipEv): |
110 |
– |
""" |
111 |
– |
Set skipEvents |
112 |
– |
""" |
113 |
– |
inModule = self.cfg.inputSource |
114 |
– |
inModule.setSkipEvents(skipEv) ## Add Daniele |
115 |
– |
return |
116 |
– |
|
117 |
– |
def outputModule(self, output): |
118 |
– |
|
119 |
– |
#set output module |
120 |
– |
outModule = self.cfg.outputModules['out'] |
121 |
– |
outModule.setFileName('file:'+str(output)) |
122 |
– |
|
123 |
– |
return |
124 |
– |
|
58 |
|
def psetWriter(self, name): |
59 |
|
""" |
60 |
|
Write out modified CMSSW.cfg |
61 |
|
""" |
62 |
|
|
63 |
< |
file1 = open(common.work_space.jobDir()+name,"w") |
64 |
< |
file1.write(str(self.cfg)) |
65 |
< |
file1.close() |
63 |
> |
# FUTURE: Can drop cfg mode for CMSSW < 2_1_x |
64 |
> |
outFile = open(common.work_space.jobDir()+name,"w") |
65 |
> |
if name.endswith('py'): |
66 |
> |
outFile.write("import FWCore.ParameterSet.Config as cms\n") |
67 |
> |
outFile.write(self.cmsProcess.dumpPython()) |
68 |
> |
else: |
69 |
> |
outFile.write(str(self.cfg)) |
70 |
> |
outFile.close() |
71 |
|
|
72 |
|
return |
73 |
|
|
96 |
|
if name not in messageLogger.fwkJobReports: |
97 |
|
messageLogger.fwkJobReports.append(name) |
98 |
|
|
99 |
< |
return |
99 |
> |
return |
100 |
> |
|
101 |
> |
def getTFileService(self): |
102 |
> |
""" Get Output filename from TFileService and return it. If not existing, return None """ |
103 |
> |
if not self.cfg.data.services.has_key('TFileService'): |
104 |
> |
return None |
105 |
> |
tFileService = self.cfg.data.services['TFileService'] |
106 |
> |
if "fileName" in tFileService.parameterNames_(): |
107 |
> |
fileName = getattr(tFileService,'fileName',None).value() |
108 |
> |
return fileName |
109 |
> |
return None |
110 |
> |
|
111 |
> |
def getPoolOutputModule(self): |
112 |
> |
""" Get Output filename from PoolOutputModule and return it. If not existing, return None """ |
113 |
> |
if not self.cfg.data.outputModules: |
114 |
> |
return None |
115 |
> |
poolOutputModule = self.cfg.data.outputModules |
116 |
> |
for out in poolOutputModule: |
117 |
> |
return poolOutputModule[out].fileName.value() |
118 |
> |
|