ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.23
Committed: Wed Jul 5 14:10:24 2006 UTC (18 years, 9 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
Changes since 1.22: +22 -12 lines
Log Message:
fix problem in splitting and modify seed only if defined

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