ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.22
Committed: Tue Jul 4 16:30:39 2006 UTC (18 years, 9 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_2_0_pre9
Changes since 1.21: +128 -92 lines
Log Message:
better job splitting for cmssw

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