ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.118
Committed: Fri Sep 14 10:52:35 2007 UTC (17 years, 7 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_5_4, CRAB_1_5_4_pre2, CRAB_1_5_4_pre1
Changes since 1.117: +2 -2 lines
Log Message:
bug fix for g4Seed and mixSeed in pset manipulator

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