ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
Revision: 1.236
Committed: Mon Sep 8 07:42:41 2008 UTC (16 years, 7 months ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_DLS_PHED
Changes since 1.235: +5 -1 lines
Log Message:
added protection if datasetpath=""

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