ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.43
Committed: Fri Sep 22 15:02:15 2006 UTC (18 years, 7 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_3_0_pre4
Changes since 1.42: +2 -4 lines
Log Message:
working dir creation on OSG moved to mktemp

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