ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.34
Committed: Fri Jul 28 18:51:44 2006 UTC (18 years, 9 months ago) by mkirn
Content type: text/x-python
Branch: MAIN
Changes since 1.33: +4 -2 lines
Log Message:
Burt Holzman fix for arguments and VO_CMS_SW_DIR/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     txt += "if [ $nargs -lt 2 ]\n"
725 slacapra 1.1 txt += "then\n"
726 mkirn 1.33 txt += " echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$nargs+ \n"
727 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
728 gutsche 1.7 txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
729 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
730 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
731     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
732     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
733 gutsche 1.3 ## OLI_Daniele
734     txt += ' if [ $middleware == OSG ]; then \n'
735     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
736     txt += ' cd $RUNTIME_AREA\n'
737     txt += ' /bin/rm -rf $WORKING_DIR\n'
738     txt += ' if [ -d $WORKING_DIR ] ;then\n'
739 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'
740     txt += ' echo "JOB_EXIT_STATUS = 50114"\n'
741     txt += ' echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
742     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
743 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
744     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
745     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
746 gutsche 1.3 txt += ' fi\n'
747     txt += ' fi \n'
748 slacapra 1.1 txt += " exit 1\n"
749     txt += "fi\n"
750     txt += "\n"
751    
752     # Prepare job-specific part
753     job = common.job_list[nj]
754     pset = os.path.basename(job.configFilename())
755     txt += '\n'
756 slacapra 1.10 if (self.datasetPath): # standard job
757 mkirn 1.32 #txt += 'InputFiles=$2\n'
758     txt += 'InputFiles=${args[1]}\n'
759 slacapra 1.10 txt += 'echo "Inputfiles:<$InputFiles>"\n'
760     txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset.cfg\n'
761     else: # pythia like job
762 slacapra 1.23 if (self.sourceSeed):
763 mkirn 1.34 # txt += 'Seed=$2\n'
764     txt += 'Seed=${args[1]}\n'
765 slacapra 1.23 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 mkirn 1.34 # txt += 'VtxSeed=$3\n'
769     txt += 'VtxSeed=${args[2]}\n'
770 slacapra 1.28 txt += 'echo "VtxSeed: <$VtxSeed>"\n'
771     txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp.cfg > pset.cfg\n'
772     else:
773     txt += 'mv tmp.cfg pset.cfg\n'
774 slacapra 1.24 else:
775     txt += '# Copy untouched pset\n'
776 slacapra 1.26 txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
777 slacapra 1.24
778 slacapra 1.1
779     if len(self.additional_inbox_files) > 0:
780     for file in self.additional_inbox_files:
781 mkirn 1.31 relFile = file.split("/")[-1]
782     txt += 'if [ -e $RUNTIME_AREA/'+relFile+' ] ; then\n'
783     txt += ' cp $RUNTIME_AREA/'+relFile+' .\n'
784     txt += ' chmod +x '+relFile+'\n'
785 slacapra 1.1 txt += 'fi\n'
786     pass
787    
788     txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
789    
790     txt += '\n'
791     txt += 'echo "***** cat pset.cfg *********"\n'
792     txt += 'cat pset.cfg\n'
793     txt += 'echo "****** end pset.cfg ********"\n'
794 gutsche 1.3 txt += '\n'
795     # txt += 'echo "***** cat pset1.cfg *********"\n'
796     # txt += 'cat pset1.cfg\n'
797     # txt += 'echo "****** end pset1.cfg ********"\n'
798     return txt
799    
800     def wsBuildExe(self, nj):
801     """
802     Put in the script the commands to build an executable
803     or a library.
804     """
805    
806     txt = ""
807    
808     if os.path.isfile(self.tgzNameWithPath):
809     txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
810     txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
811     txt += 'untar_status=$? \n'
812     txt += 'if [ $untar_status -ne 0 ]; then \n'
813     txt += ' echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
814     txt += ' echo "JOB_EXIT_STATUS = $untar_status" \n'
815 gutsche 1.7 txt += ' echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
816 gutsche 1.3 txt += ' if [ $middleware == OSG ]; then \n'
817     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
818     txt += ' cd $RUNTIME_AREA\n'
819     txt += ' /bin/rm -rf $WORKING_DIR\n'
820     txt += ' if [ -d $WORKING_DIR ] ;then\n'
821 gutsche 1.13 txt += ' echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
822     txt += ' echo "JOB_EXIT_STATUS = 50999"\n'
823     txt += ' echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
824     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
825     txt += ' rm -f $RUNTIME_AREA/$repo \n'
826     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
827     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
828 gutsche 1.3 txt += ' fi\n'
829     txt += ' fi \n'
830     txt += ' \n'
831 gutsche 1.7 txt += ' exit 1 \n'
832 gutsche 1.3 txt += 'else \n'
833     txt += ' echo "Successful untar" \n'
834     txt += 'fi \n'
835     pass
836    
837 slacapra 1.1 return txt
838    
839     def modifySteeringCards(self, nj):
840     """
841     modify the card provided by the user,
842     writing a new card into share dir
843     """
844    
845     def executableName(self):
846     return self.executable
847    
848     def executableArgs(self):
849 gutsche 1.3 return " -p pset.cfg"
850 slacapra 1.1
851     def inputSandbox(self, nj):
852     """
853     Returns a list of filenames to be put in JDL input sandbox.
854     """
855     inp_box = []
856     # dict added to delete duplicate from input sandbox file list
857     seen = {}
858     ## code
859     if os.path.isfile(self.tgzNameWithPath):
860     inp_box.append(self.tgzNameWithPath)
861     ## config
862     inp_box.append(common.job_list[nj].configFilename())
863     ## additional input files
864 gutsche 1.3 #for file in self.additional_inbox_files:
865     # inp_box.append(common.work_space.cwdDir()+file)
866 slacapra 1.1 return inp_box
867    
868     def outputSandbox(self, nj):
869     """
870     Returns a list of filenames to be put in JDL output sandbox.
871     """
872     out_box = []
873    
874     stdout=common.job_list[nj].stdout()
875     stderr=common.job_list[nj].stderr()
876    
877     ## User Declared output files
878     for out in self.output_file:
879     n_out = nj + 1
880     out_box.append(self.numberFile_(out,str(n_out)))
881     return out_box
882     return []
883    
884     def prepareSteeringCards(self):
885     """
886     Make initial modifications of the user's steering card file.
887     """
888     return
889    
890     def wsRenameOutput(self, nj):
891     """
892     Returns part of a job script which renames the produced files.
893     """
894    
895     txt = '\n'
896 gutsche 1.7 txt += '# directory content\n'
897     txt += 'ls \n'
898 slacapra 1.1 file_list = ''
899     for fileWithSuffix in self.output_file:
900     output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
901 gutsche 1.7 file_list=file_list+output_file_num+' '
902 slacapra 1.1 txt += '\n'
903 gutsche 1.7 txt += '# check output file\n'
904 slacapra 1.1 txt += 'ls '+fileWithSuffix+'\n'
905 fanzago 1.18 txt += 'ls_result=$?\n'
906     #txt += 'exe_result=$?\n'
907     txt += 'if [ $ls_result -ne 0 ] ; then\n'
908     txt += ' echo "ERROR: Problem with output file"\n'
909     #txt += ' echo "JOB_EXIT_STATUS = $exe_result"\n'
910     #txt += ' echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
911     #txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
912 gutsche 1.3 ### OLI_DANIELE
913 gutsche 1.7 if common.scheduler.boss_scheduler_name == 'condor_g':
914     txt += ' if [ $middleware == OSG ]; then \n'
915     txt += ' echo "prepare dummy output file"\n'
916     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
917     txt += ' fi \n'
918 slacapra 1.1 txt += 'else\n'
919     txt += ' cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
920     txt += 'fi\n'
921    
922 gutsche 1.7 txt += 'cd $RUNTIME_AREA\n'
923 slacapra 1.1 file_list=file_list[:-1]
924 slacapra 1.2 txt += 'file_list="'+file_list+'"\n'
925 fanzago 1.18 txt += 'cd $RUNTIME_AREA\n'
926 gutsche 1.3 ### OLI_DANIELE
927     txt += 'if [ $middleware == OSG ]; then\n'
928     txt += ' cd $RUNTIME_AREA\n'
929     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
930     txt += ' /bin/rm -rf $WORKING_DIR\n'
931     txt += ' if [ -d $WORKING_DIR ] ;then\n'
932 gutsche 1.7 txt += ' echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
933     txt += ' echo "JOB_EXIT_STATUS = 60999"\n'
934     txt += ' echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
935     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
936 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
937     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
938     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
939 gutsche 1.3 txt += ' fi\n'
940     txt += 'fi\n'
941     txt += '\n'
942 slacapra 1.1 return txt
943    
944     def numberFile_(self, file, txt):
945     """
946     append _'txt' before last extension of a file
947     """
948     p = string.split(file,".")
949     # take away last extension
950     name = p[0]
951     for x in p[1:-1]:
952     name=name+"."+x
953     # add "_txt"
954     if len(p)>1:
955     ext = p[len(p)-1]
956     #result = name + '_' + str(txt) + "." + ext
957     result = name + '_' + txt + "." + ext
958     else:
959     #result = name + '_' + str(txt)
960     result = name + '_' + txt
961    
962     return result
963    
964     def getRequirements(self):
965     """
966     return job requirements to add to jdl files
967     """
968     req = ''
969 slacapra 1.10 if common.analisys_common_info['sw_version']:
970     req='Member("VO-cms-' + \
971     common.analisys_common_info['sw_version'] + \
972     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
973 slacapra 1.1 if common.analisys_common_info['sites']:
974     if len(common.analisys_common_info['sites'])>0:
975     req = req + ' && ('
976     for i in range(len(common.analisys_common_info['sites'])):
977     req = req + 'other.GlueCEInfoHostName == "' \
978     + common.analisys_common_info['sites'][i] + '"'
979     if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
980     req = req + ' || '
981     req = req + ')'
982     #print "req = ", req
983     return req
984 gutsche 1.3
985     def configFilename(self):
986     """ return the config filename """
987     return self.name()+'.cfg'
988    
989     ### OLI_DANIELE
990     def wsSetupCMSOSGEnvironment_(self):
991     """
992     Returns part of a job script which is prepares
993     the execution environment and which is common for all CMS jobs.
994     """
995     txt = '\n'
996     txt += ' echo "### SETUP CMS OSG ENVIRONMENT ###"\n'
997     txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
998     txt += ' # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
999     txt += ' source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
1000     txt += ' elif [ -f $OSG_APP/cmssoft/cmsset_default.sh ] ;then\n'
1001     txt += ' # Use $OSG_APP/cmssoft/cmsset_default.sh to setup cms software\n'
1002     txt += ' source $OSG_APP/cmssoft/cmsset_default.sh '+self.version+'\n'
1003     txt += ' else\n'
1004     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'
1005     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1006     txt += ' echo "JobExitCode=10020" | 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 += '\n'
1013     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
1014     txt += ' cd $RUNTIME_AREA\n'
1015     txt += ' /bin/rm -rf $WORKING_DIR\n'
1016     txt += ' if [ -d $WORKING_DIR ] ;then\n'
1017 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'
1018     txt += ' echo "JOB_EXIT_STATUS = 10017"\n'
1019     txt += ' echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
1020     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1021 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1022     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1023     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1024 gutsche 1.3 txt += ' fi\n'
1025     txt += '\n'
1026 gutsche 1.7 txt += ' exit 1\n'
1027 gutsche 1.3 txt += ' fi\n'
1028     txt += '\n'
1029     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1030     txt += ' echo " END SETUP CMS OSG ENVIRONMENT "\n'
1031    
1032     return txt
1033    
1034     ### OLI_DANIELE
1035     def wsSetupCMSLCGEnvironment_(self):
1036     """
1037     Returns part of a job script which is prepares
1038     the execution environment and which is common for all CMS jobs.
1039     """
1040     txt = ' \n'
1041     txt += ' echo " ### SETUP CMS LCG ENVIRONMENT ### "\n'
1042     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
1043     txt += ' echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
1044     txt += ' echo "JOB_EXIT_STATUS = 10031" \n'
1045     txt += ' echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
1046     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1047 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1048     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1049     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1050 gutsche 1.7 txt += ' exit 1\n'
1051 gutsche 1.3 txt += ' else\n'
1052     txt += ' echo "Sourcing environment... "\n'
1053     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1054     txt += ' echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1055     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1056     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1057     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1058 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1059     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1060     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1061 gutsche 1.7 txt += ' exit 1\n'
1062 gutsche 1.3 txt += ' fi\n'
1063     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1064     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1065     txt += ' result=$?\n'
1066     txt += ' if [ $result -ne 0 ]; then\n'
1067     txt += ' echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1068     txt += ' echo "JOB_EXIT_STATUS = 10032"\n'
1069     txt += ' echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1070     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1071 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1072     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1073     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1074 gutsche 1.7 txt += ' exit 1\n'
1075 gutsche 1.3 txt += ' fi\n'
1076     txt += ' fi\n'
1077     txt += ' \n'
1078     txt += ' string=`cat /etc/redhat-release`\n'
1079     txt += ' echo $string\n'
1080     txt += ' if [[ $string = *alhalla* ]]; then\n'
1081     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1082     txt += ' elif [[ $string = *Enterprise* ]] || [[ $string = *cientific* ]]; then\n'
1083     txt += ' export SCRAM_ARCH=slc3_ia32_gcc323\n'
1084     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1085     txt += ' else\n'
1086 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10033 ==> ERROR OS unknown, LCG environment not initialized"\n'
1087 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10033"\n'
1088     txt += ' echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
1089     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1090 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1091     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1092     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1093 gutsche 1.7 txt += ' exit 1\n'
1094 gutsche 1.3 txt += ' fi\n'
1095     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1096     txt += ' echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1097     return txt
1098 gutsche 1.5
1099     def setParam_(self, param, value):
1100     self._params[param] = value
1101    
1102     def getParams(self):
1103     return self._params
1104 gutsche 1.8
1105     def setTaskid_(self):
1106     self._taskId = self.cfg_params['taskId']
1107    
1108     def getTaskid(self):
1109     return self._taskId