ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.30.2.2.2.1
Committed: Thu Aug 24 15:32:56 2006 UTC (18 years, 8 months ago) by fanzago
Content type: text/x-python
Branch: CRAB_BOSS4_v1
Changes since 1.30.2.2: +10 -6 lines
Log Message:
first changes to use iterator

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