1 |
spiga |
1.1 |
import common
|
2 |
|
|
from crab_exceptions import *
|
3 |
|
|
from crab_util import *
|
4 |
|
|
from WMCore.SiteScreening.BlackWhiteListParser import SEBlackWhiteListParser
|
5 |
|
|
|
6 |
|
|
class JobSplitter:
|
7 |
|
|
def __init__( self, cfg_params, args ):
|
8 |
|
|
self.cfg_params = cfg_params
|
9 |
spiga |
1.3 |
self.args=args
|
10 |
spiga |
1.1 |
#self.maxEvents
|
11 |
|
|
# init BlackWhiteListParser
|
12 |
spiga |
1.14 |
seWhiteList = cfg_params.get('GRID.se_white_list',[])
|
13 |
|
|
seBlackList = cfg_params.get('GRID.se_black_list',[])
|
14 |
slacapra |
1.18 |
self.blackWhiteListParser = SEBlackWhiteListParser(seWhiteList, seBlackList, common.logger())
|
15 |
spiga |
1.1 |
|
16 |
|
|
|
17 |
|
|
def checkUserSettings(self):
|
18 |
|
|
## Events per job
|
19 |
|
|
if self.cfg_params.has_key('CMSSW.events_per_job'):
|
20 |
|
|
self.eventsPerJob =int( self.cfg_params['CMSSW.events_per_job'])
|
21 |
|
|
self.selectEventsPerJob = 1
|
22 |
|
|
else:
|
23 |
|
|
self.eventsPerJob = -1
|
24 |
|
|
self.selectEventsPerJob = 0
|
25 |
|
|
|
26 |
|
|
## number of jobs
|
27 |
|
|
if self.cfg_params.has_key('CMSSW.number_of_jobs'):
|
28 |
|
|
self.theNumberOfJobs =int( self.cfg_params['CMSSW.number_of_jobs'])
|
29 |
|
|
self.selectNumberOfJobs = 1
|
30 |
|
|
else:
|
31 |
|
|
self.theNumberOfJobs = 0
|
32 |
|
|
self.selectNumberOfJobs = 0
|
33 |
|
|
|
34 |
|
|
if self.cfg_params.has_key('CMSSW.total_number_of_events'):
|
35 |
|
|
self.total_number_of_events = int(self.cfg_params['CMSSW.total_number_of_events'])
|
36 |
|
|
self.selectTotalNumberEvents = 1
|
37 |
|
|
if self.selectNumberOfJobs == 1:
|
38 |
|
|
if (self.total_number_of_events != -1) and int(self.total_number_of_events) < int(self.theNumberOfJobs):
|
39 |
|
|
msg = 'Must specify at least one event per job. total_number_of_events > number_of_jobs '
|
40 |
|
|
raise CrabException(msg)
|
41 |
|
|
else:
|
42 |
|
|
self.total_number_of_events = 0
|
43 |
|
|
self.selectTotalNumberEvents = 0
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
########################################################################
|
47 |
|
|
def jobSplittingByEvent( self ):
|
48 |
|
|
"""
|
49 |
|
|
Perform job splitting. Jobs run over an integer number of files
|
50 |
|
|
and no more than one block.
|
51 |
|
|
ARGUMENT: blockSites: dictionary with blocks as keys and list of host sites as values
|
52 |
|
|
REQUIRES: self.selectTotalNumberEvents, self.selectEventsPerJob, self.selectNumberofJobs,
|
53 |
|
|
self.total_number_of_events, self.eventsPerJob, self.theNumberOfJobs,
|
54 |
|
|
self.maxEvents, self.filesbyblock
|
55 |
spiga |
1.3 |
SETS: jobDestination - Site destination(s) for each job (a list of lists)
|
56 |
spiga |
1.1 |
self.total_number_of_jobs - Total # of jobs
|
57 |
|
|
self.list_of_args - File(s) job will run on (a list of lists)
|
58 |
|
|
"""
|
59 |
|
|
|
60 |
spiga |
1.3 |
jobDestination=[]
|
61 |
spiga |
1.1 |
self.checkUserSettings()
|
62 |
|
|
if ( (self.selectTotalNumberEvents + self.selectEventsPerJob + self.selectNumberOfJobs) != 2 ):
|
63 |
|
|
msg = 'Must define exactly two of total_number_of_events, events_per_job, or number_of_jobs.'
|
64 |
|
|
raise CrabException(msg)
|
65 |
|
|
|
66 |
spiga |
1.4 |
blockSites = self.args['blockSites']
|
67 |
|
|
pubdata = self.args['pubdata']
|
68 |
spiga |
1.3 |
filesbyblock=pubdata.getFiles()
|
69 |
|
|
|
70 |
|
|
self.eventsbyblock=pubdata.getEventsPerBlock()
|
71 |
|
|
self.eventsbyfile=pubdata.getEventsPerFile()
|
72 |
|
|
self.parentFiles=pubdata.getParent()
|
73 |
spiga |
1.1 |
|
74 |
|
|
## get max number of events
|
75 |
spiga |
1.3 |
self.maxEvents=pubdata.getMaxEvents()
|
76 |
spiga |
1.1 |
|
77 |
|
|
self.useParent = int(self.cfg_params.get('CMSSW.use_parent',0))
|
78 |
|
|
noBboundary = int(self.cfg_params.get('CMSSW.no_block_boundary',0))
|
79 |
|
|
|
80 |
|
|
# ---- Handle the possible job splitting configurations ---- #
|
81 |
|
|
if (self.selectTotalNumberEvents):
|
82 |
|
|
totalEventsRequested = self.total_number_of_events
|
83 |
|
|
if (self.selectEventsPerJob):
|
84 |
|
|
eventsPerJobRequested = self.eventsPerJob
|
85 |
|
|
if (self.selectNumberOfJobs):
|
86 |
|
|
totalEventsRequested = self.theNumberOfJobs * self.eventsPerJob
|
87 |
|
|
|
88 |
|
|
# If user requested all the events in the dataset
|
89 |
|
|
if (totalEventsRequested == -1):
|
90 |
|
|
eventsRemaining=self.maxEvents
|
91 |
|
|
# If user requested more events than are in the dataset
|
92 |
|
|
elif (totalEventsRequested > self.maxEvents):
|
93 |
|
|
eventsRemaining = self.maxEvents
|
94 |
spiga |
1.13 |
common.logger.info("Requested "+str(self.total_number_of_events)+ " events, but only "+str(self.maxEvents)+" events are available.")
|
95 |
spiga |
1.1 |
# If user requested less events than are in the dataset
|
96 |
|
|
else:
|
97 |
|
|
eventsRemaining = totalEventsRequested
|
98 |
|
|
|
99 |
|
|
# If user requested more events per job than are in the dataset
|
100 |
|
|
if (self.selectEventsPerJob and eventsPerJobRequested > self.maxEvents):
|
101 |
|
|
eventsPerJobRequested = self.maxEvents
|
102 |
|
|
|
103 |
|
|
# For user info at end
|
104 |
|
|
totalEventCount = 0
|
105 |
|
|
|
106 |
|
|
if (self.selectTotalNumberEvents and self.selectNumberOfJobs):
|
107 |
|
|
eventsPerJobRequested = int(eventsRemaining/self.theNumberOfJobs)
|
108 |
|
|
|
109 |
|
|
if (self.selectNumberOfJobs):
|
110 |
spiga |
1.13 |
common.logger.info("May not create the exact number_of_jobs requested.")
|
111 |
spiga |
1.1 |
|
112 |
|
|
# old... to remove Daniele
|
113 |
|
|
totalNumberOfJobs = 999999999
|
114 |
|
|
|
115 |
spiga |
1.3 |
blocks = blockSites.keys()
|
116 |
spiga |
1.1 |
blockCount = 0
|
117 |
|
|
# Backup variable in case self.maxEvents counted events in a non-included block
|
118 |
|
|
numBlocksInDataset = len(blocks)
|
119 |
|
|
|
120 |
|
|
jobCount = 0
|
121 |
|
|
list_of_lists = []
|
122 |
|
|
|
123 |
|
|
# list tracking which jobs are in which jobs belong to which block
|
124 |
|
|
jobsOfBlock = {}
|
125 |
|
|
|
126 |
|
|
parString = ""
|
127 |
spiga |
1.16 |
pString = ""
|
128 |
spiga |
1.1 |
filesEventCount = 0
|
129 |
|
|
|
130 |
|
|
# ---- Iterate over the blocks in the dataset until ---- #
|
131 |
|
|
# ---- we've met the requested total # of events ---- #
|
132 |
|
|
while ( (eventsRemaining > 0) and (blockCount < numBlocksInDataset) and (jobCount < totalNumberOfJobs)):
|
133 |
|
|
block = blocks[blockCount]
|
134 |
|
|
blockCount += 1
|
135 |
|
|
if block not in jobsOfBlock.keys() :
|
136 |
|
|
jobsOfBlock[block] = []
|
137 |
|
|
|
138 |
|
|
if self.eventsbyblock.has_key(block) :
|
139 |
|
|
numEventsInBlock = self.eventsbyblock[block]
|
140 |
spiga |
1.13 |
common.logger.debug('Events in Block File '+str(numEventsInBlock))
|
141 |
spiga |
1.1 |
|
142 |
spiga |
1.4 |
files = filesbyblock[block]
|
143 |
spiga |
1.1 |
numFilesInBlock = len(files)
|
144 |
|
|
if (numFilesInBlock <= 0):
|
145 |
|
|
continue
|
146 |
|
|
fileCount = 0
|
147 |
|
|
if noBboundary == 0: # DD
|
148 |
|
|
# ---- New block => New job ---- #
|
149 |
|
|
parString = ""
|
150 |
spiga |
1.16 |
pString=""
|
151 |
spiga |
1.1 |
# counter for number of events in files currently worked on
|
152 |
|
|
filesEventCount = 0
|
153 |
|
|
# flag if next while loop should touch new file
|
154 |
|
|
newFile = 1
|
155 |
|
|
# job event counter
|
156 |
|
|
jobSkipEventCount = 0
|
157 |
|
|
|
158 |
|
|
# ---- Iterate over the files in the block until we've met the requested ---- #
|
159 |
|
|
# ---- total # of events or we've gone over all the files in this block ---- #
|
160 |
spiga |
1.15 |
msg='\n'
|
161 |
spiga |
1.1 |
while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
|
162 |
|
|
file = files[fileCount]
|
163 |
|
|
if self.useParent==1:
|
164 |
|
|
parent = self.parentFiles[file]
|
165 |
spiga |
1.13 |
common.logger.log(10-1, "File "+str(file)+" has the following parents: "+str(parent))
|
166 |
spiga |
1.1 |
if newFile :
|
167 |
|
|
try:
|
168 |
|
|
numEventsInFile = self.eventsbyfile[file]
|
169 |
spiga |
1.13 |
common.logger.log(10-1, "File "+str(file)+" has "+str(numEventsInFile)+" events")
|
170 |
spiga |
1.1 |
# increase filesEventCount
|
171 |
|
|
filesEventCount += numEventsInFile
|
172 |
|
|
# Add file to current job
|
173 |
spiga |
1.11 |
parString += file + ','
|
174 |
spiga |
1.16 |
if self.useParent==1:
|
175 |
|
|
for f in parent :
|
176 |
|
|
pString += f + ','
|
177 |
spiga |
1.1 |
newFile = 0
|
178 |
|
|
except KeyError:
|
179 |
spiga |
1.13 |
common.logger.info("File "+str(file)+" has unknown number of events: skipping")
|
180 |
spiga |
1.1 |
|
181 |
|
|
eventsPerJobRequested = min(eventsPerJobRequested, eventsRemaining)
|
182 |
|
|
# if less events in file remain than eventsPerJobRequested
|
183 |
|
|
if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested):
|
184 |
|
|
if noBboundary == 1: ## DD
|
185 |
|
|
newFile = 1
|
186 |
|
|
fileCount += 1
|
187 |
|
|
else:
|
188 |
|
|
# if last file in block
|
189 |
|
|
if ( fileCount == numFilesInBlock-1 ) :
|
190 |
|
|
# end job using last file, use remaining events in block
|
191 |
|
|
# close job and touch new file
|
192 |
spiga |
1.11 |
fullString = parString[:-1]
|
193 |
spiga |
1.1 |
if self.useParent==1:
|
194 |
spiga |
1.11 |
fullParentString = pString[:-1]
|
195 |
spiga |
1.1 |
list_of_lists.append([fullString,fullParentString,str(-1),str(jobSkipEventCount)])
|
196 |
|
|
else:
|
197 |
|
|
list_of_lists.append([fullString,str(-1),str(jobSkipEventCount)])
|
198 |
spiga |
1.15 |
msg += "Job %s can run over %s events (last file in block).\n"%(str(jobCount+1), str(filesEventCount - jobSkipEventCount))
|
199 |
spiga |
1.3 |
jobDestination.append(blockSites[block])
|
200 |
slacapra |
1.20 |
msg += "Job %s Destination: %s\n"%(str(jobCount+1),str(SE2CMS(jobDestination[jobCount])))
|
201 |
spiga |
1.1 |
# fill jobs of block dictionary
|
202 |
|
|
jobsOfBlock[block].append(jobCount+1)
|
203 |
|
|
# reset counter
|
204 |
|
|
jobCount = jobCount + 1
|
205 |
|
|
totalEventCount = totalEventCount + filesEventCount - jobSkipEventCount
|
206 |
|
|
eventsRemaining = eventsRemaining - filesEventCount + jobSkipEventCount
|
207 |
|
|
jobSkipEventCount = 0
|
208 |
|
|
# reset file
|
209 |
|
|
pString = ""
|
210 |
|
|
parString = ""
|
211 |
|
|
filesEventCount = 0
|
212 |
|
|
newFile = 1
|
213 |
|
|
fileCount += 1
|
214 |
|
|
else :
|
215 |
|
|
# go to next file
|
216 |
|
|
newFile = 1
|
217 |
|
|
fileCount += 1
|
218 |
|
|
# if events in file equal to eventsPerJobRequested
|
219 |
|
|
elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
|
220 |
|
|
# close job and touch new file
|
221 |
spiga |
1.11 |
fullString = parString[:-1]
|
222 |
spiga |
1.1 |
if self.useParent==1:
|
223 |
spiga |
1.11 |
fullParentString = pString[:-1]
|
224 |
spiga |
1.1 |
list_of_lists.append([fullString,fullParentString,str(eventsPerJobRequested),str(jobSkipEventCount)])
|
225 |
|
|
else:
|
226 |
|
|
list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
|
227 |
spiga |
1.15 |
msg += "Job %s can run over %s events.\n"%(str(jobCount+1),str(eventsPerJobRequested))
|
228 |
spiga |
1.3 |
jobDestination.append(blockSites[block])
|
229 |
slacapra |
1.20 |
msg+= "Job %s Destination: %s\n"%(str(jobCount+1),str(SE2CMS(jobDestination[jobCount])))
|
230 |
spiga |
1.1 |
jobsOfBlock[block].append(jobCount+1)
|
231 |
|
|
# reset counter
|
232 |
|
|
jobCount = jobCount + 1
|
233 |
|
|
totalEventCount = totalEventCount + eventsPerJobRequested
|
234 |
|
|
eventsRemaining = eventsRemaining - eventsPerJobRequested
|
235 |
|
|
jobSkipEventCount = 0
|
236 |
|
|
# reset file
|
237 |
|
|
pString = ""
|
238 |
|
|
parString = ""
|
239 |
|
|
filesEventCount = 0
|
240 |
|
|
newFile = 1
|
241 |
|
|
fileCount += 1
|
242 |
|
|
|
243 |
|
|
# if more events in file remain than eventsPerJobRequested
|
244 |
|
|
else :
|
245 |
|
|
# close job but don't touch new file
|
246 |
spiga |
1.11 |
fullString = parString[:-1]
|
247 |
spiga |
1.1 |
if self.useParent==1:
|
248 |
spiga |
1.11 |
fullParentString = pString[:-1]
|
249 |
spiga |
1.1 |
list_of_lists.append([fullString,fullParentString,str(eventsPerJobRequested),str(jobSkipEventCount)])
|
250 |
|
|
else:
|
251 |
|
|
list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
|
252 |
spiga |
1.15 |
msg += "Job %s can run over %s events.\n"%(str(jobCount+1),str(eventsPerJobRequested))
|
253 |
spiga |
1.3 |
jobDestination.append(blockSites[block])
|
254 |
slacapra |
1.20 |
msg+= "Job %s Destination: %s\n"%(str(jobCount+1),str(SE2CMS(jobDestination[jobCount])))
|
255 |
spiga |
1.1 |
jobsOfBlock[block].append(jobCount+1)
|
256 |
|
|
# increase counter
|
257 |
|
|
jobCount = jobCount + 1
|
258 |
|
|
totalEventCount = totalEventCount + eventsPerJobRequested
|
259 |
|
|
eventsRemaining = eventsRemaining - eventsPerJobRequested
|
260 |
|
|
# calculate skip events for last file
|
261 |
|
|
# use filesEventCount (contains several files), jobSkipEventCount and eventsPerJobRequest
|
262 |
|
|
jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
|
263 |
|
|
# remove all but the last file
|
264 |
|
|
filesEventCount = self.eventsbyfile[file]
|
265 |
spiga |
1.16 |
pString_tmp=''
|
266 |
spiga |
1.1 |
if self.useParent==1:
|
267 |
spiga |
1.16 |
for f in parent : pString_tmp += f + ','
|
268 |
|
|
pString = pString_tmp
|
269 |
spiga |
1.11 |
parString = file + ','
|
270 |
spiga |
1.1 |
pass # END if
|
271 |
|
|
pass # END while (iterate over files in the block)
|
272 |
|
|
pass # END while (iterate over blocks in the dataset)
|
273 |
spiga |
1.15 |
common.logger.debug(msg)
|
274 |
spiga |
1.1 |
self.ncjobs = self.total_number_of_jobs = jobCount
|
275 |
|
|
if (eventsRemaining > 0 and jobCount < totalNumberOfJobs ):
|
276 |
spiga |
1.13 |
common.logger.info("Could not run on all requested events because some blocks not hosted at allowed sites.")
|
277 |
|
|
common.logger.info(str(jobCount)+" job(s) can run on "+str(totalEventCount)+" events.\n")
|
278 |
spiga |
1.1 |
|
279 |
|
|
# skip check on block with no sites DD
|
280 |
spiga |
1.5 |
if noBboundary == 0 : self.checkBlockNoSite(blocks,jobsOfBlock,blockSites)
|
281 |
spiga |
1.1 |
|
282 |
|
|
# prepare dict output
|
283 |
|
|
dictOut = {}
|
284 |
spiga |
1.11 |
dictOut['params']= ['InputFiles','MaxEvents','SkipEvents']
|
285 |
|
|
if self.useParent: dictOut['params']= ['InputFiles','ParentFiles','MaxEvents','SkipEvents']
|
286 |
spiga |
1.1 |
dictOut['args'] = list_of_lists
|
287 |
spiga |
1.3 |
dictOut['jobDestination'] = jobDestination
|
288 |
spiga |
1.1 |
dictOut['njobs']=self.total_number_of_jobs
|
289 |
|
|
|
290 |
|
|
return dictOut
|
291 |
|
|
|
292 |
|
|
# keep trace of block with no sites to print a warning at the end
|
293 |
|
|
|
294 |
spiga |
1.5 |
def checkBlockNoSite(self,blocks,jobsOfBlock,blockSites):
|
295 |
spiga |
1.1 |
# screen output
|
296 |
|
|
screenOutput = "List of jobs and available destination sites:\n\n"
|
297 |
|
|
noSiteBlock = []
|
298 |
|
|
bloskNoSite = []
|
299 |
spiga |
1.10 |
allBlock = []
|
300 |
spiga |
1.1 |
|
301 |
|
|
blockCounter = 0
|
302 |
|
|
for block in blocks:
|
303 |
|
|
if block in jobsOfBlock.keys() :
|
304 |
|
|
blockCounter += 1
|
305 |
spiga |
1.10 |
allBlock.append( blockCounter )
|
306 |
slacapra |
1.19 |
sites=self.blackWhiteListParser.checkWhiteList(self.blackWhiteListParser.checkBlackList(blockSites[block],[block]),[block])
|
307 |
spiga |
1.1 |
screenOutput += "Block %5i: jobs %20s: sites: %s\n" % (blockCounter,spanRanges(jobsOfBlock[block]),
|
308 |
slacapra |
1.20 |
', '.join(SE2CMS(sites)))
|
309 |
slacapra |
1.19 |
if len(sites) == 0:
|
310 |
spiga |
1.1 |
noSiteBlock.append( spanRanges(jobsOfBlock[block]) )
|
311 |
|
|
bloskNoSite.append( blockCounter )
|
312 |
|
|
|
313 |
spiga |
1.13 |
common.logger.info(screenOutput)
|
314 |
spiga |
1.1 |
if len(noSiteBlock) > 0 and len(bloskNoSite) > 0:
|
315 |
|
|
msg = 'WARNING: No sites are hosting any part of data for block:\n '
|
316 |
|
|
virgola = ""
|
317 |
|
|
if len(bloskNoSite) > 1:
|
318 |
|
|
virgola = ","
|
319 |
|
|
for block in bloskNoSite:
|
320 |
|
|
msg += ' ' + str(block) + virgola
|
321 |
|
|
msg += '\n Related jobs:\n '
|
322 |
|
|
virgola = ""
|
323 |
|
|
if len(noSiteBlock) > 1:
|
324 |
|
|
virgola = ","
|
325 |
|
|
for range_jobs in noSiteBlock:
|
326 |
|
|
msg += str(range_jobs) + virgola
|
327 |
|
|
msg += '\n will not be submitted and this block of data can not be analyzed!\n'
|
328 |
spiga |
1.14 |
if self.cfg_params.has_key('GRID.se_white_list'):
|
329 |
|
|
msg += 'WARNING: SE White List: '+self.cfg_params['GRID.se_white_list']+'\n'
|
330 |
spiga |
1.1 |
msg += '(Hint: By whitelisting you force the job to run at this particular site(s).\n'
|
331 |
|
|
msg += 'Please check if the dataset is available at this site!)\n'
|
332 |
spiga |
1.14 |
if self.cfg_params.has_key('GRID.ce_white_list'):
|
333 |
|
|
msg += 'WARNING: CE White List: '+self.cfg_params['GRID.ce_white_list']+'\n'
|
334 |
spiga |
1.1 |
msg += '(Hint: By whitelisting you force the job to run at this particular site(s).\n'
|
335 |
|
|
msg += 'Please check if the dataset is available at this site!)\n'
|
336 |
|
|
|
337 |
spiga |
1.13 |
common.logger.info(msg)
|
338 |
spiga |
1.1 |
|
339 |
spiga |
1.10 |
if bloskNoSite == allBlock:
|
340 |
|
|
raise CrabException('No jobs created')
|
341 |
|
|
|
342 |
spiga |
1.1 |
return
|
343 |
|
|
|
344 |
|
|
|
345 |
|
|
########################################################################
|
346 |
|
|
def jobSplittingByRun(self):
|
347 |
|
|
"""
|
348 |
|
|
"""
|
349 |
|
|
from sets import Set
|
350 |
|
|
from WMCore.JobSplitting.RunBased import RunBased
|
351 |
|
|
from WMCore.DataStructs.Workflow import Workflow
|
352 |
|
|
from WMCore.DataStructs.File import File
|
353 |
|
|
from WMCore.DataStructs.Fileset import Fileset
|
354 |
|
|
from WMCore.DataStructs.Subscription import Subscription
|
355 |
|
|
from WMCore.JobSplitting.SplitterFactory import SplitterFactory
|
356 |
|
|
from WMCore.DataStructs.Run import Run
|
357 |
|
|
|
358 |
|
|
self.checkUserSettings()
|
359 |
spiga |
1.4 |
blockSites = self.args['blockSites']
|
360 |
|
|
pubdata = self.args['pubdata']
|
361 |
spiga |
1.1 |
|
362 |
|
|
if self.selectNumberOfJobs == 0 :
|
363 |
|
|
self.theNumberOfJobs = 9999999
|
364 |
|
|
blocks = {}
|
365 |
|
|
runList = []
|
366 |
|
|
thefiles = Fileset(name='FilesToSplit')
|
367 |
spiga |
1.3 |
fileList = pubdata.getListFiles()
|
368 |
spiga |
1.1 |
for f in fileList:
|
369 |
|
|
block = f['Block']['Name']
|
370 |
|
|
try:
|
371 |
spiga |
1.3 |
f['Block']['StorageElementList'].extend(blockSites[block])
|
372 |
spiga |
1.1 |
except:
|
373 |
|
|
continue
|
374 |
|
|
wmbsFile = File(f['LogicalFileName'])
|
375 |
spiga |
1.3 |
[ wmbsFile['locations'].add(x) for x in blockSites[block] ]
|
376 |
spiga |
1.1 |
wmbsFile['block'] = block
|
377 |
|
|
runNum = f['RunsList'][0]['RunNumber']
|
378 |
|
|
runList.append(runNum)
|
379 |
|
|
myRun = Run(runNumber=runNum)
|
380 |
|
|
wmbsFile.addRun( myRun )
|
381 |
|
|
thefiles.addFile(
|
382 |
|
|
wmbsFile
|
383 |
|
|
)
|
384 |
|
|
|
385 |
|
|
work = Workflow()
|
386 |
|
|
subs = Subscription(
|
387 |
|
|
fileset = thefiles,
|
388 |
|
|
workflow = work,
|
389 |
|
|
split_algo = 'RunBased',
|
390 |
|
|
type = "Processing")
|
391 |
|
|
splitter = SplitterFactory()
|
392 |
|
|
jobfactory = splitter(subs)
|
393 |
|
|
|
394 |
|
|
#loop over all runs
|
395 |
|
|
set = Set(runList)
|
396 |
|
|
list_of_lists = []
|
397 |
|
|
jobDestination = []
|
398 |
|
|
count = 0
|
399 |
spiga |
1.17 |
for jobGroup in jobfactory():
|
400 |
spiga |
1.1 |
if count < self.theNumberOfJobs:
|
401 |
spiga |
1.17 |
res = self.getJobInfo(jobGroup)
|
402 |
spiga |
1.1 |
parString = ''
|
403 |
|
|
for file in res['lfns']:
|
404 |
spiga |
1.11 |
parString += file + ','
|
405 |
|
|
fullString = parString[:-1]
|
406 |
spiga |
1.1 |
list_of_lists.append([fullString,str(-1),str(0)])
|
407 |
spiga |
1.2 |
#need to check single file location
|
408 |
spiga |
1.1 |
jobDestination.append(res['locations'])
|
409 |
|
|
count +=1
|
410 |
|
|
# prepare dict output
|
411 |
|
|
dictOut = {}
|
412 |
spiga |
1.11 |
dictOut['params']= ['InputFiles','MaxEvents','SkipEvents']
|
413 |
spiga |
1.1 |
dictOut['args'] = list_of_lists
|
414 |
|
|
dictOut['jobDestination'] = jobDestination
|
415 |
|
|
dictOut['njobs']=count
|
416 |
|
|
|
417 |
|
|
return dictOut
|
418 |
|
|
|
419 |
|
|
def getJobInfo( self,jobGroup ):
|
420 |
|
|
res = {}
|
421 |
|
|
lfns = []
|
422 |
|
|
locations = []
|
423 |
|
|
tmp_check=0
|
424 |
|
|
for job in jobGroup.jobs:
|
425 |
|
|
for file in job.getFiles():
|
426 |
|
|
lfns.append(file['lfn'])
|
427 |
|
|
for loc in file['locations']:
|
428 |
|
|
if tmp_check < 1 :
|
429 |
|
|
locations.append(loc)
|
430 |
spiga |
1.8 |
tmp_check = tmp_check + 1
|
431 |
spiga |
1.1 |
### qui va messo il check per la locations
|
432 |
|
|
res['lfns'] = lfns
|
433 |
|
|
res['locations'] = locations
|
434 |
|
|
return res
|
435 |
|
|
|
436 |
|
|
########################################################################
|
437 |
|
|
def jobSplittingNoInput(self):
|
438 |
|
|
"""
|
439 |
|
|
Perform job splitting based on number of event per job
|
440 |
|
|
"""
|
441 |
spiga |
1.13 |
common.logger.debug('Splitting per events')
|
442 |
spiga |
1.3 |
self.checkUserSettings()
|
443 |
|
|
jobDestination=[]
|
444 |
spiga |
1.6 |
if ( (self.selectTotalNumberEvents + self.selectEventsPerJob + self.selectNumberOfJobs) != 2 ):
|
445 |
|
|
msg = 'Must define exactly two of total_number_of_events, events_per_job, or number_of_jobs.'
|
446 |
spiga |
1.3 |
raise CrabException(msg)
|
447 |
|
|
|
448 |
|
|
managedGenerators =self.args['managedGenerators']
|
449 |
|
|
generator = self.args['generator']
|
450 |
|
|
firstRun = self.cfg_params.get('CMSSW.first_run',None)
|
451 |
spiga |
1.1 |
|
452 |
|
|
if (self.selectEventsPerJob):
|
453 |
spiga |
1.13 |
common.logger.info('Required '+str(self.eventsPerJob)+' events per job ')
|
454 |
spiga |
1.1 |
if (self.selectNumberOfJobs):
|
455 |
spiga |
1.13 |
common.logger.info('Required '+str(self.theNumberOfJobs)+' jobs in total ')
|
456 |
spiga |
1.1 |
if (self.selectTotalNumberEvents):
|
457 |
spiga |
1.13 |
common.logger.info('Required '+str(self.total_number_of_events)+' events in total ')
|
458 |
spiga |
1.1 |
|
459 |
|
|
if (self.total_number_of_events < 0):
|
460 |
|
|
msg='Cannot split jobs per Events with "-1" as total number of events'
|
461 |
|
|
raise CrabException(msg)
|
462 |
|
|
|
463 |
|
|
if (self.selectEventsPerJob):
|
464 |
|
|
if (self.selectTotalNumberEvents):
|
465 |
|
|
self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
|
466 |
|
|
elif(self.selectNumberOfJobs) :
|
467 |
|
|
self.total_number_of_jobs =self.theNumberOfJobs
|
468 |
|
|
self.total_number_of_events =int(self.theNumberOfJobs*self.eventsPerJob)
|
469 |
|
|
|
470 |
|
|
elif (self.selectNumberOfJobs) :
|
471 |
|
|
self.total_number_of_jobs = self.theNumberOfJobs
|
472 |
|
|
self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
|
473 |
|
|
|
474 |
spiga |
1.13 |
common.logger.debug('N jobs '+str(self.total_number_of_jobs))
|
475 |
spiga |
1.1 |
|
476 |
|
|
# is there any remainder?
|
477 |
|
|
check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
|
478 |
|
|
|
479 |
spiga |
1.13 |
common.logger.debug('Check '+str(check))
|
480 |
spiga |
1.1 |
|
481 |
spiga |
1.13 |
common.logger.info(str(self.total_number_of_jobs)+' jobs can be created, each for '+str(self.eventsPerJob)+' for a total of '+str(self.total_number_of_jobs*self.eventsPerJob)+' events')
|
482 |
spiga |
1.1 |
if check > 0:
|
483 |
spiga |
1.13 |
common.logger.info('Warning: asked '+str(self.total_number_of_events)+' but can do only '+str(int(self.total_number_of_jobs)*self.eventsPerJob))
|
484 |
spiga |
1.1 |
|
485 |
|
|
# argument is seed number.$i
|
486 |
|
|
self.list_of_args = []
|
487 |
|
|
for i in range(self.total_number_of_jobs):
|
488 |
|
|
## Since there is no input, any site is good
|
489 |
spiga |
1.3 |
jobDestination.append([""]) #must be empty to write correctly the xml
|
490 |
spiga |
1.1 |
args=[]
|
491 |
spiga |
1.3 |
if (firstRun):
|
492 |
spiga |
1.1 |
## pythia first run
|
493 |
spiga |
1.3 |
args.append(str(firstRun)+str(i))
|
494 |
|
|
if (generator in managedGenerators):
|
495 |
|
|
if (generator == 'comphep' and i == 0):
|
496 |
spiga |
1.1 |
# COMPHEP is brain-dead and wants event #'s like 1,100,200,300
|
497 |
|
|
args.append('1')
|
498 |
|
|
else:
|
499 |
|
|
args.append(str(i*self.eventsPerJob))
|
500 |
spiga |
1.7 |
args.append(str(self.eventsPerJob))
|
501 |
spiga |
1.1 |
self.list_of_args.append(args)
|
502 |
|
|
# prepare dict output
|
503 |
spiga |
1.11 |
|
504 |
spiga |
1.1 |
dictOut = {}
|
505 |
spiga |
1.11 |
dictOut['params'] = ['MaxEvents']
|
506 |
|
|
if (firstRun):
|
507 |
|
|
dictOut['params'] = ['FirstRun','MaxEvents']
|
508 |
spiga |
1.12 |
if ( generator in managedGenerators ) : dictOut['params'] = ['FirstRun', 'FirstEvent', 'MaxEvents']
|
509 |
spiga |
1.11 |
else:
|
510 |
spiga |
1.12 |
if (generator in managedGenerators) : dictOut['params'] = ['FirstEvent', 'MaxEvents']
|
511 |
spiga |
1.1 |
dictOut['args'] = self.list_of_args
|
512 |
spiga |
1.3 |
dictOut['jobDestination'] = jobDestination
|
513 |
spiga |
1.1 |
dictOut['njobs']=self.total_number_of_jobs
|
514 |
|
|
|
515 |
|
|
return dictOut
|
516 |
|
|
|
517 |
|
|
|
518 |
|
|
def jobSplittingForScript(self):
|
519 |
|
|
"""
|
520 |
|
|
Perform job splitting based on number of job
|
521 |
|
|
"""
|
522 |
|
|
self.checkUserSettings()
|
523 |
spiga |
1.3 |
if (self.selectNumberOfJobs == 0):
|
524 |
spiga |
1.1 |
msg = 'must specify number_of_jobs.'
|
525 |
|
|
raise crabexception(msg)
|
526 |
spiga |
1.3 |
jobDestination = []
|
527 |
spiga |
1.13 |
common.logger.debug('Splitting per job')
|
528 |
|
|
common.logger.info('Required '+str(self.theNumberOfJobs)+' jobs in total ')
|
529 |
spiga |
1.1 |
|
530 |
|
|
self.total_number_of_jobs = self.theNumberOfJobs
|
531 |
|
|
|
532 |
spiga |
1.13 |
common.logger.debug('N jobs '+str(self.total_number_of_jobs))
|
533 |
spiga |
1.1 |
|
534 |
spiga |
1.13 |
common.logger.info(str(self.total_number_of_jobs)+' jobs can be created')
|
535 |
spiga |
1.1 |
|
536 |
|
|
# argument is seed number.$i
|
537 |
spiga |
1.11 |
#self.list_of_args = []
|
538 |
spiga |
1.1 |
for i in range(self.total_number_of_jobs):
|
539 |
spiga |
1.3 |
jobDestination.append([""])
|
540 |
spiga |
1.11 |
# self.list_of_args.append([str(i)])
|
541 |
spiga |
1.1 |
|
542 |
|
|
# prepare dict output
|
543 |
|
|
dictOut = {}
|
544 |
spiga |
1.11 |
dictOut['args'] = [] # self.list_of_args
|
545 |
spiga |
1.3 |
dictOut['jobDestination'] = jobDestination
|
546 |
spiga |
1.1 |
dictOut['njobs']=self.total_number_of_jobs
|
547 |
|
|
return dictOut
|
548 |
|
|
|
549 |
|
|
|
550 |
|
|
def jobSplittingByLumi(self):
|
551 |
|
|
"""
|
552 |
|
|
"""
|
553 |
|
|
return
|
554 |
|
|
def Algos(self):
|
555 |
|
|
"""
|
556 |
|
|
Define key splittingType matrix
|
557 |
|
|
"""
|
558 |
|
|
SplitAlogs = {
|
559 |
|
|
'EventBased' : self.jobSplittingByEvent,
|
560 |
|
|
'RunBased' : self.jobSplittingByRun,
|
561 |
|
|
'LumiBased' : self.jobSplittingByLumi,
|
562 |
|
|
'NoInput' : self.jobSplittingNoInput,
|
563 |
|
|
'ForScript' : self.jobSplittingForScript
|
564 |
|
|
}
|
565 |
|
|
return SplitAlogs
|
566 |
|
|
|