ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.270
Committed: Fri Feb 6 14:23:37 2009 UTC (16 years, 2 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_5_0_pre2
Changes since 1.269: +15 -1 lines
Log Message:
preserver order of blocks

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