ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.290
Committed: Tue Apr 28 14:58:45 2009 UTC (16 years ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.289: +1 -1 lines
Log Message:
prepare correctly cms environment also for lsc/caf

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