ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.36
Committed: Wed Aug 9 15:52:57 2006 UTC (18 years, 8 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
Changes since 1.35: +0 -1 lines
Log Message:
targetSite sent to dashboard is job specific

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