ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.54.2.1
Committed: Wed Dec 6 10:46:02 2006 UTC (18 years, 4 months ago) by slacapra
Content type: text/x-python
Branch: branch_1_4_1
CVS Tags: CRAB_1_4_2
Changes since 1.54: +1 -0 lines
Log Message:
add code version to DB

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