ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.51
Committed: Tue Oct 17 11:46:57 2006 UTC (18 years, 6 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
Changes since 1.50: +3 -0 lines
Log Message:
strip whitespaces from file names

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