ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/PsetManipulator.py
Revision: 1.15
Committed: Fri Jan 4 17:30:56 2008 UTC (17 years, 3 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_2_0_pre13, CRAB_2_2_0_pre12, CRAB_2_2_0_pre11, CRAB_2_2_0_pre10, bp_osg_bdii, CRAB_2_2_0_pre9, CRAB_2_2_0_pre8, CRAB_2_2_0_pre7, CRAB_2_1_2, CRAB_2_2_0_pre5, CRAB_2_1_2_pre2, CRAB_2_1_2_pre1, CRAB_2_2_0_pre4, CRAB_2_2_0_pre2, CRAB_2_1_1, CRAB_2_1_1_pre3, CRAB_2_2_0_pre1, CRAB_2_1_1_pre1, CRAB_2_1_0, CRAB_2_1_0_pre6, CRAB_2_1_0_pre5, CRAB_2_1_0_pre4, CRAB_2_1_0_pre3, CRAB_2_1_0_pre2, CRAB_2_1_0_pre1
Branch point for: osg_bdii, CRAB_2_1_2_br, CRAB_2_1_1_pre2
Changes since 1.14: +20 -19 lines
Log Message:
Add support for LSF/CAF direct submission
Re-establish a correct inheritance pattern for Scheruled* classes
Start to remove some unneeded try: catch: statement and replace them with appropriate if:then:
Erase any use of cfg_param as a common block (expecially in conjuction with apmon) and replace it with the user of task DB
Several minor cleanup

File Contents

# Content
1 #!/usr/bin/env python
2
3 import os
4 import common
5 from crab_util import *
6 from crab_exceptions import *
7 from crab_logger import Logger
8
9 from ProdCommon.CMSConfigTools.ConfigAPI.CfgInterface import CfgInterface
10 from FWCore.ParameterSet.DictTypes import SortedKeysDict
11 from FWCore.ParameterSet.Modules import Service
12 from FWCore.ParameterSet.Types import *
13
14 import FWCore.ParameterSet.Types as CfgTypes
15 import FWCore.ParameterSet.Modules as CfgModules
16
17 class PsetManipulator:
18 def __init__(self, pset):
19 """
20 Read in Pset object and initialize
21 """
22
23 self.pset = pset
24 #convert Pset
25 from FWCore.ParameterSet.Config import include
26 common.logger.debug(3,"PsetManipulator::__init__: PSet file = "+self.pset)
27 if (self.pset.endswith('py') or self.pset.endswith('pycfg') ):
28 handle = open(self.pset, 'r')
29 try: # Nested form for Python < 2.5
30 try:
31 self.cfo = imp.load_source("pycfg", self.pset, handle)
32 except Exception, ex:
33 msg = "Your pycfg file is not valid python: %s" % str(ex)
34 raise CrabException(msg)
35 finally:
36 handle.close()
37 self.cfg = CfgInterface(self.cfo.process)
38 else:
39 try:
40 self.cfo = include(self.pset)
41 self.cfg = CfgInterface(self.cfo)
42 except Exception, ex:
43 msg = "Your cfg file is not valid, %s\n" % str(ex)
44 msg += " https://twiki.cern.ch/twiki/bin/view/CMS/CrabFaq#Problem_with_ParameterSet_parsin\n"
45 msg += " may help you understand the problem."
46 raise CrabException(msg)
47 pass
48
49 def inputModule(self, source):
50 """
51 Set vString Filenames key
52 """
53 # set input module
54 inModule = self.cfg.inputSource
55 inModule.setFileNames(source)
56 return
57
58 def pythiaSeed(self,seed):
59 """
60 Set pythia seed key
61 """
62 ranGenerator = self.cfg.data.services['RandomNumberGeneratorService']
63 ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(seed))
64 return
65
66 def vtxSeed(self,vtxSeed):
67 """
68 Set vtx seed key
69 """
70 ranGenerator = self.cfg.data.services['RandomNumberGeneratorService']
71 ranModules = ranGenerator.moduleSeeds
72 # set seed
73 ranModules.VtxSmeared = CfgTypes.untracked(CfgTypes.uint32(vtxSeed))
74 return
75
76 def g4Seed(self,g4Seed):
77 """
78 Set g4 seed key
79 """
80 ranGenerator = self.cfg.data.services['RandomNumberGeneratorService']
81 ranModules = ranGenerator.moduleSeeds
82 # set seed
83 ranModules.g4SimHits = CfgTypes.untracked(CfgTypes.uint32(g4Seed))
84 return
85
86 def mixSeed(self,mixSeed):
87 """
88 Set mix seed key
89 """
90 ranGenerator = self.cfg.data.services['RandomNumberGeneratorService']
91 ranModules = ranGenerator.moduleSeeds
92 ranModules.mix = CfgTypes.untracked(CfgTypes.uint32(mixSeed))
93 return
94
95 def pythiaFirstRun(self, firstrun):
96 """
97 Set firstRun
98 """
99 inModule = self.cfg.inputSource
100 inModule.setFirstRun(firstrun) ## Add Daniele
101 return
102
103 def maxEvent(self, maxEv):
104 """
105 Set max event in the standalone untracked module
106 """
107 self.cfg.maxEvents.setMaxEventsInput(maxEv)
108 return
109
110 def skipEvent(self, skipEv):
111 """
112 Set skipEvents
113 """
114 inModule = self.cfg.inputSource
115 inModule.setSkipEvents(skipEv) ## Add Daniele
116 return
117
118 def outputModule(self, output):
119
120 #set output module
121 outModule = self.cfg.outputModules['out']
122 outModule.setFileName('file:'+str(output))
123
124 return
125
126 def psetWriter(self, name):
127 """
128 Write out modified CMSSW.cfg
129 """
130
131 file1 = open(common.work_space.jobDir()+name,"w")
132 file1.write(str(self.cfg))
133 file1.close()
134
135 return
136
137 def addCrabFJR(self,name):
138 """
139 _addCrabFJR_
140 add CRAB specific FrameworkJobReport (FJR)
141 if a FJR already exists in input CMSSW parameter-set, add a second one.
142 This code is not needed for CMSSW >= 1.5.x and is non-functional in CMSSW >= 1.7.x.
143 It should be removed at some point in the future.
144 """
145
146 # Check if MessageLogger service already exists in configuration. If not, add it
147 svcs = self.cfg.data.services
148 if not svcs.has_key('MessageLogger'):
149 self.cfg.data.add_(CfgModules.Service("MessageLogger"))
150
151 messageLogger = self.cfg.data.services['MessageLogger']
152
153 # Add fwkJobReports to Message logger if it doesn't exist
154 if "fwkJobReports" not in messageLogger.parameterNames_():
155 messageLogger.fwkJobReports = CfgTypes.untracked(CfgTypes.vstring())
156
157 # should figure out how to remove "name" if it is there.
158
159 if name not in messageLogger.fwkJobReports:
160 messageLogger.fwkJobReports.append(name)
161
162 return