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