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.3 by gutsche, Sun May 28 02:27:52 2006 UTC vs.
Revision 1.26 by slacapra, Thu Jul 6 11:08:46 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
9 #from DataDiscovery_EDM import DataDiscovery_EDM
10   import DataDiscovery_EDM
11 #from DataLocation_EDM import DataLocation_EDM
11   import DataLocation_EDM
12   import Scram
13  
# Line 23 | Line 22 | class Cmssw(JobType):
22          # Marco.
23          self._params = {}
24          self.cfg_params = cfg_params
26
25          log = common.logger
26          
27          self.scram = Scram.Scram(cfg_params)
# Line 35 | Line 33 | class Cmssw(JobType):
33  
34  
35          self.version = self.scram.getSWVersion()
36 +        self.setParam_('application', self.version)
37          common.analisys_common_info['sw_version'] = self.version
38          ### FEDE
39          common.analisys_common_info['copy_input_data'] = 0
# Line 42 | Line 41 | class Cmssw(JobType):
41  
42          ### collect Data cards
43          try:
44 <         #   self.owner = cfg_params['CMSSW.owner']
45 <         #   log.debug(6, "CMSSW::CMSSW(): owner = "+self.owner)
46 <         #   self.dataset = cfg_params['CMSSW.dataset']
47 <            self.datasetPath = cfg_params['CMSSW.datasetpath']
48 <            log.debug(6, "CMSSW::CMSSW(): datasetPath = "+self.datasetPath)
44 >            tmp =  cfg_params['CMSSW.datasetpath']
45 >            log.debug(6, "CMSSW::CMSSW(): datasetPath = "+tmp)
46 >            if string.lower(tmp)=='none':
47 >                self.datasetPath = None
48 >                self.selectNoInput = 1
49 >            else:
50 >                self.datasetPath = tmp
51 >                self.selectNoInput = 0
52          except KeyError:
51        #    msg = "Error: owner and/or dataset not defined "
53              msg = "Error: datasetpath not defined "  
54              raise CrabException(msg)
55 +
56 +        # ML monitoring
57 +        # split dataset path style: /PreProdR3Minbias/SIM/GEN-SIM
58 +        if not self.datasetPath:
59 +            self.setParam_('dataset', 'None')
60 +            self.setParam_('owner', 'None')
61 +        else:
62 +            datasetpath_split = self.datasetPath.split("/")
63 +            self.setParam_('dataset', datasetpath_split[1])
64 +            self.setParam_('owner', datasetpath_split[-1])
65 +
66 +        self.setTaskid_()
67 +        self.setParam_('taskId', self.cfg_params['taskId'])
68 +
69          self.dataTiers = []
55 #       try:
56 #           tmpDataTiers = string.split(cfg_params['CMSSW.data_tier'],',')
57 #           for tmp in tmpDataTiers:
58 #               tmp=string.strip(tmp)
59 #               self.dataTiers.append(tmp)
60 #               pass
61 #           pass
62 #       except KeyError:
63 #           pass
64 #       log.debug(6, "Cmssw::Cmssw(): dataTiers = "+str(self.dataTiers))
70  
71          ## now the application
72          try:
73              self.executable = cfg_params['CMSSW.executable']
74 +            self.setParam_('exe', self.executable)
75              log.debug(6, "CMSSW::CMSSW(): executable = "+self.executable)
76              msg = "Default executable cmsRun overridden. Switch to " + self.executable
77              log.debug(3,msg)
78          except KeyError:
79              self.executable = 'cmsRun'
80 +            self.setParam_('exe', self.executable)
81              msg = "User executable not defined. Use cmsRun"
82              log.debug(3,msg)
83              pass
# Line 105 | Line 112 | class Cmssw(JobType):
112  
113          # script_exe file as additional file in inputSandbox
114          try:
115 <           self.scriptExe = cfg_params['USER.script_exe']
116 <           self.additional_inbox_files.append(self.scriptExe)
115 >            self.scriptExe = cfg_params['USER.script_exe']
116 >            self.additional_inbox_files.append(self.scriptExe)
117 >            if self.scriptExe != '':
118 >               if not os.path.isfile(self.scriptExe):
119 >                  msg ="WARNING. file "+self.scriptExe+" not found"
120 >                  raise CrabException(msg)
121          except KeyError:
122             pass
112        if self.scriptExe != '':
113           if os.path.isfile(self.scriptExe):
114              pass
115           else:
116              log.message("WARNING. file "+self.scriptExe+" not found")
117              sys.exit()
123                    
124          ## additional input files
125          try:
# Line 129 | Line 134 | class Cmssw(JobType):
134          except KeyError:
135              pass
136  
137 +        # files per job
138          try:
139              self.filesPerJob = int(cfg_params['CMSSW.files_per_jobs']) #Daniele
140 +            self.selectFilesPerJob = 1
141 +        except KeyError:
142 +            self.filesPerJob = 0
143 +            self.selectFilesPerJob = 0
144 +
145 +        ## Events per job
146 +        try:
147 +            self.eventsPerJob =int( cfg_params['CMSSW.events_per_job'])
148 +            self.selectEventsPerJob = 1
149 +        except KeyError:
150 +            self.eventsPerJob = -1
151 +            self.selectEventsPerJob = 0
152 +    
153 +        ## number of jobs
154 +        try:
155 +            self.theNumberOfJobs =int( cfg_params['CMSSW.number_of_jobs'])
156 +            self.selectNumberOfJobs = 1
157          except KeyError:
158 <            self.filesPerJob = 1
158 >            self.theNumberOfJobs = 0
159 >            self.selectNumberOfJobs = 0
160  
161 <        ## Max event   will be total_number_of_events ???  Daniele
161 >        ## source seed for pythia
162          try:
163 <            self.maxEv = cfg_params['CMSSW.event_per_job']
163 >            self.sourceSeed = int(cfg_params['CMSSW.pythia_seed'])
164          except KeyError:
165 <            self.maxEv = "-1"
166 <        ##  
165 >            self.sourceSeed = None
166 >            common.logger.debug(5,"No seed given")
167 >
168 >        if not (self.selectFilesPerJob + self.selectEventsPerJob + self.selectNumberOfJobs == 1 ):
169 >            msg = 'Must define either files_per_jobs or events_per_job or number_of_jobs'
170 >            raise CrabException(msg)
171 >
172          try:
173              self.total_number_of_events = int(cfg_params['CMSSW.total_number_of_events'])
174          except KeyError:
# Line 184 | Line 213 | class Cmssw(JobType):
213          self.maxEvents=0  # max events available   ( --> check the requested nb. of evts in Creator.py)
214          self.DBSPaths={}  # all dbs paths requested ( --> input to the site local discovery script)
215          ## Perform the data location and discovery (based on DBS/DLS)
216 <        self.DataDiscoveryAndLocation(cfg_params)
216 >        ## SL: Don't if NONE is specified as input (pythia use case)
217 >        common.analisys_common_info['sites']=None
218 >        if self.datasetPath:
219 >            self.DataDiscoveryAndLocation(cfg_params)
220          #DBSDLS-end          
221  
222          self.tgzNameWithPath = self.getTarBall(self.executable)
223 +    
224 +        ## Select Splitting
225 +        if self.selectNoInput: self.jobSplittingNoInput()
226 +        elif self.selectFilesPerJob or self.selectEventsPerJob or self.selectNumberOfJobs: self.jobSplittingPerFiles()
227 +        else:
228 +            msg = 'Don\'t know how to split...'
229 +            raise CrabException(msg)
230  
231 <        self.jobSplitting()  #Daniele job Splitting
232 <        self.PsetEdit.maxEvent(self.maxEv) #Daniele  
233 <        self.PsetEdit.inputModule("INPUT") #Daniele  
234 <        self.PsetEdit.psetWriter(self.configFilename())
231 >        # modify Pset
232 >        try:
233 >            if (self.datasetPath): # standard job
234 >                #self.PsetEdit.maxEvent(self.eventsPerJob)
235 >                # always process all events in a file
236 >                self.PsetEdit.maxEvent("-1")
237 >                self.PsetEdit.inputModule("INPUT")
238 >
239 >            else:  # pythia like job
240 >                self.PsetEdit.maxEvent(self.eventsPerJob)
241 >                if (self.sourceSeed) :
242 >                    self.PsetEdit.pythiaSeed("INPUT")
243 >        
244 >            self.PsetEdit.psetWriter(self.configFilename())
245 >        except:
246 >            msg='Error while manipuliating ParameterSet: exiting...'
247 >            raise CrabException(msg)
248  
249      def DataDiscoveryAndLocation(self, cfg_params):
250  
251          common.logger.debug(10,"CMSSW::DataDiscoveryAndLocation()")
252  
201        #datasetPath = "/"+self.owner+"/"+self.dataTiers[0]+"/"+self.dataset
202        
253          datasetPath=self.datasetPath
254  
255          ## TODO
# Line 208 | Line 258 | class Cmssw(JobType):
258  
259          ## Contact the DBS
260          try:
261 <            self.pubdata=DataDiscovery_EDM.DataDiscovery_EDM(datasetPath, dataTiers, dataTiers)
261 >            self.pubdata=DataDiscovery_EDM.DataDiscovery_EDM(datasetPath, dataTiers, cfg_params)
262              self.pubdata.fetchDBSInfo()
263  
264          except DataDiscovery_EDM.NotExistingDatasetError, ex :
# Line 227 | Line 277 | class Cmssw(JobType):
277          common.logger.message("Required data are :"+self.datasetPath)
278  
279          filesbyblock=self.pubdata.getFiles()
280 + #        print filesbyblock
281          self.AllInputFiles=filesbyblock.values()
282          self.files = self.AllInputFiles        
283  
233        ## TEMP
234    #    self.filesTmp = filesbyblock.values()
235    #    self.files = []
236    #    locPath='rfio:cmsbose2.bo.infn.it:/flatfiles/SE00/cms/fanfani/ProdTest/'
237    #    locPath=''
238    #    tmp = []
239    #    for file in self.filesTmp[0]:
240    #        tmp.append(locPath+file)
241    #    self.files.append(tmp)
242        ## END TEMP
243
284          ## get max number of events
285          #common.logger.debug(10,"number of events for primary fileblocks %i"%self.pubdata.getMaxEvents())
286          self.maxEvents=self.pubdata.getMaxEvents() ##  self.maxEvents used in Creator.py
# Line 265 | Line 305 | class Cmssw(JobType):
305              msg = 'No sites hosting all the needed data! Exiting... '
306              raise CrabException(msg)
307  
308 <        common.logger.message("List of Sites hosting the data : "+str(sites))
308 >        common.logger.message("List of Sites ("+str(len(sites))+") hosting the data : "+str(sites))
309          common.logger.debug(6, "List of Sites: "+str(sites))
310          common.analisys_common_info['sites']=sites    ## used in SchedulerEdg.py in createSchScript
311 +        self.setParam_('TargetCE', ','.join(sites))
312          return
313      
314 <    def jobSplitting(self):
314 >    def jobSplittingPerFiles(self):
315          """
316 <        first implemntation for job splitting  
317 <        """    
318 <      #  print 'eventi totali '+str(self.maxEvents)
278 <      #  print 'eventi totali richiesti dallo user '+str(self.total_number_of_events)
279 <        #print 'files per job '+str(self.filesPerJob)
280 <        common.logger.message('Required '+str(self.filesPerJob)+' files per job ')
316 >        Perform job splitting based on number of files to be accessed per job
317 >        """
318 >        common.logger.debug(5,'Splitting per input files')
319          common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
320 +        common.logger.message('Available '+str(self.maxEvents)+' events in total ')
321 +        common.logger.message('Required '+str(self.filesPerJob)+' files per job ')
322 +        common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
323 +        common.logger.message('Required '+str(self.eventsPerJob)+' events per job')
324 +
325 +        ## if asked to process all events, do it
326 +        if self.total_number_of_events == -1:
327 +            self.total_number_of_events=self.maxEvents
328 +        else:
329 +            if self.total_number_of_events>self.maxEvents:
330 +                common.logger.message("Asked "+str(self.total_number_of_events)+" but only "+str(self.maxEvents)+" available.")
331 +                self.total_number_of_events=self.maxEvents
332 +            pass
333  
334          ## TODO: SL need to have (from DBS) a detailed list of how many events per each file
335          n_tot_files = (len(self.files[0]))
336          ## SL: this is wrong if the files have different number of events
337          evPerFile = int(self.maxEvents)/n_tot_files
338 <        
338 >
339          common.logger.debug(5,'Events per File '+str(evPerFile))
340  
341 <        ## if asked to process all events, do it
342 <        if self.total_number_of_events == -1:
343 <            self.total_number_of_events=self.maxEvents
344 <            self.total_number_of_jobs = int(n_tot_files)*1/int(self.filesPerJob)
345 <            common.logger.message(str(self.total_number_of_jobs)+' jobs will be created for all available events '+str(self.total_number_of_events)+' events')
341 >        ## compute job splitting parameters: filesPerJob, eventsPerJob and theNumberOfJobs
342 >        if self.selectFilesPerJob:
343 >            ## user define files per event.
344 >            filesPerJob = self.filesPerJob
345 >            eventsPerJob = filesPerJob*evPerFile
346 >            theNumberOfJobs = int(self.total_number_of_events*1./eventsPerJob)
347 >            check = int(self.total_number_of_events) - (theNumberOfJobs*eventsPerJob)
348 >            if check > 0:
349 >                theNumberOfJobs +=1
350 >                filesLastJob = int(check*1./evPerFile+0.5)
351 >                common.logger.message('Warning: last job will be created with '+str(check)+' files')
352 >            else:
353 >                filesLastJob = filesPerJob
354 >
355 >        elif self.selectNumberOfJobs:
356 >            ## User select the number of jobs: last might be bigger to match request of events
357 >            theNumberOfJobs =  self.theNumberOfJobs
358 >
359 >            eventsPerJob = self.total_number_of_events/theNumberOfJobs
360 >            filesPerJob = int(eventsPerJob/evPerFile)
361 >            if (filesPerJob==0) : filesPerJob=1
362 >            check = int(self.total_number_of_events) - (int(theNumberOfJobs)*filesPerJob*evPerFile)
363 >            if not check == 0:
364 >                if check<0:
365 >                    missingFiles = int(check/evPerFile)
366 >                    additionalJobs = int(missingFiles/filesPerJob)
367 >                    #print missingFiles, additionalJobs
368 >                    theNumberOfJobs+=additionalJobs
369 >                    common.logger.message('Warning: will create only '+str(theNumberOfJobs)+' jobs')
370 >                    check = int(self.total_number_of_events) - (int(theNumberOfJobs)*filesPerJob*evPerFile)
371 >                    
372 >                if check >0 :
373 >                    filesLastJob = filesPerJob+int(check*1./evPerFile+0.5)
374 >                    common.logger.message('Warning: last job will be created with '+str(filesLastJob*evPerFile)+' events')
375 >                else:
376 >                    filesLastJob = filesPerJob
377 >            else:
378 >                filesLastJob = filesPerJob
379 >        elif self.selectEventsPerJob:
380 >            # SL case if asked events per job
381 >            ## estimate the number of files per job to match the user requirement
382 >            filesPerJob = int(float(self.eventsPerJob)/float(evPerFile))
383 >            if filesPerJob==0: filesPerJob=1
384 >            common.logger.debug(5,"filesPerJob "+str(filesPerJob))
385 >            if (filesPerJob==0): filesPerJob=1
386 >            eventsPerJob=filesPerJob*evPerFile
387 >            theNumberOfJobs = int(self.total_number_of_events)/int(eventsPerJob)
388 >            check = int(self.total_number_of_events) - (int(theNumberOfJobs)*eventsPerJob)
389 >            if not check == 0:
390 >                missingFiles = int(check/evPerFile)
391 >                additionalJobs = int(missingFiles/filesPerJob)
392 >                if ( additionalJobs>0) : theNumberOfJobs+=additionalJobs
393 >                check = int(self.total_number_of_events) - (int(theNumberOfJobs)*eventsPerJob)
394 >                if not check == 0:
395 >                    if (check <0 ):
396 >                        filesLastJob = filesPerJob+int(check*1./evPerFile-0.5)
397 >                    else:
398 >                        theNumberOfJobs+=1
399 >                        filesLastJob = int(check*1./evPerFile+0.5)
400 >
401 >                    common.logger.message('Warning: last job will be created with '+str(filesLastJob*evPerFile)+' events')
402 >                else:
403 >                    filesLastJob = filesPerJob
404 >            else:
405 >                filesLastJob = filesPerJob
406          
407 <        else:
408 <            self.total_number_of_files = int(self.total_number_of_events/evPerFile)
409 <            ## SL: if ask for less event than what is computed to be available on a
410 <            ##     file, process the first file anyhow.
411 <            if self.total_number_of_files == 0:
412 <                self.total_number_of_files = self.total_number_of_files + 1
407 >        self.total_number_of_jobs = theNumberOfJobs
408 >
409 >        totalEventsToBeUsed=theNumberOfJobs*filesPerJob*evPerFile
410 >        if not check == 0:
411 >        #    print (theNumberOfJobs-1)*filesPerJob*evPerFile,filesLastJob*evPerFile
412 >            totalEventsToBeUsed=(theNumberOfJobs-1)*filesPerJob*evPerFile+filesLastJob*evPerFile
413 >
414 >        common.logger.message(str(self.total_number_of_jobs)+' jobs will be created, each for '+str(filesPerJob*evPerFile)+' events, for a total of '+str(totalEventsToBeUsed)+' events')
415  
416 <            common.logger.debug(5,'N files  '+str(self.total_number_of_files))
416 >        totalFilesToBeUsed=filesPerJob*(theNumberOfJobs-1)+filesLastJob
417  
418 <            check = 0
418 >        ## set job arguments (files)
419 >        list_of_lists = []
420 >        lastFile=0
421 >        for i in range(0, int(totalFilesToBeUsed), filesPerJob)[:-1]:
422 >            parString = "\\{"
423 >            
424 >            lastFile=i+filesPerJob
425 >            params = self.files[0][i: lastFile]
426 >            for i in range(len(params) - 1):
427 >                parString += '\\\"' + params[i] + '\\\"\,'
428              
429 <            ## Compute the number of jobs
430 <            #self.total_number_of_jobs = int(n_tot_files)*1/int(self.filesPerJob)
431 <            self.total_number_of_jobs = int(self.total_number_of_files/self.filesPerJob)
310 <            common.logger.debug(5,'N jobs  '+str(self.total_number_of_jobs))
429 >            parString += '\\\"' + params[len(params) - 1] + '\\\"\\}'
430 >            list_of_lists.append([parString])
431 >            pass
432  
433 <            ## is there any remainder?
434 <            check = int(self.total_number_of_files) - (int(self.total_number_of_jobs)*self.filesPerJob)
433 >        ## last job
434 >        parString = "\\{"
435 >        
436 >        params = self.files[0][lastFile: lastFile+filesLastJob]
437 >        for i in range(len(params) - 1):
438 >            parString += '\\\"' + params[i] + '\\\"\,'
439 >        
440 >        parString += '\\\"' + params[len(params) - 1] + '\\\"\\}'
441 >        list_of_lists.append([parString])
442 >        pass
443  
444 <            common.logger.debug(5,'Check  '+str(check))
444 >        self.list_of_args = list_of_lists
445 >        # print self.list_of_args[0]
446 >        return
447  
448 <            if check > 0:
449 <                self.total_number_of_jobs =  self.total_number_of_jobs + 1
450 <                common.logger.message('Warning: last job will be created with '+str(check)+' files')
448 >    def jobSplittingNoInput(self):
449 >        """
450 >        Perform job splitting based on number of event per job
451 >        """
452 >        common.logger.debug(5,'Splitting per events')
453 >        common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
454 >        common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
455 >        common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
456  
457 <            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')
458 <            pass
457 >        if (self.total_number_of_events < 0):
458 >            msg='Cannot split jobs per Events with "-1" as total number of events'
459 >            raise CrabException(msg)
460  
461 <        list_of_lists = []
462 <        for i in xrange(0, int(n_tot_files), self.filesPerJob):
463 <            list_of_lists.append(self.files[0][i: i+self.filesPerJob])
461 >        if (self.selectEventsPerJob):
462 >            self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
463 >        elif (self.selectNumberOfJobs) :
464 >            self.total_number_of_jobs = self.theNumberOfJobs
465 >            self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
466 >
467 >        common.logger.debug(5,'N jobs  '+str(self.total_number_of_jobs))
468 >
469 >        # is there any remainder?
470 >        check = int(self.total_number_of_events) - (int(self.total_number_of_jobs)*self.eventsPerJob)
471 >
472 >        common.logger.debug(5,'Check  '+str(check))
473 >
474 >        common.logger.message(str(self.total_number_of_jobs)+' jobs will be created, each for '+str(self.eventsPerJob)+' for a total of '+str(self.total_number_of_jobs*self.eventsPerJob)+' events')
475 >        if check > 0:
476 >            common.logger.message('Warning: asked '+str(self.total_number_of_events)+' but will do only '+str(int(self.total_number_of_jobs)*self.eventsPerJob))
477 >
478 >
479 >        # argument is seed number.$i
480 >        self.list_of_args = []
481 >        for i in range(self.total_number_of_jobs):
482 >            if (self.sourceSeed):
483 >                self.list_of_args.append([(str(self.sourceSeed)+str(i))])
484 >            else:
485 >                self.list_of_args.append([str(i)])
486 >        #print self.list_of_args
487  
328        self.list_of_files = list_of_lists
329      
488          return
489  
490      def split(self, jobParams):
# Line 334 | Line 492 | class Cmssw(JobType):
492          common.jobDB.load()
493          #### Fabio
494          njobs = self.total_number_of_jobs
495 <        filelist = self.list_of_files
495 >        arglist = self.list_of_args
496          # create the empty structure
497          for i in range(njobs):
498              jobParams.append("")
499          
500          for job in range(njobs):
501 <            jobParams[job] = filelist[job]
501 >            jobParams[job] = arglist[job]
502 >            # print str(arglist[job])
503 >            # print jobParams[job]
504              common.jobDB.setArguments(job, jobParams[job])
505  
506          common.jobDB.save()
507          return
508      
509      def getJobTypeArguments(self, nj, sched):
510 <        params = common.jobDB.arguments(nj)
511 <        #print params
512 <        parString = "\\{"
513 <        
354 <        for i in range(len(params) - 1):
355 <            parString += '\\\"' + params[i] + '\\\"\,'
356 <        
357 <        parString += '\\\"' + params[len(params) - 1] + '\\\"\\}'
358 <        return parString
510 >        result = ''
511 >        for i in common.jobDB.arguments(nj):
512 >            result=result+str(i)+" "
513 >        return result
514    
515      def numberOfJobs(self):
516          # Fabio
362
517          return self.total_number_of_jobs
364
365
518  
519      def checkBlackList(self, allSites):
520          if len(self.reCEBlackList)==0: return allSites
# Line 498 | Line 650 | class Cmssw(JobType):
650          txt += '    echo "Creating working directory: $WORKING_DIR"\n'
651          txt += '    /bin/mkdir -p $WORKING_DIR\n'
652          txt += '    if [ ! -d $WORKING_DIR ] ;then\n'
653 <        txt += '        echo "OSG WORKING DIR ==> $WORKING_DIR could not be created on on WN `hostname`"\n'
654 <    
655 <        txt += '        echo "JOB_EXIT_STATUS = 1"\n'
653 >        txt += '        echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
654 >        txt += '        echo "JOB_EXIT_STATUS = 10016"\n'
655 >        txt += '        echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
656 >        txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
657 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
658 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
659 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
660          txt += '        exit 1\n'
661          txt += '    fi\n'
662          txt += '\n'
# Line 516 | Line 672 | class Cmssw(JobType):
672          txt += scram+' project CMSSW '+self.version+'\n'
673          txt += 'status=$?\n'
674          txt += 'if [ $status != 0 ] ; then\n'
675 <        txt += '   echo "SET_EXE_ENV 1 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
675 >        txt += '   echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
676          txt += '   echo "JOB_EXIT_STATUS = 10034"\n'
677 <        txt += '   echo "SanityCheckCode = 10034" | tee -a $RUNTIME_AREA/$repo\n'
677 >        txt += '   echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
678          txt += '   dumpStatus $RUNTIME_AREA/$repo\n'
679 +        txt += '   rm -f $RUNTIME_AREA/$repo \n'
680 +        txt += '   echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
681 +        txt += '   echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
682          ## OLI_Daniele
683          txt += '    if [ $middleware == OSG ]; then \n'
684          txt += '        echo "Remove working directory: $WORKING_DIR"\n'
685          txt += '        cd $RUNTIME_AREA\n'
686          txt += '        /bin/rm -rf $WORKING_DIR\n'
687          txt += '        if [ -d $WORKING_DIR ] ;then\n'
688 <        txt += '            echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
688 >        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'
689 >        txt += '            echo "JOB_EXIT_STATUS = 10018"\n'
690 >        txt += '            echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
691 >        txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
692 >        txt += '            rm -f $RUNTIME_AREA/$repo \n'
693 >        txt += '            echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
694 >        txt += '            echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
695          txt += '        fi\n'
696          txt += '    fi \n'
697          txt += '   exit 1 \n'
# Line 538 | Line 703 | class Cmssw(JobType):
703  
704          # Handle the arguments:
705          txt += "\n"
706 <        txt += "## ARGUMNETS: $1 Job Number\n"
542 <        # txt += "## ARGUMNETS: $2 First Event for this job\n"
543 <        # txt += "## ARGUMNETS: $3 Max Event for this job\n"
706 >        txt += "## number of arguments (first argument always jobnumber)\n"
707          txt += "\n"
708          txt += "narg=$#\n"
709          txt += "if [ $narg -lt 2 ]\n"
710          txt += "then\n"
711          txt += "    echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$narg+ \n"
712          txt += '    echo "JOB_EXIT_STATUS = 50113"\n'
713 <        txt += '    echo "SanityCheckCode = 50113" | tee -a $RUNTIME_AREA/$repo\n'
713 >        txt += '    echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
714          txt += '    dumpStatus $RUNTIME_AREA/$repo\n'
715 +        txt += '    rm -f $RUNTIME_AREA/$repo \n'
716 +        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
717 +        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
718          ## OLI_Daniele
719          txt += '    if [ $middleware == OSG ]; then \n'
720          txt += '        echo "Remove working directory: $WORKING_DIR"\n'
721          txt += '        cd $RUNTIME_AREA\n'
722          txt += '        /bin/rm -rf $WORKING_DIR\n'
723          txt += '        if [ -d $WORKING_DIR ] ;then\n'
724 <        txt += '            echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
724 >        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'
725 >        txt += '            echo "JOB_EXIT_STATUS = 50114"\n'
726 >        txt += '            echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
727 >        txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
728 >        txt += '            rm -f $RUNTIME_AREA/$repo \n'
729 >        txt += '            echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
730 >        txt += '            echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
731          txt += '        fi\n'
732          txt += '    fi \n'
733          txt += "    exit 1\n"
734          txt += "fi\n"
735          txt += "\n"
564        txt += "NJob=$1\n"
565        txt += "InputFiles=$2\n"
566        txt += "echo \"<$InputFiles>\"\n"
567        # txt += "Args = ` cat $2 |  sed -e \'s/\\\\//g\' -e \'s/\"/\\x27/g\' `"
568
569        ### OLI_DANIELE
570        txt += 'if [ $middleware == LCG ]; then \n'
571        txt += '    echo "MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
572        txt += '    echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
573        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo\n'
574        txt += 'elif [ $middleware == OSG ]; then\n'
575
576        # OLI: added monitoring for dashbord, use hash of crab.cfg
577        if common.scheduler.boss_scheduler_name == 'condor_g':
578            # create hash of cfg file
579            hash = makeCksum(common.work_space.cfgFileName())
580            txt += '    echo "MonitorJobID=`echo ${NJob}_'+hash+'_$GLOBUS_GRAM_JOB_CONTACT`" | tee -a $RUNTIME_AREA/$repo\n'
581            txt += '    echo "SyncGridJobId=`echo $GLOBUS_GRAM_JOB_CONTACT`" | tee -a $RUNTIME_AREA/$repo\n'
582            txt += '    echo "SyncCE=`echo $hostname`" | tee -a $RUNTIME_AREA/$repo\n'
583        else :
584            txt += '    echo "MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
585            txt += '    echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
586            txt += '    echo "SyncCE=`$EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo\n'
587
588        txt += 'fi\n'
589        txt += 'dumpStatus $RUNTIME_AREA/$repo\n'
736  
737          # Prepare job-specific part
738          job = common.job_list[nj]
739          pset = os.path.basename(job.configFilename())
740          txt += '\n'
741 <        #txt += 'echo sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' \n'
742 <        txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset.cfg\n'
743 <        #txt += 'sed "s#{\'INPUT\'}#${InputFiles}#" $RUNTIME_AREA/'+pset+' > pset1.cfg\n'
741 >        if (self.datasetPath): # standard job
742 >            txt += 'InputFiles=$2\n'
743 >            txt += 'echo "Inputfiles:<$InputFiles>"\n'
744 >            txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset.cfg\n'
745 >        else:  # pythia like job
746 >            if (self.sourceSeed):
747 >                txt += 'Seed=$2\n'
748 >                txt += 'echo "Seed: <$Seed>"\n'
749 >                txt += 'sed "s#INPUT#$Seed#" $RUNTIME_AREA/'+pset+' > pset.cfg\n'
750 >            else:
751 >                txt += '# Copy untouched pset\n'
752 >                txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
753 >
754  
755          if len(self.additional_inbox_files) > 0:
756              for file in self.additional_inbox_files:
# Line 631 | Line 787 | class Cmssw(JobType):
787              txt += 'if [ $untar_status -ne 0 ]; then \n'
788              txt += '   echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
789              txt += '   echo "JOB_EXIT_STATUS = $untar_status" \n'
790 <            txt += '   echo "SanityCheckCode = $untar_status" | tee -a $repo\n'
790 >            txt += '   echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
791              txt += '   if [ $middleware == OSG ]; then \n'
792              txt += '       echo "Remove working directory: $WORKING_DIR"\n'
793              txt += '       cd $RUNTIME_AREA\n'
794              txt += '       /bin/rm -rf $WORKING_DIR\n'
795              txt += '       if [ -d $WORKING_DIR ] ;then\n'
796 <            txt += '           echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
796 >            txt += '           echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
797 >            txt += '           echo "JOB_EXIT_STATUS = 50999"\n'
798 >            txt += '           echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
799 >            txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
800 >            txt += '           rm -f $RUNTIME_AREA/$repo \n'
801 >            txt += '           echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
802 >            txt += '           echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
803              txt += '       fi\n'
804              txt += '   fi \n'
805              txt += '   \n'
806 <            txt += '   exit $untar_status \n'
806 >            txt += '   exit 1 \n'
807              txt += 'else \n'
808              txt += '   echo "Successful untar" \n'
809              txt += 'fi \n'
# Line 706 | Line 868 | class Cmssw(JobType):
868          """
869  
870          txt = '\n'
871 +        txt += '# directory content\n'
872 +        txt += 'ls \n'
873          file_list = ''
710        check = len(self.output_file)
711        i = 0
874          for fileWithSuffix in self.output_file:
713            i= i + 1
875              output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
876 <            file_list=file_list+output_file_num+''
716 <            txt += '\n'
717 <            txt += 'ls \n'
876 >            file_list=file_list+output_file_num+' '
877              txt += '\n'
878 +            txt += '# check output file\n'
879              txt += 'ls '+fileWithSuffix+'\n'
880 <            txt += 'exe_result=$?\n'
881 <            txt += 'if [ $exe_result -ne 0 ] ; then\n'
882 <            txt += '   echo "ERROR: No output file to manage"\n'
880 >            txt += 'ls_result=$?\n'
881 >            #txt += 'exe_result=$?\n'
882 >            txt += 'if [ $ls_result -ne 0 ] ; then\n'
883 >            txt += '   echo "ERROR: Problem with output file"\n'
884 >            #txt += '   echo "JOB_EXIT_STATUS = $exe_result"\n'
885 >            #txt += '   echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
886 >            #txt += '   dumpStatus $RUNTIME_AREA/$repo\n'
887              ### OLI_DANIELE
888 <            txt += '    if [ $middleware == OSG ]; then \n'
889 <            txt += '        echo "prepare dummy output file"\n'
890 <            txt += '        cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
891 <            txt += '    fi \n'
888 >            if common.scheduler.boss_scheduler_name == 'condor_g':
889 >                txt += '    if [ $middleware == OSG ]; then \n'
890 >                txt += '        echo "prepare dummy output file"\n'
891 >                txt += '        echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
892 >                txt += '    fi \n'
893              txt += 'else\n'
894              txt += '   cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
895              txt += 'fi\n'
731            if i == check:
732                txt += 'cd $RUNTIME_AREA\n'
733                pass      
734            pass
896        
897 +        txt += 'cd $RUNTIME_AREA\n'
898          file_list=file_list[:-1]
899          txt += 'file_list="'+file_list+'"\n'
900 +        txt += 'cd $RUNTIME_AREA\n'
901          ### OLI_DANIELE
902          txt += 'if [ $middleware == OSG ]; then\n'  
903          txt += '    cd $RUNTIME_AREA\n'
904          txt += '    echo "Remove working directory: $WORKING_DIR"\n'
905          txt += '    /bin/rm -rf $WORKING_DIR\n'
906          txt += '    if [ -d $WORKING_DIR ] ;then\n'
907 <        txt += '        echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
907 >        txt += '        echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
908 >        txt += '        echo "JOB_EXIT_STATUS = 60999"\n'
909 >        txt += '        echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
910 >        txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
911 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
912 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
913 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
914          txt += '    fi\n'
915          txt += 'fi\n'
916          txt += '\n'
# Line 772 | Line 941 | class Cmssw(JobType):
941          return job requirements to add to jdl files
942          """
943          req = ''
944 +        if common.analisys_common_info['sw_version']:
945 +            req='Member("VO-cms-' + \
946 +                 common.analisys_common_info['sw_version'] + \
947 +                 '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
948          if common.analisys_common_info['sites']:
776            if common.analisys_common_info['sw_version']:
777                req='Member("VO-cms-' + \
778                     common.analisys_common_info['sw_version'] + \
779                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
949              if len(common.analisys_common_info['sites'])>0:
950                  req = req + ' && ('
951                  for i in range(len(common.analisys_common_info['sites'])):
# Line 811 | Line 980 | class Cmssw(JobType):
980          txt += '       echo "JOB_EXIT_STATUS = 10020"\n'
981          txt += '       echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
982          txt += '       dumpStatus $RUNTIME_AREA/$repo\n'
983 <        txt += '       exit\n'
983 >        txt += '       rm -f $RUNTIME_AREA/$repo \n'
984 >        txt += '       echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
985 >        txt += '       echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
986 >        txt += '       exit 1\n'
987          txt += '\n'
988          txt += '       echo "Remove working directory: $WORKING_DIR"\n'
989          txt += '       cd $RUNTIME_AREA\n'
990          txt += '       /bin/rm -rf $WORKING_DIR\n'
991          txt += '       if [ -d $WORKING_DIR ] ;then\n'
992 <        txt += '           echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
992 >        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/cmsset_default.sh file not found"\n'
993 >        txt += '            echo "JOB_EXIT_STATUS = 10017"\n'
994 >        txt += '            echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
995 >        txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
996 >        txt += '            rm -f $RUNTIME_AREA/$repo \n'
997 >        txt += '            echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
998 >        txt += '            echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
999          txt += '       fi\n'
1000          txt += '\n'
1001 <        txt += '       exit\n'
1001 >        txt += '       exit 1\n'
1002          txt += '   fi\n'
1003          txt += '\n'
1004          txt += '   echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
# Line 836 | Line 1014 | class Cmssw(JobType):
1014          """
1015          txt  = '   \n'
1016          txt += '   echo " ### SETUP CMS LCG  ENVIRONMENT ### "\n'
839        txt += '      echo "JOB_EXIT_STATUS = 0"\n'
1017          txt += '   if [ ! $VO_CMS_SW_DIR ] ;then\n'
1018          txt += '       echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
1019          txt += '       echo "JOB_EXIT_STATUS = 10031" \n'
1020          txt += '       echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
1021          txt += '       dumpStatus $RUNTIME_AREA/$repo\n'
1022 <        txt += '       exit\n'
1022 >        txt += '       rm -f $RUNTIME_AREA/$repo \n'
1023 >        txt += '       echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1024 >        txt += '       echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1025 >        txt += '       exit 1\n'
1026          txt += '   else\n'
1027          txt += '       echo "Sourcing environment... "\n'
1028          txt += '       if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
# Line 850 | Line 1030 | class Cmssw(JobType):
1030          txt += '           echo "JOB_EXIT_STATUS = 10020"\n'
1031          txt += '           echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1032          txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
1033 <        txt += '           exit\n'
1033 >        txt += '           rm -f $RUNTIME_AREA/$repo \n'
1034 >        txt += '           echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1035 >        txt += '           echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1036 >        txt += '           exit 1\n'
1037          txt += '       fi\n'
1038          txt += '       echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1039          txt += '       source $VO_CMS_SW_DIR/cmsset_default.sh\n'
# Line 860 | Line 1043 | class Cmssw(JobType):
1043          txt += '           echo "JOB_EXIT_STATUS = 10032"\n'
1044          txt += '           echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1045          txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
1046 <        txt += '           exit\n'
1046 >        txt += '           rm -f $RUNTIME_AREA/$repo \n'
1047 >        txt += '           echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1048 >        txt += '           echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1049 >        txt += '           exit 1\n'
1050          txt += '       fi\n'
1051          txt += '   fi\n'
1052          txt += '   \n'
# Line 872 | Line 1058 | class Cmssw(JobType):
1058          txt += '       export SCRAM_ARCH=slc3_ia32_gcc323\n'
1059          txt += '       echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1060          txt += '   else\n'
1061 <        txt += '       echo "SET_CMS_ENV 1 ==> ERROR OS unknown, LCG environment not initialized"\n'
1061 >        txt += '       echo "SET_CMS_ENV 10033 ==> ERROR OS unknown, LCG environment not initialized"\n'
1062          txt += '       echo "JOB_EXIT_STATUS = 10033"\n'
1063          txt += '       echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
1064          txt += '       dumpStatus $RUNTIME_AREA/$repo\n'
1065 <        txt += '       exit\n'
1065 >        txt += '       rm -f $RUNTIME_AREA/$repo \n'
1066 >        txt += '       echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1067 >        txt += '       echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1068 >        txt += '       exit 1\n'
1069          txt += '   fi\n'
1070          txt += '   echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1071          txt += '   echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1072          return txt
1073 +
1074 +    def setParam_(self, param, value):
1075 +        self._params[param] = value
1076 +
1077 +    def getParams(self):
1078 +        return self._params
1079 +
1080 +    def setTaskid_(self):
1081 +        self._taskId = self.cfg_params['taskId']
1082 +        
1083 +    def getTaskid(self):
1084 +        return self._taskId

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines