ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.355.2.3
Committed: Fri Apr 30 09:55:03 2010 UTC (15 years ago) by fanzago
Content type: text/x-python
Branch: CRAB_multiout
Changes since 1.355.2.2: +2 -2 lines
Log Message:
fixed logger message

File Contents

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