ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.260
Committed: Wed Dec 3 19:53:26 2008 UTC (16 years, 4 months ago) by ewv
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_4_3_pre6
Changes since 1.259: +1 -6 lines
Log Message:
Do it right for MadGraph

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 ewv 1.250 from WMCore.SiteScreening.BlackWhiteListParser import SEBlackWhiteListParser
6 slacapra 1.1 import common
7     import Scram
8    
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 fanzago 1.115 # init BlackWhiteListParser
22 ewv 1.254 seWhiteList = cfg_params.get('EDG.se_white_list',[])
23     seBlackList = cfg_params.get('EDG.se_black_list',[])
24     self.blackWhiteListParser = SEBlackWhiteListParser(seWhiteList, seBlackList, common.logger)
25 fanzago 1.115
26 spiga 1.234 ### Temporary patch to automatically skip the ISB size check:
27     server=self.cfg_params.get('CRAB.server_name',None)
28 ewv 1.250 size = 9.5
29 spiga 1.249 if server or common.scheduler.name().upper() in ['LSF','CAF']: size = 99999
30 spiga 1.234 ### D.S.
31     self.MaxTarBallSize = float(self.cfg_params.get('EDG.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 log = common.logger
37 ewv 1.131
38 slacapra 1.1 self.scram = Scram.Scram(cfg_params)
39     self.additional_inbox_files = []
40     self.scriptExe = ''
41     self.executable = ''
42 slacapra 1.71 self.executable_arch = self.scram.getArch()
43 slacapra 1.1 self.tgz_name = 'default.tgz'
44 corvo 1.56 self.scriptName = 'CMSSW.sh'
45 ewv 1.192 self.pset = ''
46 spiga 1.187 self.datasetPath = ''
47 gutsche 1.3
48 gutsche 1.50 # set FJR file name
49     self.fjrFileName = 'crab_fjr.xml'
50    
51 slacapra 1.1 self.version = self.scram.getSWVersion()
52 ewv 1.182 version_array = self.version.split('_')
53 ewv 1.184 self.CMSSW_major = 0
54     self.CMSSW_minor = 0
55     self.CMSSW_patch = 0
56 ewv 1.182 try:
57 ewv 1.184 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 slacapra 1.1 ### collect Data cards
65 gutsche 1.66
66 slacapra 1.153 if not cfg_params.has_key('CMSSW.datasetpath'):
67 ewv 1.131 msg = "Error: datasetpath not defined "
68 slacapra 1.1 raise CrabException(msg)
69 ewv 1.226
70 fanzago 1.221 ### Temporary: added to remove input file control in the case of PU
71 farinafa 1.224 self.dataset_pu = cfg_params.get('CMSSW.dataset_pu', None)
72 ewv 1.226
73 slacapra 1.153 tmp = cfg_params['CMSSW.datasetpath']
74     log.debug(6, "CMSSW::CMSSW(): datasetPath = "+tmp)
75 spiga 1.236
76     if tmp =='':
77     msg = "Error: datasetpath not defined "
78     raise CrabException(msg)
79     elif string.lower(tmp)=='none':
80 slacapra 1.153 self.datasetPath = None
81     self.selectNoInput = 1
82     else:
83     self.datasetPath = tmp
84     self.selectNoInput = 0
85 gutsche 1.5
86 slacapra 1.1 self.dataTiers = []
87 spiga 1.197 self.debugWrap = ''
88     self.debug_wrapper = cfg_params.get('USER.debug_wrapper',False)
89     if self.debug_wrapper: self.debugWrap='--debug'
90 slacapra 1.1 ## now the application
91 ewv 1.258 self.managedGenerators = ['madgraph']
92     self.generator = cfg_params.get('CMSSW.generator','pythia').lower()
93 slacapra 1.153 self.executable = cfg_params.get('CMSSW.executable','cmsRun')
94     log.debug(6, "CMSSW::CMSSW(): executable = "+self.executable)
95 slacapra 1.1
96 slacapra 1.153 if not cfg_params.has_key('CMSSW.pset'):
97 slacapra 1.1 raise CrabException("PSet file missing. Cannot run cmsRun ")
98 slacapra 1.153 self.pset = cfg_params['CMSSW.pset']
99     log.debug(6, "Cmssw::Cmssw(): PSet file = "+self.pset)
100     if self.pset.lower() != 'none' :
101     if (not os.path.exists(self.pset)):
102     raise CrabException("User defined PSet file "+self.pset+" does not exist")
103     else:
104     self.pset = None
105 slacapra 1.1
106     # output files
107 slacapra 1.53 ## stuff which must be returned always via sandbox
108     self.output_file_sandbox = []
109    
110     # add fjr report by default via sandbox
111     self.output_file_sandbox.append(self.fjrFileName)
112    
113     # other output files to be returned via sandbox or copied to SE
114 mcinquil 1.216 outfileflag = False
115 slacapra 1.153 self.output_file = []
116     tmp = cfg_params.get('CMSSW.output_file',None)
117     if tmp :
118 slacapra 1.207 self.output_file = [x.strip() for x in tmp.split(',')]
119 mcinquil 1.216 outfileflag = True #output found
120     #else:
121     # log.message("No output file defined: only stdout/err and the CRAB Framework Job Report will be available\n")
122 slacapra 1.1
123     # script_exe file as additional file in inputSandbox
124 slacapra 1.153 self.scriptExe = cfg_params.get('USER.script_exe',None)
125     if self.scriptExe :
126 slacapra 1.176 if not os.path.isfile(self.scriptExe):
127     msg ="ERROR. file "+self.scriptExe+" not found"
128     raise CrabException(msg)
129     self.additional_inbox_files.append(string.strip(self.scriptExe))
130 slacapra 1.70
131 spiga 1.42 if self.datasetPath == None and self.pset == None and self.scriptExe == '' :
132 slacapra 1.176 msg ="Error. script_exe not defined"
133     raise CrabException(msg)
134 spiga 1.42
135 ewv 1.226 # use parent files...
136 spiga 1.204 self.useParent = self.cfg_params.get('CMSSW.use_parent',False)
137    
138 slacapra 1.1 ## additional input files
139 slacapra 1.153 if cfg_params.has_key('USER.additional_input_files'):
140 slacapra 1.29 tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
141 slacapra 1.70 for tmp in tmpAddFiles:
142     tmp = string.strip(tmp)
143     dirname = ''
144     if not tmp[0]=="/": dirname = "."
145 corvo 1.85 files = []
146     if string.find(tmp,"*")>-1:
147     files = glob.glob(os.path.join(dirname, tmp))
148     if len(files)==0:
149     raise CrabException("No additional input file found with this pattern: "+tmp)
150     else:
151     files.append(tmp)
152 slacapra 1.70 for file in files:
153     if not os.path.exists(file):
154     raise CrabException("Additional input file not found: "+file)
155 slacapra 1.45 pass
156 slacapra 1.105 self.additional_inbox_files.append(string.strip(file))
157 slacapra 1.1 pass
158     pass
159 slacapra 1.70 common.logger.debug(5,"Additional input files: "+str(self.additional_inbox_files))
160 slacapra 1.153 pass
161 gutsche 1.3
162 slacapra 1.9 ## Events per job
163 slacapra 1.153 if cfg_params.has_key('CMSSW.events_per_job'):
164 slacapra 1.10 self.eventsPerJob =int( cfg_params['CMSSW.events_per_job'])
165 slacapra 1.9 self.selectEventsPerJob = 1
166 slacapra 1.153 else:
167 slacapra 1.9 self.eventsPerJob = -1
168     self.selectEventsPerJob = 0
169 ewv 1.131
170 slacapra 1.22 ## number of jobs
171 slacapra 1.153 if cfg_params.has_key('CMSSW.number_of_jobs'):
172 slacapra 1.22 self.theNumberOfJobs =int( cfg_params['CMSSW.number_of_jobs'])
173     self.selectNumberOfJobs = 1
174 slacapra 1.153 else:
175 slacapra 1.22 self.theNumberOfJobs = 0
176     self.selectNumberOfJobs = 0
177 slacapra 1.10
178 slacapra 1.153 if cfg_params.has_key('CMSSW.total_number_of_events'):
179 gutsche 1.35 self.total_number_of_events = int(cfg_params['CMSSW.total_number_of_events'])
180     self.selectTotalNumberEvents = 1
181 spiga 1.193 if self.selectNumberOfJobs == 1:
182 spiga 1.202 if (self.total_number_of_events != -1) and int(self.total_number_of_events) < int(self.theNumberOfJobs):
183 spiga 1.193 msg = 'Must specify at least one event per job. total_number_of_events > number_of_jobs '
184     raise CrabException(msg)
185 slacapra 1.153 else:
186 gutsche 1.35 self.total_number_of_events = 0
187     self.selectTotalNumberEvents = 0
188    
189 spiga 1.187 if self.pset != None:
190 spiga 1.42 if ( (self.selectTotalNumberEvents + self.selectEventsPerJob + self.selectNumberOfJobs) != 2 ):
191     msg = 'Must define exactly two of total_number_of_events, events_per_job, or number_of_jobs.'
192     raise CrabException(msg)
193     else:
194     if (self.selectNumberOfJobs == 0):
195     msg = 'Must specify number_of_jobs.'
196     raise CrabException(msg)
197 gutsche 1.35
198 ewv 1.160 ## New method of dealing with seeds
199     self.incrementSeeds = []
200     self.preserveSeeds = []
201     if cfg_params.has_key('CMSSW.preserve_seeds'):
202     tmpList = cfg_params['CMSSW.preserve_seeds'].split(',')
203     for tmp in tmpList:
204     tmp.strip()
205     self.preserveSeeds.append(tmp)
206     if cfg_params.has_key('CMSSW.increment_seeds'):
207     tmpList = cfg_params['CMSSW.increment_seeds'].split(',')
208     for tmp in tmpList:
209     tmp.strip()
210     self.incrementSeeds.append(tmp)
211    
212 ewv 1.227 ## FUTURE: Can remove in CRAB 2.4.0
213     self.sourceSeed = cfg_params.get('CMSSW.pythia_seed',None)
214 slacapra 1.153 self.sourceSeedVtx = cfg_params.get('CMSSW.vtx_seed',None)
215 ewv 1.227 self.sourceSeedG4 = cfg_params.get('CMSSW.g4_seed',None)
216 slacapra 1.153 self.sourceSeedMix = cfg_params.get('CMSSW.mix_seed',None)
217 ewv 1.227 if self.sourceSeed or self.sourceSeedVtx or self.sourceSeedG4 or self.sourceSeedMix:
218     msg = 'pythia_seed, vtx_seed, g4_seed, and mix_seed are no longer valid settings. You must use increment_seeds or preserve_seeds'
219     raise CrabException(msg)
220 slacapra 1.90
221 slacapra 1.153 self.firstRun = cfg_params.get('CMSSW.first_run',None)
222 slacapra 1.90
223 ewv 1.147 # Copy/return
224 slacapra 1.153 self.copy_data = int(cfg_params.get('USER.copy_data',0))
225     self.return_data = int(cfg_params.get('USER.return_data',0))
226 ewv 1.147
227 slacapra 1.1 #DBSDLS-start
228 ewv 1.131 ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
229 slacapra 1.1 self.maxEvents=0 # max events available ( --> check the requested nb. of evts in Creator.py)
230     self.DBSPaths={} # all dbs paths requested ( --> input to the site local discovery script)
231 gutsche 1.35 self.jobDestination=[] # Site destination(s) for each job (list of lists)
232 slacapra 1.1 ## Perform the data location and discovery (based on DBS/DLS)
233 slacapra 1.9 ## SL: Don't if NONE is specified as input (pythia use case)
234 gutsche 1.35 blockSites = {}
235 slacapra 1.9 if self.datasetPath:
236 gutsche 1.35 blockSites = self.DataDiscoveryAndLocation(cfg_params)
237 ewv 1.131 #DBSDLS-end
238 slacapra 1.1
239 slacapra 1.9 ## Select Splitting
240 ewv 1.131 if self.selectNoInput:
241 spiga 1.187 if self.pset == None:
242 spiga 1.42 self.jobSplittingForScript()
243     else:
244     self.jobSplittingNoInput()
245 afanfani 1.237 elif (cfg_params.get('CMSSW.noblockboundary',0)):
246     self.jobSplittingNoBlockBoundary(blockSites)
247 gutsche 1.92 else:
248 corvo 1.56 self.jobSplittingByBlocks(blockSites)
249 gutsche 1.5
250 spiga 1.208 # modify Pset only the first time
251     if isNew:
252     if self.pset != None:
253     import PsetManipulator as pp
254     PsetEdit = pp.PsetManipulator(self.pset)
255     try:
256     # Add FrameworkJobReport to parameter-set, set max events.
257     # Reset later for data jobs by writeCFG which does all modifications
258     PsetEdit.addCrabFJR(self.fjrFileName) # FUTURE: Job report addition not needed by CMSSW>1.5
259     PsetEdit.maxEvent(self.eventsPerJob)
260     PsetEdit.psetWriter(self.configFilename())
261 slacapra 1.215 ## If present, add TFileService to output files
262     if not int(cfg_params.get('CMSSW.skip_TFileService_output',0)):
263     tfsOutput = PsetEdit.getTFileService()
264 ewv 1.226 if tfsOutput:
265 slacapra 1.215 if tfsOutput in self.output_file:
266     common.logger.debug(5,"Output from TFileService "+tfsOutput+" already in output files")
267     else:
268 mcinquil 1.216 outfileflag = True #output found
269 slacapra 1.215 self.output_file.append(tfsOutput)
270     common.logger.message("Adding "+tfsOutput+" to output files (from TFileService)")
271 slacapra 1.218 pass
272     pass
273     ## If present and requested, add PoolOutputModule to output files
274 slacapra 1.219 if int(cfg_params.get('CMSSW.get_edm_output',0)):
275 slacapra 1.218 edmOutput = PsetEdit.getPoolOutputModule()
276 ewv 1.226 if edmOutput:
277 slacapra 1.218 if edmOutput in self.output_file:
278     common.logger.debug(5,"Output from PoolOutputModule "+edmOutput+" already in output files")
279     else:
280     self.output_file.append(edmOutput)
281     common.logger.message("Adding "+edmOutput+" to output files (from PoolOutputModule)")
282     pass
283     pass
284 slacapra 1.215 except CrabException:
285 spiga 1.208 msg='Error while manipulating ParameterSet: exiting...'
286     raise CrabException(msg)
287 ewv 1.226 ## Prepare inputSandbox TarBall (only the first time)
288 spiga 1.208 self.tgzNameWithPath = self.getTarBall(self.executable)
289 gutsche 1.3
290 slacapra 1.1 def DataDiscoveryAndLocation(self, cfg_params):
291    
292 slacapra 1.86 import DataDiscovery
293     import DataLocation
294 gutsche 1.3 common.logger.debug(10,"CMSSW::DataDiscoveryAndLocation()")
295    
296     datasetPath=self.datasetPath
297    
298 slacapra 1.1 ## Contact the DBS
299 gutsche 1.92 common.logger.message("Contacting Data Discovery Services ...")
300 slacapra 1.1 try:
301 spiga 1.208 self.pubdata=DataDiscovery.DataDiscovery(datasetPath, cfg_params,self.skip_blocks)
302 slacapra 1.1 self.pubdata.fetchDBSInfo()
303    
304 slacapra 1.41 except DataDiscovery.NotExistingDatasetError, ex :
305 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
306     raise CrabException(msg)
307 slacapra 1.41 except DataDiscovery.NoDataTierinProvenanceError, ex :
308 slacapra 1.1 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
309     raise CrabException(msg)
310 slacapra 1.41 except DataDiscovery.DataDiscoveryError, ex:
311 gutsche 1.66 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
312 slacapra 1.1 raise CrabException(msg)
313    
314 gutsche 1.35 self.filesbyblock=self.pubdata.getFiles()
315 mkirn 1.37 self.eventsbyblock=self.pubdata.getEventsPerBlock()
316     self.eventsbyfile=self.pubdata.getEventsPerFile()
317 spiga 1.204 self.parentFiles=self.pubdata.getParent()
318 gutsche 1.3
319 slacapra 1.1 ## get max number of events
320 ewv 1.192 self.maxEvents=self.pubdata.getMaxEvents()
321 slacapra 1.1
322     ## Contact the DLS and build a list of sites hosting the fileblocks
323     try:
324 slacapra 1.41 dataloc=DataLocation.DataLocation(self.filesbyblock.keys(),cfg_params)
325 gutsche 1.6 dataloc.fetchDLSInfo()
326 slacapra 1.41 except DataLocation.DataLocationError , ex:
327 slacapra 1.1 msg = 'ERROR ***: failed Data Location in DLS \n %s '%ex.getErrorMessage()
328     raise CrabException(msg)
329 ewv 1.131
330 slacapra 1.1
331 gutsche 1.35 sites = dataloc.getSites()
332     allSites = []
333     listSites = sites.values()
334 slacapra 1.63 for listSite in listSites:
335     for oneSite in listSite:
336 gutsche 1.35 allSites.append(oneSite)
337     allSites = self.uniquelist(allSites)
338 gutsche 1.3
339 gutsche 1.92 # screen output
340     common.logger.message("Requested dataset: " + datasetPath + " has " + str(self.maxEvents) + " events in " + str(len(self.filesbyblock.keys())) + " blocks.\n")
341    
342 gutsche 1.35 return sites
343 ewv 1.131
344 gutsche 1.35 def jobSplittingByBlocks(self, blockSites):
345 slacapra 1.9 """
346 gutsche 1.35 Perform job splitting. Jobs run over an integer number of files
347     and no more than one block.
348     ARGUMENT: blockSites: dictionary with blocks as keys and list of host sites as values
349     REQUIRES: self.selectTotalNumberEvents, self.selectEventsPerJob, self.selectNumberofJobs,
350     self.total_number_of_events, self.eventsPerJob, self.theNumberOfJobs,
351     self.maxEvents, self.filesbyblock
352     SETS: self.jobDestination - Site destination(s) for each job (a list of lists)
353     self.total_number_of_jobs - Total # of jobs
354     self.list_of_args - File(s) job will run on (a list of lists)
355     """
356    
357     # ---- Handle the possible job splitting configurations ---- #
358     if (self.selectTotalNumberEvents):
359     totalEventsRequested = self.total_number_of_events
360     if (self.selectEventsPerJob):
361     eventsPerJobRequested = self.eventsPerJob
362     if (self.selectNumberOfJobs):
363     totalEventsRequested = self.theNumberOfJobs * self.eventsPerJob
364    
365     # If user requested all the events in the dataset
366     if (totalEventsRequested == -1):
367     eventsRemaining=self.maxEvents
368     # If user requested more events than are in the dataset
369     elif (totalEventsRequested > self.maxEvents):
370     eventsRemaining = self.maxEvents
371     common.logger.message("Requested "+str(self.total_number_of_events)+ " events, but only "+str(self.maxEvents)+" events are available.")
372     # If user requested less events than are in the dataset
373     else:
374     eventsRemaining = totalEventsRequested
375 slacapra 1.22
376 slacapra 1.41 # If user requested more events per job than are in the dataset
377     if (self.selectEventsPerJob and eventsPerJobRequested > self.maxEvents):
378     eventsPerJobRequested = self.maxEvents
379    
380 gutsche 1.35 # For user info at end
381     totalEventCount = 0
382 gutsche 1.3
383 gutsche 1.35 if (self.selectTotalNumberEvents and self.selectNumberOfJobs):
384     eventsPerJobRequested = int(eventsRemaining/self.theNumberOfJobs)
385 slacapra 1.22
386 gutsche 1.35 if (self.selectNumberOfJobs):
387     common.logger.message("May not create the exact number_of_jobs requested.")
388 slacapra 1.23
389 gutsche 1.38 if ( self.ncjobs == 'all' ) :
390     totalNumberOfJobs = 999999999
391     else :
392     totalNumberOfJobs = self.ncjobs
393 ewv 1.131
394 gutsche 1.35 blocks = blockSites.keys()
395     blockCount = 0
396     # Backup variable in case self.maxEvents counted events in a non-included block
397     numBlocksInDataset = len(blocks)
398 gutsche 1.3
399 gutsche 1.35 jobCount = 0
400     list_of_lists = []
401 gutsche 1.3
402 gutsche 1.92 # list tracking which jobs are in which jobs belong to which block
403     jobsOfBlock = {}
404    
405 gutsche 1.35 # ---- Iterate over the blocks in the dataset until ---- #
406     # ---- we've met the requested total # of events ---- #
407 gutsche 1.38 while ( (eventsRemaining > 0) and (blockCount < numBlocksInDataset) and (jobCount < totalNumberOfJobs)):
408 gutsche 1.35 block = blocks[blockCount]
409 gutsche 1.44 blockCount += 1
410 gutsche 1.104 if block not in jobsOfBlock.keys() :
411     jobsOfBlock[block] = []
412 ewv 1.131
413 gutsche 1.68 if self.eventsbyblock.has_key(block) :
414     numEventsInBlock = self.eventsbyblock[block]
415     common.logger.debug(5,'Events in Block File '+str(numEventsInBlock))
416 ewv 1.131
417 gutsche 1.68 files = self.filesbyblock[block]
418     numFilesInBlock = len(files)
419     if (numFilesInBlock <= 0):
420     continue
421     fileCount = 0
422    
423     # ---- New block => New job ---- #
424 ewv 1.131 parString = ""
425 gutsche 1.68 # counter for number of events in files currently worked on
426     filesEventCount = 0
427     # flag if next while loop should touch new file
428     newFile = 1
429     # job event counter
430     jobSkipEventCount = 0
431 ewv 1.131
432 gutsche 1.68 # ---- Iterate over the files in the block until we've met the requested ---- #
433     # ---- total # of events or we've gone over all the files in this block ---- #
434 spiga 1.204 pString=''
435 gutsche 1.68 while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
436     file = files[fileCount]
437 spiga 1.204 if self.useParent:
438     parent = self.parentFiles[file]
439     for f in parent :
440     pString += '\\\"' + f + '\\\"\,'
441     common.logger.debug(6, "File "+str(file)+" has the following parents: "+str(parent))
442     common.logger.write("File "+str(file)+" has the following parents: "+str(parent))
443 gutsche 1.68 if newFile :
444     try:
445     numEventsInFile = self.eventsbyfile[file]
446     common.logger.debug(6, "File "+str(file)+" has "+str(numEventsInFile)+" events")
447     # increase filesEventCount
448     filesEventCount += numEventsInFile
449     # Add file to current job
450     parString += '\\\"' + file + '\\\"\,'
451     newFile = 0
452     except KeyError:
453     common.logger.message("File "+str(file)+" has unknown number of events: skipping")
454 ewv 1.131
455 slacapra 1.177 eventsPerJobRequested = min(eventsPerJobRequested, eventsRemaining)
456 gutsche 1.68 # if less events in file remain than eventsPerJobRequested
457 slacapra 1.177 if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested):
458 gutsche 1.68 # if last file in block
459     if ( fileCount == numFilesInBlock-1 ) :
460     # end job using last file, use remaining events in block
461     # close job and touch new file
462     fullString = parString[:-2]
463 spiga 1.204 if self.useParent:
464     fullParentString = pString[:-2]
465     list_of_lists.append([fullString,fullParentString,str(-1),str(jobSkipEventCount)])
466     else:
467     list_of_lists.append([fullString,str(-1),str(jobSkipEventCount)])
468 gutsche 1.68 common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(filesEventCount - jobSkipEventCount)+" events (last file in block).")
469     self.jobDestination.append(blockSites[block])
470     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
471 gutsche 1.92 # fill jobs of block dictionary
472 gutsche 1.104 jobsOfBlock[block].append(jobCount+1)
473 gutsche 1.68 # reset counter
474     jobCount = jobCount + 1
475     totalEventCount = totalEventCount + filesEventCount - jobSkipEventCount
476     eventsRemaining = eventsRemaining - filesEventCount + jobSkipEventCount
477     jobSkipEventCount = 0
478     # reset file
479 spiga 1.204 pString = ""
480 ewv 1.131 parString = ""
481 gutsche 1.68 filesEventCount = 0
482     newFile = 1
483     fileCount += 1
484     else :
485     # go to next file
486     newFile = 1
487     fileCount += 1
488     # if events in file equal to eventsPerJobRequested
489     elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
490 gutsche 1.38 # close job and touch new file
491     fullString = parString[:-2]
492 spiga 1.204 if self.useParent:
493     fullParentString = pString[:-2]
494     list_of_lists.append([fullString,fullParentString,str(eventsPerJobRequested),str(jobSkipEventCount)])
495 ewv 1.226 else:
496 spiga 1.204 list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
497 gutsche 1.68 common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
498 gutsche 1.38 self.jobDestination.append(blockSites[block])
499     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
500 gutsche 1.104 jobsOfBlock[block].append(jobCount+1)
501 gutsche 1.38 # reset counter
502     jobCount = jobCount + 1
503 gutsche 1.68 totalEventCount = totalEventCount + eventsPerJobRequested
504     eventsRemaining = eventsRemaining - eventsPerJobRequested
505 gutsche 1.38 jobSkipEventCount = 0
506     # reset file
507 spiga 1.204 pString = ""
508 ewv 1.131 parString = ""
509 gutsche 1.38 filesEventCount = 0
510     newFile = 1
511     fileCount += 1
512 ewv 1.131
513 gutsche 1.68 # if more events in file remain than eventsPerJobRequested
514 gutsche 1.38 else :
515 gutsche 1.68 # close job but don't touch new file
516     fullString = parString[:-2]
517 spiga 1.204 if self.useParent:
518     fullParentString = pString[:-2]
519     list_of_lists.append([fullString,fullParentString,str(eventsPerJobRequested),str(jobSkipEventCount)])
520     else:
521     list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
522 gutsche 1.68 common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
523     self.jobDestination.append(blockSites[block])
524     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
525 gutsche 1.104 jobsOfBlock[block].append(jobCount+1)
526 gutsche 1.68 # increase counter
527     jobCount = jobCount + 1
528     totalEventCount = totalEventCount + eventsPerJobRequested
529     eventsRemaining = eventsRemaining - eventsPerJobRequested
530     # calculate skip events for last file
531     # use filesEventCount (contains several files), jobSkipEventCount and eventsPerJobRequest
532     jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
533     # remove all but the last file
534     filesEventCount = self.eventsbyfile[file]
535 spiga 1.204 if self.useParent:
536     for f in parent : pString += '\\\"' + f + '\\\"\,'
537 ewv 1.160 parString = '\\\"' + file + '\\\"\,'
538 gutsche 1.68 pass # END if
539     pass # END while (iterate over files in the block)
540 gutsche 1.35 pass # END while (iterate over blocks in the dataset)
541 slacapra 1.41 self.ncjobs = self.total_number_of_jobs = jobCount
542 gutsche 1.38 if (eventsRemaining > 0 and jobCount < totalNumberOfJobs ):
543 gutsche 1.35 common.logger.message("Could not run on all requested events because some blocks not hosted at allowed sites.")
544 gutsche 1.92 common.logger.message(str(jobCount)+" job(s) can run on "+str(totalEventCount)+" events.\n")
545 ewv 1.131
546 gutsche 1.92 # screen output
547     screenOutput = "List of jobs and available destination sites:\n\n"
548    
549 mcinquil 1.124 # keep trace of block with no sites to print a warning at the end
550     noSiteBlock = []
551     bloskNoSite = []
552    
553 gutsche 1.92 blockCounter = 0
554 gutsche 1.104 for block in blocks:
555     if block in jobsOfBlock.keys() :
556     blockCounter += 1
557 slacapra 1.176 screenOutput += "Block %5i: jobs %20s: sites: %s\n" % (blockCounter,spanRanges(jobsOfBlock[block]),
558     ','.join(self.blackWhiteListParser.checkWhiteList(self.blackWhiteListParser.checkBlackList(blockSites[block],block),block)))
559 mcinquil 1.124 if len(self.blackWhiteListParser.checkWhiteList(self.blackWhiteListParser.checkBlackList(blockSites[block],block),block)) == 0:
560 ewv 1.131 noSiteBlock.append( spanRanges(jobsOfBlock[block]) )
561 mcinquil 1.124 bloskNoSite.append( blockCounter )
562 ewv 1.131
563 mcinquil 1.124 common.logger.message(screenOutput)
564 fanzago 1.127 if len(noSiteBlock) > 0 and len(bloskNoSite) > 0:
565 mcinquil 1.126 msg = 'WARNING: No sites are hosting any part of data for block:\n '
566     virgola = ""
567     if len(bloskNoSite) > 1:
568     virgola = ","
569     for block in bloskNoSite:
570     msg += ' ' + str(block) + virgola
571     msg += '\n Related jobs:\n '
572     virgola = ""
573     if len(noSiteBlock) > 1:
574     virgola = ","
575     for range_jobs in noSiteBlock:
576     msg += str(range_jobs) + virgola
577     msg += '\n will not be submitted and this block of data can not be analyzed!\n'
578 slacapra 1.155 if self.cfg_params.has_key('EDG.se_white_list'):
579     msg += 'WARNING: SE White List: '+self.cfg_params['EDG.se_white_list']+'\n'
580     msg += '(Hint: By whitelisting you force the job to run at this particular site(s).\n'
581     msg += 'Please check if the dataset is available at this site!)\n'
582     if self.cfg_params.has_key('EDG.ce_white_list'):
583     msg += 'WARNING: CE White List: '+self.cfg_params['EDG.ce_white_list']+'\n'
584     msg += '(Hint: By whitelisting you force the job to run at this particular site(s).\n'
585     msg += 'Please check if the dataset is available at this site!)\n'
586    
587 mcinquil 1.126 common.logger.message(msg)
588 gutsche 1.92
589 slacapra 1.9 self.list_of_args = list_of_lists
590     return
591    
592 afanfani 1.237 def jobSplittingNoBlockBoundary(self,blockSites):
593     """
594     """
595     # ---- Handle the possible job splitting configurations ---- #
596     if (self.selectTotalNumberEvents):
597     totalEventsRequested = self.total_number_of_events
598     if (self.selectEventsPerJob):
599     eventsPerJobRequested = self.eventsPerJob
600     if (self.selectNumberOfJobs):
601     totalEventsRequested = self.theNumberOfJobs * self.eventsPerJob
602 ewv 1.250
603 afanfani 1.237 # If user requested all the events in the dataset
604     if (totalEventsRequested == -1):
605     eventsRemaining=self.maxEvents
606     # If user requested more events than are in the dataset
607     elif (totalEventsRequested > self.maxEvents):
608     eventsRemaining = self.maxEvents
609     common.logger.message("Requested "+str(self.total_number_of_events)+ " events, but only "+str(self.maxEvents)+" events are available.")
610     # If user requested less events than are in the dataset
611     else:
612     eventsRemaining = totalEventsRequested
613 ewv 1.250
614 afanfani 1.237 # If user requested more events per job than are in the dataset
615     if (self.selectEventsPerJob and eventsPerJobRequested > self.maxEvents):
616     eventsPerJobRequested = self.maxEvents
617 ewv 1.250
618 afanfani 1.237 # For user info at end
619     totalEventCount = 0
620    
621     if (self.selectTotalNumberEvents and self.selectNumberOfJobs):
622     eventsPerJobRequested = int(eventsRemaining/self.theNumberOfJobs)
623 ewv 1.250
624 afanfani 1.237 if (self.selectNumberOfJobs):
625     common.logger.message("May not create the exact number_of_jobs requested.")
626 ewv 1.250
627 afanfani 1.237 if ( self.ncjobs == 'all' ) :
628     totalNumberOfJobs = 999999999
629     else :
630     totalNumberOfJobs = self.ncjobs
631 ewv 1.250
632 afanfani 1.237 blocks = blockSites.keys()
633     blockCount = 0
634     # Backup variable in case self.maxEvents counted events in a non-included block
635     numBlocksInDataset = len(blocks)
636 ewv 1.250
637 afanfani 1.237 jobCount = 0
638     list_of_lists = []
639    
640     #AF
641     #AF do not reset input files and event count on block boundary
642     #AF
643     parString=""
644     filesEventCount = 0
645     #AF
646    
647     # list tracking which jobs are in which jobs belong to which block
648     jobsOfBlock = {}
649     while ( (eventsRemaining > 0) and (blockCount < numBlocksInDataset) and (jobCount < totalNumberOfJobs)):
650     block = blocks[blockCount]
651     blockCount += 1
652     if block not in jobsOfBlock.keys() :
653     jobsOfBlock[block] = []
654    
655     if self.eventsbyblock.has_key(block) :
656     numEventsInBlock = self.eventsbyblock[block]
657     common.logger.debug(5,'Events in Block File '+str(numEventsInBlock))
658     files = self.filesbyblock[block]
659     numFilesInBlock = len(files)
660     if (numFilesInBlock <= 0):
661     continue
662     fileCount = 0
663     #AF
664     #AF do not reset input files and event count of block boundary
665     #AF
666     ## ---- New block => New job ---- #
667     #parString = ""
668     # counter for number of events in files currently worked on
669     #filesEventCount = 0
670     #AF
671     # flag if next while loop should touch new file
672     newFile = 1
673     # job event counter
674     jobSkipEventCount = 0
675    
676     # ---- Iterate over the files in the block until we've met the requested ---- #
677     # ---- total # of events or we've gone over all the files in this block ---- #
678     pString=''
679     while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
680     file = files[fileCount]
681     if self.useParent:
682     parent = self.parentFiles[file]
683     for f in parent :
684     pString += '\\\"' + f + '\\\"\,'
685     common.logger.debug(6, "File "+str(file)+" has the following parents: "+str(parent))
686     common.logger.write("File "+str(file)+" has the following parents: "+str(parent))
687     if newFile :
688     try:
689     numEventsInFile = self.eventsbyfile[file]
690     common.logger.debug(6, "File "+str(file)+" has "+str(numEventsInFile)+" events")
691     # increase filesEventCount
692 ewv 1.250 filesEventCount += numEventsInFile
693 afanfani 1.237 # Add file to current job
694     parString += '\\\"' + file + '\\\"\,'
695     newFile = 0
696     except KeyError:
697     common.logger.message("File "+str(file)+" has unknown number of events: skipping")
698     eventsPerJobRequested = min(eventsPerJobRequested, eventsRemaining)
699 ewv 1.250 #common.logger.message("AF filesEventCount %s - jobSkipEventCount %s "%(filesEventCount,jobSkipEventCount))
700 afanfani 1.237 # if less events in file remain than eventsPerJobRequested
701     if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested):
702     #AF
703     #AF skip fileboundary part
704     #AF
705     # go to next file
706     newFile = 1
707     fileCount += 1
708     # if events in file equal to eventsPerJobRequested
709     elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
710     # close job and touch new file
711     fullString = parString[:-2]
712     if self.useParent:
713     fullParentString = pString[:-2]
714     list_of_lists.append([fullString,fullParentString,str(eventsPerJobRequested),str(jobSkipEventCount)])
715     else:
716     list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
717     common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
718     self.jobDestination.append(blockSites[block])
719     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
720     jobsOfBlock[block].append(jobCount+1)
721     # reset counter
722     jobCount = jobCount + 1
723     totalEventCount = totalEventCount + eventsPerJobRequested
724     eventsRemaining = eventsRemaining - eventsPerJobRequested
725     jobSkipEventCount = 0
726     # reset file
727     pString = ""
728     parString = ""
729     filesEventCount = 0
730     newFile = 1
731     fileCount += 1
732    
733     # if more events in file remain than eventsPerJobRequested
734     else :
735     # close job but don't touch new file
736     fullString = parString[:-2]
737     if self.useParent:
738     fullParentString = pString[:-2]
739     list_of_lists.append([fullString,fullParentString,str(eventsPerJobRequested),str(jobSkipEventCount)])
740     else:
741     list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
742     common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
743     self.jobDestination.append(blockSites[block])
744     common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
745     jobsOfBlock[block].append(jobCount+1)
746     # increase counter
747     jobCount = jobCount + 1
748     totalEventCount = totalEventCount + eventsPerJobRequested
749     eventsRemaining = eventsRemaining - eventsPerJobRequested
750     # calculate skip events for last file
751     # use filesEventCount (contains several files), jobSkipEventCount and eventsPerJobRequest
752     jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
753     # remove all but the last file
754     filesEventCount = self.eventsbyfile[file]
755     if self.useParent:
756     for f in parent : pString += '\\\"' + f + '\\\"\,'
757     parString = '\\\"' + file + '\\\"\,'
758     pass # END if
759     pass # END while (iterate over files in the block)
760     pass # END while (iterate over blocks in the dataset)
761     self.ncjobs = self.total_number_of_jobs = jobCount
762     if (eventsRemaining > 0 and jobCount < totalNumberOfJobs ):
763     common.logger.message("eventsRemaining "+str(eventsRemaining))
764     common.logger.message("jobCount "+str(jobCount))
765     common.logger.message(" totalNumberOfJobs "+str(totalNumberOfJobs))
766     common.logger.message("Could not run on all requested events because some blocks not hosted at allowed sites.")
767     common.logger.message(str(jobCount)+" job(s) can run on "+str(totalEventCount)+" events.\n")
768    
769     # screen output
770     screenOutput = "List of jobs and available destination sites:\n\n"
771    
772     #AF
773 ewv 1.250 #AF skip check on block with no sites
774     #AF
775 afanfani 1.237 self.list_of_args = list_of_lists
776    
777     return
778    
779    
780    
781 slacapra 1.21 def jobSplittingNoInput(self):
782 slacapra 1.9 """
783     Perform job splitting based on number of event per job
784     """
785     common.logger.debug(5,'Splitting per events')
786 fanzago 1.130
787 ewv 1.131 if (self.selectEventsPerJob):
788 fanzago 1.130 common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
789     if (self.selectNumberOfJobs):
790     common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
791     if (self.selectTotalNumberEvents):
792     common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
793 slacapra 1.9
794 slacapra 1.10 if (self.total_number_of_events < 0):
795     msg='Cannot split jobs per Events with "-1" as total number of events'
796     raise CrabException(msg)
797    
798 slacapra 1.22 if (self.selectEventsPerJob):
799 spiga 1.65 if (self.selectTotalNumberEvents):
800     self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
801 ewv 1.131 elif(self.selectNumberOfJobs) :
802 spiga 1.65 self.total_number_of_jobs =self.theNumberOfJobs
803 ewv 1.131 self.total_number_of_events =int(self.theNumberOfJobs*self.eventsPerJob)
804 spiga 1.65
805 slacapra 1.22 elif (self.selectNumberOfJobs) :
806     self.total_number_of_jobs = self.theNumberOfJobs
807     self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
808 ewv 1.131
809 slacapra 1.9 common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
810    
811     # is there any remainder?
812     check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
813    
814     common.logger.debug(5,'Check '+str(check))
815    
816 gutsche 1.35 common.logger.message(str(self.total_number_of_jobs)+' jobs can be created, each for '+str(self.eventsPerJob)+' for a total of '+str(self.total_number_of_jobs*self.eventsPerJob)+' events')
817 slacapra 1.9 if check > 0:
818 gutsche 1.35 common.logger.message('Warning: asked '+str(self.total_number_of_events)+' but can do only '+str(int(self.total_number_of_jobs)*self.eventsPerJob))
819 slacapra 1.9
820 slacapra 1.10 # argument is seed number.$i
821 slacapra 1.9 self.list_of_args = []
822     for i in range(self.total_number_of_jobs):
823 gutsche 1.35 ## Since there is no input, any site is good
824 ewv 1.131 self.jobDestination.append([""]) #must be empty to write correctly the xml
825 slacapra 1.90 args=[]
826 spiga 1.57 if (self.firstRun):
827 slacapra 1.138 ## pythia first run
828 slacapra 1.90 args.append(str(self.firstRun)+str(i))
829 ewv 1.258 if (self.generator in self.managedGenerators):
830 ewv 1.260 args.append(str((i-1)*self.eventsPerJob))
831 slacapra 1.90 self.list_of_args.append(args)
832 gutsche 1.3 return
833    
834 spiga 1.42
835 spiga 1.187 def jobSplittingForScript(self):
836 spiga 1.42 """
837     Perform job splitting based on number of job
838     """
839     common.logger.debug(5,'Splitting per job')
840     common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
841    
842     self.total_number_of_jobs = self.theNumberOfJobs
843    
844     common.logger.debug(5,'N jobs '+str(self.total_number_of_jobs))
845    
846     common.logger.message(str(self.total_number_of_jobs)+' jobs can be created')
847    
848     # argument is seed number.$i
849     self.list_of_args = []
850     for i in range(self.total_number_of_jobs):
851     self.jobDestination.append([""])
852     self.list_of_args.append([str(i)])
853     return
854    
855 spiga 1.208 def split(self, jobParams,firstJobID):
856 ewv 1.131
857 gutsche 1.3 njobs = self.total_number_of_jobs
858 slacapra 1.9 arglist = self.list_of_args
859 gutsche 1.3 # create the empty structure
860     for i in range(njobs):
861     jobParams.append("")
862 ewv 1.131
863 spiga 1.165 listID=[]
864     listField=[]
865 spiga 1.208 for id in range(njobs):
866     job = id + int(firstJobID)
867     jobParams[id] = arglist[id]
868 spiga 1.167 listID.append(job+1)
869 spiga 1.162 job_ToSave ={}
870 spiga 1.169 concString = ' '
871 spiga 1.165 argu=''
872 spiga 1.208 if len(jobParams[id]):
873     argu += concString.join(jobParams[id] )
874 spiga 1.187 job_ToSave['arguments']= str(job+1)+' '+argu
875 spiga 1.208 job_ToSave['dlsDestination']= self.jobDestination[id]
876 spiga 1.165 listField.append(job_ToSave)
877 spiga 1.169 msg="Job "+str(job)+" Arguments: "+str(job+1)+" "+argu+"\n" \
878 spiga 1.208 +" Destination: "+str(self.jobDestination[id])
879 spiga 1.165 common.logger.debug(5,msg)
880 spiga 1.187 common._db.updateJob_(listID,listField)
881 spiga 1.181 self.argsList = (len(jobParams[0])+1)
882 gutsche 1.3
883     return
884 ewv 1.131
885 gutsche 1.3 def numberOfJobs(self):
886     return self.total_number_of_jobs
887    
888 slacapra 1.1 def getTarBall(self, exe):
889     """
890     Return the TarBall with lib and exe
891     """
892 slacapra 1.242 self.tgzNameWithPath = common.work_space.pathForTgz()+self.tgz_name
893 slacapra 1.1 if os.path.exists(self.tgzNameWithPath):
894     return self.tgzNameWithPath
895    
896     # Prepare a tar gzipped file with user binaries.
897     self.buildTar_(exe)
898    
899     return string.strip(self.tgzNameWithPath)
900    
901     def buildTar_(self, executable):
902    
903     # First of all declare the user Scram area
904     swArea = self.scram.getSWArea_()
905     swReleaseTop = self.scram.getReleaseTop_()
906 ewv 1.131
907 slacapra 1.1 ## check if working area is release top
908     if swReleaseTop == '' or swArea == swReleaseTop:
909 afanfani 1.172 common.logger.debug(3,"swArea = "+swArea+" swReleaseTop ="+swReleaseTop)
910 slacapra 1.1 return
911    
912 slacapra 1.61 import tarfile
913     try: # create tar ball
914     tar = tarfile.open(self.tgzNameWithPath, "w:gz")
915     ## First find the executable
916 slacapra 1.86 if (self.executable != ''):
917 slacapra 1.61 exeWithPath = self.scram.findFile_(executable)
918     if ( not exeWithPath ):
919     raise CrabException('User executable '+executable+' not found')
920 ewv 1.131
921 slacapra 1.61 ## then check if it's private or not
922     if exeWithPath.find(swReleaseTop) == -1:
923     # the exe is private, so we must ship
924     common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
925     path = swArea+'/'
926 corvo 1.85 # distinguish case when script is in user project area or given by full path somewhere else
927     if exeWithPath.find(path) >= 0 :
928     exe = string.replace(exeWithPath, path,'')
929 slacapra 1.129 tar.add(path+exe,exe)
930 corvo 1.85 else :
931     tar.add(exeWithPath,os.path.basename(executable))
932 slacapra 1.61 pass
933     else:
934     # the exe is from release, we'll find it on WN
935     pass
936 ewv 1.131
937 slacapra 1.61 ## Now get the libraries: only those in local working area
938 slacapra 1.256 tar.dereference=True
939 slacapra 1.61 libDir = 'lib'
940     lib = swArea+'/' +libDir
941     common.logger.debug(5,"lib "+lib+" to be tarred")
942     if os.path.exists(lib):
943     tar.add(lib,libDir)
944 ewv 1.131
945 slacapra 1.61 ## Now check if module dir is present
946     moduleDir = 'module'
947     module = swArea + '/' + moduleDir
948     if os.path.isdir(module):
949     tar.add(module,moduleDir)
950 slacapra 1.256 tar.dereference=False
951 slacapra 1.61
952     ## Now check if any data dir(s) is present
953 spiga 1.179 self.dataExist = False
954 slacapra 1.212 todo_list = [(i, i) for i in os.listdir(swArea+"/src")]
955 slacapra 1.206 while len(todo_list):
956     entry, name = todo_list.pop()
957 slacapra 1.211 if name.startswith('crab_0_') or name.startswith('.') or name == 'CVS':
958 slacapra 1.206 continue
959 slacapra 1.212 if os.path.isdir(swArea+"/src/"+entry):
960 slacapra 1.206 entryPath = entry + '/'
961 slacapra 1.212 todo_list += [(entryPath + i, i) for i in os.listdir(swArea+"/src/"+entry)]
962 slacapra 1.206 if name == 'data':
963     self.dataExist=True
964     common.logger.debug(5,"data "+entry+" to be tarred")
965 slacapra 1.212 tar.add(swArea+"/src/"+entry,"src/"+entry)
966 slacapra 1.206 pass
967     pass
968 ewv 1.182
969 spiga 1.179 ### CMSSW ParameterSet
970     if not self.pset is None:
971     cfg_file = common.work_space.jobDir()+self.configFilename()
972 ewv 1.182 tar.add(cfg_file,self.configFilename())
973 spiga 1.179 common.logger.debug(5,"File added to "+self.tgzNameWithPath+" : "+str(tar.getnames()))
974 slacapra 1.61
975 fanzago 1.93
976 fanzago 1.152 ## Add ProdCommon dir to tar
977 slacapra 1.211 prodcommonDir = './'
978     prodcommonPath = os.environ['CRABDIR'] + '/' + 'external/'
979 spiga 1.244 neededStuff = ['ProdCommon/__init__.py','ProdCommon/FwkJobRep', 'ProdCommon/CMSConfigTools', \
980     'ProdCommon/Core', 'ProdCommon/MCPayloads', 'IMProv', 'ProdCommon/Storage']
981 slacapra 1.214 for file in neededStuff:
982     tar.add(prodcommonPath+file,prodcommonDir+file)
983 spiga 1.179 common.logger.debug(5,"Files added to "+self.tgzNameWithPath+" : "+str(tar.getnames()))
984    
985     ##### ML stuff
986     ML_file_list=['report.py', 'DashboardAPI.py', 'Logger.py', 'ProcInfo.py', 'apmon.py']
987     path=os.environ['CRABDIR'] + '/python/'
988     for file in ML_file_list:
989     tar.add(path+file,file)
990     common.logger.debug(5,"Files added to "+self.tgzNameWithPath+" : "+str(tar.getnames()))
991    
992     ##### Utils
993 spiga 1.238 Utils_file_list=['parseCrabFjr.py','writeCfg.py', 'fillCrabFjr.py','cmscp.py']
994 spiga 1.179 for file in Utils_file_list:
995     tar.add(path+file,file)
996     common.logger.debug(5,"Files added to "+self.tgzNameWithPath+" : "+str(tar.getnames()))
997 ewv 1.131
998 ewv 1.182 ##### AdditionalFiles
999 slacapra 1.253 tar.dereference=True
1000 spiga 1.179 for file in self.additional_inbox_files:
1001     tar.add(file,string.split(file,'/')[-1])
1002 slacapra 1.253 tar.dereference=False
1003 slacapra 1.61 common.logger.debug(5,"Files added to "+self.tgzNameWithPath+" : "+str(tar.getnames()))
1004 ewv 1.182
1005 slacapra 1.61 tar.close()
1006 mcinquil 1.241 except IOError, exc:
1007     common.logger.write(str(exc))
1008 slacapra 1.220 raise CrabException('Could not create tar-ball '+self.tgzNameWithPath)
1009 mcinquil 1.241 except tarfile.TarError, exc:
1010     common.logger.write(str(exc))
1011 slacapra 1.206 raise CrabException('Could not create tar-ball '+self.tgzNameWithPath)
1012 gutsche 1.72
1013     ## check for tarball size
1014     tarballinfo = os.stat(self.tgzNameWithPath)
1015     if ( tarballinfo.st_size > self.MaxTarBallSize*1024*1024 ) :
1016 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) \
1017 ewv 1.250 +'MB input sandbox limit \n'
1018 spiga 1.238 msg += ' and not supported by the direct GRID submission system.\n'
1019     msg += ' Please use the CRAB server mode by setting server_name=<NAME> in section [CRAB] of your crab.cfg.\n'
1020     msg += ' For further infos please see https://twiki.cern.ch/twiki/bin/view/CMS/CrabServer#CRABSERVER_for_Users'
1021     raise CrabException(msg)
1022 gutsche 1.72
1023 slacapra 1.61 ## create tar-ball with ML stuff
1024 slacapra 1.97
1025 spiga 1.165 def wsSetupEnvironment(self, nj=0):
1026 slacapra 1.1 """
1027     Returns part of a job script which prepares
1028     the execution environment for the job 'nj'.
1029     """
1030 ewv 1.184 if (self.CMSSW_major >= 2 and self.CMSSW_minor >= 1) or (self.CMSSW_major >= 3):
1031     psetName = 'pset.py'
1032     else:
1033     psetName = 'pset.cfg'
1034 slacapra 1.1 # Prepare JobType-independent part
1035 ewv 1.160 txt = '\n#Written by cms_cmssw::wsSetupEnvironment\n'
1036 fanzago 1.133 txt += 'echo ">>> setup environment"\n'
1037 ewv 1.131 txt += 'if [ $middleware == LCG ]; then \n'
1038 gutsche 1.3 txt += self.wsSetupCMSLCGEnvironment_()
1039     txt += 'elif [ $middleware == OSG ]; then\n'
1040 gutsche 1.43 txt += ' WORKING_DIR=`/bin/mktemp -d $OSG_WN_TMP/cms_XXXXXXXXXXXX`\n'
1041 ewv 1.132 txt += ' if [ ! $? == 0 ] ;then\n'
1042 fanzago 1.161 txt += ' echo "ERROR ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
1043     txt += ' job_exit_code=10016\n'
1044     txt += ' func_exit\n'
1045 gutsche 1.3 txt += ' fi\n'
1046 fanzago 1.133 txt += ' echo ">>> Created working directory: $WORKING_DIR"\n'
1047 gutsche 1.3 txt += '\n'
1048     txt += ' echo "Change to working directory: $WORKING_DIR"\n'
1049     txt += ' cd $WORKING_DIR\n'
1050 fanzago 1.133 txt += ' echo ">>> current directory (WORKING_DIR): $WORKING_DIR"\n'
1051 ewv 1.131 txt += self.wsSetupCMSOSGEnvironment_()
1052 gutsche 1.3 txt += 'fi\n'
1053 slacapra 1.1
1054     # Prepare JobType-specific part
1055     scram = self.scram.commandName()
1056     txt += '\n\n'
1057 fanzago 1.133 txt += 'echo ">>> specific cmssw setup environment:"\n'
1058     txt += 'echo "CMSSW_VERSION = '+self.version+'"\n'
1059 slacapra 1.1 txt += scram+' project CMSSW '+self.version+'\n'
1060     txt += 'status=$?\n'
1061     txt += 'if [ $status != 0 ] ; then\n'
1062 fanzago 1.161 txt += ' echo "ERROR ==> CMSSW '+self.version+' not found on `hostname`" \n'
1063     txt += ' job_exit_code=10034\n'
1064 fanzago 1.163 txt += ' func_exit\n'
1065 slacapra 1.1 txt += 'fi \n'
1066     txt += 'cd '+self.version+'\n'
1067 fanzago 1.99 txt += 'SOFTWARE_DIR=`pwd`\n'
1068 fanzago 1.133 txt += 'echo ">>> current directory (SOFTWARE_DIR): $SOFTWARE_DIR" \n'
1069 slacapra 1.1 txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
1070 fanzago 1.180 txt += 'if [ $? != 0 ] ; then\n'
1071     txt += ' echo "ERROR ==> Problem with the command: "\n'
1072     txt += ' echo "eval \`'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME \` at `hostname`"\n'
1073     txt += ' job_exit_code=10034\n'
1074     txt += ' func_exit\n'
1075     txt += 'fi \n'
1076 slacapra 1.1 # Handle the arguments:
1077     txt += "\n"
1078 gutsche 1.7 txt += "## number of arguments (first argument always jobnumber)\n"
1079 slacapra 1.1 txt += "\n"
1080 spiga 1.165 txt += "if [ $nargs -lt "+str(self.argsList)+" ]\n"
1081 slacapra 1.1 txt += "then\n"
1082 fanzago 1.161 txt += " echo 'ERROR ==> Too few arguments' +$nargs+ \n"
1083     txt += ' job_exit_code=50113\n'
1084     txt += " func_exit\n"
1085 slacapra 1.1 txt += "fi\n"
1086     txt += "\n"
1087    
1088     # Prepare job-specific part
1089     job = common.job_list[nj]
1090 ewv 1.131 if (self.datasetPath):
1091 spiga 1.238 self.primaryDataset = self.datasetPath.split("/")[1]
1092     DataTier = self.datasetPath.split("/")[2]
1093 fanzago 1.93 txt += '\n'
1094     txt += 'DatasetPath='+self.datasetPath+'\n'
1095    
1096 spiga 1.238 txt += 'PrimaryDataset='+self.primaryDataset +'\n'
1097     txt += 'DataTier='+DataTier+'\n'
1098 fanzago 1.96 txt += 'ApplicationFamily=cmsRun\n'
1099 fanzago 1.93
1100     else:
1101 ewv 1.250 self.primaryDataset = 'null'
1102 fanzago 1.93 txt += 'DatasetPath=MCDataTier\n'
1103     txt += 'PrimaryDataset=null\n'
1104     txt += 'DataTier=null\n'
1105     txt += 'ApplicationFamily=MCDataTier\n'
1106 ewv 1.170 if self.pset != None:
1107 spiga 1.42 pset = os.path.basename(job.configFilename())
1108     txt += '\n'
1109 spiga 1.95 txt += 'cp $RUNTIME_AREA/'+pset+' .\n'
1110 spiga 1.42 if (self.datasetPath): # standard job
1111 ewv 1.160 txt += 'InputFiles=${args[1]}; export InputFiles\n'
1112 ewv 1.226 if (self.useParent):
1113 spiga 1.204 txt += 'ParentFiles=${args[2]}; export ParentFiles\n'
1114     txt += 'MaxEvents=${args[3]}; export MaxEvents\n'
1115     txt += 'SkipEvents=${args[4]}; export SkipEvents\n'
1116     else:
1117     txt += 'MaxEvents=${args[2]}; export MaxEvents\n'
1118     txt += 'SkipEvents=${args[3]}; export SkipEvents\n'
1119 spiga 1.42 txt += 'echo "Inputfiles:<$InputFiles>"\n'
1120 spiga 1.204 if (self.useParent): txt += 'echo "ParentFiles:<$ParentFiles>"\n'
1121 spiga 1.42 txt += 'echo "MaxEvents:<$MaxEvents>"\n'
1122     txt += 'echo "SkipEvents:<$SkipEvents>"\n'
1123     else: # pythia like job
1124 ewv 1.258 argNum = 1
1125 ewv 1.160 txt += 'PreserveSeeds=' + ','.join(self.preserveSeeds) + '; export PreserveSeeds\n'
1126     txt += 'IncrementSeeds=' + ','.join(self.incrementSeeds) + '; export IncrementSeeds\n'
1127     txt += 'echo "PreserveSeeds: <$PreserveSeeds>"\n'
1128     txt += 'echo "IncrementSeeds:<$IncrementSeeds>"\n'
1129 slacapra 1.90 if (self.firstRun):
1130 ewv 1.258 txt += 'export FirstRun=${args[%s]}\n' % argNum
1131 spiga 1.57 txt += 'echo "FirstRun: <$FirstRun>"\n'
1132 ewv 1.258 argNum += 1
1133     if (self.generator in self.managedGenerators):
1134 ewv 1.259 txt += 'export FirstEvent=${args[%s]}\n' % argNum
1135     txt += 'echo "FirstEvent:<$FirstEvent>"\n'
1136     argNum += 1
1137 slacapra 1.90
1138 ewv 1.184 txt += 'mv -f ' + pset + ' ' + psetName + '\n'
1139 slacapra 1.1
1140    
1141 fanzago 1.163 if self.pset != None:
1142 ewv 1.184 # FUTURE: Can simply for 2_1_x and higher
1143 spiga 1.42 txt += '\n'
1144 spiga 1.197 if self.debug_wrapper==True:
1145 spiga 1.188 txt += 'echo "***** cat ' + psetName + ' *********"\n'
1146     txt += 'cat ' + psetName + '\n'
1147     txt += 'echo "****** end ' + psetName + ' ********"\n'
1148     txt += '\n'
1149 ewv 1.226 if (self.CMSSW_major >= 2 and self.CMSSW_minor >= 1) or (self.CMSSW_major >= 3):
1150     txt += 'PSETHASH=`edmConfigHash ' + psetName + '` \n'
1151     else:
1152     txt += 'PSETHASH=`edmConfigHash < ' + psetName + '` \n'
1153 fanzago 1.94 txt += 'echo "PSETHASH = $PSETHASH" \n'
1154 fanzago 1.93 txt += '\n'
1155 gutsche 1.3 return txt
1156 slacapra 1.176
1157 fanzago 1.166 def wsUntarSoftware(self, nj=0):
1158 gutsche 1.3 """
1159     Put in the script the commands to build an executable
1160     or a library.
1161     """
1162    
1163 fanzago 1.166 txt = '\n#Written by cms_cmssw::wsUntarSoftware\n'
1164 gutsche 1.3
1165     if os.path.isfile(self.tgzNameWithPath):
1166 fanzago 1.133 txt += 'echo ">>> tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+' :" \n'
1167 slacapra 1.255 txt += 'tar xzf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
1168 spiga 1.199 if self.debug_wrapper:
1169 slacapra 1.255 txt += 'tar tzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
1170 spiga 1.199 txt += 'ls -Al \n'
1171 gutsche 1.3 txt += 'untar_status=$? \n'
1172     txt += 'if [ $untar_status -ne 0 ]; then \n'
1173 fanzago 1.161 txt += ' echo "ERROR ==> Untarring .tgz file failed"\n'
1174     txt += ' job_exit_code=$untar_status\n'
1175     txt += ' func_exit\n'
1176 gutsche 1.3 txt += 'else \n'
1177     txt += ' echo "Successful untar" \n'
1178     txt += 'fi \n'
1179 gutsche 1.50 txt += '\n'
1180 slacapra 1.211 txt += 'echo ">>> Include $RUNTIME_AREA in PYTHONPATH:"\n'
1181 gutsche 1.50 txt += 'if [ -z "$PYTHONPATH" ]; then\n'
1182 slacapra 1.211 txt += ' export PYTHONPATH=$RUNTIME_AREA/\n'
1183 gutsche 1.50 txt += 'else\n'
1184 slacapra 1.211 txt += ' export PYTHONPATH=$RUNTIME_AREA/:${PYTHONPATH}\n'
1185 fanzago 1.93 txt += 'echo "PYTHONPATH=$PYTHONPATH"\n'
1186 gutsche 1.50 txt += 'fi\n'
1187     txt += '\n'
1188    
1189 gutsche 1.3 pass
1190 ewv 1.131
1191 slacapra 1.1 return txt
1192 ewv 1.170
1193 fanzago 1.166 def wsBuildExe(self, nj=0):
1194     """
1195     Put in the script the commands to build an executable
1196     or a library.
1197     """
1198    
1199     txt = '\n#Written by cms_cmssw::wsBuildExe\n'
1200     txt += 'echo ">>> moving CMSSW software directories in `pwd`" \n'
1201    
1202 ewv 1.170 txt += 'rm -r lib/ module/ \n'
1203     txt += 'mv $RUNTIME_AREA/lib/ . \n'
1204     txt += 'mv $RUNTIME_AREA/module/ . \n'
1205 spiga 1.186 if self.dataExist == True:
1206     txt += 'rm -r src/ \n'
1207     txt += 'mv $RUNTIME_AREA/src/ . \n'
1208 ewv 1.182 if len(self.additional_inbox_files)>0:
1209 spiga 1.179 for file in self.additional_inbox_files:
1210 spiga 1.191 txt += 'mv $RUNTIME_AREA/'+os.path.basename(file)+' . \n'
1211 slacapra 1.214 # txt += 'mv $RUNTIME_AREA/ProdCommon/ . \n'
1212     # txt += 'mv $RUNTIME_AREA/IMProv/ . \n'
1213 ewv 1.170
1214 slacapra 1.211 txt += 'echo ">>> Include $RUNTIME_AREA in PYTHONPATH:"\n'
1215 fanzago 1.166 txt += 'if [ -z "$PYTHONPATH" ]; then\n'
1216 slacapra 1.211 txt += ' export PYTHONPATH=$RUNTIME_AREA/\n'
1217 fanzago 1.166 txt += 'else\n'
1218 slacapra 1.211 txt += ' export PYTHONPATH=$RUNTIME_AREA/:${PYTHONPATH}\n'
1219 fanzago 1.166 txt += 'echo "PYTHONPATH=$PYTHONPATH"\n'
1220     txt += 'fi\n'
1221     txt += '\n'
1222    
1223     return txt
1224 slacapra 1.1
1225 ewv 1.131
1226 slacapra 1.1 def executableName(self):
1227 ewv 1.192 if self.scriptExe:
1228 spiga 1.42 return "sh "
1229     else:
1230     return self.executable
1231 slacapra 1.1
1232     def executableArgs(self):
1233 ewv 1.160 # FUTURE: This function tests the CMSSW version. Can be simplified as we drop support for old versions
1234 slacapra 1.70 if self.scriptExe:#CarlosDaniele
1235 spiga 1.42 return self.scriptExe + " $NJob"
1236 fanzago 1.115 else:
1237 ewv 1.160 ex_args = ""
1238 ewv 1.171 # FUTURE: This tests the CMSSW version. Can remove code as versions deprecated
1239 ewv 1.160 # Framework job report
1240 ewv 1.184 if (self.CMSSW_major >= 1 and self.CMSSW_minor >= 5) or (self.CMSSW_major >= 2):
1241 fanzago 1.166 ex_args += " -j $RUNTIME_AREA/crab_fjr_$NJob.xml"
1242 ewv 1.184 # Type of config file
1243     if self.CMSSW_major >= 2 :
1244 ewv 1.171 ex_args += " -p pset.py"
1245 fanzago 1.115 else:
1246 ewv 1.160 ex_args += " -p pset.cfg"
1247     return ex_args
1248 slacapra 1.1
1249     def inputSandbox(self, nj):
1250     """
1251     Returns a list of filenames to be put in JDL input sandbox.
1252     """
1253     inp_box = []
1254     if os.path.isfile(self.tgzNameWithPath):
1255     inp_box.append(self.tgzNameWithPath)
1256 spiga 1.243 inp_box.append(common.work_space.jobDir() + self.scriptName)
1257 slacapra 1.1 return inp_box
1258    
1259     def outputSandbox(self, nj):
1260     """
1261     Returns a list of filenames to be put in JDL output sandbox.
1262     """
1263     out_box = []
1264    
1265     ## User Declared output files
1266 slacapra 1.54 for out in (self.output_file+self.output_file_sandbox):
1267 ewv 1.131 n_out = nj + 1
1268 slacapra 1.207 out_box.append(numberFile(out,str(n_out)))
1269 slacapra 1.1 return out_box
1270    
1271    
1272     def wsRenameOutput(self, nj):
1273     """
1274     Returns part of a job script which renames the produced files.
1275     """
1276    
1277 ewv 1.160 txt = '\n#Written by cms_cmssw::wsRenameOutput\n'
1278 fanzago 1.148 txt += 'echo ">>> current directory (SOFTWARE_DIR): $SOFTWARE_DIR" \n'
1279     txt += 'echo ">>> current directory content:"\n'
1280 ewv 1.226 if self.debug_wrapper:
1281 spiga 1.199 txt += 'ls -Al\n'
1282 fanzago 1.145 txt += '\n'
1283 slacapra 1.54
1284 fanzago 1.128 for fileWithSuffix in (self.output_file):
1285 slacapra 1.207 output_file_num = numberFile(fileWithSuffix, '$NJob')
1286 slacapra 1.1 txt += '\n'
1287 gutsche 1.7 txt += '# check output file\n'
1288 slacapra 1.106 txt += 'if [ -e ./'+fileWithSuffix+' ] ; then\n'
1289 ewv 1.147 if (self.copy_data == 1): # For OSG nodes, file is in $WORKING_DIR, should not be moved to $RUNTIME_AREA
1290     txt += ' mv '+fileWithSuffix+' '+output_file_num+'\n'
1291 spiga 1.209 txt += ' ln -s `pwd`/'+output_file_num+' $RUNTIME_AREA/'+fileWithSuffix+'\n'
1292 ewv 1.147 else:
1293     txt += ' mv '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
1294     txt += ' ln -s $RUNTIME_AREA/'+output_file_num+' $RUNTIME_AREA/'+fileWithSuffix+'\n'
1295 slacapra 1.106 txt += 'else\n'
1296 fanzago 1.161 txt += ' job_exit_code=60302\n'
1297     txt += ' echo "WARNING: Output file '+fileWithSuffix+' not found"\n'
1298 ewv 1.156 if common.scheduler.name().upper() == 'CONDOR_G':
1299 gutsche 1.7 txt += ' if [ $middleware == OSG ]; then \n'
1300     txt += ' echo "prepare dummy output file"\n'
1301     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
1302     txt += ' fi \n'
1303 slacapra 1.1 txt += 'fi\n'
1304 slacapra 1.105 file_list = []
1305     for fileWithSuffix in (self.output_file):
1306 spiga 1.246 file_list.append(numberFile('$SOFTWARE_DIR/'+fileWithSuffix, '$NJob'))
1307 ewv 1.131
1308 spiga 1.245 txt += 'file_list="'+string.join(file_list,',')+'"\n'
1309 fanzago 1.149 txt += '\n'
1310 fanzago 1.148 txt += 'echo ">>> current directory (SOFTWARE_DIR): $SOFTWARE_DIR" \n'
1311     txt += 'echo ">>> current directory content:"\n'
1312 ewv 1.226 if self.debug_wrapper:
1313 spiga 1.199 txt += 'ls -Al\n'
1314 fanzago 1.148 txt += '\n'
1315 gutsche 1.7 txt += 'cd $RUNTIME_AREA\n'
1316 fanzago 1.133 txt += 'echo ">>> current directory (RUNTIME_AREA): $RUNTIME_AREA"\n'
1317 slacapra 1.1 return txt
1318    
1319 slacapra 1.63 def getRequirements(self, nj=[]):
1320 slacapra 1.1 """
1321 ewv 1.131 return job requirements to add to jdl files
1322 slacapra 1.1 """
1323     req = ''
1324 slacapra 1.47 if self.version:
1325 slacapra 1.10 req='Member("VO-cms-' + \
1326 slacapra 1.47 self.version + \
1327 slacapra 1.10 '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
1328 ewv 1.192 if self.executable_arch:
1329 gutsche 1.107 req+=' && Member("VO-cms-' + \
1330 slacapra 1.105 self.executable_arch + \
1331     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
1332 gutsche 1.35
1333     req = req + ' && (other.GlueHostNetworkAdapterOutboundIP)'
1334 afanfani 1.229 if ( common.scheduler.name() == "glitecoll" ) or ( common.scheduler.name() == "glite"):
1335 afanfani 1.158 req += ' && other.GlueCEStateStatus == "Production" '
1336 gutsche 1.35
1337 slacapra 1.1 return req
1338 gutsche 1.3
1339     def configFilename(self):
1340     """ return the config filename """
1341 ewv 1.182 # FUTURE: Can remove cfg mode for CMSSW >= 2_1_x
1342 ewv 1.184 if (self.CMSSW_major >= 2 and self.CMSSW_minor >= 1) or (self.CMSSW_major >= 3):
1343 ewv 1.182 return self.name()+'.py'
1344     else:
1345     return self.name()+'.cfg'
1346 gutsche 1.3
1347     def wsSetupCMSOSGEnvironment_(self):
1348     """
1349     Returns part of a job script which is prepares
1350     the execution environment and which is common for all CMS jobs.
1351     """
1352 ewv 1.160 txt = '\n#Written by cms_cmssw::wsSetupCMSOSGEnvironment_\n'
1353     txt += ' echo ">>> setup CMS OSG environment:"\n'
1354 fanzago 1.133 txt += ' echo "set SCRAM ARCH to ' + self.executable_arch + '"\n'
1355     txt += ' export SCRAM_ARCH='+self.executable_arch+'\n'
1356 fanzago 1.136 txt += ' echo "SCRAM_ARCH = $SCRAM_ARCH"\n'
1357 ewv 1.135 txt += ' if [ -f $OSG_APP/cmssoft/cms/cmsset_default.sh ] ;then\n'
1358 mkirn 1.40 txt += ' # Use $OSG_APP/cmssoft/cms/cmsset_default.sh to setup cms software\n'
1359 fanzago 1.133 txt += ' source $OSG_APP/cmssoft/cms/cmsset_default.sh '+self.version+'\n'
1360     txt += ' else\n'
1361 fanzago 1.161 txt += ' echo "ERROR ==> $OSG_APP/cmssoft/cms/cmsset_default.sh file not found"\n'
1362     txt += ' job_exit_code=10020\n'
1363     txt += ' func_exit\n'
1364 fanzago 1.133 txt += ' fi\n'
1365 gutsche 1.3 txt += '\n'
1366 fanzago 1.161 txt += ' echo "==> setup cms environment ok"\n'
1367 fanzago 1.136 txt += ' echo "SCRAM_ARCH = $SCRAM_ARCH"\n'
1368 gutsche 1.3
1369     return txt
1370 ewv 1.131
1371 gutsche 1.3 def wsSetupCMSLCGEnvironment_(self):
1372     """
1373     Returns part of a job script which is prepares
1374     the execution environment and which is common for all CMS jobs.
1375     """
1376 ewv 1.160 txt = '\n#Written by cms_cmssw::wsSetupCMSLCGEnvironment_\n'
1377     txt += ' echo ">>> setup CMS LCG environment:"\n'
1378 fanzago 1.133 txt += ' echo "set SCRAM ARCH and BUILD_ARCH to ' + self.executable_arch + ' ###"\n'
1379     txt += ' export SCRAM_ARCH='+self.executable_arch+'\n'
1380     txt += ' export BUILD_ARCH='+self.executable_arch+'\n'
1381     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
1382 fanzago 1.161 txt += ' echo "ERROR ==> CMS software dir not found on WN `hostname`"\n'
1383     txt += ' job_exit_code=10031\n'
1384     txt += ' func_exit\n'
1385 fanzago 1.133 txt += ' else\n'
1386     txt += ' echo "Sourcing environment... "\n'
1387     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1388 fanzago 1.161 txt += ' echo "ERROR ==> cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1389     txt += ' job_exit_code=10020\n'
1390     txt += ' func_exit\n'
1391 fanzago 1.133 txt += ' fi\n'
1392     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1393     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1394     txt += ' result=$?\n'
1395     txt += ' if [ $result -ne 0 ]; then\n'
1396 fanzago 1.161 txt += ' echo "ERROR ==> problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1397     txt += ' job_exit_code=10032\n'
1398     txt += ' func_exit\n'
1399 fanzago 1.133 txt += ' fi\n'
1400     txt += ' fi\n'
1401     txt += ' \n'
1402 fanzago 1.161 txt += ' echo "==> setup cms environment ok"\n'
1403 gutsche 1.3 return txt
1404 gutsche 1.5
1405 spiga 1.238 def wsModifyReport(self, nj):
1406 fanzago 1.93 """
1407 ewv 1.131 insert the part of the script that modifies the FrameworkJob Report
1408 fanzago 1.93 """
1409 spiga 1.238 txt = '\n#Written by cms_cmssw::wsModifyReport\n'
1410 slacapra 1.176 publish_data = int(self.cfg_params.get('USER.publish_data',0))
1411 ewv 1.131 if (publish_data == 1):
1412 ewv 1.250
1413 fanzago 1.248 processedDataset = self.cfg_params['USER.publish_data_name']
1414 spiga 1.238
1415     txt += 'if [ $StageOutExitStatus -eq 0 ]; then\n'
1416 fanzago 1.248 txt += ' FOR_LFN=$LFNBaseName\n'
1417 fanzago 1.175 txt += 'else\n'
1418     txt += ' FOR_LFN=/copy_problems/ \n'
1419     txt += ' SE=""\n'
1420     txt += ' SE_PATH=""\n'
1421     txt += 'fi\n'
1422 ewv 1.182
1423 fanzago 1.175 txt += 'echo ">>> Modify Job Report:" \n'
1424 fanzago 1.217 txt += 'chmod a+x $RUNTIME_AREA/ProdCommon/FwkJobRep/ModifyJobReport.py\n'
1425 fanzago 1.248 txt += 'ProcessedDataset='+processedDataset+'\n'
1426     #txt += 'ProcessedDataset=$procDataset \n'
1427 fanzago 1.175 txt += 'echo "ProcessedDataset = $ProcessedDataset"\n'
1428     txt += 'echo "SE = $SE"\n'
1429     txt += 'echo "SE_PATH = $SE_PATH"\n'
1430     txt += 'echo "FOR_LFN = $FOR_LFN" \n'
1431     txt += 'echo "CMSSW_VERSION = $CMSSW_VERSION"\n\n'
1432 spiga 1.238 args = '$RUNTIME_AREA/crab_fjr_$NJob.xml $NJob $FOR_LFN $PrimaryDataset $DataTier ' \
1433 fanzago 1.248 '$USER-$ProcessedDataset-$PSETHASH $ApplicationFamily '+ \
1434 fanzago 1.247 ' $executable $CMSSW_VERSION $PSETHASH $SE $SE_PATH'
1435     txt += 'echo "$RUNTIME_AREA/ProdCommon/FwkJobRep/ModifyJobReport.py '+str(args)+'"\n'
1436     txt += '$RUNTIME_AREA/ProdCommon/FwkJobRep/ModifyJobReport.py '+str(args)+'\n'
1437 fanzago 1.175 txt += 'modifyReport_result=$?\n'
1438     txt += 'if [ $modifyReport_result -ne 0 ]; then\n'
1439     txt += ' modifyReport_result=70500\n'
1440     txt += ' job_exit_code=$modifyReport_result\n'
1441     txt += ' echo "ModifyReportResult=$modifyReport_result" | tee -a $RUNTIME_AREA/$repo\n'
1442     txt += ' echo "WARNING: Problem with ModifyJobReport"\n'
1443     txt += 'else\n'
1444     txt += ' mv NewFrameworkJobReport.xml $RUNTIME_AREA/crab_fjr_$NJob.xml\n'
1445 spiga 1.103 txt += 'fi\n'
1446 fanzago 1.93 return txt
1447 fanzago 1.99
1448 ewv 1.192 def wsParseFJR(self):
1449 spiga 1.189 """
1450 ewv 1.192 Parse the FrameworkJobReport to obtain useful infos
1451 spiga 1.189 """
1452     txt = '\n#Written by cms_cmssw::wsParseFJR\n'
1453     txt += 'echo ">>> Parse FrameworkJobReport crab_fjr.xml"\n'
1454     txt += 'if [ -s $RUNTIME_AREA/crab_fjr_$NJob.xml ]; then\n'
1455     txt += ' if [ -s $RUNTIME_AREA/parseCrabFjr.py ]; then\n'
1456 spiga 1.197 txt += ' cmd_out=`python $RUNTIME_AREA/parseCrabFjr.py --input $RUNTIME_AREA/crab_fjr_$NJob.xml --dashboard $MonitorID,$MonitorJobID '+self.debugWrap+'`\n'
1457     if self.debug_wrapper :
1458     txt += ' echo "Result of parsing the FrameworkJobReport crab_fjr.xml: $cmd_out"\n'
1459     txt += ' executable_exit_status=`python $RUNTIME_AREA/parseCrabFjr.py --input $RUNTIME_AREA/crab_fjr_$NJob.xml --exitcode`\n'
1460 spiga 1.189 txt += ' if [ $executable_exit_status -eq 50115 ];then\n'
1461     txt += ' echo ">>> crab_fjr.xml contents: "\n'
1462 spiga 1.222 txt += ' cat $RUNTIME_AREA/crab_fjr_$NJob.xml\n'
1463 spiga 1.189 txt += ' echo "Wrong FrameworkJobReport --> does not contain useful info. ExitStatus: $executable_exit_status"\n'
1464 spiga 1.197 txt += ' elif [ $executable_exit_status -eq -999 ];then\n'
1465     txt += ' echo "ExitStatus from FrameworkJobReport not available. not available. Using exit code of executable from command line."\n'
1466 spiga 1.189 txt += ' else\n'
1467     txt += ' echo "Extracted ExitStatus from FrameworkJobReport parsing output: $executable_exit_status"\n'
1468     txt += ' fi\n'
1469     txt += ' else\n'
1470     txt += ' echo "CRAB python script to parse CRAB FrameworkJobReport crab_fjr.xml is not available, using exit code of executable from command line."\n'
1471     txt += ' fi\n'
1472     #### Patch to check input data reading for CMSSW16x Hopefully we-ll remove it asap
1473 spiga 1.232 txt += ' if [ $executable_exit_status -eq 0 ];then\n'
1474     txt += ' echo ">>> Executable succeded $executable_exit_status"\n'
1475 spiga 1.233 if (self.datasetPath and not (self.dataset_pu or self.useParent)) :
1476 spiga 1.189 # VERIFY PROCESSED DATA
1477     txt += ' echo ">>> Verify list of processed files:"\n'
1478 ewv 1.196 txt += ' echo $InputFiles |tr -d \'\\\\\' |tr \',\' \'\\n\'|tr -d \'"\' > input-files.txt\n'
1479 spiga 1.200 txt += ' python $RUNTIME_AREA/parseCrabFjr.py --input $RUNTIME_AREA/crab_fjr_$NJob.xml --lfn > processed-files.txt\n'
1480 spiga 1.189 txt += ' cat input-files.txt | sort | uniq > tmp.txt\n'
1481     txt += ' mv tmp.txt input-files.txt\n'
1482     txt += ' echo "cat input-files.txt"\n'
1483     txt += ' echo "----------------------"\n'
1484     txt += ' cat input-files.txt\n'
1485     txt += ' cat processed-files.txt | sort | uniq > tmp.txt\n'
1486     txt += ' mv tmp.txt processed-files.txt\n'
1487     txt += ' echo "----------------------"\n'
1488     txt += ' echo "cat processed-files.txt"\n'
1489     txt += ' echo "----------------------"\n'
1490     txt += ' cat processed-files.txt\n'
1491     txt += ' echo "----------------------"\n'
1492     txt += ' diff -q input-files.txt processed-files.txt\n'
1493     txt += ' fileverify_status=$?\n'
1494     txt += ' if [ $fileverify_status -ne 0 ]; then\n'
1495     txt += ' executable_exit_status=30001\n'
1496     txt += ' echo "ERROR ==> not all input files processed"\n'
1497     txt += ' echo " ==> list of processed files from crab_fjr.xml differs from list in pset.cfg"\n'
1498     txt += ' echo " ==> diff input-files.txt processed-files.txt"\n'
1499     txt += ' fi\n'
1500 spiga 1.232 txt += ' elif [ $executable_exit_status -ne 0 ] || [ $executable_exit_status -ne 50015 ] || [ $executable_exit_status -ne 50017 ];then\n'
1501     txt += ' echo ">>> Executable failed $executable_exit_status"\n'
1502 spiga 1.251 txt += ' echo "ExeExitCode=$executable_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
1503     txt += ' echo "EXECUTABLE_EXIT_STATUS = $executable_exit_status"\n'
1504     txt += ' job_exit_code=$executable_exit_status\n'
1505 spiga 1.232 txt += ' func_exit\n'
1506     txt += ' fi\n'
1507     txt += '\n'
1508 spiga 1.189 txt += 'else\n'
1509     txt += ' echo "CRAB FrameworkJobReport crab_fjr.xml is not available, using exit code of executable from command line."\n'
1510     txt += 'fi\n'
1511     txt += '\n'
1512     txt += 'echo "ExeExitCode=$executable_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
1513     txt += 'echo "EXECUTABLE_EXIT_STATUS = $executable_exit_status"\n'
1514     txt += 'job_exit_code=$executable_exit_status\n'
1515    
1516     return txt
1517    
1518 gutsche 1.5 def setParam_(self, param, value):
1519     self._params[param] = value
1520    
1521     def getParams(self):
1522     return self._params
1523 gutsche 1.8
1524 gutsche 1.35 def uniquelist(self, old):
1525     """
1526     remove duplicates from a list
1527     """
1528     nd={}
1529     for e in old:
1530     nd[e]=0
1531     return nd.keys()
1532 mcinquil 1.121
1533 spiga 1.257 def outList(self,list=False):
1534 mcinquil 1.121 """
1535     check the dimension of the output files
1536     """
1537 spiga 1.169 txt = ''
1538     txt += 'echo ">>> list of expected files on output sandbox"\n'
1539 mcinquil 1.121 listOutFiles = []
1540 ewv 1.170 stdout = 'CMSSW_$NJob.stdout'
1541 spiga 1.169 stderr = 'CMSSW_$NJob.stderr'
1542 fanzago 1.148 if (self.return_data == 1):
1543 spiga 1.157 for file in (self.output_file+self.output_file_sandbox):
1544 slacapra 1.207 listOutFiles.append(numberFile(file, '$NJob'))
1545 spiga 1.169 listOutFiles.append(stdout)
1546     listOutFiles.append(stderr)
1547 ewv 1.156 else:
1548 spiga 1.157 for file in (self.output_file_sandbox):
1549 slacapra 1.207 listOutFiles.append(numberFile(file, '$NJob'))
1550 spiga 1.169 listOutFiles.append(stdout)
1551     listOutFiles.append(stderr)
1552 fanzago 1.161 txt += 'echo "output files: '+string.join(listOutFiles,' ')+'"\n'
1553 spiga 1.157 txt += 'filesToCheck="'+string.join(listOutFiles,' ')+'"\n'
1554 spiga 1.169 txt += 'export filesToCheck\n'
1555 spiga 1.257 if list : return self.output_file
1556 ewv 1.170 return txt