ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.165
Committed: Mon Mar 17 14:00:59 2008 UTC (17 years, 1 month ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.164: +31 -15 lines
Log Message:
Many changes to integrate BossLite. Creation step fully implemented and optimized... Submission is now working again. Here the missing things are the support for jobs submission by range, the message sending to ML, and the listmatch_match check. Actually the requirements can be changed on the fly as was in the past. The status is fully working with BossLite. The exit code display is not there since the new boss does not implement the RealTime mon.. here the functionality is under development by Federica: to be integrated.

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