ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.39
Committed: Tue Aug 29 02:53:32 2006 UTC (18 years, 8 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
Changes since 1.38: +3 -3 lines
Log Message:
fixed argument replacing in pset

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