ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.97
Committed: Tue Jun 26 15:47:06 2007 UTC (17 years, 10 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
Changes since 1.96: +26 -10 lines
Log Message:
put additional input files into a tgz _and_ mods to cope with new syntax in pset for maxEvents for CMSSW>150

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