ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_cmssw.py
(Generate patch)

Comparing COMP/CRAB/python/cms_cmssw.py (file contents):
Revision 1.6 by gutsche, Sun Jun 4 16:53:36 2006 UTC vs.
Revision 1.41 by slacapra, Wed Sep 20 17:29:52 2006 UTC

# Line 2 | Line 2 | from JobType import JobType
2   from crab_logger import Logger
3   from crab_exceptions import *
4   from crab_util import *
5 + import math
6   import common
7   import PsetManipulator  
8  
9 < import DBSInfo_EDM
10 < import DataDiscovery_EDM
11 < import DataLocation_EDM
9 > import DBSInfo
10 > import DataDiscovery
11 > import DataLocation
12   import Scram
13  
14   import os, string, re
15  
16   class Cmssw(JobType):
17 <    def __init__(self, cfg_params):
17 >    def __init__(self, cfg_params, ncjobs):
18          JobType.__init__(self, 'CMSSW')
19          common.logger.debug(3,'CMSSW::__init__')
20  
# Line 22 | Line 23 | class Cmssw(JobType):
23          self._params = {}
24          self.cfg_params = cfg_params
25  
26 +        # number of jobs requested to be created, limit ojb splitting
27 +        self.ncjobs = ncjobs
28 +
29          log = common.logger
30          
31          self.scram = Scram.Scram(cfg_params)
# Line 41 | Line 45 | class Cmssw(JobType):
45  
46          ### collect Data cards
47          try:
48 <         #   self.owner = cfg_params['CMSSW.owner']
49 <         #   log.debug(6, "CMSSW::CMSSW(): owner = "+self.owner)
50 <         #   self.dataset = cfg_params['CMSSW.dataset']
51 <            self.datasetPath = cfg_params['CMSSW.datasetpath']
52 <            log.debug(6, "CMSSW::CMSSW(): datasetPath = "+self.datasetPath)
48 >            tmp =  cfg_params['CMSSW.datasetpath']
49 >            log.debug(6, "CMSSW::CMSSW(): datasetPath = "+tmp)
50 >            if string.lower(tmp)=='none':
51 >                self.datasetPath = None
52 >                self.selectNoInput = 1
53 >            else:
54 >                self.datasetPath = tmp
55 >                self.selectNoInput = 0
56          except KeyError:
50        #    msg = "Error: owner and/or dataset not defined "
57              msg = "Error: datasetpath not defined "  
58              raise CrabException(msg)
59  
60          # ML monitoring
61          # split dataset path style: /PreProdR3Minbias/SIM/GEN-SIM
62 <        datasetpath_split = self.datasetPath.split("/")
63 <        self.setParam_('dataset', datasetpath_split[1])
64 <        self.setParam_('owner', datasetpath_split[-1])
65 <
66 <
62 >        if not self.datasetPath:
63 >            self.setParam_('dataset', 'None')
64 >            self.setParam_('owner', 'None')
65 >        else:
66 >            datasetpath_split = self.datasetPath.split("/")
67 >            self.setParam_('dataset', datasetpath_split[1])
68 >            self.setParam_('owner', datasetpath_split[-1])
69  
70 +        self.setTaskid_()
71 +        self.setParam_('taskId', self.cfg_params['taskId'])
72  
73          self.dataTiers = []
64 #       try:
65 #           tmpDataTiers = string.split(cfg_params['CMSSW.data_tier'],',')
66 #           for tmp in tmpDataTiers:
67 #               tmp=string.strip(tmp)
68 #               self.dataTiers.append(tmp)
69 #               pass
70 #           pass
71 #       except KeyError:
72 #           pass
73 #       log.debug(6, "Cmssw::Cmssw(): dataTiers = "+str(self.dataTiers))
74  
75          ## now the application
76          try:
# Line 116 | Line 116 | class Cmssw(JobType):
116  
117          # script_exe file as additional file in inputSandbox
118          try:
119 <           self.scriptExe = cfg_params['USER.script_exe']
120 <           self.additional_inbox_files.append(self.scriptExe)
119 >            self.scriptExe = cfg_params['USER.script_exe']
120 >            self.additional_inbox_files.append(self.scriptExe)
121 >            if self.scriptExe != '':
122 >               if not os.path.isfile(self.scriptExe):
123 >                  msg ="WARNING. file "+self.scriptExe+" not found"
124 >                  raise CrabException(msg)
125          except KeyError:
126             pass
123        if self.scriptExe != '':
124           if os.path.isfile(self.scriptExe):
125              pass
126           else:
127              log.message("WARNING. file "+self.scriptExe+" not found")
128              sys.exit()
127                    
128          ## additional input files
129          try:
130 <            tmpAddFiles = string.split(cfg_params['CMSSW.additional_input_files'],',')
130 >            tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
131              for tmp in tmpAddFiles:
132                  if not os.path.exists(tmp):
133                      raise CrabException("Additional input file not found: "+tmp)
134 <                tmp=string.strip(tmp)
137 <                self.additional_inbox_files.append(tmp)
134 >                self.additional_inbox_files.append(string.strip(tmp))
135                  pass
136              pass
137          except KeyError:
138              pass
139  
140 +        # files per job
141          try:
142 <            self.filesPerJob = int(cfg_params['CMSSW.files_per_jobs']) #Daniele
142 >            if (cfg_params['CMSSW.files_per_jobs']):
143 >                raise CrabException("files_per_jobs no longer supported.  Quitting.")
144          except KeyError:
145 <            self.filesPerJob = 1
145 >            pass
146  
147 <        ## Max event   will be total_number_of_events ???  Daniele
147 >        ## Events per job
148          try:
149 <            self.maxEv = cfg_params['CMSSW.event_per_job']
149 >            self.eventsPerJob =int( cfg_params['CMSSW.events_per_job'])
150 >            self.selectEventsPerJob = 1
151          except KeyError:
152 <            self.maxEv = "-1"
153 <        ##  
152 >            self.eventsPerJob = -1
153 >            self.selectEventsPerJob = 0
154 >    
155 >        ## number of jobs
156 >        try:
157 >            self.theNumberOfJobs =int( cfg_params['CMSSW.number_of_jobs'])
158 >            self.selectNumberOfJobs = 1
159 >        except KeyError:
160 >            self.theNumberOfJobs = 0
161 >            self.selectNumberOfJobs = 0
162 >
163          try:
164              self.total_number_of_events = int(cfg_params['CMSSW.total_number_of_events'])
165 +            self.selectTotalNumberEvents = 1
166          except KeyError:
167 <            msg = 'Must define total_number_of_events'
167 >            self.total_number_of_events = 0
168 >            self.selectTotalNumberEvents = 0
169 >
170 >        if ( (self.selectTotalNumberEvents + self.selectEventsPerJob + self.selectNumberOfJobs) != 2 ):
171 >            msg = 'Must define exactly two of total_number_of_events, events_per_job, or number_of_jobs.'
172              raise CrabException(msg)
173 <        
174 <        CEBlackList = []
173 >
174 >        ## source seed for pythia
175          try:
176 <            tmpBad = string.split(cfg_params['EDG.ce_black_list'],',')
163 <            for tmp in tmpBad:
164 <                tmp=string.strip(tmp)
165 <                CEBlackList.append(tmp)
176 >            self.sourceSeed = int(cfg_params['CMSSW.pythia_seed'])
177          except KeyError:
178 <            pass
178 >            self.sourceSeed = None
179 >            common.logger.debug(5,"No seed given")
180  
181 <        self.reCEBlackList=[]
182 <        for bad in CEBlackList:
171 <            self.reCEBlackList.append(re.compile( bad ))
172 <
173 <        common.logger.debug(5,'CEBlackList: '+str(CEBlackList))
174 <
175 <        CEWhiteList = []
176 <        try:
177 <            tmpGood = string.split(cfg_params['EDG.ce_white_list'],',')
178 <            for tmp in tmpGood:
179 <                tmp=string.strip(tmp)
180 <                CEWhiteList.append(tmp)
181 >        try:
182 >            self.sourceSeedVtx = int(cfg_params['CMSSW.vtx_seed'])
183          except KeyError:
184 <            pass
185 <
184 <        #print 'CEWhiteList: ',CEWhiteList
185 <        self.reCEWhiteList=[]
186 <        for Good in CEWhiteList:
187 <            self.reCEWhiteList.append(re.compile( Good ))
188 <
189 <        common.logger.debug(5,'CEWhiteList: '+str(CEWhiteList))
184 >            self.sourceSeedVtx = None
185 >            common.logger.debug(5,"No vertex seed given")
186  
187          self.PsetEdit = PsetManipulator.PsetManipulator(self.pset) #Daniele Pset
188  
# Line 194 | Line 190 | class Cmssw(JobType):
190          ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
191          self.maxEvents=0  # max events available   ( --> check the requested nb. of evts in Creator.py)
192          self.DBSPaths={}  # all dbs paths requested ( --> input to the site local discovery script)
193 +        self.jobDestination=[]  # Site destination(s) for each job (list of lists)
194          ## Perform the data location and discovery (based on DBS/DLS)
195 <        self.DataDiscoveryAndLocation(cfg_params)
195 >        ## SL: Don't if NONE is specified as input (pythia use case)
196 >        blockSites = {}
197 >        if self.datasetPath:
198 >            blockSites = self.DataDiscoveryAndLocation(cfg_params)
199          #DBSDLS-end          
200  
201          self.tgzNameWithPath = self.getTarBall(self.executable)
202 +    
203 +        ## Select Splitting
204 +        if self.selectNoInput: self.jobSplittingNoInput()
205 +        else: self.jobSplittingByBlocks(blockSites)
206  
207 <        self.jobSplitting()  #Daniele job Splitting
208 <        self.PsetEdit.maxEvent(self.maxEv) #Daniele  
209 <        self.PsetEdit.inputModule("INPUT") #Daniele  
210 <        self.PsetEdit.psetWriter(self.configFilename())
211 <        
212 <
207 >        # modify Pset
208 >        try:
209 >            if (self.datasetPath): # standard job
210 >                # allow to processa a fraction of events in a file
211 >                self.PsetEdit.inputModule("INPUT")
212 >                self.PsetEdit.maxEvent("INPUTMAXEVENTS")
213 >                self.PsetEdit.skipEvent("INPUTSKIPEVENTS")
214 >
215 >            else:  # pythia like job
216 >                self.PsetEdit.maxEvent(self.eventsPerJob)
217 >                if (self.sourceSeed) :
218 >                    self.PsetEdit.pythiaSeed("INPUT")
219 >                    if (self.sourceSeedVtx) :
220 >                        self.PsetEdit.pythiaSeedVtx("INPUTVTX")
221 >            self.PsetEdit.psetWriter(self.configFilename())
222 >        except:
223 >            msg='Error while manipuliating ParameterSet: exiting...'
224 >            raise CrabException(msg)
225  
226      def DataDiscoveryAndLocation(self, cfg_params):
227  
228          common.logger.debug(10,"CMSSW::DataDiscoveryAndLocation()")
229  
214        #datasetPath = "/"+self.owner+"/"+self.dataTiers[0]+"/"+self.dataset
215        
230          datasetPath=self.datasetPath
231  
232          ## TODO
# Line 220 | Line 234 | class Cmssw(JobType):
234          dataTiers = dataTiersList.split(',')
235  
236          ## Contact the DBS
237 +        common.logger.message("Contacting DBS...")
238          try:
239 <            self.pubdata=DataDiscovery_EDM.DataDiscovery_EDM(datasetPath, dataTiers, cfg_params)
239 >            self.pubdata=DataDiscovery.DataDiscovery(datasetPath, dataTiers, cfg_params)
240              self.pubdata.fetchDBSInfo()
241  
242 <        except DataDiscovery_EDM.NotExistingDatasetError, ex :
242 >        except DataDiscovery.NotExistingDatasetError, ex :
243              msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
244              raise CrabException(msg)
245  
246 <        except DataDiscovery_EDM.NoDataTierinProvenanceError, ex :
246 >        except DataDiscovery.NoDataTierinProvenanceError, ex :
247              msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
248              raise CrabException(msg)
249 <        except DataDiscovery_EDM.DataDiscoveryError, ex:
249 >        except DataDiscovery.DataDiscoveryError, ex:
250              msg = 'ERROR ***: failed Data Discovery in DBS  %s'%ex.getErrorMessage()
251              raise CrabException(msg)
252  
# Line 239 | Line 254 | class Cmssw(JobType):
254          ## self.DBSPaths=self.pubdata.getDBSPaths()
255          common.logger.message("Required data are :"+self.datasetPath)
256  
257 <        filesbyblock=self.pubdata.getFiles()
258 <        self.AllInputFiles=filesbyblock.values()
259 <        self.files = self.AllInputFiles        
260 <
261 <        ## TEMP
262 <    #    self.filesTmp = filesbyblock.values()
248 <    #    self.files = []
249 <    #    locPath='rfio:cmsbose2.bo.infn.it:/flatfiles/SE00/cms/fanfani/ProdTest/'
250 <    #    locPath=''
251 <    #    tmp = []
252 <    #    for file in self.filesTmp[0]:
253 <    #        tmp.append(locPath+file)
254 <    #    self.files.append(tmp)
255 <        ## END TEMP
257 >        self.filesbyblock=self.pubdata.getFiles()
258 >        self.eventsbyblock=self.pubdata.getEventsPerBlock()
259 >        self.eventsbyfile=self.pubdata.getEventsPerFile()
260 >        # print str(self.filesbyblock)
261 >        # print 'self.eventsbyfile',len(self.eventsbyfile)
262 >        # print str(self.eventsbyfile)
263  
264          ## get max number of events
258        #common.logger.debug(10,"number of events for primary fileblocks %i"%self.pubdata.getMaxEvents())
265          self.maxEvents=self.pubdata.getMaxEvents() ##  self.maxEvents used in Creator.py
266          common.logger.message("\nThe number of available events is %s"%self.maxEvents)
267  
268 +        common.logger.message("Contacting DLS...")
269          ## Contact the DLS and build a list of sites hosting the fileblocks
270          try:
271 <            dataloc=DataLocation_EDM.DataLocation_EDM(filesbyblock.keys(),cfg_params)
271 >            dataloc=DataLocation.DataLocation(self.filesbyblock.keys(),cfg_params)
272              dataloc.fetchDLSInfo()
273 <        except DataLocation_EDM.DataLocationError , ex:
273 >        except DataLocation.DataLocationError , ex:
274              msg = 'ERROR ***: failed Data Location in DLS \n %s '%ex.getErrorMessage()
275              raise CrabException(msg)
276          
270        allsites=dataloc.getSites()
271        common.logger.debug(5,"sites are %s"%allsites)
272        sites=self.checkBlackList(allsites)
273        common.logger.debug(5,"sites are (after black list) %s"%sites)
274        sites=self.checkWhiteList(sites)
275        common.logger.debug(5,"sites are (after white list) %s"%sites)
277  
278 <        if len(sites)==0:
279 <            msg = 'No sites hosting all the needed data! Exiting... '
280 <            raise CrabException(msg)
278 >        sites = dataloc.getSites()
279 >        allSites = []
280 >        listSites = sites.values()
281 >        for list in listSites:
282 >            for oneSite in list:
283 >                allSites.append(oneSite)
284 >        allSites = self.uniquelist(allSites)
285  
286 <        common.logger.message("List of Sites hosting the data : "+str(sites))
287 <        common.logger.debug(6, "List of Sites: "+str(sites))
288 <        common.analisys_common_info['sites']=sites    ## used in SchedulerEdg.py in createSchScript
284 <        self.setParam_('TargetCE', ','.join(sites))
285 <        return
286 >        common.logger.message("Sites ("+str(len(allSites))+") hosting part/all of dataset: "+str(allSites))
287 >        common.logger.debug(6, "List of Sites: "+str(allSites))
288 >        return sites
289      
290 <    def jobSplitting(self):
290 >    def jobSplittingByBlocks(self, blockSites):
291          """
292 <        first implemntation for job splitting  
293 <        """    
294 <      #  print 'eventi totali '+str(self.maxEvents)
295 <      #  print 'eventi totali richiesti dallo user '+str(self.total_number_of_events)
296 <        #print 'files per job '+str(self.filesPerJob)
297 <        common.logger.message('Required '+str(self.filesPerJob)+' files per job ')
298 <        common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
299 <
300 <        ## TODO: SL need to have (from DBS) a detailed list of how many events per each file
301 <        n_tot_files = (len(self.files[0]))
302 <        ## SL: this is wrong if the files have different number of events
303 <        evPerFile = int(self.maxEvents)/n_tot_files
304 <        
305 <        common.logger.debug(5,'Events per File '+str(evPerFile))
306 <
307 <        ## if asked to process all events, do it
308 <        if self.total_number_of_events == -1:
309 <            self.total_number_of_events=self.maxEvents
310 <            self.total_number_of_jobs = int(n_tot_files)*1/int(self.filesPerJob)
311 <            common.logger.message(str(self.total_number_of_jobs)+' jobs will be created for all available events '+str(self.total_number_of_events)+' events')
312 <        
292 >        Perform job splitting. Jobs run over an integer number of files
293 >        and no more than one block.
294 >        ARGUMENT: blockSites: dictionary with blocks as keys and list of host sites as values
295 >        REQUIRES: self.selectTotalNumberEvents, self.selectEventsPerJob, self.selectNumberofJobs,
296 >                  self.total_number_of_events, self.eventsPerJob, self.theNumberOfJobs,
297 >                  self.maxEvents, self.filesbyblock
298 >        SETS: self.jobDestination - Site destination(s) for each job (a list of lists)
299 >              self.total_number_of_jobs - Total # of jobs
300 >              self.list_of_args - File(s) job will run on (a list of lists)
301 >        """
302 >
303 >        # ---- Handle the possible job splitting configurations ---- #
304 >        if (self.selectTotalNumberEvents):
305 >            totalEventsRequested = self.total_number_of_events
306 >        if (self.selectEventsPerJob):
307 >            eventsPerJobRequested = self.eventsPerJob
308 >            if (self.selectNumberOfJobs):
309 >                totalEventsRequested = self.theNumberOfJobs * self.eventsPerJob
310 >
311 >        # If user requested all the events in the dataset
312 >        if (totalEventsRequested == -1):
313 >            eventsRemaining=self.maxEvents
314 >        # If user requested more events than are in the dataset
315 >        elif (totalEventsRequested > self.maxEvents):
316 >            eventsRemaining = self.maxEvents
317 >            common.logger.message("Requested "+str(self.total_number_of_events)+ " events, but only "+str(self.maxEvents)+" events are available.")
318 >        # If user requested less events than are in the dataset
319          else:
320 <            self.total_number_of_files = int(self.total_number_of_events/evPerFile)
312 <            ## SL: if ask for less event than what is computed to be available on a
313 <            ##     file, process the first file anyhow.
314 <            if self.total_number_of_files == 0:
315 <                self.total_number_of_files = self.total_number_of_files + 1
320 >            eventsRemaining = totalEventsRequested
321  
322 <            common.logger.debug(5,'N files  '+str(self.total_number_of_files))
322 >        # If user requested more events per job than are in the dataset
323 >        if (self.selectEventsPerJob and eventsPerJobRequested > self.maxEvents):
324 >            eventsPerJobRequested = self.maxEvents
325  
326 <            check = 0
327 <            
321 <            ## Compute the number of jobs
322 <            #self.total_number_of_jobs = int(n_tot_files)*1/int(self.filesPerJob)
323 <            self.total_number_of_jobs = int(self.total_number_of_files/self.filesPerJob)
324 <            common.logger.debug(5,'N jobs  '+str(self.total_number_of_jobs))
326 >        # For user info at end
327 >        totalEventCount = 0
328  
329 <            ## is there any remainder?
330 <            check = int(self.total_number_of_files) - (int(self.total_number_of_jobs)*self.filesPerJob)
329 >        if (self.selectTotalNumberEvents and self.selectNumberOfJobs):
330 >            eventsPerJobRequested = int(eventsRemaining/self.theNumberOfJobs)
331  
332 <            common.logger.debug(5,'Check  '+str(check))
332 >        if (self.selectNumberOfJobs):
333 >            common.logger.message("May not create the exact number_of_jobs requested.")
334  
335 <            if check > 0:
336 <                self.total_number_of_jobs =  self.total_number_of_jobs + 1
337 <                common.logger.message('Warning: last job will be created with '+str(check)+' files')
335 >        if ( self.ncjobs == 'all' ) :
336 >            totalNumberOfJobs = 999999999
337 >        else :
338 >            totalNumberOfJobs = self.ncjobs
339 >            
340  
341 <            common.logger.message(str(self.total_number_of_jobs)+' jobs will be created for a total of '+str((self.total_number_of_jobs-1)*self.filesPerJob*evPerFile + check*evPerFile)+' events')
342 <            pass
341 >        blocks = blockSites.keys()
342 >        blockCount = 0
343 >        # Backup variable in case self.maxEvents counted events in a non-included block
344 >        numBlocksInDataset = len(blocks)
345  
346 +        jobCount = 0
347          list_of_lists = []
339        for i in xrange(0, int(n_tot_files), self.filesPerJob):
340            list_of_lists.append(self.files[0][i: i+self.filesPerJob])
348  
349 <        self.list_of_files = list_of_lists
350 <      
349 >        # ---- Iterate over the blocks in the dataset until ---- #
350 >        # ---- we've met the requested total # of events    ---- #
351 >        while ( (eventsRemaining > 0) and (blockCount < numBlocksInDataset) and (jobCount < totalNumberOfJobs)):
352 >            block = blocks[blockCount]
353 >
354 >
355 >            evInBlock = self.eventsbyblock[block]
356 >            common.logger.debug(5,'Events in Block File '+str(evInBlock))
357 >
358 >            #Correct - switch to this when DBS up
359 >            #numEventsInBlock = self.eventsbyblock[block]
360 >            numEventsInBlock = evInBlock
361 >            
362 >            files = self.filesbyblock[block]
363 >            numFilesInBlock = len(files)
364 >            if (numFilesInBlock <= 0):
365 >                continue
366 >            fileCount = 0
367 >
368 >            # ---- New block => New job ---- #
369 >            parString = "\\{"
370 >            # counter for number of events in files currently worked on
371 >            filesEventCount = 0
372 >            # flag if next while loop should touch new file
373 >            newFile = 1
374 >            # job event counter
375 >            jobSkipEventCount = 0
376 >            
377 >            # ---- Iterate over the files in the block until we've met the requested ---- #
378 >            # ---- total # of events or we've gone over all the files in this block  ---- #
379 >            while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
380 >                file = files[fileCount]
381 >                if newFile :
382 >                    try:
383 >                        numEventsInFile = self.eventsbyfile[file]
384 >                        common.logger.debug(6, "File "+str(file)+" has "+str(numEventsInFile)+" events")
385 >                        # increase filesEventCount
386 >                        filesEventCount += numEventsInFile
387 >                        # Add file to current job
388 >                        parString += '\\\"' + file + '\\\"\,'
389 >                        newFile = 0
390 >                    except KeyError:
391 >                        common.logger.message("File "+str(file)+" has unknown numbe of events: skipping")
392 >                        
393 >
394 >                # if less events in file remain than eventsPerJobRequested
395 >                if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested ) :
396 >                    # if last file in block
397 >                    if ( fileCount == numFilesInBlock ) :
398 >                        # end job using last file, use remaining events in block
399 >                        # close job and touch new file
400 >                        fullString = parString[:-2]
401 >                        fullString += '\\}'
402 >                        list_of_lists.append([fullString,str(-1),str(jobSkipEventCount)])
403 >                        common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(filesEventCount - jobSkipEventCount)+" events (last file in block).")
404 >                        self.jobDestination.append(blockSites[block])
405 >                        common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
406 >                        # reset counter
407 >                        jobCount = jobCount + 1
408 >                        totalEventCount = totalEventCount + eventsPerJobRequested
409 >                        eventsRemaining = eventsRemaining - eventsPerJobRequested
410 >                        jobSkipEventCount = 0
411 >                        # reset file
412 >                        parString = "\\{"
413 >                        filesEventCount = 0
414 >                        newFile = 1
415 >                        fileCount += 1
416 >                    else :
417 >                        # go to next file
418 >                        newFile = 1
419 >                        fileCount += 1
420 >                # if events in file equal to eventsPerJobRequested
421 >                elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
422 >                    # close job and touch new file
423 >                    fullString = parString[:-2]
424 >                    fullString += '\\}'
425 >                    list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
426 >                    common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
427 >                    self.jobDestination.append(blockSites[block])
428 >                    common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
429 >                    # reset counter
430 >                    jobCount = jobCount + 1
431 >                    totalEventCount = totalEventCount + eventsPerJobRequested
432 >                    eventsRemaining = eventsRemaining - eventsPerJobRequested
433 >                    jobSkipEventCount = 0
434 >                    # reset file
435 >                    parString = "\\{"
436 >                    filesEventCount = 0
437 >                    newFile = 1
438 >                    fileCount += 1
439 >                    
440 >                # if more events in file remain than eventsPerJobRequested
441 >                else :
442 >                    # close job but don't touch new file
443 >                    fullString = parString[:-2]
444 >                    fullString += '\\}'
445 >                    list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
446 >                    common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
447 >                    self.jobDestination.append(blockSites[block])
448 >                    common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
449 >                    # increase counter
450 >                    jobCount = jobCount + 1
451 >                    totalEventCount = totalEventCount + eventsPerJobRequested
452 >                    eventsRemaining = eventsRemaining - eventsPerJobRequested
453 >                    # calculate skip events for last file
454 >                    # use filesEventCount (contains several files), jobSkipEventCount and eventsPerJobRequest
455 >                    jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
456 >                    # remove all but the last file
457 >                    filesEventCount = self.eventsbyfile[file]
458 >                    parString = "\\{"
459 >                    parString += '\\\"' + file + '\\\"\,'
460 >                pass # END if
461 >            pass # END while (iterate over files in the block)
462 >        pass # END while (iterate over blocks in the dataset)
463 >        self.ncjobs = self.total_number_of_jobs = jobCount
464 >        if (eventsRemaining > 0 and jobCount < totalNumberOfJobs ):
465 >            common.logger.message("Could not run on all requested events because some blocks not hosted at allowed sites.")
466 >        common.logger.message("\n"+str(jobCount)+" job(s) can run on "+str(totalEventCount)+" events.\n")
467 >        
468 >        self.list_of_args = list_of_lists
469 >        return
470 >
471 >    def jobSplittingNoInput(self):
472 >        """
473 >        Perform job splitting based on number of event per job
474 >        """
475 >        common.logger.debug(5,'Splitting per events')
476 >        common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
477 >        common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
478 >        common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
479 >
480 >        if (self.total_number_of_events < 0):
481 >            msg='Cannot split jobs per Events with "-1" as total number of events'
482 >            raise CrabException(msg)
483 >
484 >        if (self.selectEventsPerJob):
485 >            self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
486 >        elif (self.selectNumberOfJobs) :
487 >            self.total_number_of_jobs = self.theNumberOfJobs
488 >            self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
489 >
490 >        common.logger.debug(5,'N jobs  '+str(self.total_number_of_jobs))
491 >
492 >        # is there any remainder?
493 >        check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
494 >
495 >        common.logger.debug(5,'Check  '+str(check))
496 >
497 >        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')
498 >        if check > 0:
499 >            common.logger.message('Warning: asked '+str(self.total_number_of_events)+' but can do only '+str(int(self.total_number_of_jobs)*self.eventsPerJob))
500 >
501 >        # argument is seed number.$i
502 >        self.list_of_args = []
503 >        for i in range(self.total_number_of_jobs):
504 >            ## Since there is no input, any site is good
505 >            self.jobDestination.append(["Any"])
506 >            if (self.sourceSeed):
507 >                if (self.sourceSeedVtx):
508 >                    ## pythia + vtx random seed
509 >                    self.list_of_args.append([
510 >                                              str(self.sourceSeed)+str(i),
511 >                                              str(self.sourceSeedVtx)+str(i)
512 >                                              ])
513 >                else:
514 >                    ## only pythia random seed
515 >                    self.list_of_args.append([(str(self.sourceSeed)+str(i))])
516 >            else:
517 >                ## no random seed
518 >                self.list_of_args.append([str(i)])
519 >        #print self.list_of_args
520 >
521          return
522  
523      def split(self, jobParams):
# Line 348 | Line 525 | class Cmssw(JobType):
525          common.jobDB.load()
526          #### Fabio
527          njobs = self.total_number_of_jobs
528 <        filelist = self.list_of_files
528 >        arglist = self.list_of_args
529          # create the empty structure
530          for i in range(njobs):
531              jobParams.append("")
532          
533          for job in range(njobs):
534 <            jobParams[job] = filelist[job]
534 >            jobParams[job] = arglist[job]
535 >            # print str(arglist[job])
536 >            # print jobParams[job]
537              common.jobDB.setArguments(job, jobParams[job])
538 +            common.logger.debug(5,"Job "+str(job)+" Destination: "+str(self.jobDestination[job]))
539 +            common.jobDB.setDestination(job, self.jobDestination[job])
540  
541          common.jobDB.save()
542          return
543      
544      def getJobTypeArguments(self, nj, sched):
545 <        params = common.jobDB.arguments(nj)
546 <        #print params
547 <        parString = "\\{"
548 <        
368 <        for i in range(len(params) - 1):
369 <            parString += '\\\"' + params[i] + '\\\"\,'
370 <        
371 <        parString += '\\\"' + params[len(params) - 1] + '\\\"\\}'
372 <        return parString
545 >        result = ''
546 >        for i in common.jobDB.arguments(nj):
547 >            result=result+str(i)+" "
548 >        return result
549    
550      def numberOfJobs(self):
551          # Fabio
376
552          return self.total_number_of_jobs
378
379
380
381    def checkBlackList(self, allSites):
382        if len(self.reCEBlackList)==0: return allSites
383        sites = []
384        for site in allSites:
385            common.logger.debug(10,'Site '+site)
386            good=1
387            for re in self.reCEBlackList:
388                if re.search(site):
389                    common.logger.message('CE in black list, skipping site '+site)
390                    good=0
391                pass
392            if good: sites.append(site)
393        if len(sites) == 0:
394            common.logger.debug(3,"No sites found after BlackList")
395        return sites
396
397    def checkWhiteList(self, allSites):
398
399        if len(self.reCEWhiteList)==0: return allSites
400        sites = []
401        for site in allSites:
402            good=0
403            for re in self.reCEWhiteList:
404                if re.search(site):
405                    common.logger.debug(5,'CE in white list, adding site '+site)
406                    good=1
407                if not good: continue
408                sites.append(site)
409        if len(sites) == 0:
410            common.logger.message("No sites found after WhiteList\n")
411        else:
412            common.logger.debug(5,"Selected sites via WhiteList are "+str(sites)+"\n")
413        return sites
553  
554      def getTarBall(self, exe):
555          """
# Line 502 | Line 641 | class Cmssw(JobType):
641          # Prepare JobType-independent part
642          txt = ''
643    
505        ### OLI: moved to front to enable header reported before any error code is submitted
506        txt += "NJob=$1\n"
507        txt += "InputFiles=$2\n"
508        txt += "echo \"<$InputFiles>\"\n"
509        # txt += "Args = ` cat $2 |  sed -e \'s/\\\\//g\' -e \'s/\"/\\x27/g\' `"
510
511        ### OLI_DANIELE
512        txt += 'if [ $middleware == LCG ]; then \n'
513        txt += '    echo "MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
514        txt += '    echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
515        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo\n'
516        txt += 'elif [ $middleware == OSG ]; then\n'
517
518        # OLI: added monitoring for dashbord, use hash of crab.cfg
519        if common.scheduler.boss_scheduler_name == 'condor_g':
520            # create hash of cfg file
521            hash = makeCksum(common.work_space.cfgFileName())
522            txt += '    echo "MonitorJobID=`echo ${NJob}_'+hash+'_$GLOBUS_GRAM_JOB_CONTACT`" | tee -a $RUNTIME_AREA/$repo\n'
523            txt += '    echo "SyncGridJobId=`echo $GLOBUS_GRAM_JOB_CONTACT`" | tee -a $RUNTIME_AREA/$repo\n'
524            txt += '    echo "SyncCE=`echo $hostname`" | tee -a $RUNTIME_AREA/$repo\n'
525        else :
526            txt += '    echo "MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
527            txt += '    echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
528            txt += '    echo "SyncCE=`$EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo\n'
529
530        txt += 'fi\n'
531        txt += 'dumpStatus $RUNTIME_AREA/$repo\n'
532        txt += '\n'
533
644          ## OLI_Daniele at this level  middleware already known
645  
646          txt += 'if [ $middleware == LCG ]; then \n'
# Line 541 | Line 651 | class Cmssw(JobType):
651          txt += '    echo "Creating working directory: $WORKING_DIR"\n'
652          txt += '    /bin/mkdir -p $WORKING_DIR\n'
653          txt += '    if [ ! -d $WORKING_DIR ] ;then\n'
654 <        txt += '        echo "OSG WORKING DIR ==> $WORKING_DIR could not be created on on WN `hostname`"\n'
655 <    
656 <        txt += '        echo "JOB_EXIT_STATUS = 1"\n'
654 >        txt += '        echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
655 >        txt += '        echo "JOB_EXIT_STATUS = 10016"\n'
656 >        txt += '        echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
657 >        txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
658 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
659 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
660 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
661          txt += '        exit 1\n'
662          txt += '    fi\n'
663          txt += '\n'
# Line 559 | Line 673 | class Cmssw(JobType):
673          txt += scram+' project CMSSW '+self.version+'\n'
674          txt += 'status=$?\n'
675          txt += 'if [ $status != 0 ] ; then\n'
676 <        txt += '   echo "SET_EXE_ENV 1 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
676 >        txt += '   echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
677          txt += '   echo "JOB_EXIT_STATUS = 10034"\n'
678 <        txt += '   echo "SanityCheckCode = 10034" | tee -a $RUNTIME_AREA/$repo\n'
678 >        txt += '   echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
679          txt += '   dumpStatus $RUNTIME_AREA/$repo\n'
680 +        txt += '   rm -f $RUNTIME_AREA/$repo \n'
681 +        txt += '   echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
682 +        txt += '   echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
683          ## OLI_Daniele
684          txt += '    if [ $middleware == OSG ]; then \n'
685          txt += '        echo "Remove working directory: $WORKING_DIR"\n'
686          txt += '        cd $RUNTIME_AREA\n'
687          txt += '        /bin/rm -rf $WORKING_DIR\n'
688          txt += '        if [ -d $WORKING_DIR ] ;then\n'
689 <        txt += '            echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
689 >        txt += '            echo "SET_CMS_ENV 10018 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after CMSSW CMSSW_0_6_1 not found on `hostname`"\n'
690 >        txt += '            echo "JOB_EXIT_STATUS = 10018"\n'
691 >        txt += '            echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
692 >        txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
693 >        txt += '            rm -f $RUNTIME_AREA/$repo \n'
694 >        txt += '            echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
695 >        txt += '            echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
696          txt += '        fi\n'
697          txt += '    fi \n'
698          txt += '   exit 1 \n'
# Line 581 | Line 704 | class Cmssw(JobType):
704  
705          # Handle the arguments:
706          txt += "\n"
707 <        txt += "## ARGUMNETS: $1 Job Number\n"
585 <        # txt += "## ARGUMNETS: $2 First Event for this job\n"
586 <        # txt += "## ARGUMNETS: $3 Max Event for this job\n"
707 >        txt += "## number of arguments (first argument always jobnumber)\n"
708          txt += "\n"
709 <        txt += "narg=$#\n"
710 <        txt += "if [ $narg -lt 2 ]\n"
709 > #        txt += "narg=$#\n"
710 >        txt += "if [ $nargs -lt 2 ]\n"
711          txt += "then\n"
712 <        txt += "    echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$narg+ \n"
712 >        txt += "    echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$nargs+ \n"
713          txt += '    echo "JOB_EXIT_STATUS = 50113"\n'
714 <        txt += '    echo "SanityCheckCode = 50113" | tee -a $RUNTIME_AREA/$repo\n'
714 >        txt += '    echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
715          txt += '    dumpStatus $RUNTIME_AREA/$repo\n'
716 +        txt += '    rm -f $RUNTIME_AREA/$repo \n'
717 +        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
718 +        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
719          ## OLI_Daniele
720          txt += '    if [ $middleware == OSG ]; then \n'
721          txt += '        echo "Remove working directory: $WORKING_DIR"\n'
722          txt += '        cd $RUNTIME_AREA\n'
723          txt += '        /bin/rm -rf $WORKING_DIR\n'
724          txt += '        if [ -d $WORKING_DIR ] ;then\n'
725 <        txt += '            echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
725 >        txt += '            echo "SET_EXE_ENV 50114 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Too few arguments for CRAB job wrapper"\n'
726 >        txt += '            echo "JOB_EXIT_STATUS = 50114"\n'
727 >        txt += '            echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
728 >        txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
729 >        txt += '            rm -f $RUNTIME_AREA/$repo \n'
730 >        txt += '            echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
731 >        txt += '            echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
732          txt += '        fi\n'
733          txt += '    fi \n'
734          txt += "    exit 1\n"
# Line 609 | Line 739 | class Cmssw(JobType):
739          job = common.job_list[nj]
740          pset = os.path.basename(job.configFilename())
741          txt += '\n'
742 <        #txt += 'echo sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' \n'
743 <        txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset.cfg\n'
744 <        #txt += 'sed "s#{\'INPUT\'}#${InputFiles}#" $RUNTIME_AREA/'+pset+' > pset1.cfg\n'
742 >        if (self.datasetPath): # standard job
743 >            #txt += 'InputFiles=$2\n'
744 >            txt += 'InputFiles=${args[1]}\n'
745 >            txt += 'MaxEvents=${args[2]}\n'
746 >            txt += 'SkipEvents=${args[3]}\n'
747 >            txt += 'echo "Inputfiles:<$InputFiles>"\n'
748 >            txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset_tmp_1.cfg\n'
749 >            txt += 'echo "MaxEvents:<$MaxEvents>"\n'
750 >            txt += 'sed "s#INPUTMAXEVENTS#$MaxEvents#" $RUNTIME_AREA/ pset_tmp_1.cfg > pset_tmp_2.cfg\n'
751 >            txt += 'echo "SkipEvents:<$SkipEvents>"\n'
752 >            txt += 'sed "s#INPUTSKIPEVENTS#$SkipEvents#" $RUNTIME_AREA/ pset_tmp_2.cfg > pset.cfg\n'
753 >        else:  # pythia like job
754 >            if (self.sourceSeed):
755 > #                txt += 'Seed=$2\n'
756 >                txt += 'Seed=${args[1]}\n'
757 >                txt += 'echo "Seed: <$Seed>"\n'
758 >                txt += 'sed "s#\<INPUT\>#$Seed#" $RUNTIME_AREA/'+pset+' > tmp.cfg\n'
759 >                if (self.sourceSeedVtx):
760 > #                    txt += 'VtxSeed=$3\n'
761 >                    txt += 'VtxSeed=${args[2]}\n'
762 >                    txt += 'echo "VtxSeed: <$VtxSeed>"\n'
763 >                    txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp.cfg > pset.cfg\n'
764 >                else:
765 >                    txt += 'mv tmp.cfg pset.cfg\n'
766 >            else:
767 >                txt += '# Copy untouched pset\n'
768 >                txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
769 >
770  
771          if len(self.additional_inbox_files) > 0:
772              for file in self.additional_inbox_files:
773 <                txt += 'if [ -e $RUNTIME_AREA/'+file+' ] ; then\n'
774 <                txt += '   cp $RUNTIME_AREA/'+file+' .\n'
775 <                txt += '   chmod +x '+file+'\n'
773 >                relFile = file.split("/")[-1]
774 >                txt += 'if [ -e $RUNTIME_AREA/'+relFile+' ] ; then\n'
775 >                txt += '   cp $RUNTIME_AREA/'+relFile+' .\n'
776 >                txt += '   chmod +x '+relFile+'\n'
777                  txt += 'fi\n'
778              pass
779  
# Line 648 | Line 804 | class Cmssw(JobType):
804              txt += 'if [ $untar_status -ne 0 ]; then \n'
805              txt += '   echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
806              txt += '   echo "JOB_EXIT_STATUS = $untar_status" \n'
807 <            txt += '   echo "SanityCheckCode = $untar_status" | tee -a $repo\n'
807 >            txt += '   echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
808              txt += '   if [ $middleware == OSG ]; then \n'
809              txt += '       echo "Remove working directory: $WORKING_DIR"\n'
810              txt += '       cd $RUNTIME_AREA\n'
811              txt += '       /bin/rm -rf $WORKING_DIR\n'
812              txt += '       if [ -d $WORKING_DIR ] ;then\n'
813 <            txt += '           echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
813 >            txt += '           echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
814 >            txt += '           echo "JOB_EXIT_STATUS = 50999"\n'
815 >            txt += '           echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
816 >            txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
817 >            txt += '           rm -f $RUNTIME_AREA/$repo \n'
818 >            txt += '           echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
819 >            txt += '           echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
820              txt += '       fi\n'
821              txt += '   fi \n'
822              txt += '   \n'
823 <            txt += '   exit $untar_status \n'
823 >            txt += '   exit 1 \n'
824              txt += 'else \n'
825              txt += '   echo "Successful untar" \n'
826              txt += 'fi \n'
# Line 723 | Line 885 | class Cmssw(JobType):
885          """
886  
887          txt = '\n'
888 +        txt += '# directory content\n'
889 +        txt += 'ls \n'
890          file_list = ''
727        check = len(self.output_file)
728        i = 0
891          for fileWithSuffix in self.output_file:
730            i= i + 1
892              output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
893 <            file_list=file_list+output_file_num+''
733 <            txt += '\n'
734 <            txt += 'ls \n'
893 >            file_list=file_list+output_file_num+' '
894              txt += '\n'
895 +            txt += '# check output file\n'
896              txt += 'ls '+fileWithSuffix+'\n'
897 <            txt += 'exe_result=$?\n'
898 <            txt += 'if [ $exe_result -ne 0 ] ; then\n'
899 <            txt += '   echo "ERROR: No output file to manage"\n'
897 >            txt += 'ls_result=$?\n'
898 >            #txt += 'exe_result=$?\n'
899 >            txt += 'if [ $ls_result -ne 0 ] ; then\n'
900 >            txt += '   echo "ERROR: Problem with output file"\n'
901 >            #txt += '   echo "JOB_EXIT_STATUS = $exe_result"\n'
902 >            #txt += '   echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
903 >            #txt += '   dumpStatus $RUNTIME_AREA/$repo\n'
904              ### OLI_DANIELE
905 <            txt += '    if [ $middleware == OSG ]; then \n'
906 <            txt += '        echo "prepare dummy output file"\n'
907 <            txt += '        cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
908 <            txt += '    fi \n'
905 >            if common.scheduler.boss_scheduler_name == 'condor_g':
906 >                txt += '    if [ $middleware == OSG ]; then \n'
907 >                txt += '        echo "prepare dummy output file"\n'
908 >                txt += '        echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
909 >                txt += '    fi \n'
910              txt += 'else\n'
911              txt += '   cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
912              txt += 'fi\n'
748            if i == check:
749                txt += 'cd $RUNTIME_AREA\n'
750                pass      
751            pass
913        
914 +        txt += 'cd $RUNTIME_AREA\n'
915          file_list=file_list[:-1]
916          txt += 'file_list="'+file_list+'"\n'
917 +        txt += 'cd $RUNTIME_AREA\n'
918          ### OLI_DANIELE
919          txt += 'if [ $middleware == OSG ]; then\n'  
920          txt += '    cd $RUNTIME_AREA\n'
921          txt += '    echo "Remove working directory: $WORKING_DIR"\n'
922          txt += '    /bin/rm -rf $WORKING_DIR\n'
923          txt += '    if [ -d $WORKING_DIR ] ;then\n'
924 <        txt += '        echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
924 >        txt += '        echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
925 >        txt += '        echo "JOB_EXIT_STATUS = 60999"\n'
926 >        txt += '        echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
927 >        txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
928 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
929 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
930 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
931          txt += '    fi\n'
932          txt += 'fi\n'
933          txt += '\n'
# Line 776 | Line 945 | class Cmssw(JobType):
945          # add "_txt"
946          if len(p)>1:
947            ext = p[len(p)-1]
779          #result = name + '_' + str(txt) + "." + ext
948            result = name + '_' + txt + "." + ext
949          else:
782          #result = name + '_' + str(txt)
950            result = name + '_' + txt
951          
952          return result
# Line 789 | Line 956 | class Cmssw(JobType):
956          return job requirements to add to jdl files
957          """
958          req = ''
959 <        if common.analisys_common_info['sites']:
960 <            if common.analisys_common_info['sw_version']:
961 <                req='Member("VO-cms-' + \
962 <                     common.analisys_common_info['sw_version'] + \
963 <                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
964 <            if len(common.analisys_common_info['sites'])>0:
965 <                req = req + ' && ('
799 <                for i in range(len(common.analisys_common_info['sites'])):
800 <                    req = req + 'other.GlueCEInfoHostName == "' \
801 <                         + common.analisys_common_info['sites'][i] + '"'
802 <                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
803 <                        req = req + ' || '
804 <            req = req + ')'
805 <        #print "req = ", req
959 >        if common.analisys_common_info['sw_version']:
960 >            req='Member("VO-cms-' + \
961 >                 common.analisys_common_info['sw_version'] + \
962 >                 '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
963 >
964 >        req = req + ' && (other.GlueHostNetworkAdapterOutboundIP)'
965 >
966          return req
967  
968      def configFilename(self):
# Line 820 | Line 980 | class Cmssw(JobType):
980          txt += '   if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
981          txt += '      # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
982          txt += '       source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
983 <        txt += '   elif [ -f $OSG_APP/cmssoft/cmsset_default.sh ] ;then\n'
984 <        txt += '      # Use $OSG_APP/cmssoft/cmsset_default.sh to setup cms software\n'
985 <        txt += '       source $OSG_APP/cmssoft/cmsset_default.sh '+self.version+'\n'
983 >        txt += '   elif [ -f $OSG_APP/cmssoft/cms/cmsset_default.sh ] ;then\n'
984 >        txt += '      # Use $OSG_APP/cmssoft/cms/cmsset_default.sh to setup cms software\n'
985 >        txt += '       source $OSG_APP/cmssoft/cms/cmsset_default.sh '+self.version+'\n'
986          txt += '   else\n'
987 <        txt += '       echo "SET_CMS_ENV 10020 ==> ERROR $GRID3_APP_DIR/cmssoft/cmsset_default.sh and $OSG_APP/cmssoft/cmsset_default.sh file not found"\n'
987 >        txt += '       echo "SET_CMS_ENV 10020 ==> ERROR $GRID3_APP_DIR/cmssoft/cmsset_default.sh and $OSG_APP/cmssoft/cms/cmsset_default.sh file not found"\n'
988          txt += '       echo "JOB_EXIT_STATUS = 10020"\n'
989          txt += '       echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
990          txt += '       dumpStatus $RUNTIME_AREA/$repo\n'
991 <        txt += '       exit\n'
991 >        txt += '       rm -f $RUNTIME_AREA/$repo \n'
992 >        txt += '       echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
993 >        txt += '       echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
994 >        txt += '       exit 1\n'
995          txt += '\n'
996          txt += '       echo "Remove working directory: $WORKING_DIR"\n'
997          txt += '       cd $RUNTIME_AREA\n'
998          txt += '       /bin/rm -rf $WORKING_DIR\n'
999          txt += '       if [ -d $WORKING_DIR ] ;then\n'
1000 <        txt += '           echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
1000 >        txt += '            echo "SET_CMS_ENV 10017 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after $GRID3_APP_DIR/cmssoft/cmsset_default.sh and $OSG_APP/cmssoft/cms/cmsset_default.sh file not found"\n'
1001 >        txt += '            echo "JOB_EXIT_STATUS = 10017"\n'
1002 >        txt += '            echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
1003 >        txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
1004 >        txt += '            rm -f $RUNTIME_AREA/$repo \n'
1005 >        txt += '            echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1006 >        txt += '            echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1007          txt += '       fi\n'
1008          txt += '\n'
1009 <        txt += '       exit\n'
1009 >        txt += '       exit 1\n'
1010          txt += '   fi\n'
1011          txt += '\n'
1012          txt += '   echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
# Line 853 | Line 1022 | class Cmssw(JobType):
1022          """
1023          txt  = '   \n'
1024          txt += '   echo " ### SETUP CMS LCG  ENVIRONMENT ### "\n'
856        txt += '      echo "JOB_EXIT_STATUS = 0"\n'
1025          txt += '   if [ ! $VO_CMS_SW_DIR ] ;then\n'
1026          txt += '       echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
1027          txt += '       echo "JOB_EXIT_STATUS = 10031" \n'
1028          txt += '       echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
1029          txt += '       dumpStatus $RUNTIME_AREA/$repo\n'
1030 <        txt += '       exit\n'
1030 >        txt += '       rm -f $RUNTIME_AREA/$repo \n'
1031 >        txt += '       echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1032 >        txt += '       echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1033 >        txt += '       exit 1\n'
1034          txt += '   else\n'
1035          txt += '       echo "Sourcing environment... "\n'
1036          txt += '       if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
# Line 867 | Line 1038 | class Cmssw(JobType):
1038          txt += '           echo "JOB_EXIT_STATUS = 10020"\n'
1039          txt += '           echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1040          txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
1041 <        txt += '           exit\n'
1041 >        txt += '           rm -f $RUNTIME_AREA/$repo \n'
1042 >        txt += '           echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1043 >        txt += '           echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1044 >        txt += '           exit 1\n'
1045          txt += '       fi\n'
1046          txt += '       echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1047          txt += '       source $VO_CMS_SW_DIR/cmsset_default.sh\n'
# Line 877 | Line 1051 | class Cmssw(JobType):
1051          txt += '           echo "JOB_EXIT_STATUS = 10032"\n'
1052          txt += '           echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1053          txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
1054 <        txt += '           exit\n'
1054 >        txt += '           rm -f $RUNTIME_AREA/$repo \n'
1055 >        txt += '           echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1056 >        txt += '           echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1057 >        txt += '           exit 1\n'
1058          txt += '       fi\n'
1059          txt += '   fi\n'
1060          txt += '   \n'
# Line 889 | Line 1066 | class Cmssw(JobType):
1066          txt += '       export SCRAM_ARCH=slc3_ia32_gcc323\n'
1067          txt += '       echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1068          txt += '   else\n'
1069 <        txt += '       echo "SET_CMS_ENV 1 ==> ERROR OS unknown, LCG environment not initialized"\n'
1069 >        txt += '       echo "SET_CMS_ENV 10033 ==> ERROR OS unknown, LCG environment not initialized"\n'
1070          txt += '       echo "JOB_EXIT_STATUS = 10033"\n'
1071          txt += '       echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
1072          txt += '       dumpStatus $RUNTIME_AREA/$repo\n'
1073 <        txt += '       exit\n'
1073 >        txt += '       rm -f $RUNTIME_AREA/$repo \n'
1074 >        txt += '       echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1075 >        txt += '       echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1076 >        txt += '       exit 1\n'
1077          txt += '   fi\n'
1078          txt += '   echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1079          txt += '   echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
# Line 904 | Line 1084 | class Cmssw(JobType):
1084  
1085      def getParams(self):
1086          return self._params
1087 +
1088 +    def setTaskid_(self):
1089 +        self._taskId = self.cfg_params['taskId']
1090 +        
1091 +    def getTaskid(self):
1092 +        return self._taskId
1093 +
1094 + #######################################################################
1095 +    def uniquelist(self, old):
1096 +        """
1097 +        remove duplicates from a list
1098 +        """
1099 +        nd={}
1100 +        for e in old:
1101 +            nd[e]=0
1102 +        return nd.keys()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines