ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.30.2.2.2.3
Committed: Thu Sep 14 16:33:43 2006 UTC (18 years, 7 months ago) by spiga
Content type: text/x-python
Branch: CRAB_BOSS4_v1
Changes since 1.30.2.2.2.2: +2 -2 lines
Log Message:
minor bug fix

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