ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.102
Committed: Tue Jul 10 13:56:16 2007 UTC (17 years, 9 months ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.101: +6 -2 lines
Log Message:
export SCRAM_ARCH and BUILD_ARCH before source cmsset_default.sh execution

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     import common
6     import Scram
7    
8 slacapra 1.70 import os, string, re, shutil, glob
9 slacapra 1.1
10     class Cmssw(JobType):
11 gutsche 1.38 def __init__(self, cfg_params, ncjobs):
12 slacapra 1.1 JobType.__init__(self, 'CMSSW')
13     common.logger.debug(3,'CMSSW::__init__')
14    
15 gutsche 1.3 self._params = {}
16     self.cfg_params = cfg_params
17 gutsche 1.38
18 gutsche 1.72 try:
19     self.MaxTarBallSize = float(self.cfg_params['EDG.maxtarballsize'])
20     except KeyError:
21 slacapra 1.86 self.MaxTarBallSize = 9.5
22 gutsche 1.72
23 gutsche 1.44 # number of jobs requested to be created, limit obj splitting
24 gutsche 1.38 self.ncjobs = ncjobs
25    
26 slacapra 1.1 log = common.logger
27    
28     self.scram = Scram.Scram(cfg_params)
29     self.additional_inbox_files = []
30     self.scriptExe = ''
31     self.executable = ''
32 slacapra 1.71 self.executable_arch = self.scram.getArch()
33 slacapra 1.1 self.tgz_name = 'default.tgz'
34 slacapra 1.97 self.additional_tgz_name = 'additional.tgz'
35 corvo 1.56 self.scriptName = 'CMSSW.sh'
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.55 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 gutsche 1.66
48     ## get DBS mode
49     try:
50 slacapra 1.86 self.use_dbs_1 = int(self.cfg_params['CMSSW.use_dbs_1'])
51 gutsche 1.66 except KeyError:
52 slacapra 1.86 self.use_dbs_1 = 0
53 gutsche 1.66
54 slacapra 1.1 try:
55 slacapra 1.9 tmp = cfg_params['CMSSW.datasetpath']
56     log.debug(6, "CMSSW::CMSSW(): datasetPath = "+tmp)
57     if string.lower(tmp)=='none':
58     self.datasetPath = None
59 slacapra 1.21 self.selectNoInput = 1
60 slacapra 1.9 else:
61     self.datasetPath = tmp
62 slacapra 1.21 self.selectNoInput = 0
63 slacapra 1.1 except KeyError:
64 gutsche 1.3 msg = "Error: datasetpath not defined "
65 slacapra 1.1 raise CrabException(msg)
66 gutsche 1.5
67     # ML monitoring
68     # split dataset path style: /PreProdR3Minbias/SIM/GEN-SIM
69 slacapra 1.9 if not self.datasetPath:
70     self.setParam_('dataset', 'None')
71     self.setParam_('owner', 'None')
72     else:
73 gutsche 1.92 try:
74     datasetpath_split = self.datasetPath.split("/")
75     # standard style
76     if self.use_dbs_1 == 1 :
77     self.setParam_('dataset', datasetpath_split[1])
78     self.setParam_('owner', datasetpath_split[-1])
79     else:
80     self.setParam_('dataset', datasetpath_split[1])
81     self.setParam_('owner', datasetpath_split[2])
82     except:
83     self.setParam_('dataset', self.datasetPath)
84     self.setParam_('owner', self.datasetPath)
85    
86 gutsche 1.8 self.setTaskid_()
87     self.setParam_('taskId', self.cfg_params['taskId'])
88 gutsche 1.5
89 slacapra 1.1 self.dataTiers = []
90    
91     ## now the application
92     try:
93     self.executable = cfg_params['CMSSW.executable']
94 gutsche 1.5 self.setParam_('exe', self.executable)
95 slacapra 1.1 log.debug(6, "CMSSW::CMSSW(): executable = "+self.executable)
96     msg = "Default executable cmsRun overridden. Switch to " + self.executable
97     log.debug(3,msg)
98     except KeyError:
99     self.executable = 'cmsRun'
100 gutsche 1.5 self.setParam_('exe', self.executable)
101 slacapra 1.1 msg = "User executable not defined. Use cmsRun"
102     log.debug(3,msg)
103     pass
104    
105     try:
106     self.pset = cfg_params['CMSSW.pset']
107     log.debug(6, "Cmssw::Cmssw(): PSet file = "+self.pset)
108 spiga 1.42 if self.pset.lower() != 'none' :
109     if (not os.path.exists(self.pset)):
110     raise CrabException("User defined PSet file "+self.pset+" does not exist")
111     else:
112     self.pset = None
113 slacapra 1.1 except KeyError:
114     raise CrabException("PSet file missing. Cannot run cmsRun ")
115    
116     # output files
117 slacapra 1.53 ## stuff which must be returned always via sandbox
118     self.output_file_sandbox = []
119    
120     # add fjr report by default via sandbox
121     self.output_file_sandbox.append(self.fjrFileName)
122    
123     # other output files to be returned via sandbox or copied to SE
124 slacapra 1.1 try:
125     self.output_file = []
126     tmp = cfg_params['CMSSW.output_file']
127     if tmp != '':
128     tmpOutFiles = string.split(cfg_params['CMSSW.output_file'],',')
129     log.debug(7, 'cmssw::cmssw(): output files '+str(tmpOutFiles))
130     for tmp in tmpOutFiles:
131     tmp=string.strip(tmp)
132     self.output_file.append(tmp)
133     pass
134     else:
135 gutsche 1.92 log.message("No output file defined: only stdout/err and the CRAB Framework Job Report will be available\n")
136 slacapra 1.1 pass
137     pass
138     except KeyError:
139 gutsche 1.92 log.message("No output file defined: only stdout/err and the CRAB Framework Job Report will be available\n")
140 slacapra 1.1 pass
141    
142     # script_exe file as additional file in inputSandbox
143     try:
144 slacapra 1.10 self.scriptExe = cfg_params['USER.script_exe']
145     if self.scriptExe != '':
146     if not os.path.isfile(self.scriptExe):
147 slacapra 1.64 msg ="ERROR. file "+self.scriptExe+" not found"
148 slacapra 1.10 raise CrabException(msg)
149 spiga 1.42 self.additional_inbox_files.append(string.strip(self.scriptExe))
150 slacapra 1.1 except KeyError:
151 spiga 1.42 self.scriptExe = ''
152 slacapra 1.70
153 spiga 1.42 #CarlosDaniele
154     if self.datasetPath == None and self.pset == None and self.scriptExe == '' :
155 slacapra 1.70 msg ="Error. script_exe not defined"
156 spiga 1.42 raise CrabException(msg)
157    
158 slacapra 1.1 ## additional input files
159     try:
160 slacapra 1.29 tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
161 slacapra 1.70 for tmp in tmpAddFiles:
162     tmp = string.strip(tmp)
163     dirname = ''
164     if not tmp[0]=="/": dirname = "."
165 corvo 1.85 files = []
166     if string.find(tmp,"*")>-1:
167     files = glob.glob(os.path.join(dirname, tmp))
168     if len(files)==0:
169     raise CrabException("No additional input file found with this pattern: "+tmp)
170     else:
171     files.append(tmp)
172 slacapra 1.70 for file in files:
173     if not os.path.exists(file):
174     raise CrabException("Additional input file not found: "+file)
175 slacapra 1.45 pass
176 corvo 1.85 fname = string.split(file, '/')[-1]
177     storedFile = common.work_space.pathForTgz()+'share/'+fname
178 slacapra 1.70 shutil.copyfile(file, storedFile)
179     self.additional_inbox_files.append(string.strip(storedFile))
180 slacapra 1.1 pass
181     pass
182 slacapra 1.70 common.logger.debug(5,"Additional input files: "+str(self.additional_inbox_files))
183 slacapra 1.1 except KeyError:
184     pass
185    
186 slacapra 1.9 # files per job
187 slacapra 1.1 try:
188 gutsche 1.35 if (cfg_params['CMSSW.files_per_jobs']):
189     raise CrabException("files_per_jobs no longer supported. Quitting.")
190 gutsche 1.3 except KeyError:
191 gutsche 1.35 pass
192 gutsche 1.3
193 slacapra 1.9 ## Events per job
194 gutsche 1.3 try:
195 slacapra 1.10 self.eventsPerJob =int( cfg_params['CMSSW.events_per_job'])
196 slacapra 1.9 self.selectEventsPerJob = 1
197 gutsche 1.3 except KeyError:
198 slacapra 1.9 self.eventsPerJob = -1
199     self.selectEventsPerJob = 0
200    
201 slacapra 1.22 ## number of jobs
202     try:
203     self.theNumberOfJobs =int( cfg_params['CMSSW.number_of_jobs'])
204     self.selectNumberOfJobs = 1
205     except KeyError:
206     self.theNumberOfJobs = 0
207     self.selectNumberOfJobs = 0
208 slacapra 1.10
209 gutsche 1.35 try:
210     self.total_number_of_events = int(cfg_params['CMSSW.total_number_of_events'])
211     self.selectTotalNumberEvents = 1
212     except KeyError:
213     self.total_number_of_events = 0
214     self.selectTotalNumberEvents = 0
215    
216 spiga 1.42 if self.pset != None: #CarlosDaniele
217     if ( (self.selectTotalNumberEvents + self.selectEventsPerJob + self.selectNumberOfJobs) != 2 ):
218     msg = 'Must define exactly two of total_number_of_events, events_per_job, or number_of_jobs.'
219     raise CrabException(msg)
220     else:
221     if (self.selectNumberOfJobs == 0):
222     msg = 'Must specify number_of_jobs.'
223     raise CrabException(msg)
224 gutsche 1.35
225 slacapra 1.22 ## source seed for pythia
226     try:
227     self.sourceSeed = int(cfg_params['CMSSW.pythia_seed'])
228     except KeyError:
229 slacapra 1.23 self.sourceSeed = None
230     common.logger.debug(5,"No seed given")
231 slacapra 1.22
232 slacapra 1.28 try:
233     self.sourceSeedVtx = int(cfg_params['CMSSW.vtx_seed'])
234     except KeyError:
235     self.sourceSeedVtx = None
236     common.logger.debug(5,"No vertex seed given")
237 slacapra 1.90
238     try:
239     self.sourceSeedG4 = int(cfg_params['CMSSW.g4_seed'])
240     except KeyError:
241     self.sourceSeedG4 = None
242     common.logger.debug(5,"No g4 sim hits seed given")
243    
244     try:
245     self.sourceSeedMix = int(cfg_params['CMSSW.mix_seed'])
246     except KeyError:
247     self.sourceSeedMix = None
248     common.logger.debug(5,"No mix seed given")
249    
250 spiga 1.57 try:
251     self.firstRun = int(cfg_params['CMSSW.first_run'])
252     except KeyError:
253     self.firstRun = None
254     common.logger.debug(5,"No first run given")
255 spiga 1.42 if self.pset != None: #CarlosDaniele
256 slacapra 1.97 ver = string.split(self.version,"_")
257     if (int(ver[1])>=1 and int(ver[2])>=5):
258     import PsetManipulator150 as pp
259     else:
260     import PsetManipulator as pp
261     PsetEdit = pp.PsetManipulator(self.pset) #Daniele Pset
262 gutsche 1.3
263 slacapra 1.1 #DBSDLS-start
264     ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
265     self.maxEvents=0 # max events available ( --> check the requested nb. of evts in Creator.py)
266     self.DBSPaths={} # all dbs paths requested ( --> input to the site local discovery script)
267 gutsche 1.35 self.jobDestination=[] # Site destination(s) for each job (list of lists)
268 slacapra 1.1 ## Perform the data location and discovery (based on DBS/DLS)
269 slacapra 1.9 ## SL: Don't if NONE is specified as input (pythia use case)
270 gutsche 1.35 blockSites = {}
271 slacapra 1.9 if self.datasetPath:
272 gutsche 1.35 blockSites = self.DataDiscoveryAndLocation(cfg_params)
273 slacapra 1.1 #DBSDLS-end
274    
275     self.tgzNameWithPath = self.getTarBall(self.executable)
276 slacapra 1.10
277 slacapra 1.9 ## Select Splitting
278 spiga 1.42 if self.selectNoInput:
279     if self.pset == None: #CarlosDaniele
280     self.jobSplittingForScript()
281     else:
282     self.jobSplittingNoInput()
283 gutsche 1.92 else:
284 corvo 1.56 self.jobSplittingByBlocks(blockSites)
285 gutsche 1.5
286 slacapra 1.22 # modify Pset
287 spiga 1.42 if self.pset != None: #CarlosDaniele
288 slacapra 1.86 try:
289     if (self.datasetPath): # standard job
290     # allow to processa a fraction of events in a file
291 slacapra 1.90 PsetEdit.inputModule("INPUT")
292     PsetEdit.maxEvent("INPUTMAXEVENTS")
293     PsetEdit.skipEvent("INPUTSKIPEVENTS")
294 slacapra 1.86 else: # pythia like job
295 slacapra 1.90 PsetEdit.maxEvent(self.eventsPerJob)
296 slacapra 1.86 if (self.firstRun):
297 slacapra 1.90 PsetEdit.pythiaFirstRun("INPUTFIRSTRUN") #First Run
298 slacapra 1.86 if (self.sourceSeed) :
299 slacapra 1.90 PsetEdit.pythiaSeed("INPUT")
300 slacapra 1.86 if (self.sourceSeedVtx) :
301 slacapra 1.90 PsetEdit.vtxSeed("INPUTVTX")
302     if (self.sourceSeedG4) :
303     self.PsetEdit.g4Seed("INPUTG4")
304     if (self.sourceSeedMix) :
305     self.PsetEdit.mixSeed("INPUTMIX")
306 slacapra 1.86 # add FrameworkJobReport to parameter-set
307 slacapra 1.90 PsetEdit.addCrabFJR(self.fjrFileName)
308     PsetEdit.psetWriter(self.configFilename())
309 slacapra 1.86 except:
310     msg='Error while manipuliating ParameterSet: exiting...'
311     raise CrabException(msg)
312 gutsche 1.3
313 slacapra 1.1 def DataDiscoveryAndLocation(self, cfg_params):
314    
315 slacapra 1.86 import DataDiscovery
316     import DataDiscovery_DBS2
317     import DataLocation
318 gutsche 1.3 common.logger.debug(10,"CMSSW::DataDiscoveryAndLocation()")
319    
320     datasetPath=self.datasetPath
321    
322 slacapra 1.1 ## Contact the DBS
323 gutsche 1.92 common.logger.message("Contacting Data Discovery Services ...")
324 slacapra 1.1 try:
325 gutsche 1.66
326 slacapra 1.86 if self.use_dbs_1 == 1 :
327     self.pubdata=DataDiscovery.DataDiscovery(datasetPath, cfg_params)
328     else :
329 corvo 1.85 self.pubdata=DataDiscovery_DBS2.DataDiscovery_DBS2(datasetPath, cfg_params)
330 slacapra 1.1 self.pubdata.fetchDBSInfo()
331    
332 slacapra 1.41 except DataDiscovery.NotExistingDatasetError, ex :
333 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
334     raise CrabException(msg)
335 slacapra 1.41 except DataDiscovery.NoDataTierinProvenanceError, ex :
336 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
337     raise CrabException(msg)
338 slacapra 1.41 except DataDiscovery.DataDiscoveryError, ex:
339 gutsche 1.66 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
340 slacapra 1.1 raise CrabException(msg)
341 gutsche 1.67 except DataDiscovery_DBS2.NotExistingDatasetError_DBS2, ex :
342     msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
343     raise CrabException(msg)
344     except DataDiscovery_DBS2.NoDataTierinProvenanceError_DBS2, ex :
345     msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
346     raise CrabException(msg)
347     except DataDiscovery_DBS2.DataDiscoveryError_DBS2, ex:
348     msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
349     raise CrabException(msg)
350 slacapra 1.1
351 gutsche 1.35 self.filesbyblock=self.pubdata.getFiles()
352 mkirn 1.37 self.eventsbyblock=self.pubdata.getEventsPerBlock()
353     self.eventsbyfile=self.pubdata.getEventsPerFile()
354 gutsche 1.3
355 slacapra 1.1 ## get max number of events
356     self.maxEvents=self.pubdata.getMaxEvents() ## self.maxEvents used in Creator.py
357    
358     ## Contact the DLS and build a list of sites hosting the fileblocks
359     try:
360 slacapra 1.41 dataloc=DataLocation.DataLocation(self.filesbyblock.keys(),cfg_params)
361 gutsche 1.6 dataloc.fetchDLSInfo()
362 slacapra 1.41 except DataLocation.DataLocationError , ex:
363 slacapra 1.1 msg = 'ERROR ***: failed Data Location in DLS \n %s '%ex.getErrorMessage()
364     raise CrabException(msg)
365    
366    
367 gutsche 1.35 sites = dataloc.getSites()
368     allSites = []
369     listSites = sites.values()
370 slacapra 1.63 for listSite in listSites:
371     for oneSite in listSite:
372 gutsche 1.35 allSites.append(oneSite)
373     allSites = self.uniquelist(allSites)
374 gutsche 1.3
375 gutsche 1.92 # screen output
376     common.logger.message("Requested dataset: " + datasetPath + " has " + str(self.maxEvents) + " events in " + str(len(self.filesbyblock.keys())) + " blocks.\n")
377    
378 gutsche 1.35 return sites
379 gutsche 1.3
380 gutsche 1.35 def jobSplittingByBlocks(self, blockSites):
381 slacapra 1.9 """
382 gutsche 1.35 Perform job splitting. Jobs run over an integer number of files
383     and no more than one block.
384     ARGUMENT: blockSites: dictionary with blocks as keys and list of host sites as values
385     REQUIRES: self.selectTotalNumberEvents, self.selectEventsPerJob, self.selectNumberofJobs,
386     self.total_number_of_events, self.eventsPerJob, self.theNumberOfJobs,
387     self.maxEvents, self.filesbyblock
388     SETS: self.jobDestination - Site destination(s) for each job (a list of lists)
389     self.total_number_of_jobs - Total # of jobs
390     self.list_of_args - File(s) job will run on (a list of lists)
391     """
392    
393     # ---- Handle the possible job splitting configurations ---- #
394     if (self.selectTotalNumberEvents):
395     totalEventsRequested = self.total_number_of_events
396     if (self.selectEventsPerJob):
397     eventsPerJobRequested = self.eventsPerJob
398     if (self.selectNumberOfJobs):
399     totalEventsRequested = self.theNumberOfJobs * self.eventsPerJob
400    
401     # If user requested all the events in the dataset
402     if (totalEventsRequested == -1):
403     eventsRemaining=self.maxEvents
404     # If user requested more events than are in the dataset
405     elif (totalEventsRequested > self.maxEvents):
406     eventsRemaining = self.maxEvents
407     common.logger.message("Requested "+str(self.total_number_of_events)+ " events, but only "+str(self.maxEvents)+" events are available.")
408     # If user requested less events than are in the dataset
409     else:
410     eventsRemaining = totalEventsRequested
411 slacapra 1.22
412 slacapra 1.41 # If user requested more events per job than are in the dataset
413     if (self.selectEventsPerJob and eventsPerJobRequested > self.maxEvents):
414     eventsPerJobRequested = self.maxEvents
415    
416 gutsche 1.35 # For user info at end
417     totalEventCount = 0
418 gutsche 1.3
419 gutsche 1.35 if (self.selectTotalNumberEvents and self.selectNumberOfJobs):
420     eventsPerJobRequested = int(eventsRemaining/self.theNumberOfJobs)
421 slacapra 1.22
422 gutsche 1.35 if (self.selectNumberOfJobs):
423     common.logger.message("May not create the exact number_of_jobs requested.")
424 slacapra 1.23
425 gutsche 1.38 if ( self.ncjobs == 'all' ) :
426     totalNumberOfJobs = 999999999
427     else :
428     totalNumberOfJobs = self.ncjobs
429    
430    
431 gutsche 1.35 blocks = blockSites.keys()
432     blockCount = 0
433     # Backup variable in case self.maxEvents counted events in a non-included block
434     numBlocksInDataset = len(blocks)
435 gutsche 1.3
436 gutsche 1.35 jobCount = 0
437     list_of_lists = []
438 gutsche 1.3
439 gutsche 1.92 # list tracking which jobs are in which jobs belong to which block
440     jobsOfBlock = {}
441    
442 gutsche 1.35 # ---- Iterate over the blocks in the dataset until ---- #
443     # ---- we've met the requested total # of events ---- #
444 gutsche 1.38 while ( (eventsRemaining > 0) and (blockCount < numBlocksInDataset) and (jobCount < totalNumberOfJobs)):
445 gutsche 1.35 block = blocks[blockCount]
446 gutsche 1.44 blockCount += 1
447    
448 gutsche 1.68 if self.eventsbyblock.has_key(block) :
449     numEventsInBlock = self.eventsbyblock[block]
450     common.logger.debug(5,'Events in Block File '+str(numEventsInBlock))
451 slacapra 1.9
452 gutsche 1.68 files = self.filesbyblock[block]
453     numFilesInBlock = len(files)
454     if (numFilesInBlock <= 0):
455     continue
456     fileCount = 0
457    
458     # ---- New block => New job ---- #
459     parString = "\\{"
460     # counter for number of events in files currently worked on
461     filesEventCount = 0
462     # flag if next while loop should touch new file
463     newFile = 1
464     # job event counter
465     jobSkipEventCount = 0
466 slacapra 1.9
467 gutsche 1.68 # ---- Iterate over the files in the block until we've met the requested ---- #
468     # ---- total # of events or we've gone over all the files in this block ---- #
469     while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
470     file = files[fileCount]
471     if newFile :
472     try:
473     numEventsInFile = self.eventsbyfile[file]
474     common.logger.debug(6, "File "+str(file)+" has "+str(numEventsInFile)+" events")
475     # increase filesEventCount
476     filesEventCount += numEventsInFile
477     # Add file to current job
478     parString += '\\\"' + file + '\\\"\,'
479     newFile = 0
480     except KeyError:
481     common.logger.message("File "+str(file)+" has unknown number of events: skipping")
482 slacapra 1.41
483 gutsche 1.38
484 gutsche 1.68 # if less events in file remain than eventsPerJobRequested
485     if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested ) :
486     # if last file in block
487     if ( fileCount == numFilesInBlock-1 ) :
488     # end job using last file, use remaining events in block
489     # close job and touch new file
490     fullString = parString[:-2]
491     fullString += '\\}'
492     list_of_lists.append([fullString,str(-1),str(jobSkipEventCount)])
493     common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(filesEventCount - jobSkipEventCount)+" events (last file in block).")
494     self.jobDestination.append(blockSites[block])
495     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
496 gutsche 1.92 # fill jobs of block dictionary
497     if block in jobsOfBlock.keys() :
498     jobsOfBlock[block].append(jobCount+1)
499     else:
500     jobsOfBlock[block] = [jobCount+1]
501 gutsche 1.68 # reset counter
502     jobCount = jobCount + 1
503     totalEventCount = totalEventCount + filesEventCount - jobSkipEventCount
504     eventsRemaining = eventsRemaining - filesEventCount + jobSkipEventCount
505     jobSkipEventCount = 0
506     # reset file
507     parString = "\\{"
508     filesEventCount = 0
509     newFile = 1
510     fileCount += 1
511     else :
512     # go to next file
513     newFile = 1
514     fileCount += 1
515     # if events in file equal to eventsPerJobRequested
516     elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
517 gutsche 1.38 # close job and touch new file
518     fullString = parString[:-2]
519     fullString += '\\}'
520 gutsche 1.68 list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
521     common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
522 gutsche 1.38 self.jobDestination.append(blockSites[block])
523     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
524 gutsche 1.92 if block in jobsOfBlock.keys() :
525     jobsOfBlock[block].append(jobCount+1)
526     else:
527     jobsOfBlock[block] = [jobCount+1]
528 gutsche 1.38 # reset counter
529     jobCount = jobCount + 1
530 gutsche 1.68 totalEventCount = totalEventCount + eventsPerJobRequested
531     eventsRemaining = eventsRemaining - eventsPerJobRequested
532 gutsche 1.38 jobSkipEventCount = 0
533     # reset file
534     parString = "\\{"
535     filesEventCount = 0
536     newFile = 1
537     fileCount += 1
538 gutsche 1.68
539     # if more events in file remain than eventsPerJobRequested
540 gutsche 1.38 else :
541 gutsche 1.68 # close job but don't touch new file
542     fullString = parString[:-2]
543     fullString += '\\}'
544     list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
545     common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
546     self.jobDestination.append(blockSites[block])
547     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
548 gutsche 1.92 if block in jobsOfBlock.keys() :
549     jobsOfBlock[block].append(jobCount+1)
550     else:
551     jobsOfBlock[block] = [jobCount+1]
552 gutsche 1.68 # increase counter
553     jobCount = jobCount + 1
554     totalEventCount = totalEventCount + eventsPerJobRequested
555     eventsRemaining = eventsRemaining - eventsPerJobRequested
556     # calculate skip events for last file
557     # use filesEventCount (contains several files), jobSkipEventCount and eventsPerJobRequest
558     jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
559     # remove all but the last file
560     filesEventCount = self.eventsbyfile[file]
561     parString = "\\{"
562     parString += '\\\"' + file + '\\\"\,'
563     pass # END if
564     pass # END while (iterate over files in the block)
565 gutsche 1.35 pass # END while (iterate over blocks in the dataset)
566 slacapra 1.41 self.ncjobs = self.total_number_of_jobs = jobCount
567 gutsche 1.38 if (eventsRemaining > 0 and jobCount < totalNumberOfJobs ):
568 gutsche 1.35 common.logger.message("Could not run on all requested events because some blocks not hosted at allowed sites.")
569 gutsche 1.92 common.logger.message(str(jobCount)+" job(s) can run on "+str(totalEventCount)+" events.\n")
570 slacapra 1.22
571 gutsche 1.92 # screen output
572     screenOutput = "List of jobs and available destination sites:\n\n"
573    
574     blockCounter = 0
575     for block in jobsOfBlock.keys():
576     blockCounter += 1
577     screenOutput += "Block %5i: jobs %20s: sites: %s\n" % (blockCounter,spanRanges(jobsOfBlock[block]),','.join(blockSites[block]))
578    
579     common.logger.message(screenOutput)
580    
581 slacapra 1.9 self.list_of_args = list_of_lists
582     return
583    
584 slacapra 1.21 def jobSplittingNoInput(self):
585 slacapra 1.9 """
586     Perform job splitting based on number of event per job
587     """
588     common.logger.debug(5,'Splitting per events')
589     common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
590 slacapra 1.22 common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
591 slacapra 1.9 common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
592    
593 slacapra 1.10 if (self.total_number_of_events < 0):
594     msg='Cannot split jobs per Events with "-1" as total number of events'
595     raise CrabException(msg)
596    
597 slacapra 1.22 if (self.selectEventsPerJob):
598 spiga 1.65 if (self.selectTotalNumberEvents):
599     self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
600     elif(self.selectNumberOfJobs) :
601     self.total_number_of_jobs =self.theNumberOfJobs
602     self.total_number_of_events =int(self.theNumberOfJobs*self.eventsPerJob)
603    
604 slacapra 1.22 elif (self.selectNumberOfJobs) :
605     self.total_number_of_jobs = self.theNumberOfJobs
606     self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
607 spiga 1.65
608 slacapra 1.9 common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
609    
610     # is there any remainder?
611     check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
612    
613     common.logger.debug(5,'Check '+str(check))
614    
615 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')
616 slacapra 1.9 if check > 0:
617 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))
618 slacapra 1.9
619 slacapra 1.10 # argument is seed number.$i
620 slacapra 1.9 self.list_of_args = []
621     for i in range(self.total_number_of_jobs):
622 gutsche 1.35 ## Since there is no input, any site is good
623 slacapra 1.86 # self.jobDestination.append(["Any"])
624 spiga 1.42 self.jobDestination.append([""]) #must be empty to write correctly the xml
625 slacapra 1.90 args=[]
626 spiga 1.57 if (self.firstRun):
627     ## pythia first run
628 slacapra 1.86 #self.list_of_args.append([(str(self.firstRun)+str(i))])
629 slacapra 1.90 args.append(str(self.firstRun)+str(i))
630 spiga 1.57 else:
631     ## no first run
632 slacapra 1.86 #self.list_of_args.append([str(i)])
633 slacapra 1.90 args.append(str(i))
634 slacapra 1.23 if (self.sourceSeed):
635 slacapra 1.90 args.append(str(self.sourceSeed)+str(i))
636 slacapra 1.28 if (self.sourceSeedVtx):
637 slacapra 1.90 ## + vtx random seed
638     args.append(str(self.sourceSeedVtx)+str(i))
639     if (self.sourceSeedG4):
640     ## + G4 random seed
641     args.append(str(self.sourceSeedG4)+str(i))
642     if (self.sourceSeedMix):
643     ## + Mix random seed
644     args.append(str(self.sourceSeedMix)+str(i))
645     pass
646     pass
647     self.list_of_args.append(args)
648     pass
649 slacapra 1.86
650 slacapra 1.90 # print self.list_of_args
651 gutsche 1.3
652     return
653    
654 spiga 1.42
655     def jobSplittingForScript(self):#CarlosDaniele
656     """
657     Perform job splitting based on number of job
658     """
659     common.logger.debug(5,'Splitting per job')
660     common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
661    
662     self.total_number_of_jobs = self.theNumberOfJobs
663    
664     common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
665    
666     common.logger.message(str(self.total_number_of_jobs)+' jobs can be created')
667    
668     # argument is seed number.$i
669     self.list_of_args = []
670     for i in range(self.total_number_of_jobs):
671     ## Since there is no input, any site is good
672     # self.jobDestination.append(["Any"])
673     self.jobDestination.append([""])
674     ## no random seed
675     self.list_of_args.append([str(i)])
676     return
677    
678 gutsche 1.3 def split(self, jobParams):
679    
680     common.jobDB.load()
681     #### Fabio
682     njobs = self.total_number_of_jobs
683 slacapra 1.9 arglist = self.list_of_args
684 gutsche 1.3 # create the empty structure
685     for i in range(njobs):
686     jobParams.append("")
687    
688     for job in range(njobs):
689 slacapra 1.17 jobParams[job] = arglist[job]
690     # print str(arglist[job])
691     # print jobParams[job]
692 gutsche 1.3 common.jobDB.setArguments(job, jobParams[job])
693 gutsche 1.35 common.logger.debug(5,"Job "+str(job)+" Destination: "+str(self.jobDestination[job]))
694     common.jobDB.setDestination(job, self.jobDestination[job])
695 gutsche 1.3
696     common.jobDB.save()
697     return
698    
699     def getJobTypeArguments(self, nj, sched):
700 slacapra 1.17 result = ''
701     for i in common.jobDB.arguments(nj):
702     result=result+str(i)+" "
703     return result
704 gutsche 1.3
705     def numberOfJobs(self):
706     # Fabio
707     return self.total_number_of_jobs
708    
709 slacapra 1.1 def getTarBall(self, exe):
710     """
711     Return the TarBall with lib and exe
712     """
713    
714     # if it exist, just return it
715 corvo 1.56 #
716     # Marco. Let's start to use relative path for Boss XML files
717     #
718     self.tgzNameWithPath = common.work_space.pathForTgz()+'share/'+self.tgz_name
719 slacapra 1.1 if os.path.exists(self.tgzNameWithPath):
720     return self.tgzNameWithPath
721    
722     # Prepare a tar gzipped file with user binaries.
723     self.buildTar_(exe)
724    
725     return string.strip(self.tgzNameWithPath)
726    
727     def buildTar_(self, executable):
728    
729     # First of all declare the user Scram area
730     swArea = self.scram.getSWArea_()
731     #print "swArea = ", swArea
732 slacapra 1.63 # swVersion = self.scram.getSWVersion()
733     # print "swVersion = ", swVersion
734 slacapra 1.1 swReleaseTop = self.scram.getReleaseTop_()
735     #print "swReleaseTop = ", swReleaseTop
736    
737     ## check if working area is release top
738     if swReleaseTop == '' or swArea == swReleaseTop:
739     return
740    
741 slacapra 1.61 import tarfile
742     try: # create tar ball
743     tar = tarfile.open(self.tgzNameWithPath, "w:gz")
744     ## First find the executable
745 slacapra 1.86 if (self.executable != ''):
746 slacapra 1.61 exeWithPath = self.scram.findFile_(executable)
747     if ( not exeWithPath ):
748     raise CrabException('User executable '+executable+' not found')
749    
750     ## then check if it's private or not
751     if exeWithPath.find(swReleaseTop) == -1:
752     # the exe is private, so we must ship
753     common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
754     path = swArea+'/'
755 corvo 1.85 # distinguish case when script is in user project area or given by full path somewhere else
756     if exeWithPath.find(path) >= 0 :
757     exe = string.replace(exeWithPath, path,'')
758     tar.add(path+exe,os.path.basename(executable))
759     else :
760     tar.add(exeWithPath,os.path.basename(executable))
761 slacapra 1.61 pass
762     else:
763     # the exe is from release, we'll find it on WN
764     pass
765    
766     ## Now get the libraries: only those in local working area
767     libDir = 'lib'
768     lib = swArea+'/' +libDir
769     common.logger.debug(5,"lib "+lib+" to be tarred")
770     if os.path.exists(lib):
771     tar.add(lib,libDir)
772    
773     ## Now check if module dir is present
774     moduleDir = 'module'
775     module = swArea + '/' + moduleDir
776     if os.path.isdir(module):
777     tar.add(module,moduleDir)
778    
779     ## Now check if any data dir(s) is present
780     swAreaLen=len(swArea)
781     for root, dirs, files in os.walk(swArea):
782     if "data" in dirs:
783     common.logger.debug(5,"data "+root+"/data"+" to be tarred")
784     tar.add(root+"/data",root[swAreaLen:]+"/data")
785    
786     ## Add ProdAgent dir to tar
787     paDir = 'ProdAgentApi'
788     pa = os.environ['CRABDIR'] + '/' + 'ProdAgentApi'
789     if os.path.isdir(pa):
790     tar.add(pa,paDir)
791 fanzago 1.93
792     ### FEDE FOR DBS PUBLICATION
793     ## Add PRODCOMMON dir to tar
794     prodcommonDir = 'ProdCommon'
795     prodcommonPath = os.environ['CRABDIR'] + '/' + 'ProdCommon'
796     if os.path.isdir(prodcommonPath):
797     tar.add(prodcommonPath,prodcommonDir)
798     #############################
799 slacapra 1.61
800     common.logger.debug(5,"Files added to "+self.tgzNameWithPath+" : "+str(tar.getnames()))
801     tar.close()
802     except :
803     raise CrabException('Could not create tar-ball')
804 gutsche 1.72
805     ## check for tarball size
806     tarballinfo = os.stat(self.tgzNameWithPath)
807     if ( tarballinfo.st_size > self.MaxTarBallSize*1024*1024 ) :
808     raise CrabException('Input sandbox size of ' + str(float(tarballinfo.st_size)/1024.0/1024.0) + ' MB is larger than the allowed ' + str(self.MaxTarBallSize) + ' MB input sandbox limit and not supported by the used GRID submission system. Please make sure that no unnecessary files are in all data directories in your local CMSSW project area as they are automatically packed into the input sandbox.')
809    
810 slacapra 1.61 ## create tar-ball with ML stuff
811 corvo 1.58 self.MLtgzfile = common.work_space.pathForTgz()+'share/MLfiles.tgz'
812 slacapra 1.61 try:
813     tar = tarfile.open(self.MLtgzfile, "w:gz")
814     path=os.environ['CRABDIR'] + '/python/'
815     for file in ['report.py', 'DashboardAPI.py', 'Logger.py', 'ProcInfo.py', 'apmon.py', 'parseCrabFjr.py']:
816     tar.add(path+file,file)
817     common.logger.debug(5,"Files added to "+self.MLtgzfile+" : "+str(tar.getnames()))
818     tar.close()
819     except :
820 corvo 1.58 raise CrabException('Could not create ML files tar-ball')
821    
822 slacapra 1.1 return
823    
824 slacapra 1.97 def additionalInputFileTgz(self):
825     """
826     Put all additional files into a tar ball and return its name
827     """
828     import tarfile
829     tarName= common.work_space.pathForTgz()+'share/'+self.additional_tgz_name
830     tar = tarfile.open(tarName, "w:gz")
831     for file in self.additional_inbox_files:
832     tar.add(file,string.split(file,'/')[-1])
833     common.logger.debug(5,"Files added to "+self.additional_tgz_name+" : "+str(tar.getnames()))
834     tar.close()
835     return tarName
836    
837 slacapra 1.1 def wsSetupEnvironment(self, nj):
838     """
839     Returns part of a job script which prepares
840     the execution environment for the job 'nj'.
841     """
842     # Prepare JobType-independent part
843 gutsche 1.3 txt = ''
844    
845     ## OLI_Daniele at this level middleware already known
846    
847 spiga 1.102 txt += 'echo "### Firtst set SCRAM ARCH and BUILD_ARCH ###"\n'
848     txt += 'echo "Setting SCRAM_ARCH='+self.executable_arch+'"\n'
849     txt += 'export SCRAM_ARCH='+self.executable_arch+'\n'
850     txt += 'export BUILD_ARCH='+self.executable_arch+'\n'
851 gutsche 1.3 txt += 'if [ $middleware == LCG ]; then \n'
852     txt += self.wsSetupCMSLCGEnvironment_()
853     txt += 'elif [ $middleware == OSG ]; then\n'
854 gutsche 1.43 txt += ' WORKING_DIR=`/bin/mktemp -d $OSG_WN_TMP/cms_XXXXXXXXXXXX`\n'
855     txt += ' echo "Created working directory: $WORKING_DIR"\n'
856 gutsche 1.3 txt += ' if [ ! -d $WORKING_DIR ] ;then\n'
857 gutsche 1.7 txt += ' echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
858 slacapra 1.90 txt += ' echo "JOB_EXIT_STATUS = 10016"\n'
859     txt += ' echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
860     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
861 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
862     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
863     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
864 gutsche 1.3 txt += ' exit 1\n'
865     txt += ' fi\n'
866     txt += '\n'
867     txt += ' echo "Change to working directory: $WORKING_DIR"\n'
868     txt += ' cd $WORKING_DIR\n'
869     txt += self.wsSetupCMSOSGEnvironment_()
870     txt += 'fi\n'
871 slacapra 1.1
872     # Prepare JobType-specific part
873     scram = self.scram.commandName()
874     txt += '\n\n'
875     txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
876 spiga 1.102 # txt += 'echo "Setting SCRAM_ARCH='+self.executable_arch+'"\n'
877     # txt += 'export SCRAM_ARCH='+self.executable_arch+'\n'
878 slacapra 1.1 txt += scram+' project CMSSW '+self.version+'\n'
879     txt += 'status=$?\n'
880     txt += 'if [ $status != 0 ] ; then\n'
881 gutsche 1.7 txt += ' echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
882 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10034"\n'
883 gutsche 1.7 txt += ' echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
884 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
885 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
886     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
887     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
888 gutsche 1.3 ## OLI_Daniele
889     txt += ' if [ $middleware == OSG ]; then \n'
890     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
891     txt += ' cd $RUNTIME_AREA\n'
892     txt += ' /bin/rm -rf $WORKING_DIR\n'
893     txt += ' if [ -d $WORKING_DIR ] ;then\n'
894 fanzago 1.96 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'
895     txt += ' echo "JOB_EXIT_STATUS = 10018"\n'
896     txt += ' echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
897     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
898 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
899     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
900     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
901 gutsche 1.3 txt += ' fi\n'
902     txt += ' fi \n'
903     txt += ' exit 1 \n'
904 slacapra 1.1 txt += 'fi \n'
905     txt += 'echo "CMSSW_VERSION = '+self.version+'"\n'
906     txt += 'cd '+self.version+'\n'
907 fanzago 1.99 ########## FEDE FOR DBS2 ######################
908     txt += 'SOFTWARE_DIR=`pwd`\n'
909     txt += 'echo SOFTWARE_DIR=$SOFTWARE_DIR \n'
910     ###############################################
911 slacapra 1.1 ### needed grep for bug in scramv1 ###
912 corvo 1.58 txt += scram+' runtime -sh\n'
913 slacapra 1.1 txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
914 corvo 1.58 txt += 'echo $PATH\n'
915 slacapra 1.1
916     # Handle the arguments:
917     txt += "\n"
918 gutsche 1.7 txt += "## number of arguments (first argument always jobnumber)\n"
919 slacapra 1.1 txt += "\n"
920 mkirn 1.32 # txt += "narg=$#\n"
921     txt += "if [ $nargs -lt 2 ]\n"
922 slacapra 1.1 txt += "then\n"
923 mkirn 1.33 txt += " echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$nargs+ \n"
924 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
925 gutsche 1.7 txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
926 slacapra 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
927 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
928     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
929     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
930 gutsche 1.3 ## OLI_Daniele
931     txt += ' if [ $middleware == OSG ]; then \n'
932     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
933     txt += ' cd $RUNTIME_AREA\n'
934     txt += ' /bin/rm -rf $WORKING_DIR\n'
935     txt += ' if [ -d $WORKING_DIR ] ;then\n'
936 fanzago 1.96 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'
937     txt += ' echo "JOB_EXIT_STATUS = 50114"\n'
938     txt += ' echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
939     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
940 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
941     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
942     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
943 gutsche 1.3 txt += ' fi\n'
944     txt += ' fi \n'
945 slacapra 1.1 txt += " exit 1\n"
946     txt += "fi\n"
947     txt += "\n"
948    
949     # Prepare job-specific part
950     job = common.job_list[nj]
951 fanzago 1.93 ### FEDE FOR DBS OUTPUT PUBLICATION
952     if (self.datasetPath):
953     txt += '\n'
954     txt += 'DatasetPath='+self.datasetPath+'\n'
955    
956     datasetpath_split = self.datasetPath.split("/")
957    
958     txt += 'PrimaryDataset='+datasetpath_split[1]+'\n'
959     txt += 'DataTier='+datasetpath_split[2]+'\n'
960 fanzago 1.96 #txt += 'ProcessedDataset='+datasetpath_split[3]+'\n'
961     txt += 'ApplicationFamily=cmsRun\n'
962 fanzago 1.93
963     else:
964     txt += 'DatasetPath=MCDataTier\n'
965     txt += 'PrimaryDataset=null\n'
966     txt += 'DataTier=null\n'
967 fanzago 1.96 #txt += 'ProcessedDataset=null\n'
968 fanzago 1.93 txt += 'ApplicationFamily=MCDataTier\n'
969 spiga 1.42 if self.pset != None: #CarlosDaniele
970     pset = os.path.basename(job.configFilename())
971     txt += '\n'
972 spiga 1.95 txt += 'cp $RUNTIME_AREA/'+pset+' .\n'
973 spiga 1.42 if (self.datasetPath): # standard job
974     #txt += 'InputFiles=$2\n'
975     txt += 'InputFiles=${args[1]}\n'
976     txt += 'MaxEvents=${args[2]}\n'
977     txt += 'SkipEvents=${args[3]}\n'
978     txt += 'echo "Inputfiles:<$InputFiles>"\n'
979 slacapra 1.90 txt += 'sed "s#{\'INPUT\'}#$InputFiles#" '+pset+' > tmp && mv -f tmp '+pset+'\n'
980 spiga 1.42 txt += 'echo "MaxEvents:<$MaxEvents>"\n'
981 slacapra 1.90 txt += 'sed "s#INPUTMAXEVENTS#$MaxEvents#" '+pset+' > tmp && mv -f tmp '+pset+'\n'
982 spiga 1.42 txt += 'echo "SkipEvents:<$SkipEvents>"\n'
983 slacapra 1.90 txt += 'sed "s#INPUTSKIPEVENTS#$SkipEvents#" '+pset+' > tmp && mv -f tmp '+pset+'\n'
984 spiga 1.42 else: # pythia like job
985 slacapra 1.90 seedIndex=1
986     if (self.firstRun):
987     txt += 'FirstRun=${args['+str(seedIndex)+']}\n'
988 spiga 1.57 txt += 'echo "FirstRun: <$FirstRun>"\n'
989 slacapra 1.90 txt += 'sed "s#\<INPUTFIRSTRUN\>#$FirstRun#" '+pset+' > tmp && mv -f tmp '+pset+'\n'
990     seedIndex=seedIndex+1
991    
992 spiga 1.57 if (self.sourceSeed):
993 slacapra 1.90 txt += 'Seed=${args['+str(seedIndex)+']}\n'
994     txt += 'sed "s#\<INPUT\>#$Seed#" '+pset+' > tmp && mv -f tmp '+pset+'\n'
995     seedIndex=seedIndex+1
996     ## the following seeds are not always present
997 spiga 1.42 if (self.sourceSeedVtx):
998 slacapra 1.90 txt += 'VtxSeed=${args['+str(seedIndex)+']}\n'
999 spiga 1.42 txt += 'echo "VtxSeed: <$VtxSeed>"\n'
1000 slacapra 1.90 txt += 'sed "s#\<INPUTVTX\>#$VtxSeed#" '+pset+' > tmp && mv -f tmp '+pset+'\n'
1001     seedIndex += 1
1002     if (self.sourceSeedG4):
1003     txt += 'G4Seed=${args['+str(seedIndex)+']}\n'
1004     txt += 'echo "G4Seed: <$G4Seed>"\n'
1005     txt += 'sed "s#\<INPUTG4\>#$G4Seed#" '+pset+' > tmp && mv -f tmp '+pset+'\n'
1006     seedIndex += 1
1007     if (self.sourceSeedMix):
1008     txt += 'mixSeed=${args['+str(seedIndex)+']}\n'
1009     txt += 'echo "MixSeed: <$mixSeed>"\n'
1010     txt += 'sed "s#\<INPUTMIX\>#$mixSeed#" '+pset+' > tmp && mv -f tmp '+pset+'\n'
1011     seedIndex += 1
1012     pass
1013     pass
1014     txt += 'mv -f '+pset+' pset.cfg\n'
1015 slacapra 1.1
1016     if len(self.additional_inbox_files) > 0:
1017 slacapra 1.97 txt += 'if [ -e $RUNTIME_AREA/'+self.additional_tgz_name+' ] ; then\n'
1018     txt += ' tar xzvf $RUNTIME_AREA/'+self.additional_tgz_name+'\n'
1019     txt += 'fi\n'
1020 slacapra 1.1 pass
1021    
1022 spiga 1.42 if self.pset != None: #CarlosDaniele
1023     txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
1024    
1025     txt += '\n'
1026     txt += 'echo "***** cat pset.cfg *********"\n'
1027     txt += 'cat pset.cfg\n'
1028     txt += 'echo "****** end pset.cfg ********"\n'
1029     txt += '\n'
1030 fanzago 1.93 ### FEDE FOR DBS OUTPUT PUBLICATION
1031 fanzago 1.94 txt += 'PSETHASH=`EdmConfigHash < pset.cfg` \n'
1032     txt += 'echo "PSETHASH = $PSETHASH" \n'
1033 fanzago 1.93 ##############
1034     txt += '\n'
1035     # txt += 'echo "***** cat pset1.cfg *********"\n'
1036     # txt += 'cat pset1.cfg\n'
1037     # txt += 'echo "****** end pset1.cfg ********"\n'
1038 gutsche 1.3 return txt
1039    
1040 slacapra 1.63 def wsBuildExe(self, nj=0):
1041 gutsche 1.3 """
1042     Put in the script the commands to build an executable
1043     or a library.
1044     """
1045    
1046     txt = ""
1047    
1048     if os.path.isfile(self.tgzNameWithPath):
1049     txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
1050     txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
1051     txt += 'untar_status=$? \n'
1052     txt += 'if [ $untar_status -ne 0 ]; then \n'
1053     txt += ' echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
1054     txt += ' echo "JOB_EXIT_STATUS = $untar_status" \n'
1055 gutsche 1.7 txt += ' echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
1056 gutsche 1.3 txt += ' if [ $middleware == OSG ]; then \n'
1057     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
1058     txt += ' cd $RUNTIME_AREA\n'
1059     txt += ' /bin/rm -rf $WORKING_DIR\n'
1060     txt += ' if [ -d $WORKING_DIR ] ;then\n'
1061 gutsche 1.13 txt += ' echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
1062     txt += ' echo "JOB_EXIT_STATUS = 50999"\n'
1063     txt += ' echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
1064     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1065     txt += ' rm -f $RUNTIME_AREA/$repo \n'
1066     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1067     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1068 gutsche 1.3 txt += ' fi\n'
1069     txt += ' fi \n'
1070     txt += ' \n'
1071 gutsche 1.7 txt += ' exit 1 \n'
1072 gutsche 1.3 txt += 'else \n'
1073     txt += ' echo "Successful untar" \n'
1074     txt += 'fi \n'
1075 gutsche 1.50 txt += '\n'
1076 fanzago 1.93 txt += 'echo "Include ProdAgentApi and PRODCOMMON in PYTHONPATH"\n'
1077 gutsche 1.50 txt += 'if [ -z "$PYTHONPATH" ]; then\n'
1078 fanzago 1.93 #### FEDE FOR DBS OUTPUT PUBLICATION
1079 fanzago 1.99 txt += ' export PYTHONPATH=$SOFTWARE_DIR/ProdAgentApi:$SOFTWARE_DIR/ProdCommon\n'
1080     #txt += ' export PYTHONPATH=`pwd`/ProdAgentApi:`pwd`/ProdCommon\n'
1081 fanzago 1.93 #txt += ' export PYTHONPATH=ProdAgentApi\n'
1082 gutsche 1.50 txt += 'else\n'
1083 fanzago 1.99 txt += ' export PYTHONPATH=$SOFTWARE_DIR/ProdAgentApi:$SOFTWARE_DIR/ProdCommon:${PYTHONPATH}\n'
1084     #txt += ' export PYTHONPATH=`pwd`/ProdAgentApi:`pwd`/ProdCommon:${PYTHONPATH}\n'
1085 fanzago 1.93 #txt += ' export PYTHONPATH=ProdAgentApi:${PYTHONPATH}\n'
1086     txt += 'echo "PYTHONPATH=$PYTHONPATH"\n'
1087     ###################
1088 gutsche 1.50 txt += 'fi\n'
1089     txt += '\n'
1090    
1091 gutsche 1.3 pass
1092    
1093 slacapra 1.1 return txt
1094    
1095     def modifySteeringCards(self, nj):
1096     """
1097     modify the card provided by the user,
1098     writing a new card into share dir
1099     """
1100    
1101     def executableName(self):
1102 slacapra 1.70 if self.scriptExe: #CarlosDaniele
1103 spiga 1.42 return "sh "
1104     else:
1105     return self.executable
1106 slacapra 1.1
1107     def executableArgs(self):
1108 slacapra 1.70 if self.scriptExe:#CarlosDaniele
1109 spiga 1.42 return self.scriptExe + " $NJob"
1110     else:
1111     return " -p pset.cfg"
1112 slacapra 1.1
1113     def inputSandbox(self, nj):
1114     """
1115     Returns a list of filenames to be put in JDL input sandbox.
1116     """
1117     inp_box = []
1118 slacapra 1.53 # # dict added to delete duplicate from input sandbox file list
1119     # seen = {}
1120 slacapra 1.1 ## code
1121     if os.path.isfile(self.tgzNameWithPath):
1122     inp_box.append(self.tgzNameWithPath)
1123 corvo 1.58 if os.path.isfile(self.MLtgzfile):
1124     inp_box.append(self.MLtgzfile)
1125 slacapra 1.1 ## config
1126 slacapra 1.70 if not self.pset is None:
1127 corvo 1.56 inp_box.append(common.work_space.pathForTgz() + 'job/' + self.configFilename())
1128 slacapra 1.1 ## additional input files
1129 slacapra 1.97 tgz = self.additionalInputFileTgz()
1130     inp_box.append(tgz)
1131 slacapra 1.1 return inp_box
1132    
1133     def outputSandbox(self, nj):
1134     """
1135     Returns a list of filenames to be put in JDL output sandbox.
1136     """
1137     out_box = []
1138    
1139     ## User Declared output files
1140 slacapra 1.54 for out in (self.output_file+self.output_file_sandbox):
1141 slacapra 1.1 n_out = nj + 1
1142     out_box.append(self.numberFile_(out,str(n_out)))
1143     return out_box
1144    
1145     def prepareSteeringCards(self):
1146     """
1147     Make initial modifications of the user's steering card file.
1148     """
1149     return
1150    
1151     def wsRenameOutput(self, nj):
1152     """
1153     Returns part of a job script which renames the produced files.
1154     """
1155    
1156     txt = '\n'
1157 gutsche 1.7 txt += '# directory content\n'
1158     txt += 'ls \n'
1159 slacapra 1.54
1160     for fileWithSuffix in (self.output_file+self.output_file_sandbox):
1161 slacapra 1.1 output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
1162     txt += '\n'
1163 gutsche 1.7 txt += '# check output file\n'
1164 slacapra 1.1 txt += 'ls '+fileWithSuffix+'\n'
1165 fanzago 1.18 txt += 'ls_result=$?\n'
1166     txt += 'if [ $ls_result -ne 0 ] ; then\n'
1167 spiga 1.88 txt += ' exit_status=60302\n'
1168 fanzago 1.18 txt += ' echo "ERROR: Problem with output file"\n'
1169 gutsche 1.7 if common.scheduler.boss_scheduler_name == 'condor_g':
1170     txt += ' if [ $middleware == OSG ]; then \n'
1171     txt += ' echo "prepare dummy output file"\n'
1172     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
1173     txt += ' fi \n'
1174 slacapra 1.1 txt += 'else\n'
1175 fanzago 1.93 ### FEDE FOR DBS OUTPUT PUBLICATION
1176     txt += ' mv '+fileWithSuffix+' $RUNTIME_AREA\n'
1177     txt += ' cp $RUNTIME_AREA/'+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
1178     #################################
1179 slacapra 1.1 txt += 'fi\n'
1180    
1181 gutsche 1.7 txt += 'cd $RUNTIME_AREA\n'
1182 fanzago 1.99 #### FEDE this is the cleanEnv function
1183 gutsche 1.3 ### OLI_DANIELE
1184 fanzago 1.99 #txt += 'if [ $middleware == OSG ]; then\n'
1185     #txt += ' cd $RUNTIME_AREA\n'
1186     #txt += ' echo "Remove working directory: $WORKING_DIR"\n'
1187     #txt += ' /bin/rm -rf $WORKING_DIR\n'
1188     #txt += ' if [ -d $WORKING_DIR ] ;then\n'
1189     #txt += ' echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
1190     #txt += ' echo "JOB_EXIT_STATUS = 60999"\n'
1191     #txt += ' echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
1192     #txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1193     #txt += ' rm -f $RUNTIME_AREA/$repo \n'
1194     #txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1195     #txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1196     #txt += ' fi\n'
1197     #txt += 'fi\n'
1198     #txt += '\n'
1199 slacapra 1.54
1200     file_list = ''
1201     ## Add to filelist only files to be possibly copied to SE
1202     for fileWithSuffix in self.output_file:
1203     output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
1204     file_list=file_list+output_file_num+' '
1205     file_list=file_list[:-1]
1206     txt += 'file_list="'+file_list+'"\n'
1207    
1208 slacapra 1.1 return txt
1209    
1210     def numberFile_(self, file, txt):
1211     """
1212     append _'txt' before last extension of a file
1213     """
1214     p = string.split(file,".")
1215     # take away last extension
1216     name = p[0]
1217     for x in p[1:-1]:
1218 slacapra 1.90 name=name+"."+x
1219 slacapra 1.1 # add "_txt"
1220     if len(p)>1:
1221 slacapra 1.90 ext = p[len(p)-1]
1222     result = name + '_' + txt + "." + ext
1223 slacapra 1.1 else:
1224 slacapra 1.90 result = name + '_' + txt
1225 slacapra 1.1
1226     return result
1227    
1228 slacapra 1.63 def getRequirements(self, nj=[]):
1229 slacapra 1.1 """
1230     return job requirements to add to jdl files
1231     """
1232     req = ''
1233 slacapra 1.47 if self.version:
1234 slacapra 1.10 req='Member("VO-cms-' + \
1235 slacapra 1.47 self.version + \
1236 slacapra 1.10 '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
1237 slacapra 1.91 # if self.executable_arch:
1238     # req='Member("VO-cms-' + \
1239     # self.executable_arch + \
1240     # '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
1241 gutsche 1.35
1242     req = req + ' && (other.GlueHostNetworkAdapterOutboundIP)'
1243    
1244 slacapra 1.1 return req
1245 gutsche 1.3
1246     def configFilename(self):
1247     """ return the config filename """
1248     return self.name()+'.cfg'
1249    
1250     ### OLI_DANIELE
1251     def wsSetupCMSOSGEnvironment_(self):
1252     """
1253     Returns part of a job script which is prepares
1254     the execution environment and which is common for all CMS jobs.
1255     """
1256     txt = '\n'
1257     txt += ' echo "### SETUP CMS OSG ENVIRONMENT ###"\n'
1258     txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
1259     txt += ' # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
1260 spiga 1.87 txt += ' export SCRAM_ARCH='+self.executable_arch+'\n'
1261 gutsche 1.3 txt += ' source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
1262 mkirn 1.40 txt += ' elif [ -f $OSG_APP/cmssoft/cms/cmsset_default.sh ] ;then\n'
1263     txt += ' # Use $OSG_APP/cmssoft/cms/cmsset_default.sh to setup cms software\n'
1264 spiga 1.87 txt += ' export SCRAM_ARCH='+self.executable_arch+'\n'
1265 mkirn 1.40 txt += ' source $OSG_APP/cmssoft/cms/cmsset_default.sh '+self.version+'\n'
1266 gutsche 1.3 txt += ' else\n'
1267 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'
1268 gutsche 1.3 txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1269     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1270     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1271 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1272     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1273     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1274 gutsche 1.7 txt += ' exit 1\n'
1275 gutsche 1.3 txt += '\n'
1276     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
1277     txt += ' cd $RUNTIME_AREA\n'
1278     txt += ' /bin/rm -rf $WORKING_DIR\n'
1279     txt += ' if [ -d $WORKING_DIR ] ;then\n'
1280 fanzago 1.96 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'
1281     txt += ' echo "JOB_EXIT_STATUS = 10017"\n'
1282     txt += ' echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
1283     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1284     txt += ' rm -f $RUNTIME_AREA/$repo \n'
1285     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1286     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1287 gutsche 1.3 txt += ' fi\n'
1288     txt += '\n'
1289 gutsche 1.7 txt += ' exit 1\n'
1290 gutsche 1.3 txt += ' fi\n'
1291     txt += '\n'
1292     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1293     txt += ' echo " END SETUP CMS OSG ENVIRONMENT "\n'
1294    
1295     return txt
1296    
1297     ### OLI_DANIELE
1298     def wsSetupCMSLCGEnvironment_(self):
1299     """
1300     Returns part of a job script which is prepares
1301     the execution environment and which is common for all CMS jobs.
1302     """
1303     txt = ' \n'
1304     txt += ' echo " ### SETUP CMS LCG ENVIRONMENT ### "\n'
1305     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
1306     txt += ' echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
1307     txt += ' echo "JOB_EXIT_STATUS = 10031" \n'
1308     txt += ' echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
1309     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1310 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1311     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1312     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1313 gutsche 1.7 txt += ' exit 1\n'
1314 gutsche 1.3 txt += ' else\n'
1315     txt += ' echo "Sourcing environment... "\n'
1316     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1317     txt += ' echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1318     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1319     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1320     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1321 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1322     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1323     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1324 gutsche 1.7 txt += ' exit 1\n'
1325 gutsche 1.3 txt += ' fi\n'
1326     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1327     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1328     txt += ' result=$?\n'
1329     txt += ' if [ $result -ne 0 ]; then\n'
1330     txt += ' echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1331     txt += ' echo "JOB_EXIT_STATUS = 10032"\n'
1332     txt += ' echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1333     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1334 gutsche 1.13 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1335     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1336     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1337 gutsche 1.7 txt += ' exit 1\n'
1338 gutsche 1.3 txt += ' fi\n'
1339     txt += ' fi\n'
1340     txt += ' \n'
1341     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1342     txt += ' echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1343     return txt
1344 gutsche 1.5
1345 fanzago 1.93 ### FEDE FOR DBS OUTPUT PUBLICATION
1346     def modifyReport(self, nj):
1347     """
1348     insert the part of the script that modifies the FrameworkJob Report
1349     """
1350 fanzago 1.94
1351 fanzago 1.93 txt = ''
1352     txt += 'echo "Modify Job Report" \n'
1353 fanzago 1.99 #txt += 'chmod a+x $RUNTIME_AREA/'+self.version+'/ProdAgentApi/FwkJobRep/ModifyJobReport.py\n'
1354     ################ FEDE FOR DBS2 #############################################
1355     txt += 'chmod a+x $SOFTWARE_DIR/ProdAgentApi/FwkJobRep/ModifyJobReport.py\n'
1356     #############################################################################
1357 fanzago 1.94 try:
1358     publish_data = int(self.cfg_params['USER.publish_data'])
1359     except KeyError:
1360     publish_data = 0
1361    
1362 fanzago 1.93 txt += 'if [ -z "$SE" ]; then\n'
1363     txt += ' SE="" \n'
1364     txt += 'fi \n'
1365     txt += 'if [ -z "$SE_PATH" ]; then\n'
1366     txt += ' SE_PATH="" \n'
1367     txt += 'fi \n'
1368     txt += 'echo "SE = $SE"\n'
1369     txt += 'echo "SE_PATH = $SE_PATH"\n'
1370 fanzago 1.94
1371     if (publish_data == 1):
1372     #processedDataset = self.cfg_params['USER.processed_datasetname']
1373     processedDataset = self.cfg_params['USER.publish_data_name']
1374     txt += 'ProcessedDataset='+processedDataset+'\n'
1375     #### LFN=/store/user/<user>/processedDataset_PSETHASH
1376     txt += 'if [ "$SE_PATH" == "" ]; then\n'
1377 fanzago 1.101 #### FEDE: added slash in LFN ##############
1378     txt += ' FOR_LFN=/copy_problems/ \n'
1379 fanzago 1.94 txt += 'else \n'
1380     txt += ' tmp=`echo $SE_PATH | awk -F \'store\' \'{print$2}\'` \n'
1381 fanzago 1.101 ##### FEDE TO BE CHANGED, BECAUSE STORE IS HARDCODED!!!! ########
1382 fanzago 1.94 txt += ' FOR_LFN=/store$tmp \n'
1383     txt += 'fi \n'
1384     txt += 'echo "ProcessedDataset = $ProcessedDataset"\n'
1385     txt += 'echo "FOR_LFN = $FOR_LFN" \n'
1386     else:
1387     txt += 'ProcessedDataset=no_data_to_publish \n'
1388 fanzago 1.101 #### FEDE: added slash in LFN ##############
1389     txt += 'FOR_LFN=/local/ \n'
1390 fanzago 1.94 txt += 'echo "ProcessedDataset = $ProcessedDataset"\n'
1391     txt += 'echo "FOR_LFN = $FOR_LFN" \n'
1392     txt += 'echo "CMSSW_VERSION = $CMSSW_VERSION"\n\n'
1393 fanzago 1.99 #txt += 'echo "$RUNTIME_AREA/'+self.version+'/ProdAgentApi/FwkJobRep/ModifyJobReport.py crab_fjr_$NJob.xml $NJob $FOR_LFN $PrimaryDataset $DataTier $ProcessedDataset $ApplicationFamily $executable $CMSSW_VERSION $PSETHASH $SE $SE_PATH"\n'
1394     txt += 'echo "$SOFTWARE_DIR/ProdAgentApi/FwkJobRep/ModifyJobReport.py crab_fjr_$NJob.xml $NJob $FOR_LFN $PrimaryDataset $DataTier $ProcessedDataset $ApplicationFamily $executable $CMSSW_VERSION $PSETHASH $SE $SE_PATH"\n'
1395     txt += '$SOFTWARE_DIR/ProdAgentApi/FwkJobRep/ModifyJobReport.py crab_fjr_$NJob.xml $NJob $FOR_LFN $PrimaryDataset $DataTier $ProcessedDataset $ApplicationFamily $executable $CMSSW_VERSION $PSETHASH $SE $SE_PATH\n'
1396     #txt += '$RUNTIME_AREA/'+self.version+'/ProdAgentApi/FwkJobRep/ModifyJobReport.py crab_fjr_$NJob.xml $NJob $FOR_LFN $PrimaryDataset $DataTier $ProcessedDataset $ApplicationFamily $executable $CMSSW_VERSION $PSETHASH $SE $SE_PATH\n'
1397 fanzago 1.93 txt += 'modifyReport_result=$?\n'
1398     txt += 'echo modifyReport_result = $modifyReport_result\n'
1399 fanzago 1.100 txt += 'if [ $modifyReport_result -ne 0 ]; then\n'
1400 fanzago 1.93 txt += ' exit_status=1\n'
1401     txt += ' echo "ERROR: Problem with ModifyJobReport"\n'
1402     txt += 'else\n'
1403     txt += ' mv NewFrameworkJobReport.xml crab_fjr_$NJob.xml\n'
1404     txt += 'fi\n'
1405     return txt
1406 fanzago 1.99
1407     def cleanEnv(self):
1408     ### OLI_DANIELE
1409     txt = ''
1410     txt += 'if [ $middleware == OSG ]; then\n'
1411     txt += ' cd $RUNTIME_AREA\n'
1412     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
1413     txt += ' /bin/rm -rf $WORKING_DIR\n'
1414     txt += ' if [ -d $WORKING_DIR ] ;then\n'
1415     txt += ' echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
1416     txt += ' echo "JOB_EXIT_STATUS = 60999"\n'
1417     txt += ' echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
1418     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1419     txt += ' rm -f $RUNTIME_AREA/$repo \n'
1420     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1421     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1422     txt += ' fi\n'
1423     txt += 'fi\n'
1424     txt += '\n'
1425     return txt
1426 fanzago 1.93
1427 gutsche 1.5 def setParam_(self, param, value):
1428     self._params[param] = value
1429    
1430     def getParams(self):
1431     return self._params
1432 gutsche 1.8
1433     def setTaskid_(self):
1434     self._taskId = self.cfg_params['taskId']
1435    
1436     def getTaskid(self):
1437     return self._taskId
1438 gutsche 1.35
1439     def uniquelist(self, old):
1440     """
1441     remove duplicates from a list
1442     """
1443     nd={}
1444     for e in old:
1445     nd[e]=0
1446     return nd.keys()