ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.388
Committed: Fri Oct 26 20:45:17 2012 UTC (12 years, 6 months ago) by belforte
Content type: text/x-python
Branch: MAIN
Changes since 1.387: +16 -3 lines
Log Message:
allow user to override data location, see https://savannah.cern.ch/bugs/index.php?97801

File Contents

# User Rev Content
1 spiga 1.358
2 belforte 1.388 __revision__ = "$Id: cms_cmssw.py,v 1.387 2012/09/21 14:40:29 belforte Exp $"
3     __version__ = "$Revision: 1.387 $"
4 spiga 1.358
5 slacapra 1.1 from JobType import JobType
6     from crab_exceptions import *
7     from crab_util import *
8     import common
9 ewv 1.363 import re
10 slacapra 1.1 import Scram
11 spiga 1.269 from Splitter import JobSplitter
12 ewv 1.355 from Downloader import Downloader
13 ewv 1.363 try:
14 fanzago 1.360 import json
15     except:
16     import simplejson as json
17 slacapra 1.1
18 spiga 1.293 from IMProv.IMProvNode import IMProvNode
19 ewv 1.355 from IMProv.IMProvLoader import loadIMProvFile
20 belforte 1.388 from WMCore.SiteScreening.BlackWhiteListParser import SEBlackWhiteListParser
21    
22 slacapra 1.105 import os, string, glob
23 ewv 1.355 from xml.dom import pulldom
24 slacapra 1.1
25     class Cmssw(JobType):
26 spiga 1.208 def __init__(self, cfg_params, ncjobs,skip_blocks, isNew):
27 slacapra 1.1 JobType.__init__(self, 'CMSSW')
28 spiga 1.304 common.logger.debug('CMSSW::__init__')
29 spiga 1.208 self.skip_blocks = skip_blocks
30 farinafa 1.346 self.argsList = 2
31 spiga 1.315 self.NumEvents=0
32 gutsche 1.3 self._params = {}
33     self.cfg_params = cfg_params
34 fanzago 1.368 ### FOR MULTI ###
35 fanzago 1.360 self.var_filter=''
36 ewv 1.254
37 spiga 1.234 ### Temporary patch to automatically skip the ISB size check:
38 ewv 1.319 self.server = self.cfg_params.get('CRAB.server_name',None) or \
39     self.cfg_params.get('CRAB.use_server',0)
40 mcinquil 1.340 self.local = common.scheduler.name().upper() in ['LSF','CAF','CONDOR','SGE','PBS']
41 ewv 1.250 size = 9.5
42 spiga 1.365 if self.server :
43 spiga 1.366 size = 100
44 spiga 1.365 elif self.local:
45     size = 9999999
46 spiga 1.306 self.MaxTarBallSize = float(self.cfg_params.get('GRID.maxtarballsize',size))
47 gutsche 1.72
48 gutsche 1.44 # number of jobs requested to be created, limit obj splitting
49 gutsche 1.38 self.ncjobs = ncjobs
50    
51 slacapra 1.1 self.scram = Scram.Scram(cfg_params)
52     self.additional_inbox_files = []
53     self.scriptExe = ''
54     self.executable = ''
55 slacapra 1.71 self.executable_arch = self.scram.getArch()
56 spiga 1.320 self.tgz_name = 'default.tgz'
57 corvo 1.56 self.scriptName = 'CMSSW.sh'
58 ewv 1.192 self.pset = ''
59 spiga 1.187 self.datasetPath = ''
60 gutsche 1.3
61 spiga 1.300 self.tgzNameWithPath = common.work_space.pathForTgz()+self.tgz_name
62 gutsche 1.50 # set FJR file name
63     self.fjrFileName = 'crab_fjr.xml'
64    
65 slacapra 1.1 self.version = self.scram.getSWVersion()
66 spiga 1.304 common.logger.log(10-1,"CMSSW version is: "+str(self.version))
67 spiga 1.324 version_array = self.version.split('_')
68     self.CMSSW_major = 0
69     self.CMSSW_minor = 0
70     self.CMSSW_patch = 0
71 ewv 1.182 try:
72 spiga 1.324 self.CMSSW_major = int(version_array[1])
73     self.CMSSW_minor = int(version_array[2])
74     self.CMSSW_patch = int(version_array[3])
75 ewv 1.182 except:
76 ewv 1.184 msg = "Cannot parse CMSSW version string: " + self.version + " for major and minor release number!"
77 ewv 1.182 raise CrabException(msg)
78    
79 ewv 1.334 if self.CMSSW_major < 2 or (self.CMSSW_major == 2 and self.CMSSW_minor < 1):
80     msg = "CRAB supports CMSSW >= 2_1_x only. Use an older CRAB version."
81 ewv 1.276 raise CrabException(msg)
82     """
83     As CMSSW versions are dropped we can drop more code:
84 ewv 1.334 2.x dropped: drop check for lumi range setting
85 ewv 1.276 """
86 ewv 1.355 self.checkCMSSWVersion()
87 slacapra 1.1 ### collect Data cards
88 gutsche 1.66
89 fanzago 1.221 ### Temporary: added to remove input file control in the case of PU
90 farinafa 1.224 self.dataset_pu = cfg_params.get('CMSSW.dataset_pu', None)
91 ewv 1.226
92 fanzago 1.368 if not cfg_params.has_key('CMSSW.datasetpath'):
93     msg = "Error: datasetpath not defined in the section [CMSSW] of crab.cfg file "
94 spiga 1.236 raise CrabException(msg)
95 fanzago 1.368 else:
96     tmp = cfg_params['CMSSW.datasetpath']
97     common.logger.log(10-1, "CMSSW::CMSSW(): datasetPath = "+tmp)
98     if string.lower(tmp)=='none':
99     self.datasetPath = None
100     self.selectNoInput = 1
101     self.primaryDataset = 'null'
102     else:
103     self.datasetPath = tmp
104     self.selectNoInput = 0
105     ll = len(self.datasetPath.split("/"))
106 belforte 1.381 if (ll != 4) or self.datasetPath[0] != '/' or self.datasetPath[-1] == '/':
107 fanzago 1.368 msg = 'Your datasetpath has a invalid format ' + self.datasetPath + '\n'
108 belforte 1.380 msg += 'Expected a path in format /PRIMARY/PROCESSED/TIER'
109 fanzago 1.368 raise CrabException(msg)
110     self.primaryDataset = self.datasetPath.split("/")[1]
111     self.dataTier = self.datasetPath.split("/")[2]
112 gutsche 1.5
113 ewv 1.326 # Analysis dataset is primary/processed/tier/definition
114 ewv 1.330 self.ads = False
115     if self.datasetPath:
116     self.ads = len(self.datasetPath.split("/")) > 4
117 spiga 1.354 self.lumiMask = self.cfg_params.get('CMSSW.lumi_mask',None)
118 ewv 1.356 self.lumiParams = self.cfg_params.get('CMSSW.total_number_of_lumis',None) or \
119     self.cfg_params.get('CMSSW.lumis_per_job',None)
120 spiga 1.358
121 ewv 1.327 # FUTURE: Can remove this check
122     if self.ads and self.CMSSW_major < 3:
123     common.logger.info('Warning: Analysis dataset support is incomplete in CMSSW 2_x.')
124     common.logger.info(' Only file level, not lumi level, granularity is supported.')
125    
126 spiga 1.288 self.debugWrap=''
127 fanzago 1.285 self.debug_wrapper = int(cfg_params.get('USER.debug_wrapper',0))
128     if self.debug_wrapper == 1: self.debugWrap='--debug'
129 slacapra 1.291
130 slacapra 1.1 ## now the application
131 ewv 1.313 self.managedGenerators = ['madgraph', 'comphep', 'lhe']
132 ewv 1.258 self.generator = cfg_params.get('CMSSW.generator','pythia').lower()
133 slacapra 1.153 self.executable = cfg_params.get('CMSSW.executable','cmsRun')
134 spiga 1.305 common.logger.log(10-1, "CMSSW::CMSSW(): executable = "+self.executable)
135 slacapra 1.1
136 slacapra 1.153 if not cfg_params.has_key('CMSSW.pset'):
137 slacapra 1.1 raise CrabException("PSet file missing. Cannot run cmsRun ")
138 slacapra 1.153 self.pset = cfg_params['CMSSW.pset']
139 spiga 1.305 common.logger.log(10-1, "Cmssw::Cmssw(): PSet file = "+self.pset)
140 slacapra 1.153 if self.pset.lower() != 'none' :
141     if (not os.path.exists(self.pset)):
142     raise CrabException("User defined PSet file "+self.pset+" does not exist")
143     else:
144     self.pset = None
145 slacapra 1.1
146     # output files
147 slacapra 1.53 ## stuff which must be returned always via sandbox
148     self.output_file_sandbox = []
149    
150     # add fjr report by default via sandbox
151     self.output_file_sandbox.append(self.fjrFileName)
152    
153     # other output files to be returned via sandbox or copied to SE
154 mcinquil 1.216 outfileflag = False
155 slacapra 1.153 self.output_file = []
156     tmp = cfg_params.get('CMSSW.output_file',None)
157     if tmp :
158 slacapra 1.207 self.output_file = [x.strip() for x in tmp.split(',')]
159 mcinquil 1.216 outfileflag = True #output found
160 slacapra 1.1
161 slacapra 1.153 self.scriptExe = cfg_params.get('USER.script_exe',None)
162     if self.scriptExe :
163 slacapra 1.176 if not os.path.isfile(self.scriptExe):
164     msg ="ERROR. file "+self.scriptExe+" not found"
165     raise CrabException(msg)
166     self.additional_inbox_files.append(string.strip(self.scriptExe))
167 slacapra 1.70
168 spiga 1.314 self.AdditionalArgs = cfg_params.get('USER.script_arguments',None)
169     if self.AdditionalArgs : self.AdditionalArgs = string.replace(self.AdditionalArgs,',',' ')
170    
171 spiga 1.42 if self.datasetPath == None and self.pset == None and self.scriptExe == '' :
172 slacapra 1.176 msg ="Error. script_exe not defined"
173     raise CrabException(msg)
174 spiga 1.42
175 ewv 1.226 # use parent files...
176 spiga 1.269 self.useParent = int(self.cfg_params.get('CMSSW.use_parent',0))
177 spiga 1.204
178 slacapra 1.1 ## additional input files
179 slacapra 1.153 if cfg_params.has_key('USER.additional_input_files'):
180 slacapra 1.29 tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
181 slacapra 1.70 for tmp in tmpAddFiles:
182     tmp = string.strip(tmp)
183     dirname = ''
184     if not tmp[0]=="/": dirname = "."
185 corvo 1.85 files = []
186     if string.find(tmp,"*")>-1:
187     files = glob.glob(os.path.join(dirname, tmp))
188     if len(files)==0:
189     raise CrabException("No additional input file found with this pattern: "+tmp)
190     else:
191     files.append(tmp)
192 slacapra 1.70 for file in files:
193     if not os.path.exists(file):
194     raise CrabException("Additional input file not found: "+file)
195 slacapra 1.45 pass
196 slacapra 1.105 self.additional_inbox_files.append(string.strip(file))
197 slacapra 1.1 pass
198     pass
199 spiga 1.304 common.logger.debug("Additional input files: "+str(self.additional_inbox_files))
200 slacapra 1.153 pass
201 gutsche 1.3
202 gutsche 1.35
203 ewv 1.160 ## New method of dealing with seeds
204     self.incrementSeeds = []
205     self.preserveSeeds = []
206     if cfg_params.has_key('CMSSW.preserve_seeds'):
207     tmpList = cfg_params['CMSSW.preserve_seeds'].split(',')
208     for tmp in tmpList:
209     tmp.strip()
210     self.preserveSeeds.append(tmp)
211     if cfg_params.has_key('CMSSW.increment_seeds'):
212     tmpList = cfg_params['CMSSW.increment_seeds'].split(',')
213     for tmp in tmpList:
214     tmp.strip()
215     self.incrementSeeds.append(tmp)
216    
217 fanzago 1.318 # Copy/return/publish
218 slacapra 1.153 self.copy_data = int(cfg_params.get('USER.copy_data',0))
219     self.return_data = int(cfg_params.get('USER.return_data',0))
220 fanzago 1.318 self.publish_data = int(cfg_params.get('USER.publish_data',0))
221     if (self.publish_data == 1):
222     if not cfg_params.has_key('USER.publish_data_name'):
223     raise CrabException('Cannot publish output data, because you did not specify USER.publish_data_name parameter in the crab.cfg file')
224     else:
225     self.processedDataset = cfg_params['USER.publish_data_name']
226 ewv 1.276
227     self.conf = {}
228     self.conf['pubdata'] = None
229 spiga 1.269 # number of jobs requested to be created, limit obj splitting DD
230 slacapra 1.1 #DBSDLS-start
231 ewv 1.131 ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
232 slacapra 1.1 self.maxEvents=0 # max events available ( --> check the requested nb. of evts in Creator.py)
233     self.DBSPaths={} # all dbs paths requested ( --> input to the site local discovery script)
234 gutsche 1.35 self.jobDestination=[] # Site destination(s) for each job (list of lists)
235 slacapra 1.1 ## Perform the data location and discovery (based on DBS/DLS)
236 slacapra 1.9 ## SL: Don't if NONE is specified as input (pythia use case)
237 gutsche 1.35 blockSites = {}
238 spiga 1.342 #wmbs
239     self.automation = int(self.cfg_params.get('WMBS.automation',0))
240     if self.automation == 0:
241 belforte 1.388 self.seListParser= SEBlackWhiteListParser(logger=common.logger())
242 spiga 1.342 if self.datasetPath:
243     blockSites = self.DataDiscoveryAndLocation(cfg_params)
244     #DBSDLS-end
245 belforte 1.388 # insert here site override from crab.cfg
246     # note that b/w lists will still be applied
247     if cfg_params.has_key('GRID.data_location_override'):
248     sitesOverride = cfg_params['GRID.data_location_override'].split(',')
249     common.logger.info("DataSite overridden by user to: %s" % sitesOverride)
250     seOverride = self.seListParser.expandList(sitesOverride)
251     common.logger.info("DataLocation overridden by user to: %s\n" % seOverride)
252     for block in blockSites.keys():
253     blockSites[block] = seOverride
254    
255 spiga 1.342 self.conf['blockSites']=blockSites
256 belforte 1.388
257 spiga 1.342 ## Select Splitting
258     splitByRun = int(cfg_params.get('CMSSW.split_by_run',0))
259 ewv 1.347
260 spiga 1.342 if self.selectNoInput:
261     if self.pset == None:
262     self.algo = 'ForScript'
263     else:
264     self.algo = 'NoInput'
265     self.conf['managedGenerators']=self.managedGenerators
266     self.conf['generator']=self.generator
267 ewv 1.356 elif self.ads or self.lumiMask or self.lumiParams:
268 spiga 1.342 self.algo = 'LumiBased'
269 ewv 1.359 if splitByRun:
270     msg = "Cannot combine split by run with lumi_mask, ADS, " \
271     "or lumis_per_job. Use split by lumi mode instead."
272     raise CrabException(msg)
273    
274 spiga 1.342 elif splitByRun ==1:
275     self.algo = 'RunBased'
276 spiga 1.42 else:
277 spiga 1.342 self.algo = 'EventBased'
278     common.logger.debug("Job splitting method: %s" % self.algo)
279 ewv 1.347
280 spiga 1.342 splitter = JobSplitter(self.cfg_params,self.conf)
281     self.dict = splitter.Algos()[self.algo]()
282 gutsche 1.5
283 spiga 1.300 self.argsFile= '%s/arguments.xml'%common.work_space.shareDir()
284     self.rootArgsFilename= 'arguments'
285 spiga 1.208 # modify Pset only the first time
286 spiga 1.320 if isNew:
287     if self.pset != None: self.ModifyPset()
288 spiga 1.300
289 spiga 1.320 ## Prepare inputSandbox TarBall (only the first time)
290     self.tarNameWithPath = self.getTarBall(self.executable)
291 spiga 1.293
292    
293     def ModifyPset(self):
294     import PsetManipulator as pp
295 ewv 1.335
296     # If pycfg_params set, fake out the config script
297     # to make it think it was called with those args
298     pycfg_params = self.cfg_params.get('CMSSW.pycfg_params',None)
299     if pycfg_params:
300     trueArgv = sys.argv
301     sys.argv = [self.pset]
302     sys.argv.extend(pycfg_params.split(' '))
303 spiga 1.293 PsetEdit = pp.PsetManipulator(self.pset)
304 ewv 1.335 if pycfg_params: # Restore original sys.argv
305     sys.argv = trueArgv
306    
307 spiga 1.293 try:
308     # Add FrameworkJobReport to parameter-set, set max events.
309     # Reset later for data jobs by writeCFG which does all modifications
310 ewv 1.295 PsetEdit.maxEvent(1)
311 spiga 1.293 PsetEdit.skipEvent(0)
312     PsetEdit.psetWriter(self.configFilename())
313     ## If present, add TFileService to output files
314 slacapra 1.349 if not int(self.cfg_params.get('CMSSW.skip_tfileservice_output',0)):
315 spiga 1.293 tfsOutput = PsetEdit.getTFileService()
316     if tfsOutput:
317     if tfsOutput in self.output_file:
318 spiga 1.304 common.logger.debug("Output from TFileService "+tfsOutput+" already in output files")
319 spiga 1.293 else:
320     outfileflag = True #output found
321     self.output_file.append(tfsOutput)
322 spiga 1.304 common.logger.info("Adding "+tfsOutput+" (from TFileService) to list of output files")
323 spiga 1.293 pass
324     pass
325 fanzago 1.360
326     # If requested, add PoolOutputModule to output files
327 fanzago 1.368 ### FOR MULTI ###
328 fanzago 1.360 #edmOutput = PsetEdit.getPoolOutputModule()
329     edmOutputDict = PsetEdit.getPoolOutputModule()
330     common.logger.debug("(test) edmOutputDict = "+str(edmOutputDict))
331     filter_dict = {}
332     for key in edmOutputDict.keys():
333     filter_dict[key]=edmOutputDict[key]['dataset']
334     common.logger.debug("(test) filter_dict for multi = "+str(filter_dict))
335    
336     #### in CMSSW.sh: export var_filter
337    
338     self.var_filter = json.dumps(filter_dict)
339     common.logger.debug("(test) var_filter for multi = "+self.var_filter)
340 ewv 1.363
341 fanzago 1.360 edmOutput = edmOutputDict.keys()
342 spiga 1.293 if int(self.cfg_params.get('CMSSW.get_edm_output',0)):
343     if edmOutput:
344 ewv 1.321 for outputFile in edmOutput:
345     if outputFile in self.output_file:
346 ewv 1.325 common.logger.debug("Output from PoolOutputModule "+outputFile+" already in output files")
347 ewv 1.321 else:
348     self.output_file.append(outputFile)
349     common.logger.info("Adding "+outputFile+" (from PoolOutputModule) to list of output files")
350     # not requested, check anyhow to avoid accidental T2 overload
351 slacapra 1.297 else:
352 ewv 1.321 if edmOutput:
353     missedFiles = []
354     for outputFile in edmOutput:
355     if outputFile not in self.output_file:
356     missedFiles.append(outputFile)
357     if missedFiles:
358     msg = "ERROR: PoolOutputModule(s) are present in your ParameteSet %s \n"%self.pset
359     msg += " but the file(s) produced ( %s ) are not in the list of output files\n" % ', '.join(missedFiles)
360     msg += "WARNING: please remove them. If you want to keep them, add the file(s) to output_files or use CMSSW.get_edm_output = 1\n"
361     if int(self.cfg_params.get('CMSSW.ignore_edm_output',0)):
362     msg += " CMSSW.ignore_edm_output==1 : Hope you know what you are doing...\n"
363     common.logger.info(msg)
364 spiga 1.322 else :
365 ewv 1.321 raise CrabException(msg)
366 ewv 1.301
367     if (PsetEdit.getBadFilesSetting()):
368     msg = "WARNING: You have set skipBadFiles to True. This will continue processing on some errors and you may not be notified."
369 spiga 1.304 common.logger.info(msg)
370 ewv 1.301
371 slacapra 1.297 except CrabException, msg:
372 spiga 1.304 common.logger.info(str(msg))
373 slacapra 1.297 msg='Error while manipulating ParameterSet (see previous message, if any): exiting...'
374 spiga 1.293 raise CrabException(msg)
375    
376 ewv 1.363 valid = re.compile('^[\w\.\-]+$')
377     for fileName in self.output_file:
378     if not valid.match(fileName):
379     msg = "The file %s may only contain alphanumeric characters and -, _, ." % fileName
380     raise CrabException(msg)
381    
382 gutsche 1.3
383 slacapra 1.1 def DataDiscoveryAndLocation(self, cfg_params):
384    
385 slacapra 1.86 import DataDiscovery
386     import DataLocation
387 spiga 1.304 common.logger.log(10-1,"CMSSW::DataDiscoveryAndLocation()")
388 gutsche 1.3
389     datasetPath=self.datasetPath
390    
391 slacapra 1.1 ## Contact the DBS
392 spiga 1.304 common.logger.info("Contacting Data Discovery Services ...")
393 slacapra 1.1 try:
394 spiga 1.208 self.pubdata=DataDiscovery.DataDiscovery(datasetPath, cfg_params,self.skip_blocks)
395 slacapra 1.1 self.pubdata.fetchDBSInfo()
396    
397 slacapra 1.41 except DataDiscovery.NotExistingDatasetError, ex :
398 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
399     raise CrabException(msg)
400 slacapra 1.41 except DataDiscovery.NoDataTierinProvenanceError, ex :
401 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
402     raise CrabException(msg)
403 slacapra 1.41 except DataDiscovery.DataDiscoveryError, ex:
404 gutsche 1.66 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
405 slacapra 1.1 raise CrabException(msg)
406    
407 gutsche 1.35 self.filesbyblock=self.pubdata.getFiles()
408 spiga 1.269 self.conf['pubdata']=self.pubdata
409 gutsche 1.3
410 slacapra 1.1 ## get max number of events
411 ewv 1.192 self.maxEvents=self.pubdata.getMaxEvents()
412 slacapra 1.1
413     ## Contact the DLS and build a list of sites hosting the fileblocks
414     try:
415 slacapra 1.41 dataloc=DataLocation.DataLocation(self.filesbyblock.keys(),cfg_params)
416 gutsche 1.6 dataloc.fetchDLSInfo()
417 slacapra 1.263
418 slacapra 1.41 except DataLocation.DataLocationError , ex:
419 slacapra 1.1 msg = 'ERROR ***: failed Data Location in DLS \n %s '%ex.getErrorMessage()
420     raise CrabException(msg)
421 ewv 1.131
422 slacapra 1.1
423 slacapra 1.270 unsorted_sites = dataloc.getSites()
424     sites = self.filesbyblock.fromkeys(self.filesbyblock,'')
425     for lfn in self.filesbyblock.keys():
426     if unsorted_sites.has_key(lfn):
427     sites[lfn]=unsorted_sites[lfn]
428     else:
429     sites[lfn]=[]
430    
431 slacapra 1.264 if len(sites)==0:
432 spiga 1.267 msg = 'ERROR ***: no location for any of the blocks of this dataset: \n\t %s \n'%datasetPath
433     msg += "\tMaybe the dataset is located only at T1's (or at T0), where analysis jobs are not allowed\n"
434     msg += "\tPlease check DataDiscovery page https://cmsweb.cern.ch/dbs_discovery/\n"
435 slacapra 1.264 raise CrabException(msg)
436    
437 gutsche 1.35 allSites = []
438     listSites = sites.values()
439 slacapra 1.63 for listSite in listSites:
440     for oneSite in listSite:
441 gutsche 1.35 allSites.append(oneSite)
442 slacapra 1.291 [allSites.append(it) for it in allSites if not allSites.count(it)]
443 ewv 1.295
444 gutsche 1.3
445 gutsche 1.92 # screen output
446 spiga 1.354 if self.ads or self.lumiMask:
447     common.logger.info("Requested (A)DS %s has %s block(s)." %
448 ewv 1.350 (datasetPath, len(self.filesbyblock.keys())))
449     else:
450     common.logger.info("Requested dataset: " + datasetPath + \
451     " has " + str(self.maxEvents) + " events in " + \
452     str(len(self.filesbyblock.keys())) + " blocks.\n")
453 gutsche 1.92
454 gutsche 1.35 return sites
455 ewv 1.131
456 spiga 1.42
457 spiga 1.208 def split(self, jobParams,firstJobID):
458 ewv 1.276
459 spiga 1.293 jobParams = self.dict['args']
460 spiga 1.269 njobs = self.dict['njobs']
461     self.jobDestination = self.dict['jobDestination']
462 ewv 1.131
463 ewv 1.333 if njobs == 0:
464     raise CrabException("Asked to split zero jobs: aborting")
465 belforte 1.387 if not self.server and not self.local :
466     if common.scheduler.name().upper() == 'REMOTEGLIDEIN' :
467     if njobs > 5000 :
468     raise CrabException("too many jobs. remoteGlidein has a limit at 5000")
469     else :
470     if njobs > 500:
471     msg = "Error: this task contains more than 500 jobs. \n"
472     msg += " The CRAB SA does not submit more than 500 jobs.\n"
473     msg += " Use the server mode. \n"
474     raise CrabException(msg)
475 gutsche 1.3 # create the empty structure
476     for i in range(njobs):
477     jobParams.append("")
478 ewv 1.131
479 spiga 1.165 listID=[]
480     listField=[]
481 spiga 1.293 listDictions=[]
482 spiga 1.300 exist= os.path.exists(self.argsFile)
483 spiga 1.208 for id in range(njobs):
484     job = id + int(firstJobID)
485 spiga 1.167 listID.append(job+1)
486 spiga 1.162 job_ToSave ={}
487 spiga 1.169 concString = ' '
488 spiga 1.165 argu=''
489 spiga 1.293 str_argu = str(job+1)
490 spiga 1.208 if len(jobParams[id]):
491 ewv 1.295 argu = {'JobID': job+1}
492 spiga 1.293 for i in range(len(jobParams[id])):
493     argu[self.dict['params'][i]]=jobParams[id][i]
494 spiga 1.315 if len(jobParams[id])==1: self.NumEvents = jobParams[id][i]
495 ewv 1.295 # just for debug
496 spiga 1.293 str_argu += concString.join(jobParams[id])
497 spiga 1.314 if argu != '': listDictions.append(argu)
498 ewv 1.347 job_ToSave['arguments']= '%d %d'%( (job+1), 0)
499 spiga 1.208 job_ToSave['dlsDestination']= self.jobDestination[id]
500 spiga 1.165 listField.append(job_ToSave)
501 slacapra 1.311 from ProdCommon.SiteDB.CmsSiteMapper import CmsSEMap
502     cms_se = CmsSEMap()
503 ewv 1.295 msg="Job %s Arguments: %s\n"%(str(job+1),str_argu)
504 spiga 1.293 msg+="\t Destination: %s "%(str(self.jobDestination[id]))
505 slacapra 1.311 SEDestination = [cms_se[dest] for dest in self.jobDestination[id]]
506     msg+="\t CMSDestination: %s "%(str(SEDestination))
507 spiga 1.307 common.logger.log(10-1,msg)
508 spiga 1.293 # write xml
509 ewv 1.295 if len(listDictions):
510 spiga 1.293 if exist==False: self.CreateXML()
511     self.addEntry(listDictions)
512 spiga 1.187 common._db.updateJob_(listID,listField)
513 spiga 1.293 return
514 ewv 1.313
515 spiga 1.293 def CreateXML(self):
516     """
517 ewv 1.295 """
518 spiga 1.300 result = IMProvNode( self.rootArgsFilename )
519     outfile = file( self.argsFile, 'w').write(str(result))
520 ewv 1.295 return
521 spiga 1.293
522     def addEntry(self, listDictions):
523     """
524     _addEntry_
525 ewv 1.295
526 spiga 1.293 add an entry to the xml file
527     """
528     ## load xml
529 spiga 1.300 improvDoc = loadIMProvFile(self.argsFile)
530 spiga 1.293 entrname= 'Job'
531     for dictions in listDictions:
532     report = IMProvNode(entrname , None, **dictions)
533     improvDoc.addNode(report)
534 spiga 1.300 outfile = file( self.argsFile, 'w').write(str(improvDoc))
535 gutsche 1.3 return
536 ewv 1.131
537 gutsche 1.3 def numberOfJobs(self):
538 spiga 1.342 #wmbs
539 ewv 1.347 if self.automation==0:
540 spiga 1.342 return self.dict['njobs']
541     else:
542     return None
543 ewv 1.347
544 slacapra 1.1 def getTarBall(self, exe):
545     """
546     Return the TarBall with lib and exe
547     """
548 spiga 1.320 self.tgzNameWithPath = common.work_space.pathForTgz()+self.tgz_name
549     if os.path.exists(self.tgzNameWithPath):
550     return self.tgzNameWithPath
551 slacapra 1.1
552     # Prepare a tar gzipped file with user binaries.
553     self.buildTar_(exe)
554    
555 spiga 1.320 return string.strip(self.tgzNameWithPath)
556 slacapra 1.1
557     def buildTar_(self, executable):
558    
559     # First of all declare the user Scram area
560     swArea = self.scram.getSWArea_()
561     swReleaseTop = self.scram.getReleaseTop_()
562 ewv 1.131
563 slacapra 1.1 ## check if working area is release top
564     if swReleaseTop == '' or swArea == swReleaseTop:
565 spiga 1.304 common.logger.debug("swArea = "+swArea+" swReleaseTop ="+swReleaseTop)
566 slacapra 1.1 return
567    
568 slacapra 1.61 import tarfile
569     try: # create tar ball
570 spiga 1.320 tar = tarfile.open(self.tgzNameWithPath, "w:gz")
571 slacapra 1.61 ## First find the executable
572 slacapra 1.86 if (self.executable != ''):
573 slacapra 1.61 exeWithPath = self.scram.findFile_(executable)
574     if ( not exeWithPath ):
575     raise CrabException('User executable '+executable+' not found')
576 ewv 1.131
577 slacapra 1.61 ## then check if it's private or not
578     if exeWithPath.find(swReleaseTop) == -1:
579     # the exe is private, so we must ship
580 spiga 1.304 common.logger.debug("Exe "+exeWithPath+" to be tarred")
581 slacapra 1.61 path = swArea+'/'
582 corvo 1.85 # distinguish case when script is in user project area or given by full path somewhere else
583     if exeWithPath.find(path) >= 0 :
584     exe = string.replace(exeWithPath, path,'')
585 slacapra 1.129 tar.add(path+exe,exe)
586 corvo 1.85 else :
587     tar.add(exeWithPath,os.path.basename(executable))
588 slacapra 1.61 pass
589     else:
590     # the exe is from release, we'll find it on WN
591     pass
592 ewv 1.131
593 slacapra 1.61 ## Now get the libraries: only those in local working area
594 slacapra 1.256 tar.dereference=True
595 slacapra 1.61 libDir = 'lib'
596     lib = swArea+'/' +libDir
597 spiga 1.304 common.logger.debug("lib "+lib+" to be tarred")
598 slacapra 1.61 if os.path.exists(lib):
599     tar.add(lib,libDir)
600 ewv 1.131
601 slacapra 1.61 ## Now check if module dir is present
602     moduleDir = 'module'
603     module = swArea + '/' + moduleDir
604     if os.path.isdir(module):
605     tar.add(module,moduleDir)
606 slacapra 1.256 tar.dereference=False
607 slacapra 1.61
608     ## Now check if any data dir(s) is present
609 spiga 1.374 self.dataExist = False
610 slacapra 1.212 todo_list = [(i, i) for i in os.listdir(swArea+"/src")]
611 slacapra 1.206 while len(todo_list):
612     entry, name = todo_list.pop()
613 slacapra 1.211 if name.startswith('crab_0_') or name.startswith('.') or name == 'CVS':
614 slacapra 1.206 continue
615 slacapra 1.212 if os.path.isdir(swArea+"/src/"+entry):
616 slacapra 1.206 entryPath = entry + '/'
617 slacapra 1.212 todo_list += [(entryPath + i, i) for i in os.listdir(swArea+"/src/"+entry)]
618 spiga 1.374 if name == 'data':
619     self.dataExist=True
620     common.logger.debug("data "+entry+" to be tarred")
621     tar.add(swArea+"/src/"+entry,"src/"+entry)
622     pass
623 slacapra 1.206 pass
624 ewv 1.182
625 spiga 1.179 ### CMSSW ParameterSet
626     if not self.pset is None:
627     cfg_file = common.work_space.jobDir()+self.configFilename()
628 ewv 1.357 pickleFile = common.work_space.jobDir()+self.configFilename() + '.pkl'
629 ewv 1.182 tar.add(cfg_file,self.configFilename())
630 ewv 1.357 tar.add(pickleFile,self.configFilename() + '.pkl')
631 ewv 1.313
632 spiga 1.309 try:
633     crab_cfg_file = common.work_space.shareDir()+'/crab.cfg'
634     tar.add(crab_cfg_file,'crab.cfg')
635     except:
636     pass
637 fanzago 1.93
638 fanzago 1.152 ## Add ProdCommon dir to tar
639 slacapra 1.211 prodcommonDir = './'
640     prodcommonPath = os.environ['CRABDIR'] + '/' + 'external/'
641 spiga 1.244 neededStuff = ['ProdCommon/__init__.py','ProdCommon/FwkJobRep', 'ProdCommon/CMSConfigTools', \
642 spiga 1.298 'ProdCommon/Core', 'ProdCommon/MCPayloads', 'IMProv', 'ProdCommon/Storage', \
643     'WMCore/__init__.py','WMCore/Algorithms']
644 slacapra 1.214 for file in neededStuff:
645     tar.add(prodcommonPath+file,prodcommonDir+file)
646 spiga 1.179
647     ##### ML stuff
648     ML_file_list=['report.py', 'DashboardAPI.py', 'Logger.py', 'ProcInfo.py', 'apmon.py']
649     path=os.environ['CRABDIR'] + '/python/'
650     for file in ML_file_list:
651     tar.add(path+file,file)
652    
653     ##### Utils
654 belforte 1.382 Utils_file_list=['parseCrabFjr.py','writeCfg.py', 'fillCrabFjr.py','cmscp.py','crabWatchdog.sh']
655 spiga 1.179 for file in Utils_file_list:
656     tar.add(path+file,file)
657 ewv 1.131
658 ewv 1.182 ##### AdditionalFiles
659 slacapra 1.253 tar.dereference=True
660 spiga 1.179 for file in self.additional_inbox_files:
661     tar.add(file,string.split(file,'/')[-1])
662 slacapra 1.253 tar.dereference=False
663 spiga 1.320 common.logger.log(10-1,"Files in "+self.tgzNameWithPath+" : "+str(tar.getnames()))
664 ewv 1.182
665 slacapra 1.61 tar.close()
666 mcinquil 1.241 except IOError, exc:
667 spiga 1.320 msg = 'Could not create tar-ball %s \n'%self.tgzNameWithPath
668 spiga 1.304 msg += str(exc)
669     raise CrabException(msg)
670 mcinquil 1.241 except tarfile.TarError, exc:
671 spiga 1.320 msg = 'Could not create tar-ball %s \n'%self.tgzNameWithPath
672 spiga 1.304 msg += str(exc)
673     raise CrabException(msg)
674 spiga 1.300
675 gutsche 1.72 tarballinfo = os.stat(self.tgzNameWithPath)
676     if ( tarballinfo.st_size > self.MaxTarBallSize*1024*1024 ) :
677 fanzago 1.385 #### FEDE FOR SAVANNAH BUG 94491 ########
678     cmdOut = runCommand('tar -ztvf %s|sort -n -k3'%self.tgzNameWithPath)
679 spiga 1.365 if not self.server:
680     msg = 'Input sandbox size of ' + str(float(tarballinfo.st_size)/1024.0/1024.0) + ' MB is larger than the allowed ' + \
681     str(self.MaxTarBallSize) +'MB input sandbox limit \n'
682     msg += ' and not supported by the direct GRID submission system.\n'
683 belforte 1.386 msg += ' Please use the CRAB server mode by setting use_server=1 in section [CRAB] of your crab.cfg.\n'
684 fanzago 1.385 msg += ' Content of your default.tgz archive is \n'
685     msg += cmdOut
686 ewv 1.367 else:
687 spiga 1.365 msg = 'Input sandbox size of ' + str(float(tarballinfo.st_size)/1024.0/1024.0) + ' MB is larger than the allowed ' + \
688     str(self.MaxTarBallSize) +'MB input sandbox limit in the server.'
689 fanzago 1.385 msg += 'Content of your default.tgz archive is \n'
690     msg += cmdOut
691 spiga 1.238 raise CrabException(msg)
692 gutsche 1.72
693 slacapra 1.61 ## create tar-ball with ML stuff
694 slacapra 1.97
695 spiga 1.165 def wsSetupEnvironment(self, nj=0):
696 slacapra 1.1 """
697     Returns part of a job script which prepares
698     the execution environment for the job 'nj'.
699     """
700 ewv 1.334 psetName = 'pset.py'
701    
702 slacapra 1.1 # Prepare JobType-independent part
703 ewv 1.160 txt = '\n#Written by cms_cmssw::wsSetupEnvironment\n'
704 fanzago 1.133 txt += 'echo ">>> setup environment"\n'
705 ewv 1.347 txt += 'echo "set SCRAM ARCH to ' + self.executable_arch + '"\n'
706     txt += 'export SCRAM_ARCH=' + self.executable_arch + '\n'
707     txt += 'echo "SCRAM_ARCH = $SCRAM_ARCH"\n'
708 spiga 1.290 txt += 'if [ $middleware == LCG ] || [ $middleware == CAF ] || [ $middleware == LSF ]; then \n'
709 gutsche 1.3 txt += self.wsSetupCMSLCGEnvironment_()
710 ewv 1.283 txt += 'elif [ $middleware == OSG ]; then\n'
711 gutsche 1.43 txt += ' WORKING_DIR=`/bin/mktemp -d $OSG_WN_TMP/cms_XXXXXXXXXXXX`\n'
712 ewv 1.132 txt += ' if [ ! $? == 0 ] ;then\n'
713 fanzago 1.161 txt += ' echo "ERROR ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
714     txt += ' job_exit_code=10016\n'
715     txt += ' func_exit\n'
716 gutsche 1.3 txt += ' fi\n'
717 fanzago 1.133 txt += ' echo ">>> Created working directory: $WORKING_DIR"\n'
718 gutsche 1.3 txt += '\n'
719     txt += ' echo "Change to working directory: $WORKING_DIR"\n'
720     txt += ' cd $WORKING_DIR\n'
721 fanzago 1.133 txt += ' echo ">>> current directory (WORKING_DIR): $WORKING_DIR"\n'
722 ewv 1.131 txt += self.wsSetupCMSOSGEnvironment_()
723 spiga 1.282 #Setup SGE Environment
724 ewv 1.283 txt += 'elif [ $middleware == SGE ]; then\n'
725 spiga 1.282 txt += self.wsSetupCMSLCGEnvironment_()
726    
727 edelmann 1.289 txt += 'elif [ $middleware == ARC ]; then\n'
728     txt += self.wsSetupCMSLCGEnvironment_()
729    
730 mcinquil 1.340 #Setup PBS Environment
731 mcinquil 1.343 txt += 'elif [ $middleware == PBS ]; then\n'
732 mcinquil 1.340 txt += self.wsSetupCMSLCGEnvironment_()
733    
734 gutsche 1.3 txt += 'fi\n'
735 slacapra 1.1
736     # Prepare JobType-specific part
737     scram = self.scram.commandName()
738     txt += '\n\n'
739 fanzago 1.133 txt += 'echo ">>> specific cmssw setup environment:"\n'
740     txt += 'echo "CMSSW_VERSION = '+self.version+'"\n'
741 slacapra 1.1 txt += scram+' project CMSSW '+self.version+'\n'
742     txt += 'status=$?\n'
743     txt += 'if [ $status != 0 ] ; then\n'
744 fanzago 1.161 txt += ' echo "ERROR ==> CMSSW '+self.version+' not found on `hostname`" \n'
745     txt += ' job_exit_code=10034\n'
746 fanzago 1.163 txt += ' func_exit\n'
747 slacapra 1.1 txt += 'fi \n'
748     txt += 'cd '+self.version+'\n'
749 spiga 1.277 txt += 'SOFTWARE_DIR=`pwd`; export SOFTWARE_DIR\n'
750 fanzago 1.133 txt += 'echo ">>> current directory (SOFTWARE_DIR): $SOFTWARE_DIR" \n'
751 slacapra 1.1 txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
752 fanzago 1.180 txt += 'if [ $? != 0 ] ; then\n'
753     txt += ' echo "ERROR ==> Problem with the command: "\n'
754     txt += ' echo "eval \`'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME \` at `hostname`"\n'
755     txt += ' job_exit_code=10034\n'
756     txt += ' func_exit\n'
757     txt += 'fi \n'
758 slacapra 1.1 # Handle the arguments:
759     txt += "\n"
760 farinafa 1.346 txt += "## number of arguments (first argument always jobnumber, the second is the resubmission number)\n"
761 slacapra 1.1 txt += "\n"
762 spiga 1.165 txt += "if [ $nargs -lt "+str(self.argsList)+" ]\n"
763 slacapra 1.1 txt += "then\n"
764 fanzago 1.161 txt += " echo 'ERROR ==> Too few arguments' +$nargs+ \n"
765     txt += ' job_exit_code=50113\n'
766     txt += " func_exit\n"
767 slacapra 1.1 txt += "fi\n"
768     txt += "\n"
769    
770     # Prepare job-specific part
771     job = common.job_list[nj]
772 ewv 1.131 if (self.datasetPath):
773 fanzago 1.93 txt += '\n'
774     txt += 'DatasetPath='+self.datasetPath+'\n'
775    
776 spiga 1.238 txt += 'PrimaryDataset='+self.primaryDataset +'\n'
777 fanzago 1.318 txt += 'DataTier='+self.dataTier+'\n'
778 fanzago 1.96 txt += 'ApplicationFamily=cmsRun\n'
779 fanzago 1.93
780     else:
781     txt += 'DatasetPath=MCDataTier\n'
782     txt += 'PrimaryDataset=null\n'
783     txt += 'DataTier=null\n'
784     txt += 'ApplicationFamily=MCDataTier\n'
785 ewv 1.170 if self.pset != None:
786 spiga 1.42 pset = os.path.basename(job.configFilename())
787 ewv 1.357 pkl = os.path.basename(job.configFilename()) + '.pkl'
788 spiga 1.42 txt += '\n'
789 spiga 1.95 txt += 'cp $RUNTIME_AREA/'+pset+' .\n'
790 ewv 1.357 txt += 'cp $RUNTIME_AREA/'+pkl+' .\n'
791 spiga 1.296
792 ewv 1.295 txt += 'PreserveSeeds=' + ','.join(self.preserveSeeds) + '; export PreserveSeeds\n'
793     txt += 'IncrementSeeds=' + ','.join(self.incrementSeeds) + '; export IncrementSeeds\n'
794     txt += 'echo "PreserveSeeds: <$PreserveSeeds>"\n'
795     txt += 'echo "IncrementSeeds:<$IncrementSeeds>"\n'
796 slacapra 1.90
797 ewv 1.184 txt += 'mv -f ' + pset + ' ' + psetName + '\n'
798 fanzago 1.360 if self.var_filter:
799     #print "self.var_filter = ",self.var_filter
800     txt += "export var_filter="+"'"+self.var_filter+"'\n"
801     txt += 'echo $var_filter'
802 ewv 1.319 else:
803 spiga 1.314 txt += '\n'
804 spiga 1.331 if self.AdditionalArgs: txt += 'export AdditionalArgs=\"%s\"\n'%(self.AdditionalArgs)
805 spiga 1.315 if int(self.NumEvents) != 0: txt += 'export MaxEvents=%s\n'%str(self.NumEvents)
806 gutsche 1.3 return txt
807 slacapra 1.176
808 fanzago 1.166 def wsUntarSoftware(self, nj=0):
809 gutsche 1.3 """
810     Put in the script the commands to build an executable
811     or a library.
812     """
813    
814 fanzago 1.166 txt = '\n#Written by cms_cmssw::wsUntarSoftware\n'
815 gutsche 1.3
816     if os.path.isfile(self.tgzNameWithPath):
817 spiga 1.358 txt += 'echo ">>> tar xzf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+' :" \n'
818 belforte 1.382 txt += 'tar xzf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
819 fanzago 1.375 txt += 'untar_status=$? \n'
820 fanzago 1.285 if self.debug_wrapper==1 :
821 fanzago 1.375 txt += 'echo "----------------" \n'
822     txt += 'ls -AlR $RUNTIME_AREA \n'
823     txt += 'echo "----------------" \n'
824 gutsche 1.3 txt += 'if [ $untar_status -ne 0 ]; then \n'
825 fanzago 1.161 txt += ' echo "ERROR ==> Untarring .tgz file failed"\n'
826     txt += ' job_exit_code=$untar_status\n'
827     txt += ' func_exit\n'
828 gutsche 1.3 txt += 'else \n'
829     txt += ' echo "Successful untar" \n'
830 fanzago 1.375 txt += ' chmod a+w -R $RUNTIME_AREA \n'
831 belforte 1.379 txt += ' chmod 600 $X509_USER_PROXY \n'
832 fanzago 1.375 if self.debug_wrapper==1 :
833     txt += ' echo "changed in a+w the permission of $RUNTIME_AREA "\n'
834     txt += ' ls -AlR $RUNTIME_AREA \n'
835 gutsche 1.3 txt += 'fi \n'
836 gutsche 1.50 txt += '\n'
837 slacapra 1.211 txt += 'echo ">>> Include $RUNTIME_AREA in PYTHONPATH:"\n'
838 gutsche 1.50 txt += 'if [ -z "$PYTHONPATH" ]; then\n'
839 slacapra 1.211 txt += ' export PYTHONPATH=$RUNTIME_AREA/\n'
840 gutsche 1.50 txt += 'else\n'
841 slacapra 1.211 txt += ' export PYTHONPATH=$RUNTIME_AREA/:${PYTHONPATH}\n'
842 fanzago 1.93 txt += 'echo "PYTHONPATH=$PYTHONPATH"\n'
843 gutsche 1.50 txt += 'fi\n'
844     txt += '\n'
845    
846 gutsche 1.3 pass
847 ewv 1.131
848 slacapra 1.1 return txt
849 ewv 1.170
850 fanzago 1.166 def wsBuildExe(self, nj=0):
851     """
852     Put in the script the commands to build an executable
853     or a library.
854     """
855    
856     txt = '\n#Written by cms_cmssw::wsBuildExe\n'
857     txt += 'echo ">>> moving CMSSW software directories in `pwd`" \n'
858 fanzago 1.375
859     txt += 'rm -rf lib/ module/ \n'
860 ewv 1.170 txt += 'mv $RUNTIME_AREA/lib/ . \n'
861     txt += 'mv $RUNTIME_AREA/module/ . \n'
862 spiga 1.374 if self.dataExist == True:
863 fanzago 1.375 txt += 'rm -rf src/ \n'
864 spiga 1.374 txt += 'mv $RUNTIME_AREA/src/ . \n'
865 ewv 1.182 if len(self.additional_inbox_files)>0:
866 spiga 1.179 for file in self.additional_inbox_files:
867 spiga 1.191 txt += 'mv $RUNTIME_AREA/'+os.path.basename(file)+' . \n'
868 ewv 1.170
869 slacapra 1.211 txt += 'echo ">>> Include $RUNTIME_AREA in PYTHONPATH:"\n'
870 fanzago 1.166 txt += 'if [ -z "$PYTHONPATH" ]; then\n'
871 slacapra 1.211 txt += ' export PYTHONPATH=$RUNTIME_AREA/\n'
872 fanzago 1.166 txt += 'else\n'
873 slacapra 1.211 txt += ' export PYTHONPATH=$RUNTIME_AREA/:${PYTHONPATH}\n'
874 fanzago 1.166 txt += 'echo "PYTHONPATH=$PYTHONPATH"\n'
875     txt += 'fi\n'
876     txt += '\n'
877    
878 slacapra 1.302 if self.pset != None:
879 ewv 1.334 psetName = 'pset.py'
880    
881 slacapra 1.302 txt += '\n'
882     if self.debug_wrapper == 1:
883     txt += 'echo "***** cat ' + psetName + ' *********"\n'
884     txt += 'cat ' + psetName + '\n'
885     txt += 'echo "****** end ' + psetName + ' ********"\n'
886     txt += '\n'
887     txt += 'echo "***********************" \n'
888     txt += 'which edmConfigHash \n'
889     txt += 'echo "***********************" \n'
890 ewv 1.334 txt += 'edmConfigHash ' + psetName + ' \n'
891     txt += 'PSETHASH=`edmConfigHash ' + psetName + '` \n'
892 slacapra 1.302 txt += 'echo "PSETHASH = $PSETHASH" \n'
893 fanzago 1.368 #### temporary fix for noEdm files #####
894 slacapra 1.302 txt += 'if [ -z "$PSETHASH" ]; then \n'
895     txt += ' export PSETHASH=null\n'
896     txt += 'fi \n'
897     #############################################
898     txt += '\n'
899 fanzago 1.166 return txt
900 slacapra 1.1
901 ewv 1.131
902 slacapra 1.1 def executableName(self):
903 ewv 1.192 if self.scriptExe:
904 spiga 1.42 return "sh "
905     else:
906     return self.executable
907 slacapra 1.1
908     def executableArgs(self):
909 ewv 1.276 if self.scriptExe:
910 spiga 1.370 return os.path.basename(self.scriptExe) + " $NJob $AdditionalArgs"
911 fanzago 1.115 else:
912 ewv 1.334 return " -j $RUNTIME_AREA/crab_fjr_$NJob.xml -p pset.py"
913 slacapra 1.1
914     def inputSandbox(self, nj):
915     """
916     Returns a list of filenames to be put in JDL input sandbox.
917     """
918     inp_box = []
919     if os.path.isfile(self.tgzNameWithPath):
920     inp_box.append(self.tgzNameWithPath)
921 spiga 1.320 if os.path.isfile(self.argsFile):
922     inp_box.append(self.argsFile)
923 spiga 1.243 inp_box.append(common.work_space.jobDir() + self.scriptName)
924 slacapra 1.1 return inp_box
925    
926     def outputSandbox(self, nj):
927     """
928     Returns a list of filenames to be put in JDL output sandbox.
929     """
930     out_box = []
931    
932     ## User Declared output files
933 slacapra 1.54 for out in (self.output_file+self.output_file_sandbox):
934 ewv 1.131 n_out = nj + 1
935 slacapra 1.207 out_box.append(numberFile(out,str(n_out)))
936 slacapra 1.1 return out_box
937    
938    
939     def wsRenameOutput(self, nj):
940     """
941     Returns part of a job script which renames the produced files.
942     """
943    
944 ewv 1.160 txt = '\n#Written by cms_cmssw::wsRenameOutput\n'
945 belforte 1.386 txt += 'echo ">>> current directory $PWD" \n'
946     txt += 'echo ">>> (SOFTWARE_DIR): $SOFTWARE_DIR" \n'
947     txt += 'echo ">>> (WORKING_DIR): $WORKING_DIR" \n'
948 fanzago 1.148 txt += 'echo ">>> current directory content:"\n'
949 fanzago 1.378 #if self.debug_wrapper==1:
950     txt += 'ls -Al\n'
951 fanzago 1.145 txt += '\n'
952 slacapra 1.54
953 fanzago 1.128 for fileWithSuffix in (self.output_file):
954 farinafa 1.346 output_file_num = numberFile(fileWithSuffix, '$OutUniqueID')
955 slacapra 1.1 txt += '\n'
956 gutsche 1.7 txt += '# check output file\n'
957 slacapra 1.106 txt += 'if [ -e ./'+fileWithSuffix+' ] ; then\n'
958 ewv 1.147 if (self.copy_data == 1): # For OSG nodes, file is in $WORKING_DIR, should not be moved to $RUNTIME_AREA
959     txt += ' mv '+fileWithSuffix+' '+output_file_num+'\n'
960 spiga 1.209 txt += ' ln -s `pwd`/'+output_file_num+' $RUNTIME_AREA/'+fileWithSuffix+'\n'
961 ewv 1.147 else:
962     txt += ' mv '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
963     txt += ' ln -s $RUNTIME_AREA/'+output_file_num+' $RUNTIME_AREA/'+fileWithSuffix+'\n'
964 slacapra 1.106 txt += 'else\n'
965 fanzago 1.161 txt += ' job_exit_code=60302\n'
966     txt += ' echo "WARNING: Output file '+fileWithSuffix+' not found"\n'
967 ewv 1.156 if common.scheduler.name().upper() == 'CONDOR_G':
968 gutsche 1.7 txt += ' if [ $middleware == OSG ]; then \n'
969     txt += ' echo "prepare dummy output file"\n'
970     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
971     txt += ' fi \n'
972 slacapra 1.1 txt += 'fi\n'
973 slacapra 1.105 file_list = []
974     for fileWithSuffix in (self.output_file):
975 farinafa 1.346 file_list.append(numberFile('$SOFTWARE_DIR/'+fileWithSuffix, '$OutUniqueID'))
976 ewv 1.131
977 spiga 1.245 txt += 'file_list="'+string.join(file_list,',')+'"\n'
978 fanzago 1.149 txt += '\n'
979 belforte 1.386 txt += 'echo ">>> current directory $PWD" \n'
980     txt += 'echo ">>> (SOFTWARE_DIR): $SOFTWARE_DIR" \n'
981     txt += 'echo ">>> (WORKING_DIR): $WORKING_DIR" \n'
982 fanzago 1.148 txt += 'echo ">>> current directory content:"\n'
983 fanzago 1.378 #if self.debug_wrapper==1:
984     txt += 'ls -Al\n'
985 fanzago 1.148 txt += '\n'
986 gutsche 1.7 txt += 'cd $RUNTIME_AREA\n'
987 fanzago 1.133 txt += 'echo ">>> current directory (RUNTIME_AREA): $RUNTIME_AREA"\n'
988 slacapra 1.1 return txt
989    
990 slacapra 1.63 def getRequirements(self, nj=[]):
991 slacapra 1.1 """
992 ewv 1.131 return job requirements to add to jdl files
993 slacapra 1.1 """
994     req = ''
995 slacapra 1.47 if self.version:
996 slacapra 1.10 req='Member("VO-cms-' + \
997 slacapra 1.47 self.version + \
998 slacapra 1.10 '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
999 ewv 1.192 if self.executable_arch:
1000 gutsche 1.107 req+=' && Member("VO-cms-' + \
1001 slacapra 1.105 self.executable_arch + \
1002     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
1003 gutsche 1.35
1004     req = req + ' && (other.GlueHostNetworkAdapterOutboundIP)'
1005 spiga 1.353 if ( common.scheduler.name() in ["glite"] ):
1006 slacapra 1.316 ## 25-Jun-2009 SL: patch to use Cream enabled WMS
1007     if ( self.cfg_params.get('GRID.use_cream',None) ):
1008     req += ' && (other.GlueCEStateStatus == "Production" || other.GlueCEStateStatus == "Special")'
1009     else:
1010     req += ' && other.GlueCEStateStatus == "Production" '
1011 gutsche 1.35
1012 slacapra 1.1 return req
1013 gutsche 1.3
1014     def configFilename(self):
1015     """ return the config filename """
1016 ewv 1.334 return self.name()+'.py'
1017 gutsche 1.3
1018     def wsSetupCMSOSGEnvironment_(self):
1019     """
1020     Returns part of a job script which is prepares
1021     the execution environment and which is common for all CMS jobs.
1022     """
1023 ewv 1.160 txt = '\n#Written by cms_cmssw::wsSetupCMSOSGEnvironment_\n'
1024     txt += ' echo ">>> setup CMS OSG environment:"\n'
1025 fanzago 1.133 txt += ' echo "set SCRAM ARCH to ' + self.executable_arch + '"\n'
1026     txt += ' export SCRAM_ARCH='+self.executable_arch+'\n'
1027 fanzago 1.136 txt += ' echo "SCRAM_ARCH = $SCRAM_ARCH"\n'
1028 belforte 1.383 txt += ' echo "OSG_APP is $OSG_APP"\n'
1029 ewv 1.135 txt += ' if [ -f $OSG_APP/cmssoft/cms/cmsset_default.sh ] ;then\n'
1030 belforte 1.382 txt += ' cmsSetupFile=$OSG_APP/cmssoft/cms/cmsset_default.sh\n'
1031     txt += ' elif [ -f $CVMFS/cms.cern.ch/cmsset_default.sh ] ; then \n'
1032     txt += ' cmsSetupFile=$CVMFS/cms.cern.ch/cmsset_default.sh\n'
1033     txt += ' elif [ -f /cvmfs/cms.cern.ch/cmsset_default.sh ] ; then \n'
1034     txt += ' cmsSetupFile=/cvmfs/cms.cern.ch/cmsset_default.sh\n'
1035 fanzago 1.133 txt += ' else\n'
1036 belforte 1.383 txt += ' echo "CVMSF = $CVMFS"\n'
1037     txt += ' echo "/cvmfs/ is"\n'
1038     txt += ' echo "ls /"\n'
1039     txt += ' ls /\n'
1040     txt += ' echo "ls /cvmfs"\n'
1041     txt += ' ls /cvmfs\n'
1042     txt += ' echo "ls /cvmfs/cms.cern.ch"\n'
1043     txt += ' ls /cvmfs/cms.cern.ch\n'
1044     txt += ' ls /cvmfs/cms.cern.ch/cmsset*\n'
1045     txt += ' ls /cvmfs/cms.cern.ch/cmsset_default.sh\n'
1046 belforte 1.382 txt += ' echo "ERROR ==> cmsset_default.sh file not found"\n'
1047 fanzago 1.161 txt += ' job_exit_code=10020\n'
1048     txt += ' func_exit\n'
1049 fanzago 1.133 txt += ' fi\n'
1050 gutsche 1.3 txt += '\n'
1051 belforte 1.382 txt += ' echo "sourcing $cmsSetupFile ..."\n'
1052     txt += ' source $cmsSetupFile\n'
1053     txt += ' result=$?\n'
1054     txt += ' if [ $result -ne 0 ]; then\n'
1055     txt += ' echo "ERROR ==> problem sourcing $cmsSetupFile"\n'
1056     txt += ' job_exit_code=10032\n'
1057     txt += ' func_exit\n'
1058     txt += ' else\n'
1059     txt += ' echo "==> setup cms environment ok"\n'
1060     txt += ' echo "SCRAM_ARCH = $SCRAM_ARCH"\n'
1061     txt += ' fi\n'
1062 gutsche 1.3
1063     return txt
1064 ewv 1.131
1065 gutsche 1.3 def wsSetupCMSLCGEnvironment_(self):
1066     """
1067     Returns part of a job script which is prepares
1068     the execution environment and which is common for all CMS jobs.
1069     """
1070 ewv 1.160 txt = '\n#Written by cms_cmssw::wsSetupCMSLCGEnvironment_\n'
1071     txt += ' echo ">>> setup CMS LCG environment:"\n'
1072 fanzago 1.133 txt += ' echo "set SCRAM ARCH and BUILD_ARCH to ' + self.executable_arch + ' ###"\n'
1073     txt += ' export SCRAM_ARCH='+self.executable_arch+'\n'
1074     txt += ' export BUILD_ARCH='+self.executable_arch+'\n'
1075     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
1076 fanzago 1.161 txt += ' echo "ERROR ==> CMS software dir not found on WN `hostname`"\n'
1077     txt += ' job_exit_code=10031\n'
1078     txt += ' func_exit\n'
1079 fanzago 1.133 txt += ' else\n'
1080     txt += ' echo "Sourcing environment... "\n'
1081     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1082 fanzago 1.161 txt += ' echo "ERROR ==> cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1083     txt += ' job_exit_code=10020\n'
1084     txt += ' func_exit\n'
1085 fanzago 1.133 txt += ' fi\n'
1086     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1087     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1088     txt += ' result=$?\n'
1089     txt += ' if [ $result -ne 0 ]; then\n'
1090 fanzago 1.161 txt += ' echo "ERROR ==> problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1091     txt += ' job_exit_code=10032\n'
1092     txt += ' func_exit\n'
1093 fanzago 1.133 txt += ' fi\n'
1094     txt += ' fi\n'
1095     txt += ' \n'
1096 fanzago 1.161 txt += ' echo "==> setup cms environment ok"\n'
1097 gutsche 1.3 return txt
1098 gutsche 1.5
1099 spiga 1.238 def wsModifyReport(self, nj):
1100 fanzago 1.93 """
1101 ewv 1.131 insert the part of the script that modifies the FrameworkJob Report
1102 fanzago 1.93 """
1103 ewv 1.250
1104 fanzago 1.281 txt = ''
1105 fanzago 1.292 if (self.copy_data == 1):
1106 fanzago 1.281 txt = '\n#Written by cms_cmssw::wsModifyReport\n'
1107 ewv 1.283
1108 fanzago 1.175 txt += 'echo ">>> Modify Job Report:" \n'
1109 fanzago 1.217 txt += 'chmod a+x $RUNTIME_AREA/ProdCommon/FwkJobRep/ModifyJobReport.py\n'
1110 fanzago 1.175 txt += 'echo "CMSSW_VERSION = $CMSSW_VERSION"\n\n'
1111 fanzago 1.344
1112 fanzago 1.360 args = 'fjr $RUNTIME_AREA/crab_fjr_$NJob.xml json $RUNTIME_AREA/resultCopyFile n_job $OutUniqueID PrimaryDataset $PrimaryDataset ApplicationFamily $ApplicationFamily ApplicationName $executable cmssw_version $CMSSW_VERSION psethash $PSETHASH'
1113 fanzago 1.281
1114 fanzago 1.318 if (self.publish_data == 1):
1115     txt += 'ProcessedDataset='+self.processedDataset+'\n'
1116 fanzago 1.292 txt += 'echo "ProcessedDataset = $ProcessedDataset"\n'
1117     args += ' UserProcessedDataset $USER-$ProcessedDataset-$PSETHASH'
1118 fanzago 1.281
1119 fanzago 1.247 txt += 'echo "$RUNTIME_AREA/ProdCommon/FwkJobRep/ModifyJobReport.py '+str(args)+'"\n'
1120     txt += '$RUNTIME_AREA/ProdCommon/FwkJobRep/ModifyJobReport.py '+str(args)+'\n'
1121 fanzago 1.175 txt += 'modifyReport_result=$?\n'
1122     txt += 'if [ $modifyReport_result -ne 0 ]; then\n'
1123     txt += ' modifyReport_result=70500\n'
1124     txt += ' job_exit_code=$modifyReport_result\n'
1125     txt += ' echo "ModifyReportResult=$modifyReport_result" | tee -a $RUNTIME_AREA/$repo\n'
1126     txt += ' echo "WARNING: Problem with ModifyJobReport"\n'
1127     txt += 'else\n'
1128     txt += ' mv NewFrameworkJobReport.xml $RUNTIME_AREA/crab_fjr_$NJob.xml\n'
1129 spiga 1.103 txt += 'fi\n'
1130 fanzago 1.93 return txt
1131 ewv 1.283
1132 ewv 1.192 def wsParseFJR(self):
1133 spiga 1.189 """
1134 ewv 1.192 Parse the FrameworkJobReport to obtain useful infos
1135 spiga 1.189 """
1136     txt = '\n#Written by cms_cmssw::wsParseFJR\n'
1137     txt += 'echo ">>> Parse FrameworkJobReport crab_fjr.xml"\n'
1138     txt += 'if [ -s $RUNTIME_AREA/crab_fjr_$NJob.xml ]; then\n'
1139     txt += ' if [ -s $RUNTIME_AREA/parseCrabFjr.py ]; then\n'
1140 spiga 1.197 txt += ' cmd_out=`python $RUNTIME_AREA/parseCrabFjr.py --input $RUNTIME_AREA/crab_fjr_$NJob.xml --dashboard $MonitorID,$MonitorJobID '+self.debugWrap+'`\n'
1141 fanzago 1.285 if self.debug_wrapper==1 :
1142 spiga 1.197 txt += ' echo "Result of parsing the FrameworkJobReport crab_fjr.xml: $cmd_out"\n'
1143 spiga 1.371 txt += ' cmd_out_1=`python $RUNTIME_AREA/parseCrabFjr.py --input $RUNTIME_AREA/crab_fjr_$NJob.xml --popularity $MonitorID,$MonitorJobID,$RUNTIME_AREA/inputsReport.txt '+self.debugWrap+'`\n'
1144 spiga 1.372 # if self.debug_wrapper==1 :
1145     txt += ' echo "Result of parsing the FrameworkJobReport crab_fjr.xml: $cmd_out_1"\n'
1146 spiga 1.197 txt += ' executable_exit_status=`python $RUNTIME_AREA/parseCrabFjr.py --input $RUNTIME_AREA/crab_fjr_$NJob.xml --exitcode`\n'
1147 spiga 1.189 txt += ' if [ $executable_exit_status -eq 50115 ];then\n'
1148     txt += ' echo ">>> crab_fjr.xml contents: "\n'
1149 spiga 1.222 txt += ' cat $RUNTIME_AREA/crab_fjr_$NJob.xml\n'
1150 spiga 1.189 txt += ' echo "Wrong FrameworkJobReport --> does not contain useful info. ExitStatus: $executable_exit_status"\n'
1151 spiga 1.197 txt += ' elif [ $executable_exit_status -eq -999 ];then\n'
1152     txt += ' echo "ExitStatus from FrameworkJobReport not available. not available. Using exit code of executable from command line."\n'
1153 spiga 1.189 txt += ' else\n'
1154     txt += ' echo "Extracted ExitStatus from FrameworkJobReport parsing output: $executable_exit_status"\n'
1155     txt += ' fi\n'
1156     txt += ' else\n'
1157     txt += ' echo "CRAB python script to parse CRAB FrameworkJobReport crab_fjr.xml is not available, using exit code of executable from command line."\n'
1158     txt += ' fi\n'
1159     #### Patch to check input data reading for CMSSW16x Hopefully we-ll remove it asap
1160 spiga 1.232 txt += ' if [ $executable_exit_status -eq 0 ];then\n'
1161 fanzago 1.273 txt += ' echo ">>> Executable succeded $executable_exit_status"\n'
1162 spiga 1.232 txt += ' fi\n'
1163 spiga 1.189 txt += 'else\n'
1164     txt += ' echo "CRAB FrameworkJobReport crab_fjr.xml is not available, using exit code of executable from command line."\n'
1165     txt += 'fi\n'
1166     txt += '\n'
1167 fanzago 1.364 txt += 'if [ $executable_exit_status -ne 0 ];then\n'
1168 fanzago 1.273 txt += ' echo ">>> Executable failed $executable_exit_status"\n'
1169     txt += ' echo "ExeExitCode=$executable_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
1170     txt += ' echo "EXECUTABLE_EXIT_STATUS = $executable_exit_status"\n'
1171     txt += ' job_exit_code=$executable_exit_status\n'
1172     txt += ' func_exit\n'
1173     txt += 'fi\n\n'
1174 spiga 1.189 txt += 'echo "ExeExitCode=$executable_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
1175     txt += 'echo "EXECUTABLE_EXIT_STATUS = $executable_exit_status"\n'
1176     txt += 'job_exit_code=$executable_exit_status\n'
1177    
1178     return txt
1179    
1180 gutsche 1.5 def setParam_(self, param, value):
1181     self._params[param] = value
1182    
1183     def getParams(self):
1184     return self._params
1185 gutsche 1.8
1186 spiga 1.257 def outList(self,list=False):
1187 mcinquil 1.121 """
1188     check the dimension of the output files
1189     """
1190 spiga 1.169 txt = ''
1191     txt += 'echo ">>> list of expected files on output sandbox"\n'
1192 mcinquil 1.121 listOutFiles = []
1193 ewv 1.170 stdout = 'CMSSW_$NJob.stdout'
1194 spiga 1.169 stderr = 'CMSSW_$NJob.stderr'
1195 spiga 1.268 if len(self.output_file) <= 0:
1196     msg ="WARNING: no output files name have been defined!!\n"
1197     msg+="\tno output files will be reported back/staged\n"
1198 spiga 1.304 common.logger.info(msg)
1199 ewv 1.350
1200 fanzago 1.148 if (self.return_data == 1):
1201 farinafa 1.348 for file in (self.output_file):
1202     listOutFiles.append(numberFile(file, '$OutUniqueID'))
1203     for file in (self.output_file_sandbox):
1204     listOutFiles.append(numberFile(file, '$NJob'))
1205     listOutFiles.append(stdout)
1206     listOutFiles.append(stderr)
1207 belforte 1.384 listOutFiles.append('Watchdog_$NJob.log.gz')
1208 farinafa 1.348
1209 fanzago 1.161 txt += 'echo "output files: '+string.join(listOutFiles,' ')+'"\n'
1210 spiga 1.157 txt += 'filesToCheck="'+string.join(listOutFiles,' ')+'"\n'
1211 spiga 1.169 txt += 'export filesToCheck\n'
1212 spiga 1.341 taskinfo={}
1213     taskinfo['outfileBasename'] = self.output_file
1214     common._db.updateTask_(taskinfo)
1215 ewv 1.276
1216 spiga 1.257 if list : return self.output_file
1217 ewv 1.170 return txt
1218 ewv 1.355
1219 fanzago 1.369 def checkCMSSWVersion(self, url = "https://cmstags.cern.ch/tc/", fileName = "ReleasesXML"):
1220 ewv 1.355 """
1221     compare current CMSSW release and arch with allowed releases
1222     """
1223    
1224     downloader = Downloader(url)
1225     goodRelease = False
1226 ewv 1.367 tagCollectorUrl = url + fileName
1227 ewv 1.355
1228     try:
1229     result = downloader.config(fileName)
1230     except:
1231     common.logger.info("ERROR: Problem reading file of allowed CMSSW releases.")
1232    
1233     try:
1234     events = pulldom.parseString(result)
1235    
1236     arch = None
1237     release = None
1238     relState = None
1239     for (event, node) in events:
1240     if event == pulldom.START_ELEMENT:
1241     if node.tagName == 'architecture':
1242     arch = node.attributes.getNamedItem('name').nodeValue
1243     if node.tagName == 'project':
1244     relState = node.attributes.getNamedItem('state').nodeValue
1245 ewv 1.367 if relState == 'Announced':
1246 ewv 1.355 release = node.attributes.getNamedItem('label').nodeValue
1247     if self.executable_arch == arch and self.version == release:
1248     goodRelease = True
1249     return goodRelease
1250    
1251     if not goodRelease:
1252 ewv 1.367 msg = "WARNING: %s on %s is not among supported releases listed at %s ." % \
1253     (self.version, self.executable_arch, tagCollectorUrl)
1254 ewv 1.355 msg += "Submission may fail."
1255     common.logger.info(msg)
1256     except:
1257     common.logger.info("Problems parsing file of allowed CMSSW releases.")
1258    
1259     return goodRelease
1260