ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.114
Committed: Tue Aug 14 14:09:20 2007 UTC (17 years, 8 months ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.113: +14 -0 lines
Log Message:
re-aligned version

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