ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.277
Committed: Sun Mar 1 23:19:30 2009 UTC (16 years, 1 month ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_5_0, CRAB_2_5_0_pre7, CRAB_2_5_0_pre6, CRAB_2_5_0_pre5
Changes since 1.276: +1 -1 lines
Log Message:
export SOFTWARE_DIR and RUNTIME_AREA variables.

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