ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.49
Committed: Thu Oct 5 15:32:20 2006 UTC (18 years, 6 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_4_0_pre1
Changes since 1.48: +0 -4 lines
Log Message:
cosmetics

File Contents

# User Rev Content
1 slacapra 1.1 from JobType import JobType
2     from crab_logger import Logger
3     from crab_exceptions import *
4     from crab_util import *
5 slacapra 1.22 import math
6 slacapra 1.1 import common
7 gutsche 1.3 import PsetManipulator
8 slacapra 1.1
9 slacapra 1.41 import DBSInfo
10     import DataDiscovery
11     import DataLocation
12 slacapra 1.1 import Scram
13    
14 slacapra 1.45 import glob, os, string, re
15 slacapra 1.1
16     class Cmssw(JobType):
17 gutsche 1.38 def __init__(self, cfg_params, ncjobs):
18 slacapra 1.1 JobType.__init__(self, 'CMSSW')
19     common.logger.debug(3,'CMSSW::__init__')
20    
21 gutsche 1.3 # Marco.
22     self._params = {}
23     self.cfg_params = cfg_params
24 gutsche 1.38
25 gutsche 1.44 # number of jobs requested to be created, limit obj splitting
26 gutsche 1.38 self.ncjobs = ncjobs
27    
28 slacapra 1.1 log = common.logger
29    
30     self.scram = Scram.Scram(cfg_params)
31     scramArea = ''
32     self.additional_inbox_files = []
33     self.scriptExe = ''
34     self.executable = ''
35     self.tgz_name = 'default.tgz'
36 spiga 1.42 self.pset = '' #scrip use case Da
37     self.datasetPath = '' #scrip use case Da
38 gutsche 1.3
39 slacapra 1.1 self.version = self.scram.getSWVersion()
40 gutsche 1.5 self.setParam_('application', self.version)
41 slacapra 1.47
42 slacapra 1.1 ### collect Data cards
43     try:
44 slacapra 1.9 tmp = cfg_params['CMSSW.datasetpath']
45     log.debug(6, "CMSSW::CMSSW(): datasetPath = "+tmp)
46     if string.lower(tmp)=='none':
47     self.datasetPath = None
48 slacapra 1.21 self.selectNoInput = 1
49 slacapra 1.9 else:
50     self.datasetPath = tmp
51 slacapra 1.21 self.selectNoInput = 0
52 slacapra 1.1 except KeyError:
53 gutsche 1.3 msg = "Error: datasetpath not defined "
54 slacapra 1.1 raise CrabException(msg)
55 gutsche 1.5
56     # ML monitoring
57     # split dataset path style: /PreProdR3Minbias/SIM/GEN-SIM
58 slacapra 1.9 if not self.datasetPath:
59     self.setParam_('dataset', 'None')
60     self.setParam_('owner', 'None')
61     else:
62     datasetpath_split = self.datasetPath.split("/")
63     self.setParam_('dataset', datasetpath_split[1])
64     self.setParam_('owner', datasetpath_split[-1])
65    
66 gutsche 1.8 self.setTaskid_()
67     self.setParam_('taskId', self.cfg_params['taskId'])
68 gutsche 1.5
69 slacapra 1.1 self.dataTiers = []
70    
71     ## now the application
72     try:
73     self.executable = cfg_params['CMSSW.executable']
74 gutsche 1.5 self.setParam_('exe', self.executable)
75 slacapra 1.1 log.debug(6, "CMSSW::CMSSW(): executable = "+self.executable)
76     msg = "Default executable cmsRun overridden. Switch to " + self.executable
77     log.debug(3,msg)
78     except KeyError:
79     self.executable = 'cmsRun'
80 gutsche 1.5 self.setParam_('exe', self.executable)
81 slacapra 1.1 msg = "User executable not defined. Use cmsRun"
82     log.debug(3,msg)
83     pass
84    
85     try:
86     self.pset = cfg_params['CMSSW.pset']
87     log.debug(6, "Cmssw::Cmssw(): PSet file = "+self.pset)
88 spiga 1.42 if self.pset.lower() != 'none' :
89     if (not os.path.exists(self.pset)):
90     raise CrabException("User defined PSet file "+self.pset+" does not exist")
91     else:
92     self.pset = None
93 slacapra 1.1 except KeyError:
94     raise CrabException("PSet file missing. Cannot run cmsRun ")
95    
96     # output files
97     try:
98     self.output_file = []
99    
100     tmp = cfg_params['CMSSW.output_file']
101     if tmp != '':
102     tmpOutFiles = string.split(cfg_params['CMSSW.output_file'],',')
103     log.debug(7, 'cmssw::cmssw(): output files '+str(tmpOutFiles))
104     for tmp in tmpOutFiles:
105     tmp=string.strip(tmp)
106     self.output_file.append(tmp)
107     pass
108     else:
109     log.message("No output file defined: only stdout/err will be available")
110     pass
111     pass
112     except KeyError:
113     log.message("No output file defined: only stdout/err will be available")
114     pass
115    
116     # script_exe file as additional file in inputSandbox
117     try:
118 slacapra 1.10 self.scriptExe = cfg_params['USER.script_exe']
119     if self.scriptExe != '':
120     if not os.path.isfile(self.scriptExe):
121     msg ="WARNING. file "+self.scriptExe+" not found"
122     raise CrabException(msg)
123 spiga 1.42 self.additional_inbox_files.append(string.strip(self.scriptExe))
124 slacapra 1.1 except KeyError:
125 spiga 1.42 self.scriptExe = ''
126     #CarlosDaniele
127     if self.datasetPath == None and self.pset == None and self.scriptExe == '' :
128     msg ="WARNING. script_exe not defined"
129     raise CrabException(msg)
130    
131 slacapra 1.1 ## additional input files
132     try:
133 slacapra 1.29 tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
134 slacapra 1.1 for tmp in tmpAddFiles:
135 slacapra 1.45 dirname = ''
136     if not tmp[0]=="/": dirname = "."
137     files = glob.glob(os.path.join(dirname, tmp))
138     for file in files:
139     if not os.path.exists(file):
140     raise CrabException("Additional input file not found: "+file)
141     pass
142     self.additional_inbox_files.append(string.strip(file))
143 slacapra 1.1 pass
144     pass
145 slacapra 1.45 common.logger.debug(5,"Additional input files: "+str(self.additional_inbox_files))
146 slacapra 1.1 except KeyError:
147     pass
148    
149 slacapra 1.9 # files per job
150 slacapra 1.1 try:
151 gutsche 1.35 if (cfg_params['CMSSW.files_per_jobs']):
152     raise CrabException("files_per_jobs no longer supported. Quitting.")
153 gutsche 1.3 except KeyError:
154 gutsche 1.35 pass
155 gutsche 1.3
156 slacapra 1.9 ## Events per job
157 gutsche 1.3 try:
158 slacapra 1.10 self.eventsPerJob =int( cfg_params['CMSSW.events_per_job'])
159 slacapra 1.9 self.selectEventsPerJob = 1
160 gutsche 1.3 except KeyError:
161 slacapra 1.9 self.eventsPerJob = -1
162     self.selectEventsPerJob = 0
163    
164 slacapra 1.22 ## number of jobs
165     try:
166     self.theNumberOfJobs =int( cfg_params['CMSSW.number_of_jobs'])
167     self.selectNumberOfJobs = 1
168     except KeyError:
169     self.theNumberOfJobs = 0
170     self.selectNumberOfJobs = 0
171 slacapra 1.10
172 gutsche 1.35 try:
173     self.total_number_of_events = int(cfg_params['CMSSW.total_number_of_events'])
174     self.selectTotalNumberEvents = 1
175     except KeyError:
176     self.total_number_of_events = 0
177     self.selectTotalNumberEvents = 0
178    
179 spiga 1.42 if self.pset != None: #CarlosDaniele
180     if ( (self.selectTotalNumberEvents + self.selectEventsPerJob + self.selectNumberOfJobs) != 2 ):
181     msg = 'Must define exactly two of total_number_of_events, events_per_job, or number_of_jobs.'
182     raise CrabException(msg)
183     else:
184     if (self.selectNumberOfJobs == 0):
185     msg = 'Must specify number_of_jobs.'
186     raise CrabException(msg)
187 gutsche 1.35
188 slacapra 1.22 ## source seed for pythia
189     try:
190     self.sourceSeed = int(cfg_params['CMSSW.pythia_seed'])
191     except KeyError:
192 slacapra 1.23 self.sourceSeed = None
193     common.logger.debug(5,"No seed given")
194 slacapra 1.22
195 slacapra 1.28 try:
196     self.sourceSeedVtx = int(cfg_params['CMSSW.vtx_seed'])
197     except KeyError:
198     self.sourceSeedVtx = None
199     common.logger.debug(5,"No vertex seed given")
200 spiga 1.42 if self.pset != None: #CarlosDaniele
201     self.PsetEdit = PsetManipulator.PsetManipulator(self.pset) #Daniele Pset
202 gutsche 1.3
203 slacapra 1.1 #DBSDLS-start
204     ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
205     self.maxEvents=0 # max events available ( --> check the requested nb. of evts in Creator.py)
206     self.DBSPaths={} # all dbs paths requested ( --> input to the site local discovery script)
207 gutsche 1.35 self.jobDestination=[] # Site destination(s) for each job (list of lists)
208 slacapra 1.1 ## Perform the data location and discovery (based on DBS/DLS)
209 slacapra 1.9 ## SL: Don't if NONE is specified as input (pythia use case)
210 gutsche 1.35 blockSites = {}
211 slacapra 1.9 if self.datasetPath:
212 gutsche 1.35 blockSites = self.DataDiscoveryAndLocation(cfg_params)
213 slacapra 1.1 #DBSDLS-end
214    
215     self.tgzNameWithPath = self.getTarBall(self.executable)
216 slacapra 1.10
217 slacapra 1.9 ## Select Splitting
218 spiga 1.42 if self.selectNoInput:
219     if self.pset == None: #CarlosDaniele
220     self.jobSplittingForScript()
221     else:
222     self.jobSplittingNoInput()
223 gutsche 1.35 else: self.jobSplittingByBlocks(blockSites)
224 gutsche 1.5
225 slacapra 1.22 # modify Pset
226 spiga 1.42 if self.pset != None: #CarlosDaniele
227     try:
228     if (self.datasetPath): # standard job
229     # allow to processa a fraction of events in a file
230     self.PsetEdit.inputModule("INPUT")
231     self.PsetEdit.maxEvent("INPUTMAXEVENTS")
232     self.PsetEdit.skipEvent("INPUTSKIPEVENTS")
233     else: # pythia like job
234     self.PsetEdit.maxEvent(self.eventsPerJob)
235     if (self.sourceSeed) :
236     self.PsetEdit.pythiaSeed("INPUT")
237     if (self.sourceSeedVtx) :
238     self.PsetEdit.pythiaSeedVtx("INPUTVTX")
239     self.PsetEdit.psetWriter(self.configFilename())
240     except:
241     msg='Error while manipuliating ParameterSet: exiting...'
242     raise CrabException(msg)
243 gutsche 1.3
244 slacapra 1.1 def DataDiscoveryAndLocation(self, cfg_params):
245    
246 gutsche 1.3 common.logger.debug(10,"CMSSW::DataDiscoveryAndLocation()")
247    
248     datasetPath=self.datasetPath
249    
250     ## TODO
251     dataTiersList = ""
252     dataTiers = dataTiersList.split(',')
253 slacapra 1.1
254     ## Contact the DBS
255 slacapra 1.41 common.logger.message("Contacting DBS...")
256 slacapra 1.1 try:
257 slacapra 1.41 self.pubdata=DataDiscovery.DataDiscovery(datasetPath, dataTiers, cfg_params)
258 slacapra 1.1 self.pubdata.fetchDBSInfo()
259    
260 slacapra 1.41 except DataDiscovery.NotExistingDatasetError, ex :
261 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
262     raise CrabException(msg)
263    
264 slacapra 1.41 except DataDiscovery.NoDataTierinProvenanceError, ex :
265 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
266     raise CrabException(msg)
267 slacapra 1.41 except DataDiscovery.DataDiscoveryError, ex:
268 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS %s'%ex.getErrorMessage()
269     raise CrabException(msg)
270    
271     ## get list of all required data in the form of dbs paths (dbs path = /dataset/datatier/owner)
272 gutsche 1.3 ## self.DBSPaths=self.pubdata.getDBSPaths()
273     common.logger.message("Required data are :"+self.datasetPath)
274    
275 gutsche 1.35 self.filesbyblock=self.pubdata.getFiles()
276 mkirn 1.37 self.eventsbyblock=self.pubdata.getEventsPerBlock()
277     self.eventsbyfile=self.pubdata.getEventsPerFile()
278 slacapra 1.41 # print str(self.filesbyblock)
279     # print 'self.eventsbyfile',len(self.eventsbyfile)
280     # print str(self.eventsbyfile)
281 gutsche 1.3
282 slacapra 1.1 ## get max number of events
283     self.maxEvents=self.pubdata.getMaxEvents() ## self.maxEvents used in Creator.py
284 gutsche 1.44 common.logger.message("The number of available events is %s\n"%self.maxEvents)
285 slacapra 1.1
286 slacapra 1.41 common.logger.message("Contacting DLS...")
287 slacapra 1.1 ## Contact the DLS and build a list of sites hosting the fileblocks
288     try:
289 slacapra 1.41 dataloc=DataLocation.DataLocation(self.filesbyblock.keys(),cfg_params)
290 gutsche 1.6 dataloc.fetchDLSInfo()
291 slacapra 1.41 except DataLocation.DataLocationError , ex:
292 slacapra 1.1 msg = 'ERROR ***: failed Data Location in DLS \n %s '%ex.getErrorMessage()
293     raise CrabException(msg)
294    
295    
296 gutsche 1.35 sites = dataloc.getSites()
297     allSites = []
298     listSites = sites.values()
299     for list in listSites:
300     for oneSite in list:
301     allSites.append(oneSite)
302     allSites = self.uniquelist(allSites)
303 gutsche 1.3
304 gutsche 1.35 common.logger.message("Sites ("+str(len(allSites))+") hosting part/all of dataset: "+str(allSites))
305     common.logger.debug(6, "List of Sites: "+str(allSites))
306     return sites
307 gutsche 1.3
308 gutsche 1.35 def jobSplittingByBlocks(self, blockSites):
309 slacapra 1.9 """
310 gutsche 1.35 Perform job splitting. Jobs run over an integer number of files
311     and no more than one block.
312     ARGUMENT: blockSites: dictionary with blocks as keys and list of host sites as values
313     REQUIRES: self.selectTotalNumberEvents, self.selectEventsPerJob, self.selectNumberofJobs,
314     self.total_number_of_events, self.eventsPerJob, self.theNumberOfJobs,
315     self.maxEvents, self.filesbyblock
316     SETS: self.jobDestination - Site destination(s) for each job (a list of lists)
317     self.total_number_of_jobs - Total # of jobs
318     self.list_of_args - File(s) job will run on (a list of lists)
319     """
320    
321     # ---- Handle the possible job splitting configurations ---- #
322     if (self.selectTotalNumberEvents):
323     totalEventsRequested = self.total_number_of_events
324     if (self.selectEventsPerJob):
325     eventsPerJobRequested = self.eventsPerJob
326     if (self.selectNumberOfJobs):
327     totalEventsRequested = self.theNumberOfJobs * self.eventsPerJob
328    
329     # If user requested all the events in the dataset
330     if (totalEventsRequested == -1):
331     eventsRemaining=self.maxEvents
332     # If user requested more events than are in the dataset
333     elif (totalEventsRequested > self.maxEvents):
334     eventsRemaining = self.maxEvents
335     common.logger.message("Requested "+str(self.total_number_of_events)+ " events, but only "+str(self.maxEvents)+" events are available.")
336     # If user requested less events than are in the dataset
337     else:
338     eventsRemaining = totalEventsRequested
339 slacapra 1.22
340 slacapra 1.41 # If user requested more events per job than are in the dataset
341     if (self.selectEventsPerJob and eventsPerJobRequested > self.maxEvents):
342     eventsPerJobRequested = self.maxEvents
343    
344 gutsche 1.35 # For user info at end
345     totalEventCount = 0
346 gutsche 1.3
347 gutsche 1.35 if (self.selectTotalNumberEvents and self.selectNumberOfJobs):
348     eventsPerJobRequested = int(eventsRemaining/self.theNumberOfJobs)
349 slacapra 1.22
350 gutsche 1.35 if (self.selectNumberOfJobs):
351     common.logger.message("May not create the exact number_of_jobs requested.")
352 slacapra 1.23
353 gutsche 1.38 if ( self.ncjobs == 'all' ) :
354     totalNumberOfJobs = 999999999
355     else :
356     totalNumberOfJobs = self.ncjobs
357    
358    
359 gutsche 1.35 blocks = blockSites.keys()
360     blockCount = 0
361     # Backup variable in case self.maxEvents counted events in a non-included block
362     numBlocksInDataset = len(blocks)
363 gutsche 1.3
364 gutsche 1.35 jobCount = 0
365     list_of_lists = []
366 gutsche 1.3
367 gutsche 1.35 # ---- Iterate over the blocks in the dataset until ---- #
368     # ---- we've met the requested total # of events ---- #
369 gutsche 1.38 while ( (eventsRemaining > 0) and (blockCount < numBlocksInDataset) and (jobCount < totalNumberOfJobs)):
370 gutsche 1.35 block = blocks[blockCount]
371 gutsche 1.44 blockCount += 1
372    
373 gutsche 1.3
374 gutsche 1.44 numEventsInBlock = self.eventsbyblock[block]
375     common.logger.debug(5,'Events in Block File '+str(numEventsInBlock))
376 slacapra 1.9
377 gutsche 1.35 files = self.filesbyblock[block]
378     numFilesInBlock = len(files)
379     if (numFilesInBlock <= 0):
380     continue
381     fileCount = 0
382    
383     # ---- New block => New job ---- #
384     parString = "\\{"
385 gutsche 1.38 # counter for number of events in files currently worked on
386     filesEventCount = 0
387     # flag if next while loop should touch new file
388     newFile = 1
389     # job event counter
390     jobSkipEventCount = 0
391 slacapra 1.9
392 gutsche 1.35 # ---- Iterate over the files in the block until we've met the requested ---- #
393     # ---- total # of events or we've gone over all the files in this block ---- #
394 gutsche 1.38 while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
395 gutsche 1.35 file = files[fileCount]
396 gutsche 1.38 if newFile :
397 slacapra 1.41 try:
398     numEventsInFile = self.eventsbyfile[file]
399     common.logger.debug(6, "File "+str(file)+" has "+str(numEventsInFile)+" events")
400     # increase filesEventCount
401     filesEventCount += numEventsInFile
402     # Add file to current job
403     parString += '\\\"' + file + '\\\"\,'
404     newFile = 0
405     except KeyError:
406 gutsche 1.44 common.logger.message("File "+str(file)+" has unknown number of events: skipping")
407 slacapra 1.41
408 gutsche 1.38
409     # if less events in file remain than eventsPerJobRequested
410     if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested ) :
411     # if last file in block
412 gutsche 1.44 if ( fileCount == numFilesInBlock-1 ) :
413 gutsche 1.38 # end job using last file, use remaining events in block
414     # close job and touch new file
415     fullString = parString[:-2]
416     fullString += '\\}'
417     list_of_lists.append([fullString,str(-1),str(jobSkipEventCount)])
418 slacapra 1.41 common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(filesEventCount - jobSkipEventCount)+" events (last file in block).")
419 gutsche 1.38 self.jobDestination.append(blockSites[block])
420     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
421     # reset counter
422     jobCount = jobCount + 1
423 gutsche 1.44 totalEventCount = totalEventCount + filesEventCount - jobSkipEventCount
424     eventsRemaining = eventsRemaining - filesEventCount + jobSkipEventCount
425 gutsche 1.38 jobSkipEventCount = 0
426     # reset file
427     parString = "\\{"
428     filesEventCount = 0
429     newFile = 1
430     fileCount += 1
431     else :
432     # go to next file
433     newFile = 1
434     fileCount += 1
435     # if events in file equal to eventsPerJobRequested
436     elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
437     # close job and touch new file
438 gutsche 1.35 fullString = parString[:-2]
439     fullString += '\\}'
440 gutsche 1.38 list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
441 slacapra 1.41 common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
442 gutsche 1.38 self.jobDestination.append(blockSites[block])
443     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
444     # reset counter
445     jobCount = jobCount + 1
446     totalEventCount = totalEventCount + eventsPerJobRequested
447     eventsRemaining = eventsRemaining - eventsPerJobRequested
448     jobSkipEventCount = 0
449     # reset file
450     parString = "\\{"
451     filesEventCount = 0
452     newFile = 1
453     fileCount += 1
454    
455     # if more events in file remain than eventsPerJobRequested
456     else :
457     # close job but don't touch new file
458     fullString = parString[:-2]
459     fullString += '\\}'
460     list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
461 slacapra 1.41 common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
462 gutsche 1.35 self.jobDestination.append(blockSites[block])
463     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
464 gutsche 1.38 # increase counter
465     jobCount = jobCount + 1
466     totalEventCount = totalEventCount + eventsPerJobRequested
467     eventsRemaining = eventsRemaining - eventsPerJobRequested
468     # calculate skip events for last file
469     # use filesEventCount (contains several files), jobSkipEventCount and eventsPerJobRequest
470     jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
471     # remove all but the last file
472     filesEventCount = self.eventsbyfile[file]
473     parString = "\\{"
474     parString += '\\\"' + file + '\\\"\,'
475 slacapra 1.41 pass # END if
476 gutsche 1.35 pass # END while (iterate over files in the block)
477     pass # END while (iterate over blocks in the dataset)
478 slacapra 1.41 self.ncjobs = self.total_number_of_jobs = jobCount
479 gutsche 1.38 if (eventsRemaining > 0 and jobCount < totalNumberOfJobs ):
480 gutsche 1.35 common.logger.message("Could not run on all requested events because some blocks not hosted at allowed sites.")
481 mkirn 1.37 common.logger.message("\n"+str(jobCount)+" job(s) can run on "+str(totalEventCount)+" events.\n")
482 slacapra 1.22
483 slacapra 1.9 self.list_of_args = list_of_lists
484     return
485    
486 slacapra 1.21 def jobSplittingNoInput(self):
487 slacapra 1.9 """
488     Perform job splitting based on number of event per job
489     """
490     common.logger.debug(5,'Splitting per events')
491     common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
492 slacapra 1.22 common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
493 slacapra 1.9 common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
494    
495 slacapra 1.10 if (self.total_number_of_events < 0):
496     msg='Cannot split jobs per Events with "-1" as total number of events'
497     raise CrabException(msg)
498    
499 slacapra 1.22 if (self.selectEventsPerJob):
500     self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
501     elif (self.selectNumberOfJobs) :
502     self.total_number_of_jobs = self.theNumberOfJobs
503     self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
504 fanzago 1.12
505 slacapra 1.9 common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
506    
507     # is there any remainder?
508     check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
509    
510     common.logger.debug(5,'Check '+str(check))
511    
512 gutsche 1.35 common.logger.message(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')
513 slacapra 1.9 if check > 0:
514 gutsche 1.35 common.logger.message('Warning: asked '+str(self.total_number_of_events)+' but can do only '+str(int(self.total_number_of_jobs)*self.eventsPerJob))
515 slacapra 1.9
516 slacapra 1.10 # argument is seed number.$i
517 slacapra 1.9 self.list_of_args = []
518     for i in range(self.total_number_of_jobs):
519 gutsche 1.35 ## Since there is no input, any site is good
520 spiga 1.42 # self.jobDestination.append(["Any"])
521     self.jobDestination.append([""]) #must be empty to write correctly the xml
522 slacapra 1.23 if (self.sourceSeed):
523 slacapra 1.28 if (self.sourceSeedVtx):
524     ## pythia + vtx random seed
525     self.list_of_args.append([
526     str(self.sourceSeed)+str(i),
527     str(self.sourceSeedVtx)+str(i)
528     ])
529     else:
530     ## only pythia random seed
531     self.list_of_args.append([(str(self.sourceSeed)+str(i))])
532 slacapra 1.23 else:
533 slacapra 1.28 ## no random seed
534 slacapra 1.23 self.list_of_args.append([str(i)])
535 slacapra 1.17 #print self.list_of_args
536 gutsche 1.3
537     return
538    
539 spiga 1.42
540     def jobSplittingForScript(self):#CarlosDaniele
541     """
542     Perform job splitting based on number of job
543     """
544     common.logger.debug(5,'Splitting per job')
545     common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
546    
547     self.total_number_of_jobs = self.theNumberOfJobs
548    
549     common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
550    
551     common.logger.message(str(self.total_number_of_jobs)+' jobs can be created')
552    
553     # argument is seed number.$i
554     self.list_of_args = []
555     for i in range(self.total_number_of_jobs):
556     ## Since there is no input, any site is good
557     # self.jobDestination.append(["Any"])
558     self.jobDestination.append([""])
559     ## no random seed
560     self.list_of_args.append([str(i)])
561     return
562    
563 gutsche 1.3 def split(self, jobParams):
564    
565     common.jobDB.load()
566     #### Fabio
567     njobs = self.total_number_of_jobs
568 slacapra 1.9 arglist = self.list_of_args
569 gutsche 1.3 # create the empty structure
570     for i in range(njobs):
571     jobParams.append("")
572    
573     for job in range(njobs):
574 slacapra 1.17 jobParams[job] = arglist[job]
575     # print str(arglist[job])
576     # print jobParams[job]
577 gutsche 1.3 common.jobDB.setArguments(job, jobParams[job])
578 gutsche 1.35 common.logger.debug(5,"Job "+str(job)+" Destination: "+str(self.jobDestination[job]))
579     common.jobDB.setDestination(job, self.jobDestination[job])
580 gutsche 1.3
581     common.jobDB.save()
582     return
583    
584     def getJobTypeArguments(self, nj, sched):
585 slacapra 1.17 result = ''
586     for i in common.jobDB.arguments(nj):
587     result=result+str(i)+" "
588     return result
589 gutsche 1.3
590     def numberOfJobs(self):
591     # Fabio
592     return self.total_number_of_jobs
593    
594 slacapra 1.1 def getTarBall(self, exe):
595     """
596     Return the TarBall with lib and exe
597     """
598    
599     # if it exist, just return it
600     self.tgzNameWithPath = common.work_space.shareDir()+self.tgz_name
601     if os.path.exists(self.tgzNameWithPath):
602     return self.tgzNameWithPath
603    
604     # Prepare a tar gzipped file with user binaries.
605     self.buildTar_(exe)
606    
607     return string.strip(self.tgzNameWithPath)
608    
609     def buildTar_(self, executable):
610    
611     # First of all declare the user Scram area
612     swArea = self.scram.getSWArea_()
613     #print "swArea = ", swArea
614     swVersion = self.scram.getSWVersion()
615     #print "swVersion = ", swVersion
616     swReleaseTop = self.scram.getReleaseTop_()
617     #print "swReleaseTop = ", swReleaseTop
618    
619     ## check if working area is release top
620     if swReleaseTop == '' or swArea == swReleaseTop:
621     return
622    
623     filesToBeTarred = []
624     ## First find the executable
625     if (self.executable != ''):
626     exeWithPath = self.scram.findFile_(executable)
627     # print exeWithPath
628     if ( not exeWithPath ):
629     raise CrabException('User executable '+executable+' not found')
630    
631     ## then check if it's private or not
632     if exeWithPath.find(swReleaseTop) == -1:
633     # the exe is private, so we must ship
634     common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
635     path = swArea+'/'
636     exe = string.replace(exeWithPath, path,'')
637     filesToBeTarred.append(exe)
638     pass
639     else:
640     # the exe is from release, we'll find it on WN
641     pass
642    
643     ## Now get the libraries: only those in local working area
644     libDir = 'lib'
645     lib = swArea+'/' +libDir
646     common.logger.debug(5,"lib "+lib+" to be tarred")
647     if os.path.exists(lib):
648     filesToBeTarred.append(libDir)
649    
650 gutsche 1.3 ## Now check if module dir is present
651     moduleDir = 'module'
652     if os.path.isdir(swArea+'/'+moduleDir):
653     filesToBeTarred.append(moduleDir)
654    
655 slacapra 1.1 ## Now check if the Data dir is present
656     dataDir = 'src/Data/'
657     if os.path.isdir(swArea+'/'+dataDir):
658     filesToBeTarred.append(dataDir)
659    
660     ## Create the tar-ball
661     if len(filesToBeTarred)>0:
662     cwd = os.getcwd()
663     os.chdir(swArea)
664     tarcmd = 'tar zcvf ' + self.tgzNameWithPath + ' '
665     for line in filesToBeTarred:
666     tarcmd = tarcmd + line + ' '
667     cout = runCommand(tarcmd)
668     if not cout:
669     raise CrabException('Could not create tar-ball')
670     os.chdir(cwd)
671     else:
672     common.logger.debug(5,"No files to be to be tarred")
673    
674     return
675    
676     def wsSetupEnvironment(self, nj):
677     """
678     Returns part of a job script which prepares
679     the execution environment for the job 'nj'.
680     """
681     # Prepare JobType-independent part
682 gutsche 1.3 txt = ''
683    
684     ## OLI_Daniele at this level middleware already known
685    
686     txt += 'if [ $middleware == LCG ]; then \n'
687     txt += self.wsSetupCMSLCGEnvironment_()
688     txt += 'elif [ $middleware == OSG ]; then\n'
689 gutsche 1.43 txt += ' WORKING_DIR=`/bin/mktemp -d $OSG_WN_TMP/cms_XXXXXXXXXXXX`\n'
690     txt += ' echo "Created working directory: $WORKING_DIR"\n'
691 gutsche 1.3 txt += ' if [ ! -d $WORKING_DIR ] ;then\n'
692 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
693     txt += ' echo "JOB_EXIT_STATUS = 10016"\n'
694     txt += ' echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
695     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
696 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
697     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
698     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
699 gutsche 1.3 txt += ' exit 1\n'
700     txt += ' fi\n'
701     txt += '\n'
702     txt += ' echo "Change to working directory: $WORKING_DIR"\n'
703     txt += ' cd $WORKING_DIR\n'
704     txt += self.wsSetupCMSOSGEnvironment_()
705     txt += 'fi\n'
706 slacapra 1.1
707     # Prepare JobType-specific part
708     scram = self.scram.commandName()
709     txt += '\n\n'
710     txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
711     txt += scram+' project CMSSW '+self.version+'\n'
712     txt += 'status=$?\n'
713     txt += 'if [ $status != 0 ] ; then\n'
714 gutsche 1.7 txt += ' echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
715 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10034"\n'
716 gutsche 1.7 txt += ' echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
717 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
718 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
719     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
720     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
721 gutsche 1.3 ## OLI_Daniele
722     txt += ' if [ $middleware == OSG ]; then \n'
723     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
724     txt += ' cd $RUNTIME_AREA\n'
725     txt += ' /bin/rm -rf $WORKING_DIR\n'
726     txt += ' if [ -d $WORKING_DIR ] ;then\n'
727 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10018 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after CMSSW CMSSW_0_6_1 not found on `hostname`"\n'
728     txt += ' echo "JOB_EXIT_STATUS = 10018"\n'
729     txt += ' echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
730     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
731 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
732     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
733     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
734 gutsche 1.3 txt += ' fi\n'
735     txt += ' fi \n'
736     txt += ' exit 1 \n'
737 slacapra 1.1 txt += 'fi \n'
738     txt += 'echo "CMSSW_VERSION = '+self.version+'"\n'
739     txt += 'cd '+self.version+'\n'
740     ### needed grep for bug in scramv1 ###
741     txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
742    
743     # Handle the arguments:
744     txt += "\n"
745 gutsche 1.7 txt += "## number of arguments (first argument always jobnumber)\n"
746 slacapra 1.1 txt += "\n"
747 mkirn 1.32 # txt += "narg=$#\n"
748     txt += "if [ $nargs -lt 2 ]\n"
749 slacapra 1.1 txt += "then\n"
750 mkirn 1.33 txt += " echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$nargs+ \n"
751 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
752 gutsche 1.7 txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
753 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
754 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
755     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
756     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
757 gutsche 1.3 ## OLI_Daniele
758     txt += ' if [ $middleware == OSG ]; then \n'
759     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
760     txt += ' cd $RUNTIME_AREA\n'
761     txt += ' /bin/rm -rf $WORKING_DIR\n'
762     txt += ' if [ -d $WORKING_DIR ] ;then\n'
763 gutsche 1.7 txt += ' echo "SET_EXE_ENV 50114 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Too few arguments for CRAB job wrapper"\n'
764     txt += ' echo "JOB_EXIT_STATUS = 50114"\n'
765     txt += ' echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
766     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
767 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
768     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
769     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
770 gutsche 1.3 txt += ' fi\n'
771     txt += ' fi \n'
772 slacapra 1.1 txt += " exit 1\n"
773     txt += "fi\n"
774     txt += "\n"
775    
776     # Prepare job-specific part
777     job = common.job_list[nj]
778 spiga 1.42 if self.pset != None: #CarlosDaniele
779     pset = os.path.basename(job.configFilename())
780     txt += '\n'
781     if (self.datasetPath): # standard job
782     #txt += 'InputFiles=$2\n'
783     txt += 'InputFiles=${args[1]}\n'
784     txt += 'MaxEvents=${args[2]}\n'
785     txt += 'SkipEvents=${args[3]}\n'
786     txt += 'echo "Inputfiles:<$InputFiles>"\n'
787     txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset_tmp_1.cfg\n'
788     txt += 'echo "MaxEvents:<$MaxEvents>"\n'
789 gutsche 1.46 txt += 'sed "s#INPUTMAXEVENTS#$MaxEvents#" pset_tmp_1.cfg > pset_tmp_2.cfg\n'
790 spiga 1.42 txt += 'echo "SkipEvents:<$SkipEvents>"\n'
791 gutsche 1.46 txt += 'sed "s#INPUTSKIPEVENTS#$SkipEvents#" pset_tmp_2.cfg > pset.cfg\n'
792 spiga 1.42 else: # pythia like job
793     if (self.sourceSeed):
794     # txt += 'Seed=$2\n'
795     txt += 'Seed=${args[1]}\n'
796     txt += 'echo "Seed: <$Seed>"\n'
797     txt += 'sed "s#\<INPUT\>#$Seed#" $RUNTIME_AREA/'+pset+' > tmp.cfg\n'
798     if (self.sourceSeedVtx):
799     # txt += 'VtxSeed=$3\n'
800     txt += 'VtxSeed=${args[2]}\n'
801     txt += 'echo "VtxSeed: <$VtxSeed>"\n'
802     txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp.cfg > pset.cfg\n'
803     else:
804     txt += 'mv tmp.cfg pset.cfg\n'
805 slacapra 1.28 else:
806 spiga 1.42 txt += '# Copy untouched pset\n'
807     txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
808 slacapra 1.24
809 slacapra 1.1
810     if len(self.additional_inbox_files) > 0:
811     for file in self.additional_inbox_files:
812 mkirn 1.31 relFile = file.split("/")[-1]
813     txt += 'if [ -e $RUNTIME_AREA/'+relFile+' ] ; then\n'
814     txt += ' cp $RUNTIME_AREA/'+relFile+' .\n'
815     txt += ' chmod +x '+relFile+'\n'
816 slacapra 1.1 txt += 'fi\n'
817     pass
818    
819 spiga 1.42 if self.pset != None: #CarlosDaniele
820     txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
821    
822     txt += '\n'
823     txt += 'echo "***** cat pset.cfg *********"\n'
824     txt += 'cat pset.cfg\n'
825     txt += 'echo "****** end pset.cfg ********"\n'
826     txt += '\n'
827     # txt += 'echo "***** cat pset1.cfg *********"\n'
828     # txt += 'cat pset1.cfg\n'
829     # txt += 'echo "****** end pset1.cfg ********"\n'
830 gutsche 1.3 return txt
831    
832     def wsBuildExe(self, nj):
833     """
834     Put in the script the commands to build an executable
835     or a library.
836     """
837    
838     txt = ""
839    
840     if os.path.isfile(self.tgzNameWithPath):
841     txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
842     txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
843     txt += 'untar_status=$? \n'
844     txt += 'if [ $untar_status -ne 0 ]; then \n'
845     txt += ' echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
846     txt += ' echo "JOB_EXIT_STATUS = $untar_status" \n'
847 gutsche 1.7 txt += ' echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
848 gutsche 1.3 txt += ' if [ $middleware == OSG ]; then \n'
849     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
850     txt += ' cd $RUNTIME_AREA\n'
851     txt += ' /bin/rm -rf $WORKING_DIR\n'
852     txt += ' if [ -d $WORKING_DIR ] ;then\n'
853 gutsche 1.13 txt += ' echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
854     txt += ' echo "JOB_EXIT_STATUS = 50999"\n'
855     txt += ' echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
856     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
857     txt += ' rm -f $RUNTIME_AREA/$repo \n'
858     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
859     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
860 gutsche 1.3 txt += ' fi\n'
861     txt += ' fi \n'
862     txt += ' \n'
863 gutsche 1.7 txt += ' exit 1 \n'
864 gutsche 1.3 txt += 'else \n'
865     txt += ' echo "Successful untar" \n'
866     txt += 'fi \n'
867     pass
868    
869 slacapra 1.1 return txt
870    
871     def modifySteeringCards(self, nj):
872     """
873     modify the card provided by the user,
874     writing a new card into share dir
875     """
876    
877     def executableName(self):
878 spiga 1.42 if self.pset == None: #CarlosDaniele
879     return "sh "
880     else:
881     return self.executable
882 slacapra 1.1
883     def executableArgs(self):
884 spiga 1.42 if self.pset == None:#CarlosDaniele
885     return self.scriptExe + " $NJob"
886     else:
887     return " -p pset.cfg"
888 slacapra 1.1
889     def inputSandbox(self, nj):
890     """
891     Returns a list of filenames to be put in JDL input sandbox.
892     """
893     inp_box = []
894     # dict added to delete duplicate from input sandbox file list
895     seen = {}
896     ## code
897     if os.path.isfile(self.tgzNameWithPath):
898     inp_box.append(self.tgzNameWithPath)
899     ## config
900 spiga 1.42 if not self.pset is None: #CarlosDaniele
901     inp_box.append(common.job_list[nj].configFilename())
902 slacapra 1.1 ## additional input files
903 gutsche 1.3 #for file in self.additional_inbox_files:
904     # inp_box.append(common.work_space.cwdDir()+file)
905 slacapra 1.1 return inp_box
906    
907     def outputSandbox(self, nj):
908     """
909     Returns a list of filenames to be put in JDL output sandbox.
910     """
911     out_box = []
912    
913     stdout=common.job_list[nj].stdout()
914     stderr=common.job_list[nj].stderr()
915    
916     ## User Declared output files
917     for out in self.output_file:
918     n_out = nj + 1
919     out_box.append(self.numberFile_(out,str(n_out)))
920     return out_box
921     return []
922    
923     def prepareSteeringCards(self):
924     """
925     Make initial modifications of the user's steering card file.
926     """
927     return
928    
929     def wsRenameOutput(self, nj):
930     """
931     Returns part of a job script which renames the produced files.
932     """
933    
934     txt = '\n'
935 gutsche 1.7 txt += '# directory content\n'
936     txt += 'ls \n'
937 slacapra 1.1 file_list = ''
938     for fileWithSuffix in self.output_file:
939     output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
940 gutsche 1.7 file_list=file_list+output_file_num+' '
941 slacapra 1.1 txt += '\n'
942 gutsche 1.7 txt += '# check output file\n'
943 slacapra 1.1 txt += 'ls '+fileWithSuffix+'\n'
944 fanzago 1.18 txt += 'ls_result=$?\n'
945     #txt += 'exe_result=$?\n'
946     txt += 'if [ $ls_result -ne 0 ] ; then\n'
947     txt += ' echo "ERROR: Problem with output file"\n'
948     #txt += ' echo "JOB_EXIT_STATUS = $exe_result"\n'
949     #txt += ' echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
950     #txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
951 gutsche 1.3 ### OLI_DANIELE
952 gutsche 1.7 if common.scheduler.boss_scheduler_name == 'condor_g':
953     txt += ' if [ $middleware == OSG ]; then \n'
954     txt += ' echo "prepare dummy output file"\n'
955     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
956     txt += ' fi \n'
957 slacapra 1.1 txt += 'else\n'
958     txt += ' cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
959     txt += 'fi\n'
960    
961 gutsche 1.7 txt += 'cd $RUNTIME_AREA\n'
962 slacapra 1.1 file_list=file_list[:-1]
963 slacapra 1.2 txt += 'file_list="'+file_list+'"\n'
964 fanzago 1.18 txt += 'cd $RUNTIME_AREA\n'
965 gutsche 1.3 ### OLI_DANIELE
966     txt += 'if [ $middleware == OSG ]; then\n'
967     txt += ' cd $RUNTIME_AREA\n'
968     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
969     txt += ' /bin/rm -rf $WORKING_DIR\n'
970     txt += ' if [ -d $WORKING_DIR ] ;then\n'
971 gutsche 1.7 txt += ' echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
972     txt += ' echo "JOB_EXIT_STATUS = 60999"\n'
973     txt += ' echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
974     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
975 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
976     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
977     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
978 gutsche 1.3 txt += ' fi\n'
979     txt += 'fi\n'
980     txt += '\n'
981 slacapra 1.1 return txt
982    
983     def numberFile_(self, file, txt):
984     """
985     append _'txt' before last extension of a file
986     """
987     p = string.split(file,".")
988     # take away last extension
989     name = p[0]
990     for x in p[1:-1]:
991     name=name+"."+x
992     # add "_txt"
993     if len(p)>1:
994     ext = p[len(p)-1]
995     result = name + '_' + txt + "." + ext
996     else:
997     result = name + '_' + txt
998    
999     return result
1000    
1001 slacapra 1.41 def getRequirements(self):
1002 slacapra 1.1 """
1003     return job requirements to add to jdl files
1004     """
1005     req = ''
1006 slacapra 1.47 if self.version:
1007 slacapra 1.10 req='Member("VO-cms-' + \
1008 slacapra 1.47 self.version + \
1009 slacapra 1.10 '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
1010 gutsche 1.35
1011     req = req + ' && (other.GlueHostNetworkAdapterOutboundIP)'
1012    
1013 slacapra 1.1 return req
1014 gutsche 1.3
1015     def configFilename(self):
1016     """ return the config filename """
1017     return self.name()+'.cfg'
1018    
1019     ### OLI_DANIELE
1020     def wsSetupCMSOSGEnvironment_(self):
1021     """
1022     Returns part of a job script which is prepares
1023     the execution environment and which is common for all CMS jobs.
1024     """
1025     txt = '\n'
1026     txt += ' echo "### SETUP CMS OSG ENVIRONMENT ###"\n'
1027     txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
1028     txt += ' # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
1029     txt += ' source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
1030 mkirn 1.40 txt += ' elif [ -f $OSG_APP/cmssoft/cms/cmsset_default.sh ] ;then\n'
1031     txt += ' # Use $OSG_APP/cmssoft/cms/cmsset_default.sh to setup cms software\n'
1032     txt += ' source $OSG_APP/cmssoft/cms/cmsset_default.sh '+self.version+'\n'
1033 gutsche 1.3 txt += ' else\n'
1034 mkirn 1.40 txt += ' echo "SET_CMS_ENV 10020 ==> ERROR $GRID3_APP_DIR/cmssoft/cmsset_default.sh and $OSG_APP/cmssoft/cms/cmsset_default.sh file not found"\n'
1035 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1036     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1037     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1038 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1039     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1040     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1041 gutsche 1.7 txt += ' exit 1\n'
1042 gutsche 1.3 txt += '\n'
1043     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
1044     txt += ' cd $RUNTIME_AREA\n'
1045     txt += ' /bin/rm -rf $WORKING_DIR\n'
1046     txt += ' if [ -d $WORKING_DIR ] ;then\n'
1047 mkirn 1.40 txt += ' echo "SET_CMS_ENV 10017 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after $GRID3_APP_DIR/cmssoft/cmsset_default.sh and $OSG_APP/cmssoft/cms/cmsset_default.sh file not found"\n'
1048 gutsche 1.7 txt += ' echo "JOB_EXIT_STATUS = 10017"\n'
1049     txt += ' echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
1050     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1051 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1052     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1053     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1054 gutsche 1.3 txt += ' fi\n'
1055     txt += '\n'
1056 gutsche 1.7 txt += ' exit 1\n'
1057 gutsche 1.3 txt += ' fi\n'
1058     txt += '\n'
1059     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1060     txt += ' echo " END SETUP CMS OSG ENVIRONMENT "\n'
1061    
1062     return txt
1063    
1064     ### OLI_DANIELE
1065     def wsSetupCMSLCGEnvironment_(self):
1066     """
1067     Returns part of a job script which is prepares
1068     the execution environment and which is common for all CMS jobs.
1069     """
1070     txt = ' \n'
1071     txt += ' echo " ### SETUP CMS LCG ENVIRONMENT ### "\n'
1072     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
1073     txt += ' echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
1074     txt += ' echo "JOB_EXIT_STATUS = 10031" \n'
1075     txt += ' echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
1076     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1077 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1078     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1079     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1080 gutsche 1.7 txt += ' exit 1\n'
1081 gutsche 1.3 txt += ' else\n'
1082     txt += ' echo "Sourcing environment... "\n'
1083     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1084     txt += ' echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1085     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1086     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1087     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1088 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1089     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1090     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1091 gutsche 1.7 txt += ' exit 1\n'
1092 gutsche 1.3 txt += ' fi\n'
1093     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1094     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1095     txt += ' result=$?\n'
1096     txt += ' if [ $result -ne 0 ]; then\n'
1097     txt += ' echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1098     txt += ' echo "JOB_EXIT_STATUS = 10032"\n'
1099     txt += ' echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1100     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1101 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1102     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1103     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1104 gutsche 1.7 txt += ' exit 1\n'
1105 gutsche 1.3 txt += ' fi\n'
1106     txt += ' fi\n'
1107     txt += ' \n'
1108     txt += ' string=`cat /etc/redhat-release`\n'
1109     txt += ' echo $string\n'
1110     txt += ' if [[ $string = *alhalla* ]]; then\n'
1111     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1112     txt += ' elif [[ $string = *Enterprise* ]] || [[ $string = *cientific* ]]; then\n'
1113     txt += ' export SCRAM_ARCH=slc3_ia32_gcc323\n'
1114     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1115     txt += ' else\n'
1116 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10033 ==> ERROR OS unknown, LCG environment not initialized"\n'
1117 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10033"\n'
1118     txt += ' echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
1119     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1120 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1121     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1122     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1123 gutsche 1.7 txt += ' exit 1\n'
1124 gutsche 1.3 txt += ' fi\n'
1125     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1126     txt += ' echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1127     return txt
1128 gutsche 1.5
1129     def setParam_(self, param, value):
1130     self._params[param] = value
1131    
1132     def getParams(self):
1133     return self._params
1134 gutsche 1.8
1135     def setTaskid_(self):
1136     self._taskId = self.cfg_params['taskId']
1137    
1138     def getTaskid(self):
1139     return self._taskId
1140 gutsche 1.35
1141     #######################################################################
1142     def uniquelist(self, old):
1143     """
1144     remove duplicates from a list
1145     """
1146     nd={}
1147     for e in old:
1148     nd[e]=0
1149     return nd.keys()