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.12 by ewv, Fri Oct 19 08:51:49 2007 UTC vs.
Revision 1.26 by ewv, Tue Feb 24 16:19:25 2009 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 <        self.cfo = include(self.pset)
30 <        self.cfg = CfgInterface(self.cfo)
31 <
32 <    def inputModule(self, source):
33 <        """
34 <        Set  vString Filenames key
35 <        """
36 <        # set input module
37 <        inModule = self.cfg.inputSource
38 <        inModule.setFileNames(source)
39 <        return
40 <
41 <    def pythiaSeed(self,seed):
42 <        """
43 <        Set pythia seed key
44 <        """
45 <        ranGenerator = self.cfg.data.services['RandomNumberGeneratorService']
46 <        ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(seed))
47 <        return
48 <
49 <    def vtxSeed(self,vtxSeed):
50 <        """
49 <        Set vtx seed key
50 <        """
51 <        ranGenerator = self.cfg.data.services['RandomNumberGeneratorService']
52 <        ranModules   = ranGenerator.moduleSeeds
53 <        # set seed
54 <        ranModules.VtxSmeared = CfgTypes.untracked(CfgTypes.uint32(vtxSeed))
55 <        return
56 <
57 <    def g4Seed(self,g4Seed):
58 <        """
59 <        Set g4 seed key
60 <        """
61 <        ranGenerator = self.cfg.data.services['RandomNumberGeneratorService']
62 <        ranModules   = ranGenerator.moduleSeeds
63 <        # set seed
64 <        ranModules.g4SimHits = CfgTypes.untracked(CfgTypes.uint32(g4Seed))
65 <        return
66 <
67 <    def mixSeed(self,mixSeed):
68 <        """
69 <        Set mix seed key
70 <        """
71 <        ranGenerator = self.cfg.data.services['RandomNumberGeneratorService']
72 <        ranModules   = ranGenerator.moduleSeeds
73 <        ranModules.mix = CfgTypes.untracked(CfgTypes.uint32(mixSeed))
74 <        return
75 <
76 <    def pythiaFirstRun(self, firstrun):
77 <        """
78 <        Set firstRun
79 <        """
80 <        inModule = self.cfg.inputSource
81 <        inModule.setFirstRun(firstrun)   ## Add Daniele
82 <        return
29 >        # FUTURE: Can drop cfg mode for CMSSW < 2_1_x
30 >        if self.pset.endswith('py'):
31 >            handle = open(self.pset, 'r')
32 >            try:   # Nested form for Python < 2.5
33 >                try:
34 >                    self.cfo = imp.load_source("pycfg", self.pset, handle)
35 >                    self.cmsProcess = self.cfo.process
36 >                except Exception, ex:
37 >                    msg = "Your config file is not valid python: %s" % str(ex)
38 >                    raise CrabException(msg)
39 >            finally:
40 >                handle.close()
41 >        else:
42 >            try:
43 >                self.cfo = include(self.pset)
44 >                self.cmsProcess = self.cfo
45 >            except Exception, ex:
46 >                msg =  "Your cfg file is not valid, %s\n" % str(ex)
47 >                msg += "  https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrabFaq#Problem_with_ParameterSet_parsin\n"
48 >                msg += "  may help you understand the problem."
49 >                raise CrabException(msg)
50 >        self.cfg = CfgInterface(self.cmsProcess)
51  
52      def maxEvent(self, maxEv):
53          """
# Line 90 | Line 58 | class PsetManipulator:
58  
59      def skipEvent(self, skipEv):
60          """
61 <        Set skipEvents
61 >        Set max event in the standalone untracked module
62          """
63 <        inModule = self.cfg.inputSource
96 <        inModule.setSkipEvents(skipEv)   ## Add Daniele
97 <        return
98 <
99 <    def outputModule(self, output):
100 <
101 <        #set output module
102 <        outModule = self.cfg.outputModules['out']
103 <        outModule.setFileName('file:'+str(output))
104 <
63 >        self.cfg.inputSource.setSkipEvents(skipEv)
64          return
65  
66      def psetWriter(self, name):
# Line 109 | Line 68 | class PsetManipulator:
68          Write out modified CMSSW.cfg
69          """
70  
71 <        file1 = open(common.work_space.jobDir()+name,"w")
72 <        file1.write(str(self.cfg))
73 <        file1.close()
71 >        # FUTURE: Can drop cfg mode for CMSSW < 2_1_x
72 >        outFile = open(common.work_space.jobDir()+name,"w")
73 >        if name.endswith('py'):
74 >            outFile.write("import FWCore.ParameterSet.Config as cms\n")
75 >            try:
76 >                outFile.write(self.cmsProcess.dumpPython())
77 >            except Exception, ex:
78 >                msg =  "Your cfg file is not valid, %s\n" % str(ex)
79 >                msg += "  https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrabFaq#Problem_with_ParameterSet_parsin\n"
80 >                msg += "  may help you understand the problem."
81 >                raise CrabException(msg)
82 >
83 >        else:
84 >            outFile.write(self.cfg.data.dumpConfig())
85 >        outFile.close()
86  
87          return
88  
89 <    def addCrabFJR(self,name):
90 <        """
91 <        _addCrabFJR_
92 <        add CRAB specific FrameworkJobReport (FJR)
93 <        if a FJR already exists in input CMSSW parameter-set, add a second one
94 <        """
95 <
96 <        # Check if MessageLogger service already exists in configuration. If not, add it
97 <        svcs = self.cfg.data.services
98 <        if not svcs.has_key('MessageLogger'):
99 <            self.cfg.data.add_(CfgModules.Service("MessageLogger"))
100 <
101 <        messageLogger = self.cfg.data.services['MessageLogger']
102 <
103 <        # Add fwkJobReports to Message logger if it doesn't exist
104 <        if "fwkJobReports" not in messageLogger.parameterNames_():
105 <            messageLogger.fwkJobReports = CfgTypes.untracked(CfgTypes.vstring())
135 <
136 <        # should figure out how to remove "name" if it is there.
137 <
138 <        if name not in messageLogger.fwkJobReports:
139 <            messageLogger.fwkJobReports.append(name)
89 >    def getTFileService(self):
90 >        """ Get Output filename from TFileService and return it. If not existing, return None """
91 >        if not self.cfg.data.services.has_key('TFileService'):
92 >            return None
93 >        tFileService = self.cfg.data.services['TFileService']
94 >        if "fileName" in tFileService.parameterNames_():
95 >            fileName = getattr(tFileService,'fileName',None).value()
96 >            return fileName
97 >        return None
98 >
99 >    def getPoolOutputModule(self):
100 >        """ Get Output filename from PoolOutputModule and return it. If not existing, return None """
101 >        if not self.cfg.data.outputModules:
102 >            return None
103 >        poolOutputModule = self.cfg.data.outputModules
104 >        for out in poolOutputModule:
105 >            return poolOutputModule[out].fileName.value()
106  
141        return

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines