ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.32
Committed: Fri Jul 28 18:04:01 2006 UTC (18 years, 9 months ago) by mkirn
Content type: text/x-python
Branch: MAIN
Changes since 1.31: +5 -3 lines
Log Message:
Burt Holzman fix for arguments and /uscmst1/prod/sw/cms/cmsset_default.sh

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