ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/PsetManipulator.py
Revision: 1.22
Committed: Tue Aug 5 21:48:05 2008 UTC (16 years, 8 months ago) by ewv
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_4_2_pre2, CRAB_2_4_2_pre1, CRAB_2_4_1, CRAB_2_4_1_pre4, CRAB_2_4_1_pre3, CRAB_2_4_1_pre2, CRAB_2_4_1_pre1, CRAB_2_4_0_Tutorial, CRAB_2_4_0_Tutorial_pre1, CRAB_2_4_0, CRAB_2_4_0_pre9, CRAB_2_4_0_pre8, CRAB_2_4_0_pre7, CRAB_2_4_0_pre6, CRAB_2_4_0_pre5, CRAB_2_4_0_pre4, CRAB_2_4_0_pre3, CRAB_2_4_0_pre2, CRAB_2_4_0_pre1, CRAB_DLS_PHED1, CRAB_DLS_PHED, CRAB_2_3_2_Fnal, CRAB_2_3_2, CRAB_2_3_2_pre7, CRAB_2_3_2_pre5, CRAB_2_3_2_pre4, CRAB_2_3_2_pre3, CRAB_2_3_2_pre2
Changes since 1.21: +2 -2 lines
Log Message:
Deal with change in ProdCommon, clean-up SchedulerCondor_g.py

File Contents

# User Rev Content
1 gutsche 1.1 #!/usr/bin/env python
2 ewv 1.12
3 slacapra 1.8 import os
4 gutsche 1.1 import common
5 ewv 1.16 import imp
6    
7 gutsche 1.1 from crab_util import *
8     from crab_exceptions import *
9 ewv 1.12 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 gutsche 1.1
16 ewv 1.12 import FWCore.ParameterSet.Types as CfgTypes
17     import FWCore.ParameterSet.Modules as CfgModules
18 gutsche 1.1
19     class PsetManipulator:
20     def __init__(self, pset):
21 ewv 1.12 """
22     Read in Pset object and initialize
23 gutsche 1.1 """
24    
25     self.pset = pset
26     #convert Pset
27 ewv 1.12 from FWCore.ParameterSet.Config import include
28     common.logger.debug(3,"PsetManipulator::__init__: PSet file = "+self.pset)
29 ewv 1.16 if self.pset.endswith('py'):
30 slacapra 1.15 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 ewv 1.17 self.cmsProcess = self.cfo.process
35 slacapra 1.15 except Exception, ex:
36 ewv 1.16 msg = "Your config file is not valid python: %s" % str(ex)
37 slacapra 1.15 raise CrabException(msg)
38     finally:
39     handle.close()
40     else:
41 ewv 1.14 try:
42 slacapra 1.15 self.cfo = include(self.pset)
43 ewv 1.17 self.cmsProcess = self.cfo
44 ewv 1.14 except Exception, ex:
45 slacapra 1.15 msg = "Your cfg file is not valid, %s\n" % str(ex)
46 slacapra 1.21 msg += " https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrabFaq#Problem_with_ParameterSet_parsin\n"
47 slacapra 1.15 msg += " may help you understand the problem."
48     raise CrabException(msg)
49 ewv 1.17 self.cfg = CfgInterface(self.cmsProcess)
50 spiga 1.7
51 gutsche 1.1 def maxEvent(self, maxEv):
52 ewv 1.12 """
53     Set max event in the standalone untracked module
54     """
55     self.cfg.maxEvents.setMaxEventsInput(maxEv)
56 gutsche 1.1 return
57    
58     def psetWriter(self, name):
59 ewv 1.12 """
60     Write out modified CMSSW.cfg
61     """
62 gutsche 1.1
63 ewv 1.16 # 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 slacapra 1.18 outFile.write("import FWCore.ParameterSet.Config as cms\n")
67     outFile.write(self.cmsProcess.dumpPython())
68 ewv 1.16 else:
69 ewv 1.22 outFile.write(self.cfg.data.dumpConfig())
70 ewv 1.16 outFile.close()
71 gutsche 1.1
72     return
73 gutsche 1.6
74     def addCrabFJR(self,name):
75     """
76 ewv 1.12 _addCrabFJR_
77     add CRAB specific FrameworkJobReport (FJR)
78 ewv 1.13 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.
81 ewv 1.12 """
82    
83     # Check if MessageLogger service already exists in configuration. If not, add it
84     svcs = self.cfg.data.services
85     if not svcs.has_key('MessageLogger'):
86     self.cfg.data.add_(CfgModules.Service("MessageLogger"))
87 gutsche 1.6
88 ewv 1.12 messageLogger = self.cfg.data.services['MessageLogger']
89 gutsche 1.6
90 ewv 1.12 # Add fwkJobReports to Message logger if it doesn't exist
91     if "fwkJobReports" not in messageLogger.parameterNames_():
92     messageLogger.fwkJobReports = CfgTypes.untracked(CfgTypes.vstring())
93 gutsche 1.6
94 ewv 1.12 # should figure out how to remove "name" if it is there.
95 gutsche 1.6
96 ewv 1.12 if name not in messageLogger.fwkJobReports:
97     messageLogger.fwkJobReports.append(name)
98 gutsche 1.6
99 slacapra 1.15 return
100 slacapra 1.18
101     def getTFileService(self):
102     """ Get Output filename from TFileService and return it. If not existing, return None """
103     if not self.cfg.data.services.has_key('TFileService'):
104     return None
105     tFileService = self.cfg.data.services['TFileService']
106     if "fileName" in tFileService.parameterNames_():
107     fileName = getattr(tFileService,'fileName',None).value()
108     return fileName
109     return None
110 ewv 1.22
111 slacapra 1.19 def getPoolOutputModule(self):
112     """ Get Output filename from PoolOutputModule and return it. If not existing, return None """
113 slacapra 1.20 if not self.cfg.data.outputModules:
114     return None
115     poolOutputModule = self.cfg.data.outputModules
116     for out in poolOutputModule:
117     return poolOutputModule[out].fileName.value()
118 slacapra 1.18