ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.285
Committed: Fri Apr 17 14:43:04 2009 UTC (16 years ago) by fanzago
Content type: text/x-python
Branch: MAIN
Changes since 1.284: +7 -8 lines
Log Message:
fixed old debug_wrapper true

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