ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.319
Committed: Mon Jul 13 20:23:38 2009 UTC (15 years, 9 months ago) by ewv
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_6_1_pre1
Changes since 1.318: +10 -7 lines
Log Message:
raise exception for more than 500 jobs and not server

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