ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/PsetManipulator.py
Revision: 1.1
Committed: Sun May 28 02:24:35 2006 UTC (18 years, 11 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
CVS Tags: post_cmssw_integration_20060527
Log Message:
Integrate CMSSW: add parameter-set manipulation

File Contents

# Content
1 #!/usr/bin/env python
2
3 import os, sys, commands
4 import common
5 from crab_util import *
6 from crab_exceptions import *
7
8 # Crabpydir=commands.getoutput('which crab')
9 # Topdir=string.replace(Crabpydir,'/python/crab','')
10 # sys.path.append(Topdir+'/PsetCode')
11
12 from cmsconfig import cmsconfig
13 from CfgInterface import CfgInterface
14
15 class PsetManipulator:
16 def __init__(self, pset):
17 """
18 Convert Pset in Python format
19 and initialize
20 """
21
22 self.pset = pset
23 #convert Pset
24 self.pyPset = os.path.basename(pset)
25 cmd = 'EdmConfigToPython > '+common.work_space.shareDir()+self.pyPset+'py < '+ self.pset
26 #cmd = 'EdmConfigToPython > '+common.work_space.shareDir()+self.pset+'py < '+ self.pset
27 cmd_out = runCommand(cmd)
28 if cmd_out != '':
29 msg = 'Could not convert Pset.cfg into python Dictionary \n'
30 msg1= ' Did you do eval `scramv1 runtime ...` from your CMSSW working area ?'
31 raise CrabException(msg+msg1)
32 pass
33
34 par = file(common.work_space.shareDir()+self.pyPset+'py').read()
35 # par = file(common.work_space.shareDir()+self.pset+'py').read()
36
37 # get PSet
38 self.cfg = CfgInterface(par,True)
39
40
41 def inputModule(self, source):
42 """ Clean String FileName if there
43 and add vString Filenames key
44 """
45 # set input module
46 inModule = self.cfg.inputSource
47 inModule.cleanStringFileNames() ## Add Daniele
48 inModule.setFileNames(source)
49 return
50
51 def maxEvent(self, maxEv):
52 """ """
53 # set input module
54 inModule = self.cfg.inputSource
55 inModule.cleanMaxEvent()
56 inModule.setMaxEvents(maxEv) ## Add Daniele
57 return
58
59
60
61 def outputModule(self, output):
62
63 #set output module
64 outModule = self.cfg.outputModules['out']
65 outModule.setFileName('file:'+str(output))
66
67 return
68
69 def psetWriter(self, name):
70
71 configObject = cmsconfig(str(self.cfg))
72
73 file1 = open(common.work_space.jobDir()+name,"w")
74 file1.write(str(configObject.asConfigurationString()))
75 file1.close()
76
77 return