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

Comparing COMP/CRAB/python/PsetManipulator.py (file contents):
Revision 1.15 by slacapra, Fri Jan 4 17:30:56 2008 UTC vs.
Revision 1.23 by slacapra, Thu Nov 6 17:51:43 2008 UTC

# Line 2 | Line 2
2  
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
# Line 24 | Line 26 | class PsetManipulator:
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') ):
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 pycfg file is not valid python: %s" % str(ex)
36 >                    msg = "Your config file is not valid python: %s" % str(ex)
37                      raise CrabException(msg)
38              finally:
39                  handle.close()
37            self.cfg = CfgInterface(self.cfo.process)
40          else:
41              try:
42                  self.cfo = include(self.pset)
43 <                self.cfg = CfgInterface(self.cfo)
43 >                self.cmsProcess = self.cfo
44              except Exception, ex:
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"
46 >                msg += "  https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrabFaq#Problem_with_ParameterSet_parsin\n"
47                  msg += "  may help you understand the problem."
48                  raise CrabException(msg)
49 <        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
49 >        self.cfg = CfgInterface(self.cmsProcess)
50  
51      def maxEvent(self, maxEv):
52          """
# Line 107 | Line 55 | class PsetManipulator:
55          self.cfg.maxEvents.setMaxEventsInput(maxEv)
56          return
57  
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
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 >            try:
68 >                outFile.write(self.cmsProcess.dumpPython())
69 >            except Exception, ex:
70 >                msg =  "Your cfg file is not valid, %s\n" % str(ex)
71 >                msg += "  https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrabFaq#Problem_with_ParameterSet_parsin\n"
72 >                msg += "  may help you understand the problem."
73 >                raise CrabException(msg)
74 >
75 >        else:
76 >            outFile.write(self.cfg.data.dumpConfig())
77 >        outFile.close()
78  
79          return
80  
# Line 160 | Line 104 | class PsetManipulator:
104              messageLogger.fwkJobReports.append(name)
105  
106          return
107 +
108 +    def getTFileService(self):
109 +        """ Get Output filename from TFileService and return it. If not existing, return None """
110 +        if not self.cfg.data.services.has_key('TFileService'):
111 +            return None
112 +        tFileService = self.cfg.data.services['TFileService']
113 +        if "fileName" in tFileService.parameterNames_():
114 +            fileName = getattr(tFileService,'fileName',None).value()
115 +            return fileName
116 +        return None
117 +
118 +    def getPoolOutputModule(self):
119 +        """ Get Output filename from PoolOutputModule and return it. If not existing, return None """
120 +        if not self.cfg.data.outputModules:
121 +            return None
122 +        poolOutputModule = self.cfg.data.outputModules
123 +        for out in poolOutputModule:
124 +            return poolOutputModule[out].fileName.value()
125 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines