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.13 by ewv, Mon Aug 18 15:30:43 2008 UTC vs.
Revision 1.20 by ewv, Wed Jun 17 20:58:08 2009 UTC

# Line 7 | Line 7 | Re-write config file and optionally conv
7   __revision__ = "$Id$"
8   __version__ = "$Revision$"
9  
10 < import sys, getopt
10 > import getopt
11   import imp
12   import os
13 + import pickle
14 + import sys
15 + import xml.dom.minidom
16 +
17   from random import SystemRandom
18  
19   from ProdCommon.CMSConfigTools.ConfigAPI.CfgInterface import CfgInterface
# Line 35 | Line 39 | def main(argv) :
39      """
40      writeCfg
41  
42 <    - Read in existing, user supplied cfg or pycfg file
43 <    - Modify job specific parameters based on environment variables
44 <    - Write out modified cfg or pycfg file
42 >    - Read in existing, user supplied cfg 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
45  
46      required parameters: none
47  
# Line 85 | Line 89 | def main(argv) :
89          print main.__doc__
90          sys.exit()
91  
92 <  # Optional Parameters
92 >  # Read in Environment, XML and get optional Parameters
93  
90    maxEvents  = int(os.environ.get('MaxEvents', '0'))
91    skipEvents = int(os.environ.get('SkipEvents','0'))
92    firstRun   = int(os.environ.get('FirstRun',  '0'))
94      nJob       = int(os.environ.get('NJob',      '0'))
94
95    inputFiles     = os.environ.get('InputFiles','')
96    parentFiles    = os.environ.get('ParentFiles','')
95      preserveSeeds  = os.environ.get('PreserveSeeds','')
96      incrementSeeds = os.environ.get('IncrementSeeds','')
97  
98 +  # Defaults
99 +
100 +    maxEvents  = 0
101 +    skipEvents = 0
102 +    firstEvent = -1
103 +    compHEPFirstEvent = 0
104 +    firstRun   = 0
105 +
106 +    dom = xml.dom.minidom.parse(os.environ['RUNTIME_AREA']+'/arguments.xml')
107 +
108 +    for elem in dom.getElementsByTagName("Job"):
109 +        if nJob == int(elem.getAttribute("JobID")):
110 +            if elem.getAttribute("MaxEvents"):
111 +                maxEvents = int(elem.getAttribute("MaxEvents"))
112 +            if elem.getAttribute("SkipEvents"):
113 +                skipEvents = int(elem.getAttribute("SkipEvents"))
114 +            if elem.getAttribute("FirstEvent"):
115 +                firstEvent = int(elem.getAttribute("FirstEvent"))
116 +            if elem.getAttribute("FirstRun"):
117 +                firstRun = int(elem.getAttribute("FirstRun"))
118 +
119 +            generator      = str(elem.getAttribute('Generator'))
120 +            inputFiles     = str(elem.getAttribute('InputFiles'))
121 +            parentFiles    = str(elem.getAttribute('ParentFiles'))
122 +
123    # Read Input cfg or python cfg file, FUTURE: Get rid cfg mode
124  
125      if fileName.endswith('py'):
# Line 131 | Line 154 | def main(argv) :
154      if skipEvents:
155          inModule.setSkipEvents(skipEvents)
156  
157 +    # Set "skip events" for various generators
158 +    if generator == 'comphep':
159 +        cmsProcess.source.CompHEPFirstEvent = CfgTypes.int32(firstEvent)
160 +    elif generator == 'lhe':
161 +        cmsProcess.LHESource.skipEvents = CfgTypes.untracked(CfgTypes.uint32(firstEvent))
162 +    elif firstEvent != -1: # (Old? Madgraph)
163 +        cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent))
164 +
165      if inputFiles:
135        inputFiles = inputFiles.replace('\\','')
136        inputFiles = inputFiles.replace('"','')
166          inputFileNames = inputFiles.split(',')
167          inModule.setFileNames(*inputFileNames)
168  
169      # handle parent files if needed
170      if parentFiles:
142        parentFiles = parentFiles.replace('\\','')
143        parentFiles = parentFiles.replace('"','')
171          parentFileNames = parentFiles.split(',')
172          inModule.setSecondaryFileNames(*parentFileNames)
173  
# Line 212 | Line 239 | def main(argv) :
239      outFile = open(outFileName,"w")
240      if outFileName.endswith('py'):
241          outFile.write("import FWCore.ParameterSet.Config as cms\n")
242 <        outFile.write(cmsProcess.dumpPython())
242 >        outFile.write("import pickle\n")
243 >        outFile.write("pickledCfg=\"\"\"%s\"\"\"\n" % pickle.dumps(cmsProcess))
244 >        outFile.write("process = pickle.loads(pickledCfg)\n")
245          if (debug):
246 <            print "writeCfg output:"
246 >            print "writeCfg output (May not be exact):"
247              print "import FWCore.ParameterSet.Config as cms"
248              print cmsProcess.dumpPython()
249      else:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines