ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.48
Committed: Wed Oct 4 15:48:23 2006 UTC (18 years, 6 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
Changes since 1.47: +1 -1 lines
Log Message:
commented out last call to analisys_common_info

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