forked from cms-PdmV/wmcontrol
-
Notifications
You must be signed in to change notification settings - Fork 1
/
condDatasetSubmitter.py
executable file
·341 lines (285 loc) · 11.4 KB
/
condDatasetSubmitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#! /usr/bin/env python
import os
import sys
import re
from optparse import OptionParser
sys.path.append('/afs/cern.ch/cms/PPD/PdmV/tools/prod/devel/')
from phedex import phedex
DRYRUN=False
#-------------------------------------------------------------------------------
def createOptionParser():
global DRYRUN
usage=\
"""
ConditionValidation.py --gt <GT> --run <run> --conds <condition json>
"""
parser = OptionParser(usage)
parser.add_option("--gt",
dest="gt",
help="common global tag to both submissions")
parser.add_option("--basegt",
dest="basegt",
default="",
help="common global tag to base RECO+HLT submissions")
parser.add_option("--run",
help="the run number to be processed, can be a comma separated list")
parser.add_option("--ds",
help="dataset to be processed",
default="/MinimumBias/Run2012B-PromptReco-v1/RECO")
parser.add_option("--conds",
help="List of new tag,record,connection_string triplets to be tested")
parser.add_option("--dry",
default=False,
action='store_true')
parser.add_option("--Type",
help="Defines the type of the workflow",
choices=['HLT','PR','RECO+HLT'],
default='HLT')
parser.add_option("--DQM",
help="Specify what is the DQM sequence needed for PR",
default=None)
parser.add_option("--noSiteCheck",
help="Prevents the site check to be operated",
default=False,
action='store_true')
(options,args) = parser.parse_args()
if not options.gt or not options.run or not options.conds:
parser.error("options --run, --gt and --conds are mandatory")
CMSSW_VERSION='CMSSW_VERSION'
if not os.environ.has_key(CMSSW_VERSION):
print "CMSSW not properly set. Exiting"
sys.exit(1)
options.release = os.getenv(CMSSW_VERSION)
if options.dry:
DRYRUN=True
options.ds=options.ds.split(',')
options.run = options.run.split(',')
return options
#-------------------------------------------------------------------------------
def getConfCondDictionary(conditions_filename):
# read the tags fromt eh list
newCtags=eval(open(options.conds).read())
ConfCondList=[ ('REFERENCE.py','') ]
ConfCondDictionary={
'REFERENCE.py':''
}
for (i,condbunch) in enumerate(newCtags):
ConfCondDictionary['NEWCONDITIONS%s.py'%i]='%s'%('+'.join(map(lambda r : ','.join(r),condbunch)))
ConfCondList.append( ('NEWCONDITIONS%s.py'%i, '%s'%('+'.join(map(lambda r : ','.join(r),condbunch))) ) )
#return ConfCondDictionary
return ConfCondList
#-------------------------------------------------------------------------------
def isPCLReady(run):
for line in os.popen('curl -s http://cms-alcadb.web.cern.ch/cms-alcadb/Monitoring/PCLTier0Workflow/log.txt').read().split('\n'):
if not line: continue
spl=line.split()
if spl[0]==str(run):
ready=eval(spl[7])
print "\n\n\tPCL ready for ",run,"\n\n"
return ready
return False
def isAtSite(ds, run):
blocks=[]
dbsq1='dbs search --noheader --production --query "find block,block.status where dataset = %s and run = %s"'%(ds,run)
ph=phedex(ds)
print dbsq1
for line in os.popen(dbsq1):
block=line.split()[0]
status=int(line.split()[1])
if status!=0:
print block,'not closed'
continue
for b in filter(lambda b :b.name==block,ph.block):
for replica in filter(lambda r : r.custodial=='y',b.replica):
if replica.complete!='y':
print block,'not complete at custodial site'
else:
blocks.append('#'+block.split('#')[-1])
if len(blocks)==0:
print "No possible block for %s in %s"%(run,ds)
return False
else:
print "\n\n\t Block testing at succeeded for %s in %s \n\n"%(run,ds)
return list(set(blocks))
#-------------------------------------------------------------------------------
## decommissionned because we could run anywhere
#def checkIsAtFnal(run, ds):
# if not isAtFnal (run, ds):
# print "Run %s of %s is not at fnal. Impossible to continue." %(run, ds)
# sys.exit(1)
#-------------------------------------------------------------------------------
def getDriverDetails(Type):
HLTBase= {"reqtype":"HLT",
"steps":"HLT,DQM:triggerOfflineDQMSource",
"procname":"HLT2",
"datatier":"RAW,DQM ",
"eventcontent":"FEVTDEBUGHLT,DQM",
"inputcommands":'keep *,drop *_hlt*_*_HLT,drop *_TriggerResults_*_HLT',
"custcommands":'process.schedule.remove( process.HLTriggerFirstPath )',
"inclparents":"True"}
HLTRECObase={"steps":"RAW2DIGI,L1Reco,RECO",
"procname":"RECO",
"datatier":"RAW-RECO",
"eventcontent":"RAWRECO",
"inputcommands":'',
"custcommands":'',
}
if Type=='HLT':
return HLTBase
elif Type=='RECO+HLT':
HLTBase.update({'base':HLTRECObase})
return HLTBase
elif Type=='PR':
theDetails={"reqtype":"PR",
"steps":"RAW2DIGI,L1Reco,RECO,DQM",
"procname":"RECO",
"datatier":"DQM ",
"eventcontent":"DQM",
"inputcommands":'',
"custcommands":'',
"inclparents":"False"}
if options.DQM:
theDetails["steps"]="RAW2DIGI,L1Reco,RECO,DQM:%s"%(options.DQM)
return theDetails
#-------------------------------------------------------------------------------
def execme(command):
if DRYRUN:
print command
else:
print " * Executing: %s..."%command
os.system(command)
print " * Executed!"
#-------------------------------------------------------------------------------
def createCMSSWConfigs(options,confCondDictionary,allRunsAndBlocks):
details=getDriverDetails(options.Type)
if options.DQM:
details
# Create the drivers
#print confCondDictionary
#for cfgname,custconditions in confCondDictionary.items():
for c in confCondList:
(cfgname,custconditions) = c
print "\n\n\tCreating for",cfgname,"\n\n"
driver_command="cmsDriver.py %s " %details['reqtype']+\
"-s %s " %details['steps'] +\
"--processName %s " % details['procname'] +\
"--data --scenario pp " +\
"--datatier %s " % details['datatier'] +\
"--eventcontent %s " %details['eventcontent'] +\
"--conditions %s " %options.gt +\
"--python_filename %s " %cfgname +\
"--no_exec "
if details['custcommands']!="":
driver_command += '--customise_commands="%s" ' %details['custcommands']
if details['inputcommands']!="":
driver_command += '--inputCommands "%s" '%details['inputcommands']
if custconditions!="":
driver_command += '--custom_conditions="%s" ' %custconditions
execme(driver_command)
base=None
if 'base' in details:
base=details['base']
driver_command="cmsDriver.py %s " %details['reqtype']+\
"-s %s " %base['steps'] +\
"--processName %s " % base['procname'] +\
"--data --scenario pp " +\
"--datatier %s " % base['datatier'] +\
"--eventcontent %s " %base['eventcontent'] +\
"--conditions %s " %options.basegt +\
"--python_filename reco.py " +\
"--no_exec "
execme(driver_command)
matched=re.match("(.*)::All",options.gt)
gtshort=matched.group(1)
if base:
subgtshort=gtshort
matched=re.match("(.*)::All",options.basegt)
gtshort=matched.group(1)
# Creating the WMC cfgfile
wmcconf_text= '[DEFAULT] \n'+\
'group=ppd \n'+\
'user=%s\n' %os.getenv('USER')
if base:
wmcconf_text+='request_type= TaskChain \n'
else:
wmcconf_text+='request_type= ReReco \n'+\
'includeparents = %s \n' %details['inclparents']
wmcconf_text+='priority = 1000000 \n'+\
'release=%s\n' %options.release +\
'globaltag =%s::All \n' %gtshort
wmcconf_text+='dset_run_dict= {'
for ds in options.ds:
wmcconf_text+='"%s" : [%s],\n '%(ds, ','.join(options.run+ map(lambda s :'"%s"'%(s),allRunsAndBlocks[ds])))
wmcconf_text+='}\n\n'
if base:
wmcconf_text+='[HLT_validation]\n'+\
'cfg_path = reco.py\n' +\
'req_name = %s_RelVal_%s\n'%(details['reqtype'],options.run[0]) +\
'\n\n'
else:
wmcconf_text+='[%s_default]\n' %details['reqtype'] +\
'cfg_path = REFERENCE.py\n' +\
'req_name = %s_reference_RelVal_%s\n'%(details['reqtype'],options.run[0]) ## take the first one of the list to label it
task=2
for (i,c) in enumerate(confCondList):
cfgname=c[0]
if "REFERENCE" in cfgname:
if base:
wmcconf_text+='step%d_output = RAWRECOoutput\n'%task +\
'step%d_cfg = %s\n'%(task,cfgname) +\
'step%d_globaltag = %s::All\n'%(task,subgtshort) +\
'step%d_input = Task1\n\n'%task
task+=1
continue
else:
continue
if base:
wmcconf_text+='\n\n' +\
'step%d_output = RAWRECOoutput\n'%task +\
'step%d_cfg = %s\n'%(task,cfgname) +\
'step%d_globaltag = %s::All\n'%(task,subgtshort) +\
'step%d_input = Task1\n\n'%task
task+=1
else:
label=cfgname.lower().replace('.py','')
wmcconf_text+='\n\n[%s_%s]\n' %(details['reqtype'],label)+\
'cfg_path = %s\n'%cfgname+\
'req_name = %s_%s_RelVal_%s\n'%(details['reqtype'],label,options.run[0])
wmconf_name='%sConditionValidation_%s_%s_%s.conf'%(details['reqtype'],
options.release,
gtshort,
options.run[0])
if not DRYRUN:
wmcconf=open(wmconf_name,'w')
wmcconf.write(wmcconf_text)
wmcconf.close()
execme('wmcontrol.py --test --req_file %s'%wmconf_name)
print 'Now execute:\nwmcontrol.py --req_file %s'%wmconf_name
#-------------------------------------------------------------------------------
if __name__ == "__main__":
# Get the options
options = createOptionParser()
# Check for PCL availability
for run in options.run:
if not isPCLReady(run):
print "The PCL is not ready for run:",run,"... aborting"
sys.exit(2)
# Check if it is at FNAL
allRunsAndBlocks={}
if not options.noSiteCheck:
for ds in options.ds:
allRunsAndBlocks[ds]=[]
for run in options.run:
newblocks=isAtSite( ds, run)
if newblocks==False:
print "Cannot proceed with %s in %s"%(ds,run)
sys.exit(1)
else:
allRunsAndBlocks[ds].extend(newblocks)
#uniquing
for ds in allRunsAndBlocks:
allRunsAndBlocks[ds]=list(set(allRunsAndBlocks[ds]))
# Read the group of conditions from the list in the file
confCondList= getConfCondDictionary(options)
# Create the cfgs, both for cmsRun and WMControl
createCMSSWConfigs(options,confCondList,allRunsAndBlocks)