ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.44
Committed: Mon Sep 25 16:58:01 2006 UTC (18 years, 7 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_3_0_pre6, CRAB_1_3_0_pre5
Changes since 1.43: +10 -13 lines
Log Message:
fixed splitting logic, added forgotten increase of counter, changed event caluclation for last job

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 gutsche 1.44 # number of jobs requested to be created, limit obj splitting
27 gutsche 1.38 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 gutsche 1.44 common.logger.message("The number of available events is %s\n"%self.maxEvents)
284 slacapra 1.1
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.44 blockCount += 1
371    
372 gutsche 1.3
373 gutsche 1.44 numEventsInBlock = self.eventsbyblock[block]
374     common.logger.debug(5,'Events in Block File '+str(numEventsInBlock))
375 slacapra 1.9
376 gutsche 1.35 files = self.filesbyblock[block]
377     numFilesInBlock = len(files)
378     if (numFilesInBlock <= 0):
379     continue
380     fileCount = 0
381    
382     # ---- New block => New job ---- #
383     parString = "\\{"
384 gutsche 1.38 # counter for number of events in files currently worked on
385     filesEventCount = 0
386     # flag if next while loop should touch new file
387     newFile = 1
388     # job event counter
389     jobSkipEventCount = 0
390 slacapra 1.9
391 gutsche 1.35 # ---- Iterate over the files in the block until we've met the requested ---- #
392     # ---- total # of events or we've gone over all the files in this block ---- #
393 gutsche 1.38 while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
394 gutsche 1.35 file = files[fileCount]
395 gutsche 1.38 if newFile :
396 slacapra 1.41 try:
397     numEventsInFile = self.eventsbyfile[file]
398     common.logger.debug(6, "File "+str(file)+" has "+str(numEventsInFile)+" events")
399     # increase filesEventCount
400     filesEventCount += numEventsInFile
401     # Add file to current job
402     parString += '\\\"' + file + '\\\"\,'
403     newFile = 0
404     except KeyError:
405 gutsche 1.44 common.logger.message("File "+str(file)+" has unknown number of events: skipping")
406 slacapra 1.41
407 gutsche 1.38
408     # if less events in file remain than eventsPerJobRequested
409     if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested ) :
410     # if last file in block
411 gutsche 1.44 if ( fileCount == numFilesInBlock-1 ) :
412 gutsche 1.38 # end job using last file, use remaining events in block
413     # close job and touch new file
414     fullString = parString[:-2]
415     fullString += '\\}'
416     list_of_lists.append([fullString,str(-1),str(jobSkipEventCount)])
417 slacapra 1.41 common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(filesEventCount - jobSkipEventCount)+" events (last file in block).")
418 gutsche 1.38 self.jobDestination.append(blockSites[block])
419     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
420     # reset counter
421     jobCount = jobCount + 1
422 gutsche 1.44 totalEventCount = totalEventCount + filesEventCount - jobSkipEventCount
423     eventsRemaining = eventsRemaining - filesEventCount + jobSkipEventCount
424 gutsche 1.38 jobSkipEventCount = 0
425     # reset file
426     parString = "\\{"
427     filesEventCount = 0
428     newFile = 1
429     fileCount += 1
430     else :
431     # go to next file
432     newFile = 1
433     fileCount += 1
434     # if events in file equal to eventsPerJobRequested
435     elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
436     # close job and touch new file
437 gutsche 1.35 fullString = parString[:-2]
438     fullString += '\\}'
439 gutsche 1.38 list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
440 slacapra 1.41 common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
441 gutsche 1.38 self.jobDestination.append(blockSites[block])
442     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
443     # reset counter
444     jobCount = jobCount + 1
445     totalEventCount = totalEventCount + eventsPerJobRequested
446     eventsRemaining = eventsRemaining - eventsPerJobRequested
447     jobSkipEventCount = 0
448     # reset file
449     parString = "\\{"
450     filesEventCount = 0
451     newFile = 1
452     fileCount += 1
453    
454     # if more events in file remain than eventsPerJobRequested
455     else :
456     # close job but don't touch new file
457     fullString = parString[:-2]
458     fullString += '\\}'
459     list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
460 slacapra 1.41 common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
461 gutsche 1.35 self.jobDestination.append(blockSites[block])
462     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
463 gutsche 1.38 # increase counter
464     jobCount = jobCount + 1
465     totalEventCount = totalEventCount + eventsPerJobRequested
466     eventsRemaining = eventsRemaining - eventsPerJobRequested
467     # calculate skip events for last file
468     # use filesEventCount (contains several files), jobSkipEventCount and eventsPerJobRequest
469     jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
470     # remove all but the last file
471     filesEventCount = self.eventsbyfile[file]
472     parString = "\\{"
473     parString += '\\\"' + file + '\\\"\,'
474 slacapra 1.41 pass # END if
475 gutsche 1.35 pass # END while (iterate over files in the block)
476     pass # END while (iterate over blocks in the dataset)
477 slacapra 1.41 self.ncjobs = self.total_number_of_jobs = jobCount
478 gutsche 1.38 if (eventsRemaining > 0 and jobCount < totalNumberOfJobs ):
479 gutsche 1.35 common.logger.message("Could not run on all requested events because some blocks not hosted at allowed sites.")
480 mkirn 1.37 common.logger.message("\n"+str(jobCount)+" job(s) can run on "+str(totalEventCount)+" events.\n")
481 slacapra 1.22
482 slacapra 1.9 self.list_of_args = list_of_lists
483     return
484    
485 slacapra 1.21 def jobSplittingNoInput(self):
486 slacapra 1.9 """
487     Perform job splitting based on number of event per job
488     """
489     common.logger.debug(5,'Splitting per events')
490     common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
491 slacapra 1.22 common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
492 slacapra 1.9 common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
493    
494 slacapra 1.10 if (self.total_number_of_events < 0):
495     msg='Cannot split jobs per Events with "-1" as total number of events'
496     raise CrabException(msg)
497    
498 slacapra 1.22 if (self.selectEventsPerJob):
499     self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
500     elif (self.selectNumberOfJobs) :
501     self.total_number_of_jobs = self.theNumberOfJobs
502     self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
503 fanzago 1.12
504 slacapra 1.9 common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
505    
506     # is there any remainder?
507     check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
508    
509     common.logger.debug(5,'Check '+str(check))
510    
511 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')
512 slacapra 1.9 if check > 0:
513 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))
514 slacapra 1.9
515 slacapra 1.10 # argument is seed number.$i
516 slacapra 1.9 self.list_of_args = []
517     for i in range(self.total_number_of_jobs):
518 gutsche 1.35 ## Since there is no input, any site is good
519 spiga 1.42 # self.jobDestination.append(["Any"])
520     self.jobDestination.append([""]) #must be empty to write correctly the xml
521 slacapra 1.23 if (self.sourceSeed):
522 slacapra 1.28 if (self.sourceSeedVtx):
523     ## pythia + vtx random seed
524     self.list_of_args.append([
525     str(self.sourceSeed)+str(i),
526     str(self.sourceSeedVtx)+str(i)
527     ])
528     else:
529     ## only pythia random seed
530     self.list_of_args.append([(str(self.sourceSeed)+str(i))])
531 slacapra 1.23 else:
532 slacapra 1.28 ## no random seed
533 slacapra 1.23 self.list_of_args.append([str(i)])
534 slacapra 1.17 #print self.list_of_args
535 gutsche 1.3
536     return
537    
538 spiga 1.42
539     def jobSplittingForScript(self):#CarlosDaniele
540     """
541     Perform job splitting based on number of job
542     """
543     common.logger.debug(5,'Splitting per job')
544     common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
545    
546     self.total_number_of_jobs = self.theNumberOfJobs
547    
548     common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
549    
550     common.logger.message(str(self.total_number_of_jobs)+' jobs can be created')
551    
552     # argument is seed number.$i
553     self.list_of_args = []
554     for i in range(self.total_number_of_jobs):
555     ## Since there is no input, any site is good
556     # self.jobDestination.append(["Any"])
557     self.jobDestination.append([""])
558     ## no random seed
559     self.list_of_args.append([str(i)])
560     return
561    
562 gutsche 1.3 def split(self, jobParams):
563    
564     common.jobDB.load()
565     #### Fabio
566     njobs = self.total_number_of_jobs
567 slacapra 1.9 arglist = self.list_of_args
568 gutsche 1.3 # create the empty structure
569     for i in range(njobs):
570     jobParams.append("")
571    
572     for job in range(njobs):
573 slacapra 1.17 jobParams[job] = arglist[job]
574     # print str(arglist[job])
575     # print jobParams[job]
576 gutsche 1.3 common.jobDB.setArguments(job, jobParams[job])
577 gutsche 1.35 common.logger.debug(5,"Job "+str(job)+" Destination: "+str(self.jobDestination[job]))
578     common.jobDB.setDestination(job, self.jobDestination[job])
579 gutsche 1.3
580     common.jobDB.save()
581     return
582    
583     def getJobTypeArguments(self, nj, sched):
584 slacapra 1.17 result = ''
585     for i in common.jobDB.arguments(nj):
586     result=result+str(i)+" "
587     return result
588 gutsche 1.3
589     def numberOfJobs(self):
590     # Fabio
591     return self.total_number_of_jobs
592    
593 slacapra 1.1 def getTarBall(self, exe):
594     """
595     Return the TarBall with lib and exe
596     """
597    
598     # if it exist, just return it
599     self.tgzNameWithPath = common.work_space.shareDir()+self.tgz_name
600     if os.path.exists(self.tgzNameWithPath):
601     return self.tgzNameWithPath
602    
603     # Prepare a tar gzipped file with user binaries.
604     self.buildTar_(exe)
605    
606     return string.strip(self.tgzNameWithPath)
607    
608     def buildTar_(self, executable):
609    
610     # First of all declare the user Scram area
611     swArea = self.scram.getSWArea_()
612     #print "swArea = ", swArea
613     swVersion = self.scram.getSWVersion()
614     #print "swVersion = ", swVersion
615     swReleaseTop = self.scram.getReleaseTop_()
616     #print "swReleaseTop = ", swReleaseTop
617    
618     ## check if working area is release top
619     if swReleaseTop == '' or swArea == swReleaseTop:
620     return
621    
622     filesToBeTarred = []
623     ## First find the executable
624     if (self.executable != ''):
625     exeWithPath = self.scram.findFile_(executable)
626     # print exeWithPath
627     if ( not exeWithPath ):
628     raise CrabException('User executable '+executable+' not found')
629    
630     ## then check if it's private or not
631     if exeWithPath.find(swReleaseTop) == -1:
632     # the exe is private, so we must ship
633     common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
634     path = swArea+'/'
635     exe = string.replace(exeWithPath, path,'')
636     filesToBeTarred.append(exe)
637     pass
638     else:
639     # the exe is from release, we'll find it on WN
640     pass
641    
642     ## Now get the libraries: only those in local working area
643     libDir = 'lib'
644     lib = swArea+'/' +libDir
645     common.logger.debug(5,"lib "+lib+" to be tarred")
646     if os.path.exists(lib):
647     filesToBeTarred.append(libDir)
648    
649 gutsche 1.3 ## Now check if module dir is present
650     moduleDir = 'module'
651     if os.path.isdir(swArea+'/'+moduleDir):
652     filesToBeTarred.append(moduleDir)
653    
654 slacapra 1.1 ## Now check if the Data dir is present
655     dataDir = 'src/Data/'
656     if os.path.isdir(swArea+'/'+dataDir):
657     filesToBeTarred.append(dataDir)
658    
659     ## Create the tar-ball
660     if len(filesToBeTarred)>0:
661     cwd = os.getcwd()
662     os.chdir(swArea)
663     tarcmd = 'tar zcvf ' + self.tgzNameWithPath + ' '
664     for line in filesToBeTarred:
665     tarcmd = tarcmd + line + ' '
666     cout = runCommand(tarcmd)
667     if not cout:
668     raise CrabException('Could not create tar-ball')
669     os.chdir(cwd)
670     else:
671     common.logger.debug(5,"No files to be to be tarred")
672    
673     return
674    
675     def wsSetupEnvironment(self, nj):
676     """
677     Returns part of a job script which prepares
678     the execution environment for the job 'nj'.
679     """
680     # Prepare JobType-independent part
681 gutsche 1.3 txt = ''
682    
683     ## OLI_Daniele at this level middleware already known
684    
685     txt += 'if [ $middleware == LCG ]; then \n'
686     txt += self.wsSetupCMSLCGEnvironment_()
687     txt += 'elif [ $middleware == OSG ]; then\n'
688 gutsche 1.43 txt += ' WORKING_DIR=`/bin/mktemp -d $OSG_WN_TMP/cms_XXXXXXXXXXXX`\n'
689     txt += ' echo "Created working directory: $WORKING_DIR"\n'
690 gutsche 1.3 txt += ' if [ ! -d $WORKING_DIR ] ;then\n'
691 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
692     txt += ' echo "JOB_EXIT_STATUS = 10016"\n'
693     txt += ' echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
694     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
695 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
696     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
697     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
698 gutsche 1.3 txt += ' exit 1\n'
699     txt += ' fi\n'
700     txt += '\n'
701     txt += ' echo "Change to working directory: $WORKING_DIR"\n'
702     txt += ' cd $WORKING_DIR\n'
703     txt += self.wsSetupCMSOSGEnvironment_()
704     txt += 'fi\n'
705 slacapra 1.1
706     # Prepare JobType-specific part
707     scram = self.scram.commandName()
708     txt += '\n\n'
709     txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
710     txt += scram+' project CMSSW '+self.version+'\n'
711     txt += 'status=$?\n'
712     txt += 'if [ $status != 0 ] ; then\n'
713 gutsche 1.7 txt += ' echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
714 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10034"\n'
715 gutsche 1.7 txt += ' echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
716 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
717 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
718     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
719     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
720 gutsche 1.3 ## OLI_Daniele
721     txt += ' if [ $middleware == OSG ]; then \n'
722     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
723     txt += ' cd $RUNTIME_AREA\n'
724     txt += ' /bin/rm -rf $WORKING_DIR\n'
725     txt += ' if [ -d $WORKING_DIR ] ;then\n'
726 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'
727     txt += ' echo "JOB_EXIT_STATUS = 10018"\n'
728     txt += ' echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
729     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
730 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
731     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
732     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
733 gutsche 1.3 txt += ' fi\n'
734     txt += ' fi \n'
735     txt += ' exit 1 \n'
736 slacapra 1.1 txt += 'fi \n'
737     txt += 'echo "CMSSW_VERSION = '+self.version+'"\n'
738     txt += 'cd '+self.version+'\n'
739     ### needed grep for bug in scramv1 ###
740     txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
741    
742     # Handle the arguments:
743     txt += "\n"
744 gutsche 1.7 txt += "## number of arguments (first argument always jobnumber)\n"
745 slacapra 1.1 txt += "\n"
746 mkirn 1.32 # txt += "narg=$#\n"
747     txt += "if [ $nargs -lt 2 ]\n"
748 slacapra 1.1 txt += "then\n"
749 mkirn 1.33 txt += " echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$nargs+ \n"
750 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
751 gutsche 1.7 txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
752 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
753 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
754     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
755     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
756 gutsche 1.3 ## OLI_Daniele
757     txt += ' if [ $middleware == OSG ]; then \n'
758     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
759     txt += ' cd $RUNTIME_AREA\n'
760     txt += ' /bin/rm -rf $WORKING_DIR\n'
761     txt += ' if [ -d $WORKING_DIR ] ;then\n'
762 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'
763     txt += ' echo "JOB_EXIT_STATUS = 50114"\n'
764     txt += ' echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
765     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
766 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
767     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
768     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
769 gutsche 1.3 txt += ' fi\n'
770     txt += ' fi \n'
771 slacapra 1.1 txt += " exit 1\n"
772     txt += "fi\n"
773     txt += "\n"
774    
775     # Prepare job-specific part
776     job = common.job_list[nj]
777 spiga 1.42 if self.pset != None: #CarlosDaniele
778     pset = os.path.basename(job.configFilename())
779     txt += '\n'
780     if (self.datasetPath): # standard job
781     #txt += 'InputFiles=$2\n'
782     txt += 'InputFiles=${args[1]}\n'
783     txt += 'MaxEvents=${args[2]}\n'
784     txt += 'SkipEvents=${args[3]}\n'
785     txt += 'echo "Inputfiles:<$InputFiles>"\n'
786     txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset_tmp_1.cfg\n'
787     txt += 'echo "MaxEvents:<$MaxEvents>"\n'
788     txt += 'sed "s#INPUTMAXEVENTS#$MaxEvents#" $RUNTIME_AREA/ pset_tmp_1.cfg > pset_tmp_2.cfg\n'
789     txt += 'echo "SkipEvents:<$SkipEvents>"\n'
790     txt += 'sed "s#INPUTSKIPEVENTS#$SkipEvents#" $RUNTIME_AREA/ pset_tmp_2.cfg > pset.cfg\n'
791     else: # pythia like job
792     if (self.sourceSeed):
793     # txt += 'Seed=$2\n'
794     txt += 'Seed=${args[1]}\n'
795     txt += 'echo "Seed: <$Seed>"\n'
796     txt += 'sed "s#\<INPUT\>#$Seed#" $RUNTIME_AREA/'+pset+' > tmp.cfg\n'
797     if (self.sourceSeedVtx):
798     # txt += 'VtxSeed=$3\n'
799     txt += 'VtxSeed=${args[2]}\n'
800     txt += 'echo "VtxSeed: <$VtxSeed>"\n'
801     txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp.cfg > pset.cfg\n'
802     else:
803     txt += 'mv tmp.cfg pset.cfg\n'
804 slacapra 1.28 else:
805 spiga 1.42 txt += '# Copy untouched pset\n'
806     txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
807 slacapra 1.24
808 slacapra 1.1
809     if len(self.additional_inbox_files) > 0:
810     for file in self.additional_inbox_files:
811 mkirn 1.31 relFile = file.split("/")[-1]
812     txt += 'if [ -e $RUNTIME_AREA/'+relFile+' ] ; then\n'
813     txt += ' cp $RUNTIME_AREA/'+relFile+' .\n'
814     txt += ' chmod +x '+relFile+'\n'
815 slacapra 1.1 txt += 'fi\n'
816     pass
817    
818 spiga 1.42 if self.pset != None: #CarlosDaniele
819     txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
820    
821     txt += '\n'
822     txt += 'echo "***** cat pset.cfg *********"\n'
823     txt += 'cat pset.cfg\n'
824     txt += 'echo "****** end pset.cfg ********"\n'
825     txt += '\n'
826     # txt += 'echo "***** cat pset1.cfg *********"\n'
827     # txt += 'cat pset1.cfg\n'
828     # txt += 'echo "****** end pset1.cfg ********"\n'
829 gutsche 1.3 return txt
830    
831     def wsBuildExe(self, nj):
832     """
833     Put in the script the commands to build an executable
834     or a library.
835     """
836    
837     txt = ""
838    
839     if os.path.isfile(self.tgzNameWithPath):
840     txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
841     txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
842     txt += 'untar_status=$? \n'
843     txt += 'if [ $untar_status -ne 0 ]; then \n'
844     txt += ' echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
845     txt += ' echo "JOB_EXIT_STATUS = $untar_status" \n'
846 gutsche 1.7 txt += ' echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
847 gutsche 1.3 txt += ' if [ $middleware == OSG ]; then \n'
848     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
849     txt += ' cd $RUNTIME_AREA\n'
850     txt += ' /bin/rm -rf $WORKING_DIR\n'
851     txt += ' if [ -d $WORKING_DIR ] ;then\n'
852 gutsche 1.13 txt += ' echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
853     txt += ' echo "JOB_EXIT_STATUS = 50999"\n'
854     txt += ' echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
855     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
856     txt += ' rm -f $RUNTIME_AREA/$repo \n'
857     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
858     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
859 gutsche 1.3 txt += ' fi\n'
860     txt += ' fi \n'
861     txt += ' \n'
862 gutsche 1.7 txt += ' exit 1 \n'
863 gutsche 1.3 txt += 'else \n'
864     txt += ' echo "Successful untar" \n'
865     txt += 'fi \n'
866     pass
867    
868 slacapra 1.1 return txt
869    
870     def modifySteeringCards(self, nj):
871     """
872     modify the card provided by the user,
873     writing a new card into share dir
874     """
875    
876     def executableName(self):
877 spiga 1.42 if self.pset == None: #CarlosDaniele
878     return "sh "
879     else:
880     return self.executable
881 slacapra 1.1
882     def executableArgs(self):
883 spiga 1.42 if self.pset == None:#CarlosDaniele
884     return self.scriptExe + " $NJob"
885     else:
886     return " -p pset.cfg"
887 slacapra 1.1
888     def inputSandbox(self, nj):
889     """
890     Returns a list of filenames to be put in JDL input sandbox.
891     """
892     inp_box = []
893     # dict added to delete duplicate from input sandbox file list
894     seen = {}
895     ## code
896     if os.path.isfile(self.tgzNameWithPath):
897     inp_box.append(self.tgzNameWithPath)
898     ## config
899 spiga 1.42 if not self.pset is None: #CarlosDaniele
900     inp_box.append(common.job_list[nj].configFilename())
901 slacapra 1.1 ## additional input files
902 gutsche 1.3 #for file in self.additional_inbox_files:
903     # inp_box.append(common.work_space.cwdDir()+file)
904 slacapra 1.1 return inp_box
905    
906     def outputSandbox(self, nj):
907     """
908     Returns a list of filenames to be put in JDL output sandbox.
909     """
910     out_box = []
911    
912     stdout=common.job_list[nj].stdout()
913     stderr=common.job_list[nj].stderr()
914    
915     ## User Declared output files
916     for out in self.output_file:
917     n_out = nj + 1
918     out_box.append(self.numberFile_(out,str(n_out)))
919     return out_box
920     return []
921    
922     def prepareSteeringCards(self):
923     """
924     Make initial modifications of the user's steering card file.
925     """
926     return
927    
928     def wsRenameOutput(self, nj):
929     """
930     Returns part of a job script which renames the produced files.
931     """
932    
933     txt = '\n'
934 gutsche 1.7 txt += '# directory content\n'
935     txt += 'ls \n'
936 slacapra 1.1 file_list = ''
937     for fileWithSuffix in self.output_file:
938     output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
939 gutsche 1.7 file_list=file_list+output_file_num+' '
940 slacapra 1.1 txt += '\n'
941 gutsche 1.7 txt += '# check output file\n'
942 slacapra 1.1 txt += 'ls '+fileWithSuffix+'\n'
943 fanzago 1.18 txt += 'ls_result=$?\n'
944     #txt += 'exe_result=$?\n'
945     txt += 'if [ $ls_result -ne 0 ] ; then\n'
946     txt += ' echo "ERROR: Problem with output file"\n'
947     #txt += ' echo "JOB_EXIT_STATUS = $exe_result"\n'
948     #txt += ' echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
949     #txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
950 gutsche 1.3 ### OLI_DANIELE
951 gutsche 1.7 if common.scheduler.boss_scheduler_name == 'condor_g':
952     txt += ' if [ $middleware == OSG ]; then \n'
953     txt += ' echo "prepare dummy output file"\n'
954     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
955     txt += ' fi \n'
956 slacapra 1.1 txt += 'else\n'
957     txt += ' cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
958     txt += 'fi\n'
959    
960 gutsche 1.7 txt += 'cd $RUNTIME_AREA\n'
961 slacapra 1.1 file_list=file_list[:-1]
962 slacapra 1.2 txt += 'file_list="'+file_list+'"\n'
963 fanzago 1.18 txt += 'cd $RUNTIME_AREA\n'
964 gutsche 1.3 ### OLI_DANIELE
965     txt += 'if [ $middleware == OSG ]; then\n'
966     txt += ' cd $RUNTIME_AREA\n'
967     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
968     txt += ' /bin/rm -rf $WORKING_DIR\n'
969     txt += ' if [ -d $WORKING_DIR ] ;then\n'
970 gutsche 1.7 txt += ' echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
971     txt += ' echo "JOB_EXIT_STATUS = 60999"\n'
972     txt += ' echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
973     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
974 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
975     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
976     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
977 gutsche 1.3 txt += ' fi\n'
978     txt += 'fi\n'
979     txt += '\n'
980 slacapra 1.1 return txt
981    
982     def numberFile_(self, file, txt):
983     """
984     append _'txt' before last extension of a file
985     """
986     p = string.split(file,".")
987     # take away last extension
988     name = p[0]
989     for x in p[1:-1]:
990     name=name+"."+x
991     # add "_txt"
992     if len(p)>1:
993     ext = p[len(p)-1]
994     result = name + '_' + txt + "." + ext
995     else:
996     result = name + '_' + txt
997    
998     return result
999    
1000 slacapra 1.41 def getRequirements(self):
1001 slacapra 1.1 """
1002     return job requirements to add to jdl files
1003     """
1004     req = ''
1005 slacapra 1.10 if common.analisys_common_info['sw_version']:
1006     req='Member("VO-cms-' + \
1007     common.analisys_common_info['sw_version'] + \
1008     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
1009 gutsche 1.35
1010     req = req + ' && (other.GlueHostNetworkAdapterOutboundIP)'
1011    
1012 slacapra 1.1 return req
1013 gutsche 1.3
1014     def configFilename(self):
1015     """ return the config filename """
1016     return self.name()+'.cfg'
1017    
1018     ### OLI_DANIELE
1019     def wsSetupCMSOSGEnvironment_(self):
1020     """
1021     Returns part of a job script which is prepares
1022     the execution environment and which is common for all CMS jobs.
1023     """
1024     txt = '\n'
1025     txt += ' echo "### SETUP CMS OSG ENVIRONMENT ###"\n'
1026     txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
1027     txt += ' # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
1028     txt += ' source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
1029 mkirn 1.40 txt += ' elif [ -f $OSG_APP/cmssoft/cms/cmsset_default.sh ] ;then\n'
1030     txt += ' # Use $OSG_APP/cmssoft/cms/cmsset_default.sh to setup cms software\n'
1031     txt += ' source $OSG_APP/cmssoft/cms/cmsset_default.sh '+self.version+'\n'
1032 gutsche 1.3 txt += ' else\n'
1033 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'
1034 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1035     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1036     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1037 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1038     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1039     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1040 gutsche 1.7 txt += ' exit 1\n'
1041 gutsche 1.3 txt += '\n'
1042     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
1043     txt += ' cd $RUNTIME_AREA\n'
1044     txt += ' /bin/rm -rf $WORKING_DIR\n'
1045     txt += ' if [ -d $WORKING_DIR ] ;then\n'
1046 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'
1047 gutsche 1.7 txt += ' echo "JOB_EXIT_STATUS = 10017"\n'
1048     txt += ' echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
1049     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1050 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1051     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1052     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1053 gutsche 1.3 txt += ' fi\n'
1054     txt += '\n'
1055 gutsche 1.7 txt += ' exit 1\n'
1056 gutsche 1.3 txt += ' fi\n'
1057     txt += '\n'
1058     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1059     txt += ' echo " END SETUP CMS OSG ENVIRONMENT "\n'
1060    
1061     return txt
1062    
1063     ### OLI_DANIELE
1064     def wsSetupCMSLCGEnvironment_(self):
1065     """
1066     Returns part of a job script which is prepares
1067     the execution environment and which is common for all CMS jobs.
1068     """
1069     txt = ' \n'
1070     txt += ' echo " ### SETUP CMS LCG ENVIRONMENT ### "\n'
1071     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
1072     txt += ' echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
1073     txt += ' echo "JOB_EXIT_STATUS = 10031" \n'
1074     txt += ' echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
1075     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1076 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1077     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1078     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1079 gutsche 1.7 txt += ' exit 1\n'
1080 gutsche 1.3 txt += ' else\n'
1081     txt += ' echo "Sourcing environment... "\n'
1082     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1083     txt += ' echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1084     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1085     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1086     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1087 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1088     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1089     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1090 gutsche 1.7 txt += ' exit 1\n'
1091 gutsche 1.3 txt += ' fi\n'
1092     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1093     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1094     txt += ' result=$?\n'
1095     txt += ' if [ $result -ne 0 ]; then\n'
1096     txt += ' echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1097     txt += ' echo "JOB_EXIT_STATUS = 10032"\n'
1098     txt += ' echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1099     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1100 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1101     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1102     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1103 gutsche 1.7 txt += ' exit 1\n'
1104 gutsche 1.3 txt += ' fi\n'
1105     txt += ' fi\n'
1106     txt += ' \n'
1107     txt += ' string=`cat /etc/redhat-release`\n'
1108     txt += ' echo $string\n'
1109     txt += ' if [[ $string = *alhalla* ]]; then\n'
1110     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1111     txt += ' elif [[ $string = *Enterprise* ]] || [[ $string = *cientific* ]]; then\n'
1112     txt += ' export SCRAM_ARCH=slc3_ia32_gcc323\n'
1113     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1114     txt += ' else\n'
1115 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10033 ==> ERROR OS unknown, LCG environment not initialized"\n'
1116 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10033"\n'
1117     txt += ' echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
1118     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1119 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1120     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1121     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1122 gutsche 1.7 txt += ' exit 1\n'
1123 gutsche 1.3 txt += ' fi\n'
1124     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1125     txt += ' echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1126     return txt
1127 gutsche 1.5
1128     def setParam_(self, param, value):
1129     self._params[param] = value
1130    
1131     def getParams(self):
1132     return self._params
1133 gutsche 1.8
1134     def setTaskid_(self):
1135     self._taskId = self.cfg_params['taskId']
1136    
1137     def getTaskid(self):
1138     return self._taskId
1139 gutsche 1.35
1140     #######################################################################
1141     def uniquelist(self, old):
1142     """
1143     remove duplicates from a list
1144     """
1145     nd={}
1146     for e in old:
1147     nd[e]=0
1148     return nd.keys()