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.22 by ewv, Tue Aug 5 21:48:05 2008 UTC vs.
Revision 1.32 by slacapra, Tue Nov 3 17:53:04 2009 UTC

# Line 3 | Line 3
3   import os
4   import common
5   import imp
6 + import pickle
7  
8   from crab_util import *
9   from crab_exceptions import *
9 from crab_logger import Logger
10  
11   from ProdCommon.CMSConfigTools.ConfigAPI.CfgInterface import CfgInterface
12   from FWCore.ParameterSet.DictTypes import SortedKeysDict
13   from FWCore.ParameterSet.Modules   import Service
14   from FWCore.ParameterSet.Types     import *
15 + from FWCore.ParameterSet.Modules   import OutputModule
16  
17   import FWCore.ParameterSet.Types   as CfgTypes
18   import FWCore.ParameterSet.Modules as CfgModules
# Line 25 | Line 26 | class PsetManipulator:
26          self.pset = pset
27          #convert Pset
28          from FWCore.ParameterSet.Config import include
29 <        common.logger.debug(3,"PsetManipulator::__init__: PSet file = "+self.pset)
29 >        common.logger.debug("PsetManipulator::__init__: PSet file = "+self.pset)
30 >        # FUTURE: Can drop cfg mode for CMSSW < 2_1_x
31          if self.pset.endswith('py'):
32              handle = open(self.pset, 'r')
33              try:   # Nested form for Python < 2.5
# Line 55 | Line 57 | class PsetManipulator:
57          self.cfg.maxEvents.setMaxEventsInput(maxEv)
58          return
59  
60 <    def psetWriter(self, name):
60 >    def skipEvent(self, skipEv):
61          """
62 <        Write out modified CMSSW.cfg
62 >        Set max event in the standalone untracked module
63          """
64 <
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 <            outFile.write(self.cmsProcess.dumpPython())
68 <        else:
69 <            outFile.write(self.cfg.data.dumpConfig())
70 <        outFile.close()
71 <
64 >        self.cfg.inputSource.setSkipEvents(skipEv)
65          return
66  
67 <    def addCrabFJR(self,name):
67 >    def psetWriter(self, name):
68          """
69 <        _addCrabFJR_
77 <        add CRAB specific FrameworkJobReport (FJR)
78 <        if a FJR already exists in input CMSSW parameter-set, add a second one.
79 <        This code is not needed for CMSSW >= 1.5.x and is non-functional in CMSSW >= 1.7.x.
80 <        It should be removed at some point in the future.
69 >        Write out modified CMSSW.py
70          """
71  
72 <        # Check if MessageLogger service already exists in configuration. If not, add it
73 <        svcs = self.cfg.data.services
74 <        if not svcs.has_key('MessageLogger'):
75 <            self.cfg.data.add_(CfgModules.Service("MessageLogger"))
76 <
77 <        messageLogger = self.cfg.data.services['MessageLogger']
78 <
79 <        # Add fwkJobReports to Message logger if it doesn't exist
80 <        if "fwkJobReports" not in messageLogger.parameterNames_():
81 <            messageLogger.fwkJobReports = CfgTypes.untracked(CfgTypes.vstring())
82 <
83 <        # should figure out how to remove "name" if it is there.
84 <
85 <        if name not in messageLogger.fwkJobReports:
86 <            messageLogger.fwkJobReports.append(name)
72 >        pklFileName=common.work_space.jobDir()+name+".pkl"
73 >        pklFile = open(pklFileName,"w")
74 >        myPickle = pickle.Pickler(pklFile)
75 >        myPickle.dump(self.cmsProcess)
76 >        pklFile.close()
77 >        pklFile = open(pklFileName,"rb")
78 >        outFile = open(common.work_space.jobDir()+name,"w")
79 >        outFile.write("import FWCore.ParameterSet.Config as cms\n")
80 >        outFile.write("import pickle\n")
81 >        outFile.write("pickledCfg=\"\"\"")
82 >        outFile.write(pklFile.read())
83 >        outFile.write("\"\"\"\n")
84 >        outFile.write("process = pickle.loads(pickledCfg)\n")
85 >        pklFile.close()
86 >        outFile.close()
87  
88          return
89  
# Line 110 | Line 99 | class PsetManipulator:
99  
100      def getPoolOutputModule(self):
101          """ Get Output filename from PoolOutputModule and return it. If not existing, return None """
102 <        if not self.cfg.data.outputModules:
103 <            return None
104 <        poolOutputModule = self.cfg.data.outputModules
105 <        for out in poolOutputModule:
106 <            return poolOutputModule[out].fileName.value()
102 >        outputFinder = PoolOutputFinder()
103 >        for p  in self.cfg.data.endpaths.itervalues():
104 >            p.visit(outputFinder)
105 >        return outputFinder.getList()
106 >
107 >    def getBadFilesSetting(self):
108 >        setting = False
109 >        try:
110 >            if self.cfg.data.source.skipBadFiles.value():
111 >                setting = True
112 >        except AttributeError:
113 >            pass # Either no source or no setting of skipBadFiles
114 >        return setting
115 >
116 > class PoolOutputFinder(object):
117 >
118 >    def __init__(self):
119 >        self._poolList = []
120 >    def enter(self,visitee):
121 >        if isinstance(visitee,OutputModule) and visitee.type_() == "PoolOutputModule":
122 >            self._poolList.append(visitee.fileName.value())
123 >    def leave(self,visitee):
124 >        pass
125  
126 +    def getList(self):
127 +        return self._poolList

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines