ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.41
Committed: Wed Sep 20 17:29:52 2006 UTC (18 years, 7 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_3_0_pre3
Changes since 1.40: +36 -38 lines
Log Message:
BOSS4 + sub-file splitting + taskDB

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