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.23 by ewv, Thu Jul 30 18:45:44 2009 UTC vs.
Revision 1.24 by ewv, Thu Aug 27 12:42:23 2009 UTC

# Line 121 | Line 121 | def main(argv) :
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')
128 <        try:   # Nested form for Python < 2.5
129 <            try:
130 <                print "Importing .py file"
131 <                cfo = imp.load_source("pycfg", fileName, handle)
132 <                cmsProcess = cfo.process
133 <            except Exception, ex:
134 <                msg = "Your pycfg file is not valid python: %s" % str(ex)
135 <                raise ConfigException(msg)
136 <        finally:
137 <            handle.close()
138 <    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 184 | Line 175 | def main(argv) :
175      if (firstRun):
176          inModule.setFirstRun(firstRun)
177  
178 <    incrementSeedList = []
179 <    preserveSeedList  = []
189 <
190 <    if incrementSeeds:
191 <        incrementSeedList = incrementSeeds.split(',')
192 <    if preserveSeeds:
193 <        preserveSeedList  = preserveSeeds.split(',')
194 <
195 <    # FUTURE: This function tests the CMSSW version and presence of old-style seed specification.
196 <    # Reduce when we drop support for old versions
197 <    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)
201 <        oldSource    = getattr(ranGenerator, "sourceSeed",  None)
202 <        if ranModules != None or oldSource != None:     # Old format present, no matter the CMSSW version
203 <            print "Old-style random number seeds found, will be changed."
204 <            if oldSource != None:
205 <                sourceSeed = int(ranGenerator.sourceSeed.value())
206 <                if ('sourceSeed' in preserveSeedList) or ('theSource' in preserveSeedList):
207 <                    pass
208 <                elif ('sourceSeed' in incrementSeedList) or ('theSource' in incrementSeedList):
209 <                    ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(sourceSeed+nJob))
210 <                else:
211 <                    ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(MyRandom.randint(1, _MAXINT)))
212 <
213 <            for seed in incrementSeedList:
214 <                curSeed = getattr(ranGenerator.moduleSeeds, seed, None)
215 <                if curSeed:
216 <                    curValue = int(curSeed.value())
217 <                    setattr(ranGenerator.moduleSeeds, seed, CfgTypes.untracked(CfgTypes.uint32(curValue+nJob)))
218 <                    preserveSeedList.append(seed)
219 <
220 <            if ranModules != None:
221 <                for seed in ranGenerator.moduleSeeds.parameterNames_():
222 <                    if seed not in preserveSeedList:
223 <                        curSeed = getattr(ranGenerator.moduleSeeds, seed, None)
224 <                        if curSeed:
225 <                            curValue = int(curSeed.value())
226 <                            setattr(ranGenerator.moduleSeeds, seed,
227 <                                    CfgTypes.untracked(CfgTypes.uint32(MyRandom.randint(1,_MAXINT))))
228 <        elif CMSSW_major > 2 or (CMSSW_major == 2 and CMSSW_minor >= 1): # Treatment for  seeds, CMSSW 2_1_x and later
229 <            print "New-style random number seeds found, will be changed."
230 <            from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper
231 <            randSvc = RandomNumberServiceHelper(ranGenerator)
232 <
233 <            # Increment requested seed sets
234 <            for seedName in incrementSeedList:
235 <                curSeeds = randSvc.getNamedSeed(seedName)
236 <                newSeeds = [x+nJob for x in curSeeds]
237 <                randSvc.setNamedSeed(seedName, *newSeeds)
238 <                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))
253 <        outFile.write("process = pickle.loads(pickledCfg)\n")
254 <        if (debug):
255 <            print "writeCfg output (May not be exact):"
256 <            print "import FWCore.ParameterSet.Config as cms"
257 <            print cmsProcess.dumpPython()
258 <    else:
259 <        outFile.write(cfg.data.dumpConfig())
260 <        if (debug):
261 <            print "writeCfg output:"
262 <            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