ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.30.2.2
Committed: Mon Aug 7 09:47:48 2006 UTC (18 years, 8 months ago) by corvo
Content type: text/x-python
Branch: CRAB_BOSS4
Branch point for: CRAB_BOSS4_v1
Changes since 1.30.2.1: +11 -6 lines
Log Message:
Fixed parsing bug

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