ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.98
Committed: Tue Jun 26 16:02:23 2007 UTC (17 years, 10 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_5_3_pre2
Changes since 1.97: +0 -1 lines
Log Message:
printout removed

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