ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.387
Committed: Fri Sep 21 14:40:29 2012 UTC (12 years, 7 months ago) by belforte
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_8_3, CRAB_2_8_3_pre4, CRAB_2_8_3_pre3, CRAB_2_8_3_pre2, CRAB_2_8_3_pre1
Changes since 1.386: +12 -7 lines
Log Message:
allow 5K job/task for remoteGlidein

File Contents

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