ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.37
Committed: Thu Aug 10 17:08:54 2006 UTC (18 years, 8 months ago) by mkirn
Content type: text/x-python
Branch: MAIN
Changes since 1.36: +7 -14 lines
Log Message:
Gets events/file.  Requires cvs head of DBS/Clients/PythonAPI

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