1 |
|
#!/usr/bin/env python |
2 |
< |
|
3 |
< |
import os, sys, commands |
2 |
> |
|
3 |
> |
import os |
4 |
|
import common |
5 |
|
from crab_util import * |
6 |
|
from crab_exceptions import * |
7 |
+ |
from crab_logger import Logger |
8 |
|
|
9 |
< |
# Crabpydir=commands.getoutput('which crab') |
10 |
< |
# Topdir=string.replace(Crabpydir,'/python/crab','') |
11 |
< |
# sys.path.append(Topdir+'/PsetCode') |
9 |
> |
from ProdCommon.CMSConfigTools.ConfigAPI.CfgInterface import CfgInterface |
10 |
> |
from FWCore.ParameterSet.DictTypes import SortedKeysDict |
11 |
> |
from FWCore.ParameterSet.Modules import Service |
12 |
> |
from FWCore.ParameterSet.Types import * |
13 |
|
|
14 |
< |
from cmsconfig import cmsconfig |
15 |
< |
from CfgInterface import CfgInterface |
14 |
> |
import FWCore.ParameterSet.Types as CfgTypes |
15 |
> |
import FWCore.ParameterSet.Modules as CfgModules |
16 |
|
|
17 |
|
class PsetManipulator: |
18 |
|
def __init__(self, pset): |
19 |
< |
""" |
20 |
< |
Convert Pset in Python format |
19 |
< |
and initialize |
19 |
> |
""" |
20 |
> |
Read in Pset object and initialize |
21 |
|
""" |
22 |
|
|
23 |
|
self.pset = pset |
24 |
|
#convert Pset |
25 |
< |
self.pyPset = os.path.basename(pset) |
26 |
< |
cmd = 'EdmConfigToPython > '+common.work_space.shareDir()+self.pyPset+'py < '+ self.pset |
27 |
< |
#cmd = 'EdmConfigToPython > '+common.work_space.shareDir()+self.pset+'py < '+ self.pset |
28 |
< |
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 |
< |
self.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(self.par,True) |
25 |
> |
from FWCore.ParameterSet.Config import include |
26 |
> |
common.logger.debug(3,"PsetManipulator::__init__: PSet file = "+self.pset) |
27 |
> |
self.cfo = include(self.pset) |
28 |
> |
self.cfg = CfgInterface(self.cfo) |
29 |
|
|
30 |
|
def inputModule(self, source): |
31 |
< |
""" Clean String FileName if there |
32 |
< |
and add vString Filenames key |
31 |
> |
""" |
32 |
> |
Set vString Filenames key |
33 |
|
""" |
34 |
|
# set input module |
35 |
|
inModule = self.cfg.inputSource |
46 |
– |
inModule.cleanStringFileNames() ## Add Daniele |
36 |
|
inModule.setFileNames(source) |
37 |
|
return |
38 |
< |
|
38 |
> |
|
39 |
|
def pythiaSeed(self,seed): |
51 |
– |
""" |
52 |
– |
Set pythia seed key |
40 |
|
""" |
41 |
+ |
Set pythia seed key |
42 |
+ |
""" |
43 |
+ |
ranGenerator = self.cfg.data.services['RandomNumberGeneratorService'] |
44 |
+ |
ranGenerator.sourceSeed = CfgTypes.untracked(CfgTypes.uint32(seed)) |
45 |
+ |
return |
46 |
+ |
|
47 |
+ |
def vtxSeed(self,vtxSeed): |
48 |
+ |
""" |
49 |
+ |
Set vtx seed key |
50 |
+ |
""" |
51 |
+ |
ranGenerator = self.cfg.data.services['RandomNumberGeneratorService'] |
52 |
+ |
ranModules = ranGenerator.moduleSeeds |
53 |
+ |
# set seed |
54 |
+ |
ranModules.VtxSmeared = CfgTypes.untracked(CfgTypes.uint32(vtxSeed)) |
55 |
+ |
return |
56 |
+ |
|
57 |
+ |
def g4Seed(self,g4Seed): |
58 |
+ |
""" |
59 |
+ |
Set g4 seed key |
60 |
+ |
""" |
61 |
+ |
ranGenerator = self.cfg.data.services['RandomNumberGeneratorService'] |
62 |
+ |
ranModules = ranGenerator.moduleSeeds |
63 |
|
# set seed |
64 |
+ |
ranModules.g4SimHits = CfgTypes.untracked(CfgTypes.uint32(g4Seed)) |
65 |
+ |
return |
66 |
+ |
|
67 |
+ |
def mixSeed(self,mixSeed): |
68 |
+ |
""" |
69 |
+ |
Set mix seed key |
70 |
+ |
""" |
71 |
+ |
ranGenerator = self.cfg.data.services['RandomNumberGeneratorService'] |
72 |
+ |
ranModules = ranGenerator.moduleSeeds |
73 |
+ |
ranModules.mix = CfgTypes.untracked(CfgTypes.uint32(mixSeed)) |
74 |
+ |
return |
75 |
+ |
|
76 |
+ |
def pythiaFirstRun(self, firstrun): |
77 |
+ |
""" |
78 |
+ |
Set firstRun |
79 |
+ |
""" |
80 |
|
inModule = self.cfg.inputSource |
81 |
< |
inModule.setPythiaSeed(self.cfg,seed) |
82 |
< |
return |
81 |
> |
inModule.setFirstRun(firstrun) ## Add Daniele |
82 |
> |
return |
83 |
|
|
84 |
|
def maxEvent(self, maxEv): |
85 |
< |
""" """ |
86 |
< |
# set input module |
85 |
> |
""" |
86 |
> |
Set max event in the standalone untracked module |
87 |
> |
""" |
88 |
> |
self.cfg.maxEvents.setMaxEventsInput(maxEv) |
89 |
> |
return |
90 |
> |
|
91 |
> |
def skipEvent(self, skipEv): |
92 |
> |
""" |
93 |
> |
Set skipEvents |
94 |
> |
""" |
95 |
|
inModule = self.cfg.inputSource |
96 |
< |
inModule.cleanMaxEvent() |
64 |
< |
inModule.setMaxEvents(maxEv) ## Add Daniele |
96 |
> |
inModule.setSkipEvents(skipEv) ## Add Daniele |
97 |
|
return |
98 |
|
|
99 |
|
def outputModule(self, output): |
105 |
|
return |
106 |
|
|
107 |
|
def psetWriter(self, name): |
108 |
< |
|
109 |
< |
configObject = cmsconfig(str(self.cfg)) |
108 |
> |
""" |
109 |
> |
Write out modified CMSSW.cfg |
110 |
> |
""" |
111 |
|
|
112 |
|
file1 = open(common.work_space.jobDir()+name,"w") |
113 |
< |
file1.write(str(configObject.asConfigurationString())) |
113 |
> |
file1.write(str(self.cfg)) |
114 |
|
file1.close() |
115 |
|
|
116 |
|
return |
117 |
+ |
|
118 |
+ |
def addCrabFJR(self,name): |
119 |
+ |
""" |
120 |
+ |
_addCrabFJR_ |
121 |
+ |
add CRAB specific FrameworkJobReport (FJR) |
122 |
+ |
if a FJR already exists in input CMSSW parameter-set, add a second one |
123 |
+ |
""" |
124 |
+ |
|
125 |
+ |
# Check if MessageLogger service already exists in configuration. If not, add it |
126 |
+ |
svcs = self.cfg.data.services |
127 |
+ |
if not svcs.has_key('MessageLogger'): |
128 |
+ |
self.cfg.data.add_(CfgModules.Service("MessageLogger")) |
129 |
+ |
|
130 |
+ |
messageLogger = self.cfg.data.services['MessageLogger'] |
131 |
+ |
|
132 |
+ |
# Add fwkJobReports to Message logger if it doesn't exist |
133 |
+ |
if "fwkJobReports" not in messageLogger.parameterNames_(): |
134 |
+ |
messageLogger.fwkJobReports = CfgTypes.untracked(CfgTypes.vstring()) |
135 |
+ |
|
136 |
+ |
# should figure out how to remove "name" if it is there. |
137 |
+ |
|
138 |
+ |
if name not in messageLogger.fwkJobReports: |
139 |
+ |
messageLogger.fwkJobReports.append(name) |
140 |
+ |
|
141 |
+ |
return |