ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.331
Committed: Thu Aug 13 13:09:59 2009 UTC (15 years, 8 months ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.330: +3 -3 lines
Log Message:
fix for multiple args

File Contents

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