ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.269
Committed: Wed Feb 4 14:24:54 2009 UTC (16 years, 2 months ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_5_0_pre1
Changes since 1.268: +30 -587 lines
Log Message:
code reorganization. Added support for Run Based splitting.

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