ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.271
Committed: Mon Feb 9 18:08:52 2009 UTC (16 years, 2 months ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_5_0_pre3
Changes since 1.270: +3 -1 lines
Log Message:
adapt to Splitter changes

File Contents

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