ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/PsetManipulator.py
Revision: 1.8
Committed: Wed Jan 17 18:17:58 2007 UTC (18 years, 3 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_5_0_pre6, CRAB_1_5_0_pre5, CRAB_1_5_0_pre4
Changes since 1.7: +1 -1 lines
Log Message:
many minor fixes reported by pychecker, mostly unsude import and unused variables

File Contents

# User Rev Content
1 gutsche 1.1 #!/usr/bin/env python
2    
3 slacapra 1.8 import os
4 gutsche 1.1 import common
5     from crab_util import *
6     from crab_exceptions import *
7    
8     from cmsconfig import cmsconfig
9     from CfgInterface import CfgInterface
10    
11     class PsetManipulator:
12     def __init__(self, pset):
13     """
14     Convert Pset in Python format
15     and initialize
16     """
17    
18     self.pset = pset
19     #convert Pset
20     self.pyPset = os.path.basename(pset)
21     cmd = 'EdmConfigToPython > '+common.work_space.shareDir()+self.pyPset+'py < '+ self.pset
22     cmd_out = runCommand(cmd)
23     if cmd_out != '':
24     msg = 'Could not convert Pset.cfg into python Dictionary \n'
25     msg1= ' Did you do eval `scramv1 runtime ...` from your CMSSW working area ?'
26     raise CrabException(msg+msg1)
27     pass
28    
29 slacapra 1.2 self.par = file(common.work_space.shareDir()+self.pyPset+'py').read()
30 gutsche 1.1
31     # get PSet
32 slacapra 1.2 self.cfg = CfgInterface(self.par,True)
33 gutsche 1.1
34     def inputModule(self, source):
35     """ Clean String FileName if there
36     and add vString Filenames key
37     """
38     # set input module
39     inModule = self.cfg.inputSource
40     inModule.cleanStringFileNames() ## Add Daniele
41     inModule.setFileNames(source)
42     return
43 slacapra 1.2
44 slacapra 1.4 def pythiaSeed(self,seed):
45 slacapra 1.2 """
46 slacapra 1.4 Set pythia seed key
47 slacapra 1.2 """
48     # set seed
49     inModule = self.cfg.inputSource
50     inModule.setPythiaSeed(self.cfg,seed)
51 slacapra 1.4 return
52    
53     def pythiaSeedVtx(self,vtxSeed):
54     """
55     Set vtx seed key
56     """
57     # set seed
58     inModule = self.cfg.inputSource
59 spiga 1.3 inModule.setPythiaVtxSeed(self.cfg,vtxSeed)
60 slacapra 1.2 return
61 gutsche 1.1
62 spiga 1.7 def pythiaFirstRun(self, firstrun):
63     """ """
64     # set input module
65     inModule = self.cfg.inputSource
66     inModule.setFirstRun(firstrun) ## Add Daniele
67     return
68    
69 gutsche 1.1 def maxEvent(self, maxEv):
70     """ """
71     # set input module
72     inModule = self.cfg.inputSource
73     inModule.cleanMaxEvent()
74     inModule.setMaxEvents(maxEv) ## Add Daniele
75     return
76    
77 gutsche 1.5 def skipEvent(self, skipEv):
78     """ """
79     # set input module
80     inModule = self.cfg.inputSource
81     inModule.cleanSkipEvent()
82     inModule.setSkipEvents(skipEv) ## Add Daniele
83     return
84    
85 gutsche 1.1 def outputModule(self, output):
86    
87     #set output module
88     outModule = self.cfg.outputModules['out']
89     outModule.setFileName('file:'+str(output))
90    
91     return
92    
93     def psetWriter(self, name):
94    
95     configObject = cmsconfig(str(self.cfg))
96    
97     file1 = open(common.work_space.jobDir()+name,"w")
98     file1.write(str(configObject.asConfigurationString()))
99     file1.close()
100    
101     return
102 gutsche 1.6
103     def addCrabFJR(self,name):
104     """
105    
106     _addCrabFJR_
107    
108     add CRAB specific FrameworkJobReport (FJR)
109    
110     if already a FJR exist in input CMSSW parameter-set, add a second one
111    
112     """
113    
114     # check if MessageLogger service already exist in configuration, if not, add it
115     if not "MessageLogger" in self.cfg.cmsConfig.serviceNames() :
116     self.cfg.cmsConfig.psdata['services']['MessageLogger'] = {
117     '@classname': ('string', 'tracked', 'MessageLogger'),
118     }
119    
120     # get MessageLogger service
121     loggerSvc = self.cfg.cmsConfig.service("MessageLogger")
122    
123     # check if FJR is in MessageLogger service configuration, if not, add it
124     if not loggerSvc.has_key("fwkJobReports"):
125     loggerSvc['fwkJobReports'] = ("vstring", "untracked", [])
126    
127     # check if crab FJR configuration is in MessageLogger configuration, if not, add it
128     if not '\"'+name+'\"' in loggerSvc['fwkJobReports'][2] :
129     loggerSvc['fwkJobReports'][2].append('\"'+name+'\"')
130    
131     # check that default is taken for CRAB FJR configuration and any user specific is removed
132     if loggerSvc.has_key(name):
133     del loggerSvc[name]