ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.35
Committed: Thu Aug 3 22:44:40 2006 UTC (18 years, 8 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
Changes since 1.34: +185 -238 lines
Log Message:
Commit for Malina: Handled block-splitting for CMSSW and CE->SE in .jdl files

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.35 if (cfg_params['CMSSW.files_per_jobs']):
139     raise CrabException("files_per_jobs no longer supported. Quitting.")
140 gutsche 1.3 except KeyError:
141 gutsche 1.35 pass
142 gutsche 1.3
143 slacapra 1.9 ## Events per job
144 gutsche 1.3 try:
145 slacapra 1.10 self.eventsPerJob =int( cfg_params['CMSSW.events_per_job'])
146 slacapra 1.9 self.selectEventsPerJob = 1
147 gutsche 1.3 except KeyError:
148 slacapra 1.9 self.eventsPerJob = -1
149     self.selectEventsPerJob = 0
150    
151 slacapra 1.22 ## number of jobs
152     try:
153     self.theNumberOfJobs =int( cfg_params['CMSSW.number_of_jobs'])
154     self.selectNumberOfJobs = 1
155     except KeyError:
156     self.theNumberOfJobs = 0
157     self.selectNumberOfJobs = 0
158 slacapra 1.10
159 gutsche 1.35 try:
160     self.total_number_of_events = int(cfg_params['CMSSW.total_number_of_events'])
161     self.selectTotalNumberEvents = 1
162     except KeyError:
163     self.total_number_of_events = 0
164     self.selectTotalNumberEvents = 0
165    
166     if ( (self.selectTotalNumberEvents + self.selectEventsPerJob + self.selectNumberOfJobs) != 2 ):
167     msg = 'Must define exactly two of total_number_of_events, events_per_job, or number_of_jobs.'
168     raise CrabException(msg)
169    
170 slacapra 1.22 ## source seed for pythia
171     try:
172     self.sourceSeed = int(cfg_params['CMSSW.pythia_seed'])
173     except KeyError:
174 slacapra 1.23 self.sourceSeed = None
175     common.logger.debug(5,"No seed given")
176 slacapra 1.22
177 slacapra 1.28 try:
178     self.sourceSeedVtx = int(cfg_params['CMSSW.vtx_seed'])
179     except KeyError:
180     self.sourceSeedVtx = None
181     common.logger.debug(5,"No vertex seed given")
182    
183 gutsche 1.3 self.PsetEdit = PsetManipulator.PsetManipulator(self.pset) #Daniele Pset
184    
185 slacapra 1.1 #DBSDLS-start
186     ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
187     self.maxEvents=0 # max events available ( --> check the requested nb. of evts in Creator.py)
188     self.DBSPaths={} # all dbs paths requested ( --> input to the site local discovery script)
189 gutsche 1.35 self.jobDestination=[] # Site destination(s) for each job (list of lists)
190 slacapra 1.1 ## Perform the data location and discovery (based on DBS/DLS)
191 slacapra 1.9 ## SL: Don't if NONE is specified as input (pythia use case)
192 gutsche 1.35 blockSites = {}
193 slacapra 1.9 if self.datasetPath:
194 gutsche 1.35 blockSites = self.DataDiscoveryAndLocation(cfg_params)
195 slacapra 1.1 #DBSDLS-end
196    
197     self.tgzNameWithPath = self.getTarBall(self.executable)
198 slacapra 1.10
199 slacapra 1.9 ## Select Splitting
200 slacapra 1.22 if self.selectNoInput: self.jobSplittingNoInput()
201 gutsche 1.35 else: self.jobSplittingByBlocks(blockSites)
202 gutsche 1.5
203 slacapra 1.22 # modify Pset
204     try:
205     if (self.datasetPath): # standard job
206 slacapra 1.23 # always process all events in a file
207     self.PsetEdit.maxEvent("-1")
208     self.PsetEdit.inputModule("INPUT")
209 slacapra 1.22
210     else: # pythia like job
211 slacapra 1.23 self.PsetEdit.maxEvent(self.eventsPerJob)
212     if (self.sourceSeed) :
213 slacapra 1.28 self.PsetEdit.pythiaSeed("INPUT")
214     if (self.sourceSeedVtx) :
215     self.PsetEdit.pythiaSeedVtx("INPUTVTX")
216 slacapra 1.22 self.PsetEdit.psetWriter(self.configFilename())
217     except:
218     msg='Error while manipuliating ParameterSet: exiting...'
219     raise CrabException(msg)
220 gutsche 1.3
221 slacapra 1.1 def DataDiscoveryAndLocation(self, cfg_params):
222    
223 gutsche 1.3 common.logger.debug(10,"CMSSW::DataDiscoveryAndLocation()")
224    
225     datasetPath=self.datasetPath
226    
227     ## TODO
228     dataTiersList = ""
229     dataTiers = dataTiersList.split(',')
230 slacapra 1.1
231     ## Contact the DBS
232     try:
233 afanfani 1.4 self.pubdata=DataDiscovery_EDM.DataDiscovery_EDM(datasetPath, dataTiers, cfg_params)
234 slacapra 1.1 self.pubdata.fetchDBSInfo()
235    
236 gutsche 1.3 except DataDiscovery_EDM.NotExistingDatasetError, ex :
237 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
238     raise CrabException(msg)
239    
240 gutsche 1.3 except DataDiscovery_EDM.NoDataTierinProvenanceError, ex :
241 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
242     raise CrabException(msg)
243 gutsche 1.3 except DataDiscovery_EDM.DataDiscoveryError, ex:
244 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS %s'%ex.getErrorMessage()
245     raise CrabException(msg)
246    
247     ## get list of all required data in the form of dbs paths (dbs path = /dataset/datatier/owner)
248 gutsche 1.3 ## self.DBSPaths=self.pubdata.getDBSPaths()
249     common.logger.message("Required data are :"+self.datasetPath)
250    
251 gutsche 1.35 self.filesbyblock=self.pubdata.getFiles()
252     self.eventsbyblock=self.pubdata.getEVC()
253     ## SL we probably don't need this
254     self.files = self.filesbyblock.values()
255 gutsche 1.3
256 slacapra 1.1 ## get max number of events
257     self.maxEvents=self.pubdata.getMaxEvents() ## self.maxEvents used in Creator.py
258     common.logger.message("\nThe number of available events is %s"%self.maxEvents)
259    
260     ## Contact the DLS and build a list of sites hosting the fileblocks
261     try:
262 gutsche 1.35 dataloc=DataLocation_EDM.DataLocation_EDM(self.filesbyblock.keys(),cfg_params)
263 gutsche 1.6 dataloc.fetchDLSInfo()
264 gutsche 1.3 except DataLocation_EDM.DataLocationError , ex:
265 slacapra 1.1 msg = 'ERROR ***: failed Data Location in DLS \n %s '%ex.getErrorMessage()
266     raise CrabException(msg)
267    
268    
269 gutsche 1.35 sites = dataloc.getSites()
270     allSites = []
271     listSites = sites.values()
272     for list in listSites:
273     for oneSite in list:
274     allSites.append(oneSite)
275     allSites = self.uniquelist(allSites)
276 gutsche 1.3
277 gutsche 1.35 common.logger.message("Sites ("+str(len(allSites))+") hosting part/all of dataset: "+str(allSites))
278     common.logger.debug(6, "List of Sites: "+str(allSites))
279 gutsche 1.5 self.setParam_('TargetCE', ','.join(sites))
280 gutsche 1.35 return sites
281 gutsche 1.3
282 gutsche 1.35 def jobSplittingByBlocks(self, blockSites):
283 slacapra 1.9 """
284 gutsche 1.35 Perform job splitting. Jobs run over an integer number of files
285     and no more than one block.
286     ARGUMENT: blockSites: dictionary with blocks as keys and list of host sites as values
287     REQUIRES: self.selectTotalNumberEvents, self.selectEventsPerJob, self.selectNumberofJobs,
288     self.total_number_of_events, self.eventsPerJob, self.theNumberOfJobs,
289     self.maxEvents, self.filesbyblock
290     SETS: self.jobDestination - Site destination(s) for each job (a list of lists)
291     self.total_number_of_jobs - Total # of jobs
292     self.list_of_args - File(s) job will run on (a list of lists)
293     """
294    
295     # ---- Handle the possible job splitting configurations ---- #
296     if (self.selectTotalNumberEvents):
297     totalEventsRequested = self.total_number_of_events
298     if (self.selectEventsPerJob):
299     eventsPerJobRequested = self.eventsPerJob
300     if (self.selectNumberOfJobs):
301     totalEventsRequested = self.theNumberOfJobs * self.eventsPerJob
302    
303     # If user requested all the events in the dataset
304     if (totalEventsRequested == -1):
305     eventsRemaining=self.maxEvents
306     # If user requested more events than are in the dataset
307     elif (totalEventsRequested > self.maxEvents):
308     eventsRemaining = self.maxEvents
309     common.logger.message("Requested "+str(self.total_number_of_events)+ " events, but only "+str(self.maxEvents)+" events are available.")
310     # If user requested less events than are in the dataset
311     else:
312     eventsRemaining = totalEventsRequested
313 slacapra 1.22
314 gutsche 1.35 # For user info at end
315     totalEventCount = 0
316 gutsche 1.3
317 gutsche 1.35 if (self.selectTotalNumberEvents and self.selectNumberOfJobs):
318     eventsPerJobRequested = int(eventsRemaining/self.theNumberOfJobs)
319 slacapra 1.22
320 gutsche 1.35 if (self.selectNumberOfJobs):
321     common.logger.message("May not create the exact number_of_jobs requested.")
322 slacapra 1.23
323 gutsche 1.35 blocks = blockSites.keys()
324     blockCount = 0
325     # Backup variable in case self.maxEvents counted events in a non-included block
326     numBlocksInDataset = len(blocks)
327 gutsche 1.3
328 gutsche 1.35 jobCount = 0
329     list_of_lists = []
330 gutsche 1.3
331 gutsche 1.35 # ---- Iterate over the blocks in the dataset until ---- #
332     # ---- we've met the requested total # of events ---- #
333     while ( (eventsRemaining > 0) and (blockCount < numBlocksInDataset) ):
334     block = blocks[blockCount]
335 gutsche 1.3
336    
337 gutsche 1.35 evInBlock = self.eventsbyblock[block]
338     common.logger.debug(5,'Events in Block File '+str(evInBlock))
339    
340     #Correct - switch to this when DBS up
341     #numEventsInBlock = self.eventsbyblock[block]
342     numEventsInBlock = evInBlock
343 slacapra 1.9
344 gutsche 1.35 files = self.filesbyblock[block]
345     numFilesInBlock = len(files)
346     if (numFilesInBlock <= 0):
347     continue
348     fileCount = 0
349    
350     # ---- New block => New job ---- #
351     parString = "\\{"
352     jobEventCount = 0
353 slacapra 1.9
354 gutsche 1.35 # ---- Iterate over the files in the block until we've met the requested ---- #
355     # ---- total # of events or we've gone over all the files in this block ---- #
356     while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) ):
357     file = files[fileCount]
358     fileCount = fileCount + 1
359     #numEventsInFile = numberEventsInFile(file)
360     # !!!!!!!!!!!!!!!!! Need to get the # of events in each file. !!!!!!!!!!!!!!!!!!!!!!!!!
361     # For now, I'm assuming that all files in a block
362     # have the same number of events
363     numEventsInFile = numEventsInBlock/numFilesInBlock
364     common.logger.debug(5,"Estimated # of events in the file: "+str(numEventsInFile))
365     numEventsInFile = int(numEventsInFile)
366     common.logger.debug(5,"After rounding down: "+str(numEventsInFile))
367     # Add file to current job
368     parString += '\\\"' + file + '\\\"\,'
369     jobEventCount = jobEventCount + numEventsInFile
370     totalEventCount = totalEventCount + numEventsInFile
371     eventsRemaining = eventsRemaining - numEventsInFile
372     if (jobEventCount >= eventsPerJobRequested):
373     # ---- This job has at least CMSSW.events_per_job => End of job ---- #
374     # Don't need the last \,
375     fullString = parString[:-2]
376     fullString += '\\}'
377     list_of_lists.append([fullString])
378     common.logger.message("Job "+str(jobCount+1)+" can run over approximately "+str(jobEventCount)+" events.")
379    
380     #self.jobDestination[jobCount] = blockSites[block]
381     self.jobDestination.append(blockSites[block])
382     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
383     if ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) ):
384     # ---- Still need CMSSW.total_number_of_events ---- #
385     # ---- and not about to jump into a new block ---- #
386     # ---- => New job ---- #
387     parString = "\\{"
388     jobEventCount = 0
389     jobCount = jobCount + 1
390     pass # END if
391     pass # END if
392     pass # END while (iterate over files in the block)
393     if (jobEventCount < eventsPerJobRequested):
394     # ---- Job ending prematurely due to end of block => End of job ---- #
395     # Don't need the last \,
396     fullString = parString[:-2]
397     fullString += '\\}'
398     list_of_lists.append([fullString])
399     common.logger.message("Job "+str(jobCount+1)+" can run over approximately "+str(jobEventCount)+" events.")
400     #self.jobDestination[jobCount] = blockSites[block]
401     self.jobDestination.append(blockSites[block])
402     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
403     pass # END if
404     blockCount = blockCount + 1
405     jobCount = jobCount + 1
406     pass # END while (iterate over blocks in the dataset)
407     self.total_number_of_jobs = jobCount
408     if (eventsRemaining > 0):
409     common.logger.message("Could not run on all requested events because some blocks not hosted at allowed sites.")
410     common.logger.message("\n"+str(jobCount)+" job(s) can run on approximately "+str(totalEventCount)+" events.\n")
411 slacapra 1.22
412 slacapra 1.9 self.list_of_args = list_of_lists
413     return
414    
415 slacapra 1.21 def jobSplittingNoInput(self):
416 slacapra 1.9 """
417     Perform job splitting based on number of event per job
418     """
419     common.logger.debug(5,'Splitting per events')
420     common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
421 slacapra 1.22 common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
422 slacapra 1.9 common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
423    
424 slacapra 1.10 if (self.total_number_of_events < 0):
425     msg='Cannot split jobs per Events with "-1" as total number of events'
426     raise CrabException(msg)
427    
428 slacapra 1.22 if (self.selectEventsPerJob):
429     self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
430     elif (self.selectNumberOfJobs) :
431     self.total_number_of_jobs = self.theNumberOfJobs
432     self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
433 fanzago 1.12
434 slacapra 1.9 common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
435    
436     # is there any remainder?
437     check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
438    
439     common.logger.debug(5,'Check '+str(check))
440    
441 gutsche 1.35 common.logger.message(str(self.total_number_of_jobs)+' jobs can be created, each for '+str(self.eventsPerJob)+' for a total of '+str(self.total_number_of_jobs*self.eventsPerJob)+' events')
442 slacapra 1.9 if check > 0:
443 gutsche 1.35 common.logger.message('Warning: asked '+str(self.total_number_of_events)+' but can do only '+str(int(self.total_number_of_jobs)*self.eventsPerJob))
444 slacapra 1.9
445 slacapra 1.10 # argument is seed number.$i
446 slacapra 1.9 self.list_of_args = []
447     for i in range(self.total_number_of_jobs):
448 gutsche 1.35 ## Since there is no input, any site is good
449     self.jobDestination.append(["Any"])
450 slacapra 1.23 if (self.sourceSeed):
451 slacapra 1.28 if (self.sourceSeedVtx):
452     ## pythia + vtx random seed
453     self.list_of_args.append([
454     str(self.sourceSeed)+str(i),
455     str(self.sourceSeedVtx)+str(i)
456     ])
457     else:
458     ## only pythia random seed
459     self.list_of_args.append([(str(self.sourceSeed)+str(i))])
460 slacapra 1.23 else:
461 slacapra 1.28 ## no random seed
462 slacapra 1.23 self.list_of_args.append([str(i)])
463 slacapra 1.17 #print self.list_of_args
464 gutsche 1.3
465     return
466    
467     def split(self, jobParams):
468    
469     common.jobDB.load()
470     #### Fabio
471     njobs = self.total_number_of_jobs
472 slacapra 1.9 arglist = self.list_of_args
473 gutsche 1.3 # create the empty structure
474     for i in range(njobs):
475     jobParams.append("")
476    
477     for job in range(njobs):
478 slacapra 1.17 jobParams[job] = arglist[job]
479     # print str(arglist[job])
480     # print jobParams[job]
481 gutsche 1.3 common.jobDB.setArguments(job, jobParams[job])
482 gutsche 1.35 common.logger.debug(5,"Job "+str(job)+" Destination: "+str(self.jobDestination[job]))
483     common.jobDB.setDestination(job, self.jobDestination[job])
484 gutsche 1.3
485     common.jobDB.save()
486     return
487    
488     def getJobTypeArguments(self, nj, sched):
489 slacapra 1.17 result = ''
490     for i in common.jobDB.arguments(nj):
491     result=result+str(i)+" "
492     return result
493 gutsche 1.3
494     def numberOfJobs(self):
495     # Fabio
496     return self.total_number_of_jobs
497    
498 slacapra 1.1 def getTarBall(self, exe):
499     """
500     Return the TarBall with lib and exe
501     """
502    
503     # if it exist, just return it
504     self.tgzNameWithPath = common.work_space.shareDir()+self.tgz_name
505     if os.path.exists(self.tgzNameWithPath):
506     return self.tgzNameWithPath
507    
508     # Prepare a tar gzipped file with user binaries.
509     self.buildTar_(exe)
510    
511     return string.strip(self.tgzNameWithPath)
512    
513     def buildTar_(self, executable):
514    
515     # First of all declare the user Scram area
516     swArea = self.scram.getSWArea_()
517     #print "swArea = ", swArea
518     swVersion = self.scram.getSWVersion()
519     #print "swVersion = ", swVersion
520     swReleaseTop = self.scram.getReleaseTop_()
521     #print "swReleaseTop = ", swReleaseTop
522    
523     ## check if working area is release top
524     if swReleaseTop == '' or swArea == swReleaseTop:
525     return
526    
527     filesToBeTarred = []
528     ## First find the executable
529     if (self.executable != ''):
530     exeWithPath = self.scram.findFile_(executable)
531     # print exeWithPath
532     if ( not exeWithPath ):
533     raise CrabException('User executable '+executable+' not found')
534    
535     ## then check if it's private or not
536     if exeWithPath.find(swReleaseTop) == -1:
537     # the exe is private, so we must ship
538     common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
539     path = swArea+'/'
540     exe = string.replace(exeWithPath, path,'')
541     filesToBeTarred.append(exe)
542     pass
543     else:
544     # the exe is from release, we'll find it on WN
545     pass
546    
547     ## Now get the libraries: only those in local working area
548     libDir = 'lib'
549     lib = swArea+'/' +libDir
550     common.logger.debug(5,"lib "+lib+" to be tarred")
551     if os.path.exists(lib):
552     filesToBeTarred.append(libDir)
553    
554 gutsche 1.3 ## Now check if module dir is present
555     moduleDir = 'module'
556     if os.path.isdir(swArea+'/'+moduleDir):
557     filesToBeTarred.append(moduleDir)
558    
559 slacapra 1.1 ## Now check if the Data dir is present
560     dataDir = 'src/Data/'
561     if os.path.isdir(swArea+'/'+dataDir):
562     filesToBeTarred.append(dataDir)
563    
564     ## Create the tar-ball
565     if len(filesToBeTarred)>0:
566     cwd = os.getcwd()
567     os.chdir(swArea)
568     tarcmd = 'tar zcvf ' + self.tgzNameWithPath + ' '
569     for line in filesToBeTarred:
570     tarcmd = tarcmd + line + ' '
571     cout = runCommand(tarcmd)
572     if not cout:
573     raise CrabException('Could not create tar-ball')
574     os.chdir(cwd)
575     else:
576     common.logger.debug(5,"No files to be to be tarred")
577    
578     return
579    
580     def wsSetupEnvironment(self, nj):
581     """
582     Returns part of a job script which prepares
583     the execution environment for the job 'nj'.
584     """
585     # Prepare JobType-independent part
586 gutsche 1.3 txt = ''
587    
588     ## OLI_Daniele at this level middleware already known
589    
590     txt += 'if [ $middleware == LCG ]; then \n'
591     txt += self.wsSetupCMSLCGEnvironment_()
592     txt += 'elif [ $middleware == OSG ]; then\n'
593     txt += ' time=`date -u +"%s"`\n'
594     txt += ' WORKING_DIR=$OSG_WN_TMP/cms_$time\n'
595     txt += ' echo "Creating working directory: $WORKING_DIR"\n'
596     txt += ' /bin/mkdir -p $WORKING_DIR\n'
597     txt += ' if [ ! -d $WORKING_DIR ] ;then\n'
598 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
599     txt += ' echo "JOB_EXIT_STATUS = 10016"\n'
600     txt += ' echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
601     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
602 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
603     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
604     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
605 gutsche 1.3 txt += ' exit 1\n'
606     txt += ' fi\n'
607     txt += '\n'
608     txt += ' echo "Change to working directory: $WORKING_DIR"\n'
609     txt += ' cd $WORKING_DIR\n'
610     txt += self.wsSetupCMSOSGEnvironment_()
611     txt += 'fi\n'
612 slacapra 1.1
613     # Prepare JobType-specific part
614     scram = self.scram.commandName()
615     txt += '\n\n'
616     txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
617     txt += scram+' project CMSSW '+self.version+'\n'
618     txt += 'status=$?\n'
619     txt += 'if [ $status != 0 ] ; then\n'
620 gutsche 1.7 txt += ' echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
621 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10034"\n'
622 gutsche 1.7 txt += ' echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
623 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
624 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
625     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
626     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
627 gutsche 1.3 ## OLI_Daniele
628     txt += ' if [ $middleware == OSG ]; then \n'
629     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
630     txt += ' cd $RUNTIME_AREA\n'
631     txt += ' /bin/rm -rf $WORKING_DIR\n'
632     txt += ' if [ -d $WORKING_DIR ] ;then\n'
633 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'
634     txt += ' echo "JOB_EXIT_STATUS = 10018"\n'
635     txt += ' echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
636     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
637 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
638     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
639     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
640 gutsche 1.3 txt += ' fi\n'
641     txt += ' fi \n'
642     txt += ' exit 1 \n'
643 slacapra 1.1 txt += 'fi \n'
644     txt += 'echo "CMSSW_VERSION = '+self.version+'"\n'
645     txt += 'cd '+self.version+'\n'
646     ### needed grep for bug in scramv1 ###
647     txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
648    
649     # Handle the arguments:
650     txt += "\n"
651 gutsche 1.7 txt += "## number of arguments (first argument always jobnumber)\n"
652 slacapra 1.1 txt += "\n"
653 mkirn 1.32 # txt += "narg=$#\n"
654     txt += "if [ $nargs -lt 2 ]\n"
655 slacapra 1.1 txt += "then\n"
656 mkirn 1.33 txt += " echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$nargs+ \n"
657 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
658 gutsche 1.7 txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
659 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
660 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
661     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
662     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
663 gutsche 1.3 ## OLI_Daniele
664     txt += ' if [ $middleware == OSG ]; then \n'
665     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
666     txt += ' cd $RUNTIME_AREA\n'
667     txt += ' /bin/rm -rf $WORKING_DIR\n'
668     txt += ' if [ -d $WORKING_DIR ] ;then\n'
669 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'
670     txt += ' echo "JOB_EXIT_STATUS = 50114"\n'
671     txt += ' echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
672     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
673 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
674     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
675     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
676 gutsche 1.3 txt += ' fi\n'
677     txt += ' fi \n'
678 slacapra 1.1 txt += " exit 1\n"
679     txt += "fi\n"
680     txt += "\n"
681    
682     # Prepare job-specific part
683     job = common.job_list[nj]
684     pset = os.path.basename(job.configFilename())
685     txt += '\n'
686 slacapra 1.10 if (self.datasetPath): # standard job
687 mkirn 1.32 #txt += 'InputFiles=$2\n'
688     txt += 'InputFiles=${args[1]}\n'
689 slacapra 1.10 txt += 'echo "Inputfiles:<$InputFiles>"\n'
690     txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset.cfg\n'
691     else: # pythia like job
692 slacapra 1.23 if (self.sourceSeed):
693 mkirn 1.34 # txt += 'Seed=$2\n'
694     txt += 'Seed=${args[1]}\n'
695 slacapra 1.23 txt += 'echo "Seed: <$Seed>"\n'
696 slacapra 1.28 txt += 'sed "s#\<INPUT\>#$Seed#" $RUNTIME_AREA/'+pset+' > tmp.cfg\n'
697     if (self.sourceSeedVtx):
698 mkirn 1.34 # txt += 'VtxSeed=$3\n'
699     txt += 'VtxSeed=${args[2]}\n'
700 slacapra 1.28 txt += 'echo "VtxSeed: <$VtxSeed>"\n'
701     txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp.cfg > pset.cfg\n'
702     else:
703     txt += 'mv tmp.cfg pset.cfg\n'
704 slacapra 1.24 else:
705     txt += '# Copy untouched pset\n'
706 slacapra 1.26 txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
707 slacapra 1.24
708 slacapra 1.1
709     if len(self.additional_inbox_files) > 0:
710     for file in self.additional_inbox_files:
711 mkirn 1.31 relFile = file.split("/")[-1]
712     txt += 'if [ -e $RUNTIME_AREA/'+relFile+' ] ; then\n'
713     txt += ' cp $RUNTIME_AREA/'+relFile+' .\n'
714     txt += ' chmod +x '+relFile+'\n'
715 slacapra 1.1 txt += 'fi\n'
716     pass
717    
718     txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
719    
720     txt += '\n'
721     txt += 'echo "***** cat pset.cfg *********"\n'
722     txt += 'cat pset.cfg\n'
723     txt += 'echo "****** end pset.cfg ********"\n'
724 gutsche 1.3 txt += '\n'
725     # txt += 'echo "***** cat pset1.cfg *********"\n'
726     # txt += 'cat pset1.cfg\n'
727     # txt += 'echo "****** end pset1.cfg ********"\n'
728     return txt
729    
730     def wsBuildExe(self, nj):
731     """
732     Put in the script the commands to build an executable
733     or a library.
734     """
735    
736     txt = ""
737    
738     if os.path.isfile(self.tgzNameWithPath):
739     txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
740     txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
741     txt += 'untar_status=$? \n'
742     txt += 'if [ $untar_status -ne 0 ]; then \n'
743     txt += ' echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
744     txt += ' echo "JOB_EXIT_STATUS = $untar_status" \n'
745 gutsche 1.7 txt += ' echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
746 gutsche 1.3 txt += ' if [ $middleware == OSG ]; then \n'
747     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
748     txt += ' cd $RUNTIME_AREA\n'
749     txt += ' /bin/rm -rf $WORKING_DIR\n'
750     txt += ' if [ -d $WORKING_DIR ] ;then\n'
751 gutsche 1.13 txt += ' echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
752     txt += ' echo "JOB_EXIT_STATUS = 50999"\n'
753     txt += ' echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
754     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
755     txt += ' rm -f $RUNTIME_AREA/$repo \n'
756     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
757     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
758 gutsche 1.3 txt += ' fi\n'
759     txt += ' fi \n'
760     txt += ' \n'
761 gutsche 1.7 txt += ' exit 1 \n'
762 gutsche 1.3 txt += 'else \n'
763     txt += ' echo "Successful untar" \n'
764     txt += 'fi \n'
765     pass
766    
767 slacapra 1.1 return txt
768    
769     def modifySteeringCards(self, nj):
770     """
771     modify the card provided by the user,
772     writing a new card into share dir
773     """
774    
775     def executableName(self):
776     return self.executable
777    
778     def executableArgs(self):
779 gutsche 1.3 return " -p pset.cfg"
780 slacapra 1.1
781     def inputSandbox(self, nj):
782     """
783     Returns a list of filenames to be put in JDL input sandbox.
784     """
785     inp_box = []
786     # dict added to delete duplicate from input sandbox file list
787     seen = {}
788     ## code
789     if os.path.isfile(self.tgzNameWithPath):
790     inp_box.append(self.tgzNameWithPath)
791     ## config
792     inp_box.append(common.job_list[nj].configFilename())
793     ## additional input files
794 gutsche 1.3 #for file in self.additional_inbox_files:
795     # inp_box.append(common.work_space.cwdDir()+file)
796 slacapra 1.1 return inp_box
797    
798     def outputSandbox(self, nj):
799     """
800     Returns a list of filenames to be put in JDL output sandbox.
801     """
802     out_box = []
803    
804     stdout=common.job_list[nj].stdout()
805     stderr=common.job_list[nj].stderr()
806    
807     ## User Declared output files
808     for out in self.output_file:
809     n_out = nj + 1
810     out_box.append(self.numberFile_(out,str(n_out)))
811     return out_box
812     return []
813    
814     def prepareSteeringCards(self):
815     """
816     Make initial modifications of the user's steering card file.
817     """
818     return
819    
820     def wsRenameOutput(self, nj):
821     """
822     Returns part of a job script which renames the produced files.
823     """
824    
825     txt = '\n'
826 gutsche 1.7 txt += '# directory content\n'
827     txt += 'ls \n'
828 slacapra 1.1 file_list = ''
829     for fileWithSuffix in self.output_file:
830     output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
831 gutsche 1.7 file_list=file_list+output_file_num+' '
832 slacapra 1.1 txt += '\n'
833 gutsche 1.7 txt += '# check output file\n'
834 slacapra 1.1 txt += 'ls '+fileWithSuffix+'\n'
835 fanzago 1.18 txt += 'ls_result=$?\n'
836     #txt += 'exe_result=$?\n'
837     txt += 'if [ $ls_result -ne 0 ] ; then\n'
838     txt += ' echo "ERROR: Problem with output file"\n'
839     #txt += ' echo "JOB_EXIT_STATUS = $exe_result"\n'
840     #txt += ' echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
841     #txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
842 gutsche 1.3 ### OLI_DANIELE
843 gutsche 1.7 if common.scheduler.boss_scheduler_name == 'condor_g':
844     txt += ' if [ $middleware == OSG ]; then \n'
845     txt += ' echo "prepare dummy output file"\n'
846     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
847     txt += ' fi \n'
848 slacapra 1.1 txt += 'else\n'
849     txt += ' cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
850     txt += 'fi\n'
851    
852 gutsche 1.7 txt += 'cd $RUNTIME_AREA\n'
853 slacapra 1.1 file_list=file_list[:-1]
854 slacapra 1.2 txt += 'file_list="'+file_list+'"\n'
855 fanzago 1.18 txt += 'cd $RUNTIME_AREA\n'
856 gutsche 1.3 ### OLI_DANIELE
857     txt += 'if [ $middleware == OSG ]; then\n'
858     txt += ' cd $RUNTIME_AREA\n'
859     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
860     txt += ' /bin/rm -rf $WORKING_DIR\n'
861     txt += ' if [ -d $WORKING_DIR ] ;then\n'
862 gutsche 1.7 txt += ' echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
863     txt += ' echo "JOB_EXIT_STATUS = 60999"\n'
864     txt += ' echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
865     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
866 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
867     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
868     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
869 gutsche 1.3 txt += ' fi\n'
870     txt += 'fi\n'
871     txt += '\n'
872 slacapra 1.1 return txt
873    
874     def numberFile_(self, file, txt):
875     """
876     append _'txt' before last extension of a file
877     """
878     p = string.split(file,".")
879     # take away last extension
880     name = p[0]
881     for x in p[1:-1]:
882     name=name+"."+x
883     # add "_txt"
884     if len(p)>1:
885     ext = p[len(p)-1]
886     #result = name + '_' + str(txt) + "." + ext
887     result = name + '_' + txt + "." + ext
888     else:
889     #result = name + '_' + str(txt)
890     result = name + '_' + txt
891    
892     return result
893    
894 gutsche 1.35 def getRequirements(self, nj):
895 slacapra 1.1 """
896     return job requirements to add to jdl files
897     """
898     req = ''
899 slacapra 1.10 if common.analisys_common_info['sw_version']:
900     req='Member("VO-cms-' + \
901     common.analisys_common_info['sw_version'] + \
902     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
903 gutsche 1.35
904     req = req + ' && (other.GlueHostNetworkAdapterOutboundIP)'
905    
906     ## here we should get the requirement for job nj
907     sites = common.jobDB.destination(nj)
908    
909     # check for "Any" site, in case no requirement for site
910     if len(sites)>0 and sites[0]!="Any":
911     req = req + ' && anyMatch(other.storage.CloseSEs, ('
912     for site in sites:
913     #req = req + 'other.GlueCEInfoHostName == "' + site + '" || '
914     req = req + 'target.GlueSEUniqueID=="' + site + '" || '
915     pass
916     # remove last ||
917     req = req[0:-4]
918     req = req + '))'
919    
920 slacapra 1.1 return req
921 gutsche 1.3
922     def configFilename(self):
923     """ return the config filename """
924     return self.name()+'.cfg'
925    
926     ### OLI_DANIELE
927     def wsSetupCMSOSGEnvironment_(self):
928     """
929     Returns part of a job script which is prepares
930     the execution environment and which is common for all CMS jobs.
931     """
932     txt = '\n'
933     txt += ' echo "### SETUP CMS OSG ENVIRONMENT ###"\n'
934     txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
935     txt += ' # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
936     txt += ' source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
937     txt += ' elif [ -f $OSG_APP/cmssoft/cmsset_default.sh ] ;then\n'
938     txt += ' # Use $OSG_APP/cmssoft/cmsset_default.sh to setup cms software\n'
939     txt += ' source $OSG_APP/cmssoft/cmsset_default.sh '+self.version+'\n'
940     txt += ' else\n'
941     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'
942     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
943     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
944     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
945 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
946     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
947     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
948 gutsche 1.7 txt += ' exit 1\n'
949 gutsche 1.3 txt += '\n'
950     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
951     txt += ' cd $RUNTIME_AREA\n'
952     txt += ' /bin/rm -rf $WORKING_DIR\n'
953     txt += ' if [ -d $WORKING_DIR ] ;then\n'
954 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'
955     txt += ' echo "JOB_EXIT_STATUS = 10017"\n'
956     txt += ' echo "JobExitCode=10017" | 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 += '\n'
963 gutsche 1.7 txt += ' exit 1\n'
964 gutsche 1.3 txt += ' fi\n'
965     txt += '\n'
966     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
967     txt += ' echo " END SETUP CMS OSG ENVIRONMENT "\n'
968    
969     return txt
970    
971     ### OLI_DANIELE
972     def wsSetupCMSLCGEnvironment_(self):
973     """
974     Returns part of a job script which is prepares
975     the execution environment and which is common for all CMS jobs.
976     """
977     txt = ' \n'
978     txt += ' echo " ### SETUP CMS LCG ENVIRONMENT ### "\n'
979     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
980     txt += ' echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
981     txt += ' echo "JOB_EXIT_STATUS = 10031" \n'
982     txt += ' echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
983     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
984 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
985     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
986     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
987 gutsche 1.7 txt += ' exit 1\n'
988 gutsche 1.3 txt += ' else\n'
989     txt += ' echo "Sourcing environment... "\n'
990     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
991     txt += ' echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
992     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
993     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
994     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
995 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
996     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
997     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
998 gutsche 1.7 txt += ' exit 1\n'
999 gutsche 1.3 txt += ' fi\n'
1000     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1001     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1002     txt += ' result=$?\n'
1003     txt += ' if [ $result -ne 0 ]; then\n'
1004     txt += ' echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1005     txt += ' echo "JOB_EXIT_STATUS = 10032"\n'
1006     txt += ' echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1007     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1008 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1009     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1010     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1011 gutsche 1.7 txt += ' exit 1\n'
1012 gutsche 1.3 txt += ' fi\n'
1013     txt += ' fi\n'
1014     txt += ' \n'
1015     txt += ' string=`cat /etc/redhat-release`\n'
1016     txt += ' echo $string\n'
1017     txt += ' if [[ $string = *alhalla* ]]; then\n'
1018     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1019     txt += ' elif [[ $string = *Enterprise* ]] || [[ $string = *cientific* ]]; then\n'
1020     txt += ' export SCRAM_ARCH=slc3_ia32_gcc323\n'
1021     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1022     txt += ' else\n'
1023 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10033 ==> ERROR OS unknown, LCG environment not initialized"\n'
1024 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10033"\n'
1025     txt += ' echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
1026     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1027 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1028     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1029     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1030 gutsche 1.7 txt += ' exit 1\n'
1031 gutsche 1.3 txt += ' fi\n'
1032     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1033     txt += ' echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1034     return txt
1035 gutsche 1.5
1036     def setParam_(self, param, value):
1037     self._params[param] = value
1038    
1039     def getParams(self):
1040     return self._params
1041 gutsche 1.8
1042     def setTaskid_(self):
1043     self._taskId = self.cfg_params['taskId']
1044    
1045     def getTaskid(self):
1046     return self._taskId
1047 gutsche 1.35
1048     #######################################################################
1049     def uniquelist(self, old):
1050     """
1051     remove duplicates from a list
1052     """
1053     nd={}
1054     for e in old:
1055     nd[e]=0
1056     return nd.keys()