ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/PsetManipulator.py
Revision: 1.25
Committed: Tue Feb 24 16:16:15 2009 UTC (16 years, 2 months ago) by ewv
Content type: text/x-python
Branch: MAIN
Changes since 1.24: +0 -27 lines
Log Message:
Remove support for CMSSW < 1.5, old method of adding FJR

File Contents

# Content
1 #!/usr/bin/env python
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
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
16 import FWCore.ParameterSet.Types as CfgTypes
17 import FWCore.ParameterSet.Modules as CfgModules
18
19 class PsetManipulator:
20 def __init__(self, pset):
21 """
22 Read in Pset object and initialize
23 """
24
25 self.pset = pset
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'):
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 config file is not valid python: %s" % str(ex)
37 raise CrabException(msg)
38 finally:
39 handle.close()
40 else:
41 try:
42 self.cfo = include(self.pset)
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/SWGuideCrabFaq#Problem_with_ParameterSet_parsin\n"
47 msg += " may help you understand the problem."
48 raise CrabException(msg)
49 self.cfg = CfgInterface(self.cmsProcess)
50
51 def maxEvent(self, maxEv):
52 """
53 Set max event in the standalone untracked module
54 """
55 self.cfg.maxEvents.setMaxEventsInput(maxEv)
56 return
57
58 def skipEvent(self, skipEv):
59 """
60 Set max event in the standalone untracked module
61 """
62 self.cfg.inputSource.setSkipEvents(skipEv)
63 return
64
65 def psetWriter(self, name):
66 """
67 Write out modified CMSSW.cfg
68 """
69
70 # FUTURE: Can drop cfg mode for CMSSW < 2_1_x
71 outFile = open(common.work_space.jobDir()+name,"w")
72 if name.endswith('py'):
73 outFile.write("import FWCore.ParameterSet.Config as cms\n")
74 try:
75 outFile.write(self.cmsProcess.dumpPython())
76 except Exception, ex:
77 msg = "Your cfg file is not valid, %s\n" % str(ex)
78 msg += " https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrabFaq#Problem_with_ParameterSet_parsin\n"
79 msg += " may help you understand the problem."
80 raise CrabException(msg)
81
82 else:
83 outFile.write(self.cfg.data.dumpConfig())
84 outFile.close()
85
86 return
87
88 def getTFileService(self):
89 """ Get Output filename from TFileService and return it. If not existing, return None """
90 if not self.cfg.data.services.has_key('TFileService'):
91 return None
92 tFileService = self.cfg.data.services['TFileService']
93 if "fileName" in tFileService.parameterNames_():
94 fileName = getattr(tFileService,'fileName',None).value()
95 return fileName
96 return None
97
98 def getPoolOutputModule(self):
99 """ Get Output filename from PoolOutputModule and return it. If not existing, return None """
100 if not self.cfg.data.outputModules:
101 return None
102 poolOutputModule = self.cfg.data.outputModules
103 for out in poolOutputModule:
104 return poolOutputModule[out].fileName.value()
105