ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/writeCfg.py
(Generate patch)

Comparing COMP/CRAB/python/writeCfg.py (file contents):
Revision 1.21 by ewv, Fri Jun 19 18:46:54 2009 UTC vs.
Revision 1.25 by ewv, Fri Aug 28 18:56:43 2009 UTC

# Line 39 | Line 39 | def main(argv) :
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  
# Line 119 | Line 119 | def main(argv) :
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  
# Line 172 | Line 164 | def main(argv) :
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  = []
181 <
182 <    if incrementSeeds:
183 <        incrementSeedList = incrementSeeds.split(',')
184 <    if preserveSeeds:
185 <        preserveSeedList  = preserveSeeds.split(',')
186 <
187 <    # FUTURE: This function tests the CMSSW version and presence of old-style seed specification.
188 <    # Reduce when we drop support for old versions
189 <    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)
193 <        oldSource    = getattr(ranGenerator, "sourceSeed",  None)
194 <        if ranModules != None or oldSource != None:     # Old format present, no matter the CMSSW version
195 <            print "Old-style random number seeds found, will be changed."
196 <            if oldSource != None:
197 <                sourceSeed = int(ranGenerator.sourceSeed.value())
198 <                if ('sourceSeed' in preserveSeedList) or ('theSource' in preserveSeedList):
199 <                    pass
200 <                elif ('sourceSeed' in incrementSeedList) or ('theSource' in incrementSeedList):
201 <                    ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(sourceSeed+nJob))
202 <                else:
203 <                    ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(MyRandom.randint(1, _MAXINT)))
204 <
205 <            for seed in incrementSeedList:
206 <                curSeed = getattr(ranGenerator.moduleSeeds, seed, None)
207 <                if curSeed:
208 <                    curValue = int(curSeed.value())
209 <                    setattr(ranGenerator.moduleSeeds, seed, CfgTypes.untracked(CfgTypes.uint32(curValue+nJob)))
210 <                    preserveSeedList.append(seed)
211 <
212 <            if ranModules != None:
213 <                for seed in ranGenerator.moduleSeeds.parameterNames_():
214 <                    if seed not in preserveSeedList:
215 <                        curSeed = getattr(ranGenerator.moduleSeeds, seed, None)
216 <                        if curSeed:
217 <                            curValue = int(curSeed.value())
218 <                            setattr(ranGenerator.moduleSeeds, seed,
219 <                                    CfgTypes.untracked(CfgTypes.uint32(MyRandom.randint(1,_MAXINT))))
220 <        elif CMSSW_major > 2 or (CMSSW_major == 2 and CMSSW_minor >= 1): # Treatment for  seeds, CMSSW 2_1_x and later
221 <            print "New-style random number seeds found, will be changed."
222 <            from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper
223 <            randSvc = RandomNumberServiceHelper(ranGenerator)
224 <
225 <            # Increment requested seed sets
226 <            for seedName in incrementSeedList:
227 <                curSeeds = randSvc.getNamedSeed(seedName)
228 <                newSeeds = [x+nJob for x in curSeeds]
229 <                randSvc.setNamedSeed(seedName, *newSeeds)
230 <                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))
245 <        outFile.write("process = pickle.loads(pickledCfg)\n")
246 <        if (debug):
247 <            print "writeCfg output (May not be exact):"
248 <            print "import FWCore.ParameterSet.Config as cms"
249 <            print cmsProcess.dumpPython()
250 <    else:
251 <        outFile.write(cfg.data.dumpConfig())
252 <        if (debug):
253 <            print "writeCfg output:"
254 <            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__' :

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines