ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.29
Committed: Fri Jul 7 12:30:18 2006 UTC (18 years, 9 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
Changes since 1.28: +4 -3 lines
Log Message:
additional_input_files is in USER section, not in CMSSW

File Contents

# User Rev Content
1 slacapra 1.1 from JobType import JobType
2     from crab_logger import Logger
3     from crab_exceptions import *
4     from crab_util import *
5 slacapra 1.22 import math
6 slacapra 1.1 import common
7 gutsche 1.3 import PsetManipulator
8 slacapra 1.1
9 gutsche 1.3 import DBSInfo_EDM
10     import DataDiscovery_EDM
11     import DataLocation_EDM
12 slacapra 1.1 import Scram
13    
14     import os, string, re
15    
16     class Cmssw(JobType):
17     def __init__(self, cfg_params):
18     JobType.__init__(self, 'CMSSW')
19     common.logger.debug(3,'CMSSW::__init__')
20    
21     self.analisys_common_info = {}
22 gutsche 1.3 # Marco.
23     self._params = {}
24     self.cfg_params = cfg_params
25 slacapra 1.1 log = common.logger
26    
27     self.scram = Scram.Scram(cfg_params)
28     scramArea = ''
29     self.additional_inbox_files = []
30     self.scriptExe = ''
31     self.executable = ''
32     self.tgz_name = 'default.tgz'
33    
34 gutsche 1.3
35 slacapra 1.1 self.version = self.scram.getSWVersion()
36 gutsche 1.5 self.setParam_('application', self.version)
37 slacapra 1.1 common.analisys_common_info['sw_version'] = self.version
38 gutsche 1.3 ### FEDE
39     common.analisys_common_info['copy_input_data'] = 0
40     common.analisys_common_info['events_management'] = 1
41 slacapra 1.1
42     ### collect Data cards
43     try:
44 slacapra 1.9 tmp = cfg_params['CMSSW.datasetpath']
45     log.debug(6, "CMSSW::CMSSW(): datasetPath = "+tmp)
46     if string.lower(tmp)=='none':
47     self.datasetPath = None
48 slacapra 1.21 self.selectNoInput = 1
49 slacapra 1.9 else:
50     self.datasetPath = tmp
51 slacapra 1.21 self.selectNoInput = 0
52 slacapra 1.1 except KeyError:
53 gutsche 1.3 msg = "Error: datasetpath not defined "
54 slacapra 1.1 raise CrabException(msg)
55 gutsche 1.5
56     # ML monitoring
57     # split dataset path style: /PreProdR3Minbias/SIM/GEN-SIM
58 slacapra 1.9 if not self.datasetPath:
59     self.setParam_('dataset', 'None')
60     self.setParam_('owner', 'None')
61     else:
62     datasetpath_split = self.datasetPath.split("/")
63     self.setParam_('dataset', datasetpath_split[1])
64     self.setParam_('owner', datasetpath_split[-1])
65    
66 gutsche 1.8 self.setTaskid_()
67     self.setParam_('taskId', self.cfg_params['taskId'])
68 gutsche 1.5
69 slacapra 1.1 self.dataTiers = []
70    
71     ## now the application
72     try:
73     self.executable = cfg_params['CMSSW.executable']
74 gutsche 1.5 self.setParam_('exe', self.executable)
75 slacapra 1.1 log.debug(6, "CMSSW::CMSSW(): executable = "+self.executable)
76     msg = "Default executable cmsRun overridden. Switch to " + self.executable
77     log.debug(3,msg)
78     except KeyError:
79     self.executable = 'cmsRun'
80 gutsche 1.5 self.setParam_('exe', self.executable)
81 slacapra 1.1 msg = "User executable not defined. Use cmsRun"
82     log.debug(3,msg)
83     pass
84    
85     try:
86     self.pset = cfg_params['CMSSW.pset']
87     log.debug(6, "Cmssw::Cmssw(): PSet file = "+self.pset)
88     if (not os.path.exists(self.pset)):
89     raise CrabException("User defined PSet file "+self.pset+" does not exist")
90     except KeyError:
91     raise CrabException("PSet file missing. Cannot run cmsRun ")
92    
93     # output files
94     try:
95     self.output_file = []
96    
97     tmp = cfg_params['CMSSW.output_file']
98     if tmp != '':
99     tmpOutFiles = string.split(cfg_params['CMSSW.output_file'],',')
100     log.debug(7, 'cmssw::cmssw(): output files '+str(tmpOutFiles))
101     for tmp in tmpOutFiles:
102     tmp=string.strip(tmp)
103     self.output_file.append(tmp)
104     pass
105     else:
106     log.message("No output file defined: only stdout/err will be available")
107     pass
108     pass
109     except KeyError:
110     log.message("No output file defined: only stdout/err will be available")
111     pass
112    
113     # script_exe file as additional file in inputSandbox
114     try:
115 slacapra 1.10 self.scriptExe = cfg_params['USER.script_exe']
116     self.additional_inbox_files.append(self.scriptExe)
117     if self.scriptExe != '':
118     if not os.path.isfile(self.scriptExe):
119     msg ="WARNING. file "+self.scriptExe+" not found"
120     raise CrabException(msg)
121 slacapra 1.1 except KeyError:
122     pass
123    
124     ## additional input files
125     try:
126 slacapra 1.29 tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
127     print self.additional_inbox_files
128 slacapra 1.1 for tmp in tmpAddFiles:
129 gutsche 1.3 if not os.path.exists(tmp):
130     raise CrabException("Additional input file not found: "+tmp)
131 slacapra 1.29 self.additional_inbox_files.append(string.strip(tmp))
132 slacapra 1.1 pass
133     pass
134     except KeyError:
135     pass
136 slacapra 1.29 print self.additional_inbox_files
137 slacapra 1.1
138 slacapra 1.9 # files per job
139 slacapra 1.1 try:
140 gutsche 1.3 self.filesPerJob = int(cfg_params['CMSSW.files_per_jobs']) #Daniele
141 slacapra 1.9 self.selectFilesPerJob = 1
142 gutsche 1.3 except KeyError:
143 slacapra 1.9 self.filesPerJob = 0
144     self.selectFilesPerJob = 0
145 gutsche 1.3
146 slacapra 1.9 ## Events per job
147 gutsche 1.3 try:
148 slacapra 1.10 self.eventsPerJob =int( cfg_params['CMSSW.events_per_job'])
149 slacapra 1.9 self.selectEventsPerJob = 1
150 gutsche 1.3 except KeyError:
151 slacapra 1.9 self.eventsPerJob = -1
152     self.selectEventsPerJob = 0
153    
154 slacapra 1.22 ## number of jobs
155     try:
156     self.theNumberOfJobs =int( cfg_params['CMSSW.number_of_jobs'])
157     self.selectNumberOfJobs = 1
158     except KeyError:
159     self.theNumberOfJobs = 0
160     self.selectNumberOfJobs = 0
161 slacapra 1.10
162 slacapra 1.22 ## source seed for pythia
163     try:
164     self.sourceSeed = int(cfg_params['CMSSW.pythia_seed'])
165     except KeyError:
166 slacapra 1.23 self.sourceSeed = None
167     common.logger.debug(5,"No seed given")
168 slacapra 1.22
169 slacapra 1.28 try:
170     self.sourceSeedVtx = int(cfg_params['CMSSW.vtx_seed'])
171     except KeyError:
172     self.sourceSeedVtx = None
173     common.logger.debug(5,"No vertex seed given")
174    
175 slacapra 1.22 if not (self.selectFilesPerJob + self.selectEventsPerJob + self.selectNumberOfJobs == 1 ):
176     msg = 'Must define either files_per_jobs or events_per_job or number_of_jobs'
177 slacapra 1.9 raise CrabException(msg)
178    
179 gutsche 1.3 try:
180 slacapra 1.1 self.total_number_of_events = int(cfg_params['CMSSW.total_number_of_events'])
181     except KeyError:
182 gutsche 1.3 msg = 'Must define total_number_of_events'
183 slacapra 1.1 raise CrabException(msg)
184    
185     CEBlackList = []
186     try:
187     tmpBad = string.split(cfg_params['EDG.ce_black_list'],',')
188     for tmp in tmpBad:
189     tmp=string.strip(tmp)
190     CEBlackList.append(tmp)
191     except KeyError:
192     pass
193    
194     self.reCEBlackList=[]
195     for bad in CEBlackList:
196     self.reCEBlackList.append(re.compile( bad ))
197    
198     common.logger.debug(5,'CEBlackList: '+str(CEBlackList))
199    
200     CEWhiteList = []
201     try:
202     tmpGood = string.split(cfg_params['EDG.ce_white_list'],',')
203     for tmp in tmpGood:
204     tmp=string.strip(tmp)
205     CEWhiteList.append(tmp)
206     except KeyError:
207     pass
208    
209     #print 'CEWhiteList: ',CEWhiteList
210     self.reCEWhiteList=[]
211     for Good in CEWhiteList:
212     self.reCEWhiteList.append(re.compile( Good ))
213    
214     common.logger.debug(5,'CEWhiteList: '+str(CEWhiteList))
215    
216 gutsche 1.3 self.PsetEdit = PsetManipulator.PsetManipulator(self.pset) #Daniele Pset
217    
218 slacapra 1.1 #DBSDLS-start
219     ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
220     self.maxEvents=0 # max events available ( --> check the requested nb. of evts in Creator.py)
221     self.DBSPaths={} # all dbs paths requested ( --> input to the site local discovery script)
222     ## Perform the data location and discovery (based on DBS/DLS)
223 slacapra 1.9 ## SL: Don't if NONE is specified as input (pythia use case)
224     common.analisys_common_info['sites']=None
225     if self.datasetPath:
226     self.DataDiscoveryAndLocation(cfg_params)
227 slacapra 1.1 #DBSDLS-end
228    
229     self.tgzNameWithPath = self.getTarBall(self.executable)
230 slacapra 1.10
231 slacapra 1.9 ## Select Splitting
232 slacapra 1.22 if self.selectNoInput: self.jobSplittingNoInput()
233     elif self.selectFilesPerJob or self.selectEventsPerJob or self.selectNumberOfJobs: self.jobSplittingPerFiles()
234 slacapra 1.9 else:
235     msg = 'Don\'t know how to split...'
236     raise CrabException(msg)
237 gutsche 1.5
238 slacapra 1.22 # modify Pset
239     try:
240     if (self.datasetPath): # standard job
241 slacapra 1.23 #self.PsetEdit.maxEvent(self.eventsPerJob)
242     # always process all events in a file
243     self.PsetEdit.maxEvent("-1")
244     self.PsetEdit.inputModule("INPUT")
245 slacapra 1.22
246     else: # pythia like job
247 slacapra 1.23 self.PsetEdit.maxEvent(self.eventsPerJob)
248     if (self.sourceSeed) :
249 slacapra 1.28 self.PsetEdit.pythiaSeed("INPUT")
250     if (self.sourceSeedVtx) :
251     self.PsetEdit.pythiaSeedVtx("INPUTVTX")
252 slacapra 1.22 self.PsetEdit.psetWriter(self.configFilename())
253     except:
254     msg='Error while manipuliating ParameterSet: exiting...'
255     raise CrabException(msg)
256 gutsche 1.3
257 slacapra 1.1 def DataDiscoveryAndLocation(self, cfg_params):
258    
259 gutsche 1.3 common.logger.debug(10,"CMSSW::DataDiscoveryAndLocation()")
260    
261     datasetPath=self.datasetPath
262    
263     ## TODO
264     dataTiersList = ""
265     dataTiers = dataTiersList.split(',')
266 slacapra 1.1
267     ## Contact the DBS
268     try:
269 afanfani 1.4 self.pubdata=DataDiscovery_EDM.DataDiscovery_EDM(datasetPath, dataTiers, cfg_params)
270 slacapra 1.1 self.pubdata.fetchDBSInfo()
271    
272 gutsche 1.3 except DataDiscovery_EDM.NotExistingDatasetError, ex :
273 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
274     raise CrabException(msg)
275    
276 gutsche 1.3 except DataDiscovery_EDM.NoDataTierinProvenanceError, ex :
277 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
278     raise CrabException(msg)
279 gutsche 1.3 except DataDiscovery_EDM.DataDiscoveryError, ex:
280 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS %s'%ex.getErrorMessage()
281     raise CrabException(msg)
282    
283     ## get list of all required data in the form of dbs paths (dbs path = /dataset/datatier/owner)
284 gutsche 1.3 ## self.DBSPaths=self.pubdata.getDBSPaths()
285     common.logger.message("Required data are :"+self.datasetPath)
286    
287     filesbyblock=self.pubdata.getFiles()
288 slacapra 1.21 # print filesbyblock
289 gutsche 1.3 self.AllInputFiles=filesbyblock.values()
290     self.files = self.AllInputFiles
291    
292 slacapra 1.1 ## get max number of events
293 gutsche 1.3 #common.logger.debug(10,"number of events for primary fileblocks %i"%self.pubdata.getMaxEvents())
294 slacapra 1.1 self.maxEvents=self.pubdata.getMaxEvents() ## self.maxEvents used in Creator.py
295     common.logger.message("\nThe number of available events is %s"%self.maxEvents)
296    
297     ## Contact the DLS and build a list of sites hosting the fileblocks
298     try:
299 gutsche 1.6 dataloc=DataLocation_EDM.DataLocation_EDM(filesbyblock.keys(),cfg_params)
300     dataloc.fetchDLSInfo()
301 gutsche 1.3 except DataLocation_EDM.DataLocationError , ex:
302 slacapra 1.1 msg = 'ERROR ***: failed Data Location in DLS \n %s '%ex.getErrorMessage()
303     raise CrabException(msg)
304    
305     allsites=dataloc.getSites()
306     common.logger.debug(5,"sites are %s"%allsites)
307     sites=self.checkBlackList(allsites)
308     common.logger.debug(5,"sites are (after black list) %s"%sites)
309     sites=self.checkWhiteList(sites)
310     common.logger.debug(5,"sites are (after white list) %s"%sites)
311    
312     if len(sites)==0:
313     msg = 'No sites hosting all the needed data! Exiting... '
314     raise CrabException(msg)
315 gutsche 1.3
316 slacapra 1.25 common.logger.message("List of Sites ("+str(len(sites))+") hosting the data : "+str(sites))
317 slacapra 1.1 common.logger.debug(6, "List of Sites: "+str(sites))
318     common.analisys_common_info['sites']=sites ## used in SchedulerEdg.py in createSchScript
319 gutsche 1.5 self.setParam_('TargetCE', ','.join(sites))
320 slacapra 1.1 return
321 gutsche 1.3
322 slacapra 1.9 def jobSplittingPerFiles(self):
323     """
324     Perform job splitting based on number of files to be accessed per job
325 gutsche 1.3 """
326 slacapra 1.9 common.logger.debug(5,'Splitting per input files')
327 gutsche 1.3 common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
328 slacapra 1.19 common.logger.message('Available '+str(self.maxEvents)+' events in total ')
329 slacapra 1.22 common.logger.message('Required '+str(self.filesPerJob)+' files per job ')
330     common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
331     common.logger.message('Required '+str(self.eventsPerJob)+' events per job')
332    
333     ## if asked to process all events, do it
334     if self.total_number_of_events == -1:
335     self.total_number_of_events=self.maxEvents
336     else:
337     if self.total_number_of_events>self.maxEvents:
338     common.logger.message("Asked "+str(self.total_number_of_events)+" but only "+str(self.maxEvents)+" available.")
339     self.total_number_of_events=self.maxEvents
340     pass
341 gutsche 1.3
342     ## TODO: SL need to have (from DBS) a detailed list of how many events per each file
343     n_tot_files = (len(self.files[0]))
344     ## SL: this is wrong if the files have different number of events
345     evPerFile = int(self.maxEvents)/n_tot_files
346 fanzago 1.12
347 gutsche 1.3 common.logger.debug(5,'Events per File '+str(evPerFile))
348    
349 slacapra 1.22 ## compute job splitting parameters: filesPerJob, eventsPerJob and theNumberOfJobs
350 slacapra 1.21 if self.selectFilesPerJob:
351 slacapra 1.22 ## user define files per event.
352 slacapra 1.21 filesPerJob = self.filesPerJob
353 slacapra 1.22 eventsPerJob = filesPerJob*evPerFile
354     theNumberOfJobs = int(self.total_number_of_events*1./eventsPerJob)
355     check = int(self.total_number_of_events) - (theNumberOfJobs*eventsPerJob)
356     if check > 0:
357     theNumberOfJobs +=1
358     filesLastJob = int(check*1./evPerFile+0.5)
359     common.logger.message('Warning: last job will be created with '+str(check)+' files')
360     else:
361     filesLastJob = filesPerJob
362    
363     elif self.selectNumberOfJobs:
364     ## User select the number of jobs: last might be bigger to match request of events
365     theNumberOfJobs = self.theNumberOfJobs
366    
367     eventsPerJob = self.total_number_of_events/theNumberOfJobs
368     filesPerJob = int(eventsPerJob/evPerFile)
369     if (filesPerJob==0) : filesPerJob=1
370     check = int(self.total_number_of_events) - (int(theNumberOfJobs)*filesPerJob*evPerFile)
371     if not check == 0:
372     if check<0:
373     missingFiles = int(check/evPerFile)
374     additionalJobs = int(missingFiles/filesPerJob)
375     #print missingFiles, additionalJobs
376     theNumberOfJobs+=additionalJobs
377     common.logger.message('Warning: will create only '+str(theNumberOfJobs)+' jobs')
378     check = int(self.total_number_of_events) - (int(theNumberOfJobs)*filesPerJob*evPerFile)
379    
380     if check >0 :
381     filesLastJob = filesPerJob+int(check*1./evPerFile+0.5)
382     common.logger.message('Warning: last job will be created with '+str(filesLastJob*evPerFile)+' events')
383     else:
384     filesLastJob = filesPerJob
385     else:
386     filesLastJob = filesPerJob
387 slacapra 1.21 elif self.selectEventsPerJob:
388     # SL case if asked events per job
389     ## estimate the number of files per job to match the user requirement
390 slacapra 1.22 filesPerJob = int(float(self.eventsPerJob)/float(evPerFile))
391 slacapra 1.23 if filesPerJob==0: filesPerJob=1
392 slacapra 1.22 common.logger.debug(5,"filesPerJob "+str(filesPerJob))
393 slacapra 1.21 if (filesPerJob==0): filesPerJob=1
394     eventsPerJob=filesPerJob*evPerFile
395 slacapra 1.23 theNumberOfJobs = int(self.total_number_of_events)/int(eventsPerJob)
396 slacapra 1.22 check = int(self.total_number_of_events) - (int(theNumberOfJobs)*eventsPerJob)
397     if not check == 0:
398     missingFiles = int(check/evPerFile)
399     additionalJobs = int(missingFiles/filesPerJob)
400     if ( additionalJobs>0) : theNumberOfJobs+=additionalJobs
401     check = int(self.total_number_of_events) - (int(theNumberOfJobs)*eventsPerJob)
402     if not check == 0:
403     if (check <0 ):
404     filesLastJob = filesPerJob+int(check*1./evPerFile-0.5)
405     else:
406 slacapra 1.23 theNumberOfJobs+=1
407 slacapra 1.22 filesLastJob = int(check*1./evPerFile+0.5)
408 slacapra 1.23
409 slacapra 1.22 common.logger.message('Warning: last job will be created with '+str(filesLastJob*evPerFile)+' events')
410     else:
411     filesLastJob = filesPerJob
412     else:
413     filesLastJob = filesPerJob
414 slacapra 1.21
415 slacapra 1.22 self.total_number_of_jobs = theNumberOfJobs
416 gutsche 1.3
417 slacapra 1.22 totalEventsToBeUsed=theNumberOfJobs*filesPerJob*evPerFile
418     if not check == 0:
419 slacapra 1.23 # print (theNumberOfJobs-1)*filesPerJob*evPerFile,filesLastJob*evPerFile
420 slacapra 1.22 totalEventsToBeUsed=(theNumberOfJobs-1)*filesPerJob*evPerFile+filesLastJob*evPerFile
421 gutsche 1.3
422 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')
423 gutsche 1.3
424 slacapra 1.22 totalFilesToBeUsed=filesPerJob*(theNumberOfJobs-1)+filesLastJob
425 gutsche 1.3
426 slacapra 1.22 ## set job arguments (files)
427 gutsche 1.3 list_of_lists = []
428 slacapra 1.22 lastFile=0
429     for i in range(0, int(totalFilesToBeUsed), filesPerJob)[:-1]:
430 slacapra 1.9 parString = "\\{"
431    
432 slacapra 1.22 lastFile=i+filesPerJob
433     params = self.files[0][i: lastFile]
434 slacapra 1.9 for i in range(len(params) - 1):
435     parString += '\\\"' + params[i] + '\\\"\,'
436    
437     parString += '\\\"' + params[len(params) - 1] + '\\\"\\}'
438 slacapra 1.17 list_of_lists.append([parString])
439 slacapra 1.9 pass
440    
441 slacapra 1.22 ## last job
442     parString = "\\{"
443    
444     params = self.files[0][lastFile: lastFile+filesLastJob]
445     for i in range(len(params) - 1):
446     parString += '\\\"' + params[i] + '\\\"\,'
447 slacapra 1.20
448 slacapra 1.22 parString += '\\\"' + params[len(params) - 1] + '\\\"\\}'
449     list_of_lists.append([parString])
450     pass
451 slacapra 1.20
452 slacapra 1.9 self.list_of_args = list_of_lists
453 slacapra 1.20 # print self.list_of_args[0]
454 slacapra 1.9 return
455    
456 slacapra 1.21 def jobSplittingNoInput(self):
457 slacapra 1.9 """
458     Perform job splitting based on number of event per job
459     """
460     common.logger.debug(5,'Splitting per events')
461     common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
462 slacapra 1.22 common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
463 slacapra 1.9 common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
464    
465 slacapra 1.10 if (self.total_number_of_events < 0):
466     msg='Cannot split jobs per Events with "-1" as total number of events'
467     raise CrabException(msg)
468    
469 slacapra 1.22 if (self.selectEventsPerJob):
470     self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
471     elif (self.selectNumberOfJobs) :
472     self.total_number_of_jobs = self.theNumberOfJobs
473     self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
474 fanzago 1.12
475 slacapra 1.9 common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
476    
477     # is there any remainder?
478     check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
479    
480     common.logger.debug(5,'Check '+str(check))
481    
482 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')
483 slacapra 1.9 if check > 0:
484 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))
485 slacapra 1.9
486    
487 slacapra 1.10 # argument is seed number.$i
488 slacapra 1.9 self.list_of_args = []
489     for i in range(self.total_number_of_jobs):
490 slacapra 1.23 if (self.sourceSeed):
491 slacapra 1.28 if (self.sourceSeedVtx):
492     ## pythia + vtx random seed
493     self.list_of_args.append([
494     str(self.sourceSeed)+str(i),
495     str(self.sourceSeedVtx)+str(i)
496     ])
497     else:
498     ## only pythia random seed
499     self.list_of_args.append([(str(self.sourceSeed)+str(i))])
500 slacapra 1.23 else:
501 slacapra 1.28 ## no random seed
502 slacapra 1.23 self.list_of_args.append([str(i)])
503 slacapra 1.17 #print self.list_of_args
504 gutsche 1.3
505     return
506    
507     def split(self, jobParams):
508    
509     common.jobDB.load()
510     #### Fabio
511     njobs = self.total_number_of_jobs
512 slacapra 1.9 arglist = self.list_of_args
513 gutsche 1.3 # create the empty structure
514     for i in range(njobs):
515     jobParams.append("")
516    
517     for job in range(njobs):
518 slacapra 1.17 jobParams[job] = arglist[job]
519     # print str(arglist[job])
520     # print jobParams[job]
521 gutsche 1.3 common.jobDB.setArguments(job, jobParams[job])
522    
523     common.jobDB.save()
524     return
525    
526     def getJobTypeArguments(self, nj, sched):
527 slacapra 1.17 result = ''
528     for i in common.jobDB.arguments(nj):
529     result=result+str(i)+" "
530     return result
531 gutsche 1.3
532     def numberOfJobs(self):
533     # Fabio
534     return self.total_number_of_jobs
535    
536 slacapra 1.1 def checkBlackList(self, allSites):
537     if len(self.reCEBlackList)==0: return allSites
538     sites = []
539     for site in allSites:
540     common.logger.debug(10,'Site '+site)
541     good=1
542     for re in self.reCEBlackList:
543     if re.search(site):
544     common.logger.message('CE in black list, skipping site '+site)
545     good=0
546     pass
547     if good: sites.append(site)
548     if len(sites) == 0:
549     common.logger.debug(3,"No sites found after BlackList")
550     return sites
551    
552 gutsche 1.3 def checkWhiteList(self, allSites):
553 slacapra 1.1
554 gutsche 1.3 if len(self.reCEWhiteList)==0: return allSites
555 slacapra 1.1 sites = []
556 gutsche 1.3 for site in allSites:
557 slacapra 1.1 good=0
558     for re in self.reCEWhiteList:
559     if re.search(site):
560     common.logger.debug(5,'CE in white list, adding site '+site)
561     good=1
562     if not good: continue
563     sites.append(site)
564     if len(sites) == 0:
565     common.logger.message("No sites found after WhiteList\n")
566     else:
567     common.logger.debug(5,"Selected sites via WhiteList are "+str(sites)+"\n")
568     return sites
569    
570     def getTarBall(self, exe):
571     """
572     Return the TarBall with lib and exe
573     """
574    
575     # if it exist, just return it
576     self.tgzNameWithPath = common.work_space.shareDir()+self.tgz_name
577     if os.path.exists(self.tgzNameWithPath):
578     return self.tgzNameWithPath
579    
580     # Prepare a tar gzipped file with user binaries.
581     self.buildTar_(exe)
582    
583     return string.strip(self.tgzNameWithPath)
584    
585     def buildTar_(self, executable):
586    
587     # First of all declare the user Scram area
588     swArea = self.scram.getSWArea_()
589     #print "swArea = ", swArea
590     swVersion = self.scram.getSWVersion()
591     #print "swVersion = ", swVersion
592     swReleaseTop = self.scram.getReleaseTop_()
593     #print "swReleaseTop = ", swReleaseTop
594    
595     ## check if working area is release top
596     if swReleaseTop == '' or swArea == swReleaseTop:
597     return
598    
599     filesToBeTarred = []
600     ## First find the executable
601     if (self.executable != ''):
602     exeWithPath = self.scram.findFile_(executable)
603     # print exeWithPath
604     if ( not exeWithPath ):
605     raise CrabException('User executable '+executable+' not found')
606    
607     ## then check if it's private or not
608     if exeWithPath.find(swReleaseTop) == -1:
609     # the exe is private, so we must ship
610     common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
611     path = swArea+'/'
612     exe = string.replace(exeWithPath, path,'')
613     filesToBeTarred.append(exe)
614     pass
615     else:
616     # the exe is from release, we'll find it on WN
617     pass
618    
619     ## Now get the libraries: only those in local working area
620     libDir = 'lib'
621     lib = swArea+'/' +libDir
622     common.logger.debug(5,"lib "+lib+" to be tarred")
623     if os.path.exists(lib):
624     filesToBeTarred.append(libDir)
625    
626 gutsche 1.3 ## Now check if module dir is present
627     moduleDir = 'module'
628     if os.path.isdir(swArea+'/'+moduleDir):
629     filesToBeTarred.append(moduleDir)
630    
631 slacapra 1.1 ## Now check if the Data dir is present
632     dataDir = 'src/Data/'
633     if os.path.isdir(swArea+'/'+dataDir):
634     filesToBeTarred.append(dataDir)
635    
636     ## Create the tar-ball
637     if len(filesToBeTarred)>0:
638     cwd = os.getcwd()
639     os.chdir(swArea)
640     tarcmd = 'tar zcvf ' + self.tgzNameWithPath + ' '
641     for line in filesToBeTarred:
642     tarcmd = tarcmd + line + ' '
643     cout = runCommand(tarcmd)
644     if not cout:
645     raise CrabException('Could not create tar-ball')
646     os.chdir(cwd)
647     else:
648     common.logger.debug(5,"No files to be to be tarred")
649    
650     return
651    
652     def wsSetupEnvironment(self, nj):
653     """
654     Returns part of a job script which prepares
655     the execution environment for the job 'nj'.
656     """
657     # Prepare JobType-independent part
658 gutsche 1.3 txt = ''
659    
660     ## OLI_Daniele at this level middleware already known
661    
662     txt += 'if [ $middleware == LCG ]; then \n'
663     txt += self.wsSetupCMSLCGEnvironment_()
664     txt += 'elif [ $middleware == OSG ]; then\n'
665     txt += ' time=`date -u +"%s"`\n'
666     txt += ' WORKING_DIR=$OSG_WN_TMP/cms_$time\n'
667     txt += ' echo "Creating working directory: $WORKING_DIR"\n'
668     txt += ' /bin/mkdir -p $WORKING_DIR\n'
669     txt += ' if [ ! -d $WORKING_DIR ] ;then\n'
670 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
671     txt += ' echo "JOB_EXIT_STATUS = 10016"\n'
672     txt += ' echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
673     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
674 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
675     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
676     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
677 gutsche 1.3 txt += ' exit 1\n'
678     txt += ' fi\n'
679     txt += '\n'
680     txt += ' echo "Change to working directory: $WORKING_DIR"\n'
681     txt += ' cd $WORKING_DIR\n'
682     txt += self.wsSetupCMSOSGEnvironment_()
683     txt += 'fi\n'
684 slacapra 1.1
685     # Prepare JobType-specific part
686     scram = self.scram.commandName()
687     txt += '\n\n'
688     txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
689     txt += scram+' project CMSSW '+self.version+'\n'
690     txt += 'status=$?\n'
691     txt += 'if [ $status != 0 ] ; then\n'
692 gutsche 1.7 txt += ' echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
693 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10034"\n'
694 gutsche 1.7 txt += ' echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
695 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
696 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
697     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
698     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
699 gutsche 1.3 ## OLI_Daniele
700     txt += ' if [ $middleware == OSG ]; then \n'
701     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
702     txt += ' cd $RUNTIME_AREA\n'
703     txt += ' /bin/rm -rf $WORKING_DIR\n'
704     txt += ' if [ -d $WORKING_DIR ] ;then\n'
705 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'
706     txt += ' echo "JOB_EXIT_STATUS = 10018"\n'
707     txt += ' echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
708     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
709 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
710     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
711     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
712 gutsche 1.3 txt += ' fi\n'
713     txt += ' fi \n'
714     txt += ' exit 1 \n'
715 slacapra 1.1 txt += 'fi \n'
716     txt += 'echo "CMSSW_VERSION = '+self.version+'"\n'
717     txt += 'cd '+self.version+'\n'
718     ### needed grep for bug in scramv1 ###
719     txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
720    
721     # Handle the arguments:
722     txt += "\n"
723 gutsche 1.7 txt += "## number of arguments (first argument always jobnumber)\n"
724 slacapra 1.1 txt += "\n"
725     txt += "narg=$#\n"
726 gutsche 1.3 txt += "if [ $narg -lt 2 ]\n"
727 slacapra 1.1 txt += "then\n"
728     txt += " echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$narg+ \n"
729 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
730 gutsche 1.7 txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
731 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
732 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
733     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
734     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
735 gutsche 1.3 ## OLI_Daniele
736     txt += ' if [ $middleware == OSG ]; then \n'
737     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
738     txt += ' cd $RUNTIME_AREA\n'
739     txt += ' /bin/rm -rf $WORKING_DIR\n'
740     txt += ' if [ -d $WORKING_DIR ] ;then\n'
741 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'
742     txt += ' echo "JOB_EXIT_STATUS = 50114"\n'
743     txt += ' echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
744     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
745 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
746     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
747     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
748 gutsche 1.3 txt += ' fi\n'
749     txt += ' fi \n'
750 slacapra 1.1 txt += " exit 1\n"
751     txt += "fi\n"
752     txt += "\n"
753    
754     # Prepare job-specific part
755     job = common.job_list[nj]
756     pset = os.path.basename(job.configFilename())
757     txt += '\n'
758 slacapra 1.10 if (self.datasetPath): # standard job
759     txt += 'InputFiles=$2\n'
760     txt += 'echo "Inputfiles:<$InputFiles>"\n'
761     txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset.cfg\n'
762     else: # pythia like job
763 slacapra 1.23 if (self.sourceSeed):
764     txt += 'Seed=$2\n'
765     txt += 'echo "Seed: <$Seed>"\n'
766 slacapra 1.28 txt += 'sed "s#\<INPUT\>#$Seed#" $RUNTIME_AREA/'+pset+' > tmp.cfg\n'
767     if (self.sourceSeedVtx):
768     txt += 'VtxSeed=$3\n'
769     txt += 'echo "VtxSeed: <$VtxSeed>"\n'
770     txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp.cfg > pset.cfg\n'
771     else:
772     txt += 'mv tmp.cfg pset.cfg\n'
773 slacapra 1.24 else:
774     txt += '# Copy untouched pset\n'
775 slacapra 1.26 txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
776 slacapra 1.24
777 slacapra 1.1
778     if len(self.additional_inbox_files) > 0:
779     for file in self.additional_inbox_files:
780     txt += 'if [ -e $RUNTIME_AREA/'+file+' ] ; then\n'
781     txt += ' cp $RUNTIME_AREA/'+file+' .\n'
782     txt += ' chmod +x '+file+'\n'
783     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