ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.30.2.1
Committed: Thu Jul 27 15:02:28 2006 UTC (18 years, 9 months ago) by spiga
Content type: text/x-python
Branch: CRAB_BOSS4
Changes since 1.30: +27 -10 lines
Log Message:
fix for xml syntax using 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 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 spiga 1.30.2.1 # parString += '\\\"' + params[i] + '\\\"\,'
434     parString += '&quot;' + params[i] + '&quot;\,'
435    
436     # parString += '\\\"' + params[len(params) - 1] + '\\\"\\}'
437     parString += '&quot;' + params[len(params) - 1] + '&quot;\\}'
438    
439 slacapra 1.17 list_of_lists.append([parString])
440 slacapra 1.9 pass
441    
442 slacapra 1.22 ## last job
443     parString = "\\{"
444    
445     params = self.files[0][lastFile: lastFile+filesLastJob]
446     for i in range(len(params) - 1):
447 spiga 1.30.2.1 # parString += '\\\"' + params[i] + '\\\"\,'
448     parString += '&quot;' + params[i] + '&quot;\,'
449    
450    
451     # parString += '\\\"' + params[len(params) - 1] + '\\\"\\}'
452     parString += '&quot;' + params[len(params) - 1] + '&quot;\\}'
453 slacapra 1.22 list_of_lists.append([parString])
454     pass
455 slacapra 1.20
456 slacapra 1.9 self.list_of_args = list_of_lists
457 slacapra 1.20 # print self.list_of_args[0]
458 slacapra 1.9 return
459    
460 slacapra 1.21 def jobSplittingNoInput(self):
461 slacapra 1.9 """
462     Perform job splitting based on number of event per job
463     """
464     common.logger.debug(5,'Splitting per events')
465     common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
466 slacapra 1.22 common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
467 slacapra 1.9 common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
468    
469 slacapra 1.10 if (self.total_number_of_events < 0):
470     msg='Cannot split jobs per Events with "-1" as total number of events'
471     raise CrabException(msg)
472    
473 slacapra 1.22 if (self.selectEventsPerJob):
474     self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
475     elif (self.selectNumberOfJobs) :
476     self.total_number_of_jobs = self.theNumberOfJobs
477     self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
478 fanzago 1.12
479 slacapra 1.9 common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
480    
481     # is there any remainder?
482     check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
483    
484     common.logger.debug(5,'Check '+str(check))
485    
486 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')
487 slacapra 1.9 if check > 0:
488 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))
489 slacapra 1.9
490    
491 slacapra 1.10 # argument is seed number.$i
492 slacapra 1.9 self.list_of_args = []
493     for i in range(self.total_number_of_jobs):
494 slacapra 1.23 if (self.sourceSeed):
495 slacapra 1.28 if (self.sourceSeedVtx):
496     ## pythia + vtx random seed
497     self.list_of_args.append([
498     str(self.sourceSeed)+str(i),
499     str(self.sourceSeedVtx)+str(i)
500     ])
501     else:
502     ## only pythia random seed
503     self.list_of_args.append([(str(self.sourceSeed)+str(i))])
504 slacapra 1.23 else:
505 slacapra 1.28 ## no random seed
506 slacapra 1.23 self.list_of_args.append([str(i)])
507 slacapra 1.17 #print self.list_of_args
508 gutsche 1.3
509     return
510    
511     def split(self, jobParams):
512    
513     common.jobDB.load()
514     #### Fabio
515     njobs = self.total_number_of_jobs
516 slacapra 1.9 arglist = self.list_of_args
517 gutsche 1.3 # create the empty structure
518     for i in range(njobs):
519     jobParams.append("")
520    
521     for job in range(njobs):
522 slacapra 1.17 jobParams[job] = arglist[job]
523     # print str(arglist[job])
524     # print jobParams[job]
525 gutsche 1.3 common.jobDB.setArguments(job, jobParams[job])
526    
527     common.jobDB.save()
528     return
529    
530     def getJobTypeArguments(self, nj, sched):
531 spiga 1.30.2.1 # result = ''
532     # for i in common.jobDB.arguments(nj):
533     # result=result+str(i)+" "
534     # return result
535     params = common.jobDB.arguments(nj)
536     #print params
537     parString = "\\{"
538    
539     for i in range(len(params) - 1):
540     # parString += '\\\"' + params[i] + '\\\"\,'
541     parString += '&quot;' + params[i] + '&quot;\,'
542    
543     # parString += '\\\"' + params[len(params) - 1] + '\\\"\\}'
544     parString += '&quot;' + params[len(params) - 1] + '&quot;\\}'
545     return parString
546 gutsche 1.3
547     def numberOfJobs(self):
548     # Fabio
549     return self.total_number_of_jobs
550    
551 slacapra 1.1 def checkBlackList(self, allSites):
552     if len(self.reCEBlackList)==0: return allSites
553     sites = []
554     for site in allSites:
555     common.logger.debug(10,'Site '+site)
556     good=1
557     for re in self.reCEBlackList:
558     if re.search(site):
559     common.logger.message('CE in black list, skipping site '+site)
560     good=0
561     pass
562     if good: sites.append(site)
563     if len(sites) == 0:
564     common.logger.debug(3,"No sites found after BlackList")
565     return sites
566    
567 gutsche 1.3 def checkWhiteList(self, allSites):
568 slacapra 1.1
569 gutsche 1.3 if len(self.reCEWhiteList)==0: return allSites
570 slacapra 1.1 sites = []
571 gutsche 1.3 for site in allSites:
572 slacapra 1.1 good=0
573     for re in self.reCEWhiteList:
574     if re.search(site):
575     common.logger.debug(5,'CE in white list, adding site '+site)
576     good=1
577     if not good: continue
578     sites.append(site)
579     if len(sites) == 0:
580     common.logger.message("No sites found after WhiteList\n")
581     else:
582     common.logger.debug(5,"Selected sites via WhiteList are "+str(sites)+"\n")
583     return sites
584    
585     def getTarBall(self, exe):
586     """
587     Return the TarBall with lib and exe
588     """
589    
590     # if it exist, just return it
591     self.tgzNameWithPath = common.work_space.shareDir()+self.tgz_name
592     if os.path.exists(self.tgzNameWithPath):
593     return self.tgzNameWithPath
594    
595     # Prepare a tar gzipped file with user binaries.
596     self.buildTar_(exe)
597    
598     return string.strip(self.tgzNameWithPath)
599    
600     def buildTar_(self, executable):
601    
602     # First of all declare the user Scram area
603     swArea = self.scram.getSWArea_()
604     #print "swArea = ", swArea
605     swVersion = self.scram.getSWVersion()
606     #print "swVersion = ", swVersion
607     swReleaseTop = self.scram.getReleaseTop_()
608     #print "swReleaseTop = ", swReleaseTop
609    
610     ## check if working area is release top
611     if swReleaseTop == '' or swArea == swReleaseTop:
612     return
613    
614     filesToBeTarred = []
615     ## First find the executable
616     if (self.executable != ''):
617     exeWithPath = self.scram.findFile_(executable)
618     # print exeWithPath
619     if ( not exeWithPath ):
620     raise CrabException('User executable '+executable+' not found')
621    
622     ## then check if it's private or not
623     if exeWithPath.find(swReleaseTop) == -1:
624     # the exe is private, so we must ship
625     common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
626     path = swArea+'/'
627     exe = string.replace(exeWithPath, path,'')
628     filesToBeTarred.append(exe)
629     pass
630     else:
631     # the exe is from release, we'll find it on WN
632     pass
633    
634     ## Now get the libraries: only those in local working area
635     libDir = 'lib'
636     lib = swArea+'/' +libDir
637     common.logger.debug(5,"lib "+lib+" to be tarred")
638     if os.path.exists(lib):
639     filesToBeTarred.append(libDir)
640    
641 gutsche 1.3 ## Now check if module dir is present
642     moduleDir = 'module'
643     if os.path.isdir(swArea+'/'+moduleDir):
644     filesToBeTarred.append(moduleDir)
645    
646 slacapra 1.1 ## Now check if the Data dir is present
647     dataDir = 'src/Data/'
648     if os.path.isdir(swArea+'/'+dataDir):
649     filesToBeTarred.append(dataDir)
650    
651     ## Create the tar-ball
652     if len(filesToBeTarred)>0:
653     cwd = os.getcwd()
654     os.chdir(swArea)
655     tarcmd = 'tar zcvf ' + self.tgzNameWithPath + ' '
656     for line in filesToBeTarred:
657     tarcmd = tarcmd + line + ' '
658     cout = runCommand(tarcmd)
659     if not cout:
660     raise CrabException('Could not create tar-ball')
661     os.chdir(cwd)
662     else:
663     common.logger.debug(5,"No files to be to be tarred")
664    
665     return
666    
667     def wsSetupEnvironment(self, nj):
668     """
669     Returns part of a job script which prepares
670     the execution environment for the job 'nj'.
671     """
672     # Prepare JobType-independent part
673 gutsche 1.3 txt = ''
674    
675     ## OLI_Daniele at this level middleware already known
676    
677     txt += 'if [ $middleware == LCG ]; then \n'
678     txt += self.wsSetupCMSLCGEnvironment_()
679     txt += 'elif [ $middleware == OSG ]; then\n'
680     txt += ' time=`date -u +"%s"`\n'
681     txt += ' WORKING_DIR=$OSG_WN_TMP/cms_$time\n'
682     txt += ' echo "Creating working directory: $WORKING_DIR"\n'
683     txt += ' /bin/mkdir -p $WORKING_DIR\n'
684     txt += ' if [ ! -d $WORKING_DIR ] ;then\n'
685 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
686     txt += ' echo "JOB_EXIT_STATUS = 10016"\n'
687     txt += ' echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
688     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
689 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
690     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
691     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
692 gutsche 1.3 txt += ' exit 1\n'
693     txt += ' fi\n'
694     txt += '\n'
695     txt += ' echo "Change to working directory: $WORKING_DIR"\n'
696     txt += ' cd $WORKING_DIR\n'
697     txt += self.wsSetupCMSOSGEnvironment_()
698     txt += 'fi\n'
699 slacapra 1.1
700     # Prepare JobType-specific part
701     scram = self.scram.commandName()
702     txt += '\n\n'
703     txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
704     txt += scram+' project CMSSW '+self.version+'\n'
705     txt += 'status=$?\n'
706     txt += 'if [ $status != 0 ] ; then\n'
707 gutsche 1.7 txt += ' echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
708 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10034"\n'
709 gutsche 1.7 txt += ' echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
710 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
711 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
712     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
713     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
714 gutsche 1.3 ## OLI_Daniele
715     txt += ' if [ $middleware == OSG ]; then \n'
716     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
717     txt += ' cd $RUNTIME_AREA\n'
718     txt += ' /bin/rm -rf $WORKING_DIR\n'
719     txt += ' if [ -d $WORKING_DIR ] ;then\n'
720 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'
721     txt += ' echo "JOB_EXIT_STATUS = 10018"\n'
722     txt += ' echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
723     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
724 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
725     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
726     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
727 gutsche 1.3 txt += ' fi\n'
728     txt += ' fi \n'
729     txt += ' exit 1 \n'
730 slacapra 1.1 txt += 'fi \n'
731     txt += 'echo "CMSSW_VERSION = '+self.version+'"\n'
732     txt += 'cd '+self.version+'\n'
733     ### needed grep for bug in scramv1 ###
734     txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
735    
736     # Handle the arguments:
737     txt += "\n"
738 gutsche 1.7 txt += "## number of arguments (first argument always jobnumber)\n"
739 slacapra 1.1 txt += "\n"
740     txt += "narg=$#\n"
741 gutsche 1.3 txt += "if [ $narg -lt 2 ]\n"
742 slacapra 1.1 txt += "then\n"
743     txt += " echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$narg+ \n"
744 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
745 gutsche 1.7 txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
746 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
747 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
748     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
749     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
750 gutsche 1.3 ## OLI_Daniele
751     txt += ' if [ $middleware == OSG ]; then \n'
752     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
753     txt += ' cd $RUNTIME_AREA\n'
754     txt += ' /bin/rm -rf $WORKING_DIR\n'
755     txt += ' if [ -d $WORKING_DIR ] ;then\n'
756 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'
757     txt += ' echo "JOB_EXIT_STATUS = 50114"\n'
758     txt += ' echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
759     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
760 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
761     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
762     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
763 gutsche 1.3 txt += ' fi\n'
764     txt += ' fi \n'
765 slacapra 1.1 txt += " exit 1\n"
766     txt += "fi\n"
767     txt += "\n"
768    
769     # Prepare job-specific part
770     job = common.job_list[nj]
771     pset = os.path.basename(job.configFilename())
772     txt += '\n'
773 slacapra 1.10 if (self.datasetPath): # standard job
774     txt += 'InputFiles=$2\n'
775     txt += 'echo "Inputfiles:<$InputFiles>"\n'
776     txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset.cfg\n'
777     else: # pythia like job
778 slacapra 1.23 if (self.sourceSeed):
779     txt += 'Seed=$2\n'
780     txt += 'echo "Seed: <$Seed>"\n'
781 slacapra 1.28 txt += 'sed "s#\<INPUT\>#$Seed#" $RUNTIME_AREA/'+pset+' > tmp.cfg\n'
782     if (self.sourceSeedVtx):
783     txt += 'VtxSeed=$3\n'
784     txt += 'echo "VtxSeed: <$VtxSeed>"\n'
785     txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp.cfg > pset.cfg\n'
786     else:
787     txt += 'mv tmp.cfg pset.cfg\n'
788 slacapra 1.24 else:
789     txt += '# Copy untouched pset\n'
790 slacapra 1.26 txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
791 slacapra 1.24
792 slacapra 1.1
793     if len(self.additional_inbox_files) > 0:
794     for file in self.additional_inbox_files:
795     txt += 'if [ -e $RUNTIME_AREA/'+file+' ] ; then\n'
796     txt += ' cp $RUNTIME_AREA/'+file+' .\n'
797     txt += ' chmod +x '+file+'\n'
798     txt += 'fi\n'
799     pass
800    
801     txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
802    
803     txt += '\n'
804     txt += 'echo "***** cat pset.cfg *********"\n'
805     txt += 'cat pset.cfg\n'
806     txt += 'echo "****** end pset.cfg ********"\n'
807 gutsche 1.3 txt += '\n'
808     # txt += 'echo "***** cat pset1.cfg *********"\n'
809     # txt += 'cat pset1.cfg\n'
810     # txt += 'echo "****** end pset1.cfg ********"\n'
811     return txt
812    
813     def wsBuildExe(self, nj):
814     """
815     Put in the script the commands to build an executable
816     or a library.
817     """
818    
819     txt = ""
820    
821     if os.path.isfile(self.tgzNameWithPath):
822     txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
823     txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
824     txt += 'untar_status=$? \n'
825     txt += 'if [ $untar_status -ne 0 ]; then \n'
826     txt += ' echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
827     txt += ' echo "JOB_EXIT_STATUS = $untar_status" \n'
828 gutsche 1.7 txt += ' echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
829 gutsche 1.3 txt += ' if [ $middleware == OSG ]; then \n'
830     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
831     txt += ' cd $RUNTIME_AREA\n'
832     txt += ' /bin/rm -rf $WORKING_DIR\n'
833     txt += ' if [ -d $WORKING_DIR ] ;then\n'
834 gutsche 1.13 txt += ' echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
835     txt += ' echo "JOB_EXIT_STATUS = 50999"\n'
836     txt += ' echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
837     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
838     txt += ' rm -f $RUNTIME_AREA/$repo \n'
839     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
840     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
841 gutsche 1.3 txt += ' fi\n'
842     txt += ' fi \n'
843     txt += ' \n'
844 gutsche 1.7 txt += ' exit 1 \n'
845 gutsche 1.3 txt += 'else \n'
846     txt += ' echo "Successful untar" \n'
847     txt += 'fi \n'
848     pass
849    
850 slacapra 1.1 return txt
851    
852     def modifySteeringCards(self, nj):
853     """
854     modify the card provided by the user,
855     writing a new card into share dir
856     """
857    
858     def executableName(self):
859     return self.executable
860    
861     def executableArgs(self):
862 gutsche 1.3 return " -p pset.cfg"
863 slacapra 1.1
864     def inputSandbox(self, nj):
865     """
866     Returns a list of filenames to be put in JDL input sandbox.
867     """
868     inp_box = []
869     # dict added to delete duplicate from input sandbox file list
870     seen = {}
871     ## code
872     if os.path.isfile(self.tgzNameWithPath):
873     inp_box.append(self.tgzNameWithPath)
874     ## config
875     inp_box.append(common.job_list[nj].configFilename())
876     ## additional input files
877 gutsche 1.3 #for file in self.additional_inbox_files:
878     # inp_box.append(common.work_space.cwdDir()+file)
879 slacapra 1.1 return inp_box
880    
881     def outputSandbox(self, nj):
882     """
883     Returns a list of filenames to be put in JDL output sandbox.
884     """
885     out_box = []
886    
887     stdout=common.job_list[nj].stdout()
888     stderr=common.job_list[nj].stderr()
889    
890     ## User Declared output files
891     for out in self.output_file:
892     n_out = nj + 1
893     out_box.append(self.numberFile_(out,str(n_out)))
894     return out_box
895     return []
896    
897     def prepareSteeringCards(self):
898     """
899     Make initial modifications of the user's steering card file.
900     """
901     return
902    
903     def wsRenameOutput(self, nj):
904     """
905     Returns part of a job script which renames the produced files.
906     """
907    
908     txt = '\n'
909 gutsche 1.7 txt += '# directory content\n'
910     txt += 'ls \n'
911 slacapra 1.1 file_list = ''
912     for fileWithSuffix in self.output_file:
913     output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
914 gutsche 1.7 file_list=file_list+output_file_num+' '
915 slacapra 1.1 txt += '\n'
916 gutsche 1.7 txt += '# check output file\n'
917 slacapra 1.1 txt += 'ls '+fileWithSuffix+'\n'
918 fanzago 1.18 txt += 'ls_result=$?\n'
919     #txt += 'exe_result=$?\n'
920     txt += 'if [ $ls_result -ne 0 ] ; then\n'
921     txt += ' echo "ERROR: Problem with output file"\n'
922     #txt += ' echo "JOB_EXIT_STATUS = $exe_result"\n'
923     #txt += ' echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
924     #txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
925 gutsche 1.3 ### OLI_DANIELE
926 gutsche 1.7 if common.scheduler.boss_scheduler_name == 'condor_g':
927     txt += ' if [ $middleware == OSG ]; then \n'
928     txt += ' echo "prepare dummy output file"\n'
929     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
930     txt += ' fi \n'
931 slacapra 1.1 txt += 'else\n'
932     txt += ' cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
933     txt += 'fi\n'
934    
935 gutsche 1.7 txt += 'cd $RUNTIME_AREA\n'
936 slacapra 1.1 file_list=file_list[:-1]
937 slacapra 1.2 txt += 'file_list="'+file_list+'"\n'
938 fanzago 1.18 txt += 'cd $RUNTIME_AREA\n'
939 gutsche 1.3 ### OLI_DANIELE
940     txt += 'if [ $middleware == OSG ]; then\n'
941     txt += ' cd $RUNTIME_AREA\n'
942     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
943     txt += ' /bin/rm -rf $WORKING_DIR\n'
944     txt += ' if [ -d $WORKING_DIR ] ;then\n'
945 gutsche 1.7 txt += ' echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
946     txt += ' echo "JOB_EXIT_STATUS = 60999"\n'
947     txt += ' echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
948     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
949 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
950     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
951     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
952 gutsche 1.3 txt += ' fi\n'
953     txt += 'fi\n'
954     txt += '\n'
955 slacapra 1.1 return txt
956    
957     def numberFile_(self, file, txt):
958     """
959     append _'txt' before last extension of a file
960     """
961     p = string.split(file,".")
962     # take away last extension
963     name = p[0]
964     for x in p[1:-1]:
965     name=name+"."+x
966     # add "_txt"
967     if len(p)>1:
968     ext = p[len(p)-1]
969     #result = name + '_' + str(txt) + "." + ext
970     result = name + '_' + txt + "." + ext
971     else:
972     #result = name + '_' + str(txt)
973     result = name + '_' + txt
974    
975     return result
976    
977     def getRequirements(self):
978     """
979     return job requirements to add to jdl files
980     """
981     req = ''
982 slacapra 1.10 if common.analisys_common_info['sw_version']:
983     req='Member("VO-cms-' + \
984     common.analisys_common_info['sw_version'] + \
985     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
986 slacapra 1.1 if common.analisys_common_info['sites']:
987     if len(common.analisys_common_info['sites'])>0:
988     req = req + ' && ('
989     for i in range(len(common.analisys_common_info['sites'])):
990     req = req + 'other.GlueCEInfoHostName == "' \
991     + common.analisys_common_info['sites'][i] + '"'
992     if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
993     req = req + ' || '
994     req = req + ')'
995     #print "req = ", req
996     return req
997 gutsche 1.3
998     def configFilename(self):
999     """ return the config filename """
1000     return self.name()+'.cfg'
1001    
1002     ### OLI_DANIELE
1003     def wsSetupCMSOSGEnvironment_(self):
1004     """
1005     Returns part of a job script which is prepares
1006     the execution environment and which is common for all CMS jobs.
1007     """
1008     txt = '\n'
1009     txt += ' echo "### SETUP CMS OSG ENVIRONMENT ###"\n'
1010     txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
1011     txt += ' # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
1012     txt += ' source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
1013     txt += ' elif [ -f $OSG_APP/cmssoft/cmsset_default.sh ] ;then\n'
1014     txt += ' # Use $OSG_APP/cmssoft/cmsset_default.sh to setup cms software\n'
1015     txt += ' source $OSG_APP/cmssoft/cmsset_default.sh '+self.version+'\n'
1016     txt += ' else\n'
1017     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'
1018     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1019     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1020     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1021 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1022     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1023     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1024 gutsche 1.7 txt += ' exit 1\n'
1025 gutsche 1.3 txt += '\n'
1026     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
1027     txt += ' cd $RUNTIME_AREA\n'
1028     txt += ' /bin/rm -rf $WORKING_DIR\n'
1029     txt += ' if [ -d $WORKING_DIR ] ;then\n'
1030 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'
1031     txt += ' echo "JOB_EXIT_STATUS = 10017"\n'
1032     txt += ' echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
1033     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1034 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1035     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1036     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1037 gutsche 1.3 txt += ' fi\n'
1038     txt += '\n'
1039 gutsche 1.7 txt += ' exit 1\n'
1040 gutsche 1.3 txt += ' fi\n'
1041     txt += '\n'
1042     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1043     txt += ' echo " END SETUP CMS OSG ENVIRONMENT "\n'
1044    
1045     return txt
1046    
1047     ### OLI_DANIELE
1048     def wsSetupCMSLCGEnvironment_(self):
1049     """
1050     Returns part of a job script which is prepares
1051     the execution environment and which is common for all CMS jobs.
1052     """
1053     txt = ' \n'
1054     txt += ' echo " ### SETUP CMS LCG ENVIRONMENT ### "\n'
1055     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
1056     txt += ' echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
1057     txt += ' echo "JOB_EXIT_STATUS = 10031" \n'
1058     txt += ' echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
1059     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1060 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1061     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1062     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1063 gutsche 1.7 txt += ' exit 1\n'
1064 gutsche 1.3 txt += ' else\n'
1065     txt += ' echo "Sourcing environment... "\n'
1066     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1067     txt += ' echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1068     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1069     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1070     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1071 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1072     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1073     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1074 gutsche 1.7 txt += ' exit 1\n'
1075 gutsche 1.3 txt += ' fi\n'
1076     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1077     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1078     txt += ' result=$?\n'
1079     txt += ' if [ $result -ne 0 ]; then\n'
1080     txt += ' echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1081     txt += ' echo "JOB_EXIT_STATUS = 10032"\n'
1082     txt += ' echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1083     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1084 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1085     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1086     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1087 gutsche 1.7 txt += ' exit 1\n'
1088 gutsche 1.3 txt += ' fi\n'
1089     txt += ' fi\n'
1090     txt += ' \n'
1091     txt += ' string=`cat /etc/redhat-release`\n'
1092     txt += ' echo $string\n'
1093     txt += ' if [[ $string = *alhalla* ]]; then\n'
1094     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1095     txt += ' elif [[ $string = *Enterprise* ]] || [[ $string = *cientific* ]]; then\n'
1096     txt += ' export SCRAM_ARCH=slc3_ia32_gcc323\n'
1097     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1098     txt += ' else\n'
1099 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10033 ==> ERROR OS unknown, LCG environment not initialized"\n'
1100 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10033"\n'
1101     txt += ' echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
1102     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1103 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1104     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1105     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1106 gutsche 1.7 txt += ' exit 1\n'
1107 gutsche 1.3 txt += ' fi\n'
1108     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1109     txt += ' echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1110     return txt
1111 gutsche 1.5
1112     def setParam_(self, param, value):
1113     self._params[param] = value
1114    
1115     def getParams(self):
1116     return self._params
1117 gutsche 1.8
1118     def setTaskid_(self):
1119     self._taskId = self.cfg_params['taskId']
1120    
1121     def getTaskid(self):
1122     return self._taskId