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.52 by slacapra, Tue Oct 17 11:54:02 2006 UTC vs.
Revision 1.73 by gutsche, Sun Apr 8 18:39:51 2007 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
5   import common
6   import PsetManipulator  
8
9 import DBSInfo
7   import DataDiscovery
8 + import DataDiscovery_DBS2
9   import DataLocation
10   import Scram
11  
12 < import glob, os, string, re
12 > import os, string, re, shutil, glob
13  
14   class Cmssw(JobType):
15      def __init__(self, cfg_params, ncjobs):
# Line 22 | Line 20 | class Cmssw(JobType):
20          self._params = {}
21          self.cfg_params = cfg_params
22  
23 +        try:
24 +            self.MaxTarBallSize = float(self.cfg_params['EDG.maxtarballsize'])
25 +        except KeyError:
26 +            self.MaxTarBallSize = 100.0
27 +
28          # number of jobs requested to be created, limit obj splitting
29          self.ncjobs = ncjobs
30  
31          log = common.logger
32          
33          self.scram = Scram.Scram(cfg_params)
31        scramArea = ''
34          self.additional_inbox_files = []
35          self.scriptExe = ''
36          self.executable = ''
37 +        self.executable_arch = self.scram.getArch()
38          self.tgz_name = 'default.tgz'
39 +        self.scriptName = 'CMSSW.sh'
40          self.pset = ''      #scrip use case Da  
41          self.datasetPath = '' #scrip use case Da
42  
# Line 40 | Line 44 | class Cmssw(JobType):
44          self.fjrFileName = 'crab_fjr.xml'
45  
46          self.version = self.scram.getSWVersion()
47 +        common.taskDB.setDict('codeVersion',self.version)
48          self.setParam_('application', self.version)
49  
50          ### collect Data cards
51 +
52 +        ## get DBS mode
53 +        try:
54 +            self.use_dbs_2 = int(self.cfg_params['CMSSW.use_dbs_2'])
55 +        except KeyError:
56 +            self.use_dbs_2 = 0
57 +            
58          try:
59              tmp =  cfg_params['CMSSW.datasetpath']
60              log.debug(6, "CMSSW::CMSSW(): datasetPath = "+tmp)
# Line 97 | Line 109 | class Cmssw(JobType):
109              raise CrabException("PSet file missing. Cannot run cmsRun ")
110  
111          # output files
112 <        try:
113 <            self.output_file = []
112 >        ## stuff which must be returned always via sandbox
113 >        self.output_file_sandbox = []
114  
115 <            # add fjr report by default
116 <            self.output_file.append(self.fjrFileName)
115 >        # add fjr report by default via sandbox
116 >        self.output_file_sandbox.append(self.fjrFileName)
117  
118 +        # other output files to be returned via sandbox or copied to SE
119 +        try:
120 +            self.output_file = []
121              tmp = cfg_params['CMSSW.output_file']
122              if tmp != '':
123                  tmpOutFiles = string.split(cfg_params['CMSSW.output_file'],',')
# Line 124 | Line 139 | class Cmssw(JobType):
139              self.scriptExe = cfg_params['USER.script_exe']
140              if self.scriptExe != '':
141                 if not os.path.isfile(self.scriptExe):
142 <                  msg ="WARNING. file "+self.scriptExe+" not found"
142 >                  msg ="ERROR. file "+self.scriptExe+" not found"
143                    raise CrabException(msg)
144                 self.additional_inbox_files.append(string.strip(self.scriptExe))
145          except KeyError:
146              self.scriptExe = ''
147 +
148          #CarlosDaniele
149          if self.datasetPath == None and self.pset == None and self.scriptExe == '' :
150 <           msg ="WARNING. script_exe  not defined"
150 >           msg ="Error. script_exe  not defined"
151             raise CrabException(msg)
152  
153          ## additional input files
# Line 146 | Line 162 | class Cmssw(JobType):
162                      if not os.path.exists(file):
163                          raise CrabException("Additional input file not found: "+file)
164                      pass
165 <                    self.additional_inbox_files.append(string.strip(file))
165 >                    storedFile = common.work_space.shareDir()+file
166 >                    shutil.copyfile(file, storedFile)
167 >                    self.additional_inbox_files.append(string.strip(storedFile))
168                  pass
169              pass
170              common.logger.debug(5,"Additional input files: "+str(self.additional_inbox_files))
# Line 204 | Line 222 | class Cmssw(JobType):
222          except KeyError:
223              self.sourceSeedVtx = None
224              common.logger.debug(5,"No vertex seed given")
225 +        try:
226 +            self.firstRun = int(cfg_params['CMSSW.first_run'])
227 +        except KeyError:
228 +            self.firstRun = None
229 +            common.logger.debug(5,"No first run given")
230          if self.pset != None: #CarlosDaniele
231              self.PsetEdit = PsetManipulator.PsetManipulator(self.pset) #Daniele Pset
232  
# Line 227 | Line 250 | class Cmssw(JobType):
250                  self.jobSplittingForScript()
251              else:
252                  self.jobSplittingNoInput()
253 <        else: self.jobSplittingByBlocks(blockSites)
253 >        else:
254 >            self.jobSplittingByBlocks(blockSites)
255  
256          # modify Pset
257          if self.pset != None: #CarlosDaniele
# Line 239 | Line 263 | class Cmssw(JobType):
263                      self.PsetEdit.skipEvent("INPUTSKIPEVENTS")
264                  else:  # pythia like job
265                      self.PsetEdit.maxEvent(self.eventsPerJob)
266 +                    if (self.firstRun):
267 +                        self.PsetEdit.pythiaFirstRun("INPUTFIRSTRUN")  #First Run
268                      if (self.sourceSeed) :
269                          self.PsetEdit.pythiaSeed("INPUT")
270                          if (self.sourceSeedVtx) :
# Line 256 | Line 282 | class Cmssw(JobType):
282  
283          datasetPath=self.datasetPath
284  
259        ## TODO
260        dataTiersList = ""
261        dataTiers = dataTiersList.split(',')
262
285          ## Contact the DBS
286          common.logger.message("Contacting DBS...")
287          try:
288 <            self.pubdata=DataDiscovery.DataDiscovery(datasetPath, dataTiers, cfg_params)
288 >
289 >            if self.use_dbs_2 == 1 :
290 >                self.pubdata=DataDiscovery_DBS2.DataDiscovery_DBS2(datasetPath, cfg_params)
291 >            else :
292 >                self.pubdata=DataDiscovery.DataDiscovery(datasetPath, cfg_params)
293              self.pubdata.fetchDBSInfo()
294  
295          except DataDiscovery.NotExistingDatasetError, ex :
296              msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
297              raise CrabException(msg)
272
298          except DataDiscovery.NoDataTierinProvenanceError, ex :
299              msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
300              raise CrabException(msg)
301          except DataDiscovery.DataDiscoveryError, ex:
302 <            msg = 'ERROR ***: failed Data Discovery in DBS  %s'%ex.getErrorMessage()
302 >            msg = 'ERROR ***: failed Data Discovery in DBS :  %s'%ex.getErrorMessage()
303 >            raise CrabException(msg)
304 >        except DataDiscovery_DBS2.NotExistingDatasetError_DBS2, ex :
305 >            msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
306 >            raise CrabException(msg)
307 >        except DataDiscovery_DBS2.NoDataTierinProvenanceError_DBS2, ex :
308 >            msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
309 >            raise CrabException(msg)
310 >        except DataDiscovery_DBS2.DataDiscoveryError_DBS2, ex:
311 >            msg = 'ERROR ***: failed Data Discovery in DBS :  %s'%ex.getErrorMessage()
312              raise CrabException(msg)
313  
314          ## get list of all required data in the form of dbs paths  (dbs path = /dataset/datatier/owner)
281        ## self.DBSPaths=self.pubdata.getDBSPaths()
315          common.logger.message("Required data are :"+self.datasetPath)
316  
317          self.filesbyblock=self.pubdata.getFiles()
318          self.eventsbyblock=self.pubdata.getEventsPerBlock()
319          self.eventsbyfile=self.pubdata.getEventsPerFile()
287        # print str(self.filesbyblock)
288        # print 'self.eventsbyfile',len(self.eventsbyfile)
289        # print str(self.eventsbyfile)
320  
321          ## get max number of events
322          self.maxEvents=self.pubdata.getMaxEvents() ##  self.maxEvents used in Creator.py
# Line 305 | Line 335 | class Cmssw(JobType):
335          sites = dataloc.getSites()
336          allSites = []
337          listSites = sites.values()
338 <        for list in listSites:
339 <            for oneSite in list:
338 >        for listSite in listSites:
339 >            for oneSite in listSite:
340                  allSites.append(oneSite)
341          allSites = self.uniquelist(allSites)
342  
# Line 379 | Line 409 | class Cmssw(JobType):
409              block = blocks[blockCount]
410              blockCount += 1
411              
412 <
413 <            numEventsInBlock = self.eventsbyblock[block]
414 <            common.logger.debug(5,'Events in Block File '+str(numEventsInBlock))
412 >            if self.eventsbyblock.has_key(block) :
413 >                numEventsInBlock = self.eventsbyblock[block]
414 >                common.logger.debug(5,'Events in Block File '+str(numEventsInBlock))
415              
416 <            files = self.filesbyblock[block]
417 <            numFilesInBlock = len(files)
418 <            if (numFilesInBlock <= 0):
419 <                continue
420 <            fileCount = 0
421 <
422 <            # ---- New block => New job ---- #
423 <            parString = "\\{"
424 <            # counter for number of events in files currently worked on
425 <            filesEventCount = 0
426 <            # flag if next while loop should touch new file
427 <            newFile = 1
428 <            # job event counter
429 <            jobSkipEventCount = 0
416 >                files = self.filesbyblock[block]
417 >                numFilesInBlock = len(files)
418 >                if (numFilesInBlock <= 0):
419 >                    continue
420 >                fileCount = 0
421 >
422 >                # ---- New block => New job ---- #
423 >                parString = "\\{"
424 >                # counter for number of events in files currently worked on
425 >                filesEventCount = 0
426 >                # flag if next while loop should touch new file
427 >                newFile = 1
428 >                # job event counter
429 >                jobSkipEventCount = 0
430              
431 <            # ---- Iterate over the files in the block until we've met the requested ---- #
432 <            # ---- total # of events or we've gone over all the files in this block  ---- #
433 <            while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
434 <                file = files[fileCount]
435 <                if newFile :
436 <                    try:
437 <                        numEventsInFile = self.eventsbyfile[file]
438 <                        common.logger.debug(6, "File "+str(file)+" has "+str(numEventsInFile)+" events")
439 <                        # increase filesEventCount
440 <                        filesEventCount += numEventsInFile
441 <                        # Add file to current job
442 <                        parString += '\\\"' + file + '\\\"\,'
443 <                        newFile = 0
444 <                    except KeyError:
445 <                        common.logger.message("File "+str(file)+" has unknown number of events: skipping")
431 >                # ---- Iterate over the files in the block until we've met the requested ---- #
432 >                # ---- total # of events or we've gone over all the files in this block  ---- #
433 >                while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
434 >                    file = files[fileCount]
435 >                    if newFile :
436 >                        try:
437 >                            numEventsInFile = self.eventsbyfile[file]
438 >                            common.logger.debug(6, "File "+str(file)+" has "+str(numEventsInFile)+" events")
439 >                            # increase filesEventCount
440 >                            filesEventCount += numEventsInFile
441 >                            # Add file to current job
442 >                            parString += '\\\"' + file + '\\\"\,'
443 >                            newFile = 0
444 >                        except KeyError:
445 >                            common.logger.message("File "+str(file)+" has unknown number of events: skipping")
446                          
447  
448 <                # if less events in file remain than eventsPerJobRequested
449 <                if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested ) :
450 <                    # if last file in block
451 <                    if ( fileCount == numFilesInBlock-1 ) :
452 <                        # end job using last file, use remaining events in block
448 >                    # if less events in file remain than eventsPerJobRequested
449 >                    if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested ) :
450 >                        # if last file in block
451 >                        if ( fileCount == numFilesInBlock-1 ) :
452 >                            # end job using last file, use remaining events in block
453 >                            # close job and touch new file
454 >                            fullString = parString[:-2]
455 >                            fullString += '\\}'
456 >                            list_of_lists.append([fullString,str(-1),str(jobSkipEventCount)])
457 >                            common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(filesEventCount - jobSkipEventCount)+" events (last file in block).")
458 >                            self.jobDestination.append(blockSites[block])
459 >                            common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
460 >                            # reset counter
461 >                            jobCount = jobCount + 1
462 >                            totalEventCount = totalEventCount + filesEventCount - jobSkipEventCount
463 >                            eventsRemaining = eventsRemaining - filesEventCount + jobSkipEventCount
464 >                            jobSkipEventCount = 0
465 >                            # reset file
466 >                            parString = "\\{"
467 >                            filesEventCount = 0
468 >                            newFile = 1
469 >                            fileCount += 1
470 >                        else :
471 >                            # go to next file
472 >                            newFile = 1
473 >                            fileCount += 1
474 >                    # if events in file equal to eventsPerJobRequested
475 >                    elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
476                          # close job and touch new file
477                          fullString = parString[:-2]
478                          fullString += '\\}'
479 <                        list_of_lists.append([fullString,str(-1),str(jobSkipEventCount)])
480 <                        common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(filesEventCount - jobSkipEventCount)+" events (last file in block).")
479 >                        list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
480 >                        common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
481                          self.jobDestination.append(blockSites[block])
482                          common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
483                          # reset counter
484                          jobCount = jobCount + 1
485 <                        totalEventCount = totalEventCount + filesEventCount - jobSkipEventCount
486 <                        eventsRemaining = eventsRemaining - filesEventCount + jobSkipEventCount
485 >                        totalEventCount = totalEventCount + eventsPerJobRequested
486 >                        eventsRemaining = eventsRemaining - eventsPerJobRequested
487                          jobSkipEventCount = 0
488                          # reset file
489                          parString = "\\{"
490                          filesEventCount = 0
491                          newFile = 1
492                          fileCount += 1
493 +                        
494 +                    # if more events in file remain than eventsPerJobRequested
495                      else :
496 <                        # go to next file
497 <                        newFile = 1
498 <                        fileCount += 1
499 <                # if events in file equal to eventsPerJobRequested
500 <                elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
501 <                    # close job and touch new file
502 <                    fullString = parString[:-2]
503 <                    fullString += '\\}'
504 <                    list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
505 <                    common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
506 <                    self.jobDestination.append(blockSites[block])
507 <                    common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
508 <                    # reset counter
509 <                    jobCount = jobCount + 1
510 <                    totalEventCount = totalEventCount + eventsPerJobRequested
511 <                    eventsRemaining = eventsRemaining - eventsPerJobRequested
512 <                    jobSkipEventCount = 0
513 <                    # reset file
514 <                    parString = "\\{"
515 <                    filesEventCount = 0
461 <                    newFile = 1
462 <                    fileCount += 1
463 <                    
464 <                # if more events in file remain than eventsPerJobRequested
465 <                else :
466 <                    # close job but don't touch new file
467 <                    fullString = parString[:-2]
468 <                    fullString += '\\}'
469 <                    list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
470 <                    common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
471 <                    self.jobDestination.append(blockSites[block])
472 <                    common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
473 <                    # increase counter
474 <                    jobCount = jobCount + 1
475 <                    totalEventCount = totalEventCount + eventsPerJobRequested
476 <                    eventsRemaining = eventsRemaining - eventsPerJobRequested
477 <                    # calculate skip events for last file
478 <                    # use filesEventCount (contains several files), jobSkipEventCount and eventsPerJobRequest
479 <                    jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
480 <                    # remove all but the last file
481 <                    filesEventCount = self.eventsbyfile[file]
482 <                    parString = "\\{"
483 <                    parString += '\\\"' + file + '\\\"\,'
484 <                pass # END if
485 <            pass # END while (iterate over files in the block)
496 >                        # close job but don't touch new file
497 >                        fullString = parString[:-2]
498 >                        fullString += '\\}'
499 >                        list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
500 >                        common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
501 >                        self.jobDestination.append(blockSites[block])
502 >                        common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
503 >                        # increase counter
504 >                        jobCount = jobCount + 1
505 >                        totalEventCount = totalEventCount + eventsPerJobRequested
506 >                        eventsRemaining = eventsRemaining - eventsPerJobRequested
507 >                        # calculate skip events for last file
508 >                        # use filesEventCount (contains several files), jobSkipEventCount and eventsPerJobRequest
509 >                        jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
510 >                        # remove all but the last file
511 >                        filesEventCount = self.eventsbyfile[file]
512 >                        parString = "\\{"
513 >                        parString += '\\\"' + file + '\\\"\,'
514 >                    pass # END if
515 >                pass # END while (iterate over files in the block)
516          pass # END while (iterate over blocks in the dataset)
517          self.ncjobs = self.total_number_of_jobs = jobCount
518          if (eventsRemaining > 0 and jobCount < totalNumberOfJobs ):
# Line 506 | Line 536 | class Cmssw(JobType):
536              raise CrabException(msg)
537  
538          if (self.selectEventsPerJob):
539 <            self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
539 >            if (self.selectTotalNumberEvents):
540 >                self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
541 >            elif(self.selectNumberOfJobs) :  
542 >                self.total_number_of_jobs =self.theNumberOfJobs
543 >                self.total_number_of_events =int(self.theNumberOfJobs*self.eventsPerJob)
544 >
545          elif (self.selectNumberOfJobs) :
546              self.total_number_of_jobs = self.theNumberOfJobs
547              self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
548 <
548 >
549          common.logger.debug(5,'N jobs  '+str(self.total_number_of_jobs))
550  
551          # is there any remainder?
# Line 528 | Line 563 | class Cmssw(JobType):
563              ## Since there is no input, any site is good
564             # self.jobDestination.append(["Any"])
565              self.jobDestination.append([""]) #must be empty to write correctly the xml
566 +            args=''
567 +            if (self.firstRun):
568 +                    ## pythia first run
569 +                #self.list_of_args.append([(str(self.firstRun)+str(i))])
570 +                args=args+(str(self.firstRun)+str(i))
571 +            else:
572 +                ## no first run
573 +                #self.list_of_args.append([str(i)])
574 +                args=args+str(i)
575              if (self.sourceSeed):
576                  if (self.sourceSeedVtx):
577                      ## pythia + vtx random seed
578 <                    self.list_of_args.append([
579 <                                              str(self.sourceSeed)+str(i),
580 <                                              str(self.sourceSeedVtx)+str(i)
581 <                                              ])
578 >                    #self.list_of_args.append([
579 >                    #                          str(self.sourceSeed)+str(i),
580 >                    #                          str(self.sourceSeedVtx)+str(i)
581 >                    #                          ])
582 >                    args=args+str(',')+str(self.sourceSeed)+str(i)+str(',')+str(self.sourceSeedVtx)+str(i)
583                  else:
584                      ## only pythia random seed
585 <                    self.list_of_args.append([(str(self.sourceSeed)+str(i))])
585 >                    #self.list_of_args.append([(str(self.sourceSeed)+str(i))])
586 >                    args=args +str(',')+str(self.sourceSeed)+str(i)
587              else:
588                  ## no random seed
589 <                self.list_of_args.append([str(i)])
590 <        #print self.list_of_args
589 >                if str(args)=='': args=args+(str(self.firstRun)+str(i))
590 >            arguments=args.split(',')
591 >            if len(arguments)==3:self.list_of_args.append([str(arguments[0]),str(arguments[1]),str(arguments[2])])
592 >            elif len(arguments)==2:self.list_of_args.append([str(arguments[0]),str(arguments[1])])
593 >            else :self.list_of_args.append([str(arguments[0])])
594 >            
595 >     #   print self.list_of_args
596  
597          return
598  
# Line 606 | Line 657 | class Cmssw(JobType):
657          """
658          
659          # if it exist, just return it
660 <        self.tgzNameWithPath = common.work_space.shareDir()+self.tgz_name
660 >        #
661 >        # Marco. Let's start to use relative path for Boss XML files
662 >        #
663 >        self.tgzNameWithPath = common.work_space.pathForTgz()+'share/'+self.tgz_name
664          if os.path.exists(self.tgzNameWithPath):
665              return self.tgzNameWithPath
666  
# Line 620 | Line 674 | class Cmssw(JobType):
674          # First of all declare the user Scram area
675          swArea = self.scram.getSWArea_()
676          #print "swArea = ", swArea
677 <        swVersion = self.scram.getSWVersion()
678 <        #print "swVersion = ", swVersion
677 >        # swVersion = self.scram.getSWVersion()
678 >        # print "swVersion = ", swVersion
679          swReleaseTop = self.scram.getReleaseTop_()
680          #print "swReleaseTop = ", swReleaseTop
681          
# Line 629 | Line 683 | class Cmssw(JobType):
683          if swReleaseTop == '' or swArea == swReleaseTop:
684              return
685  
686 <        filesToBeTarred = []
687 <        ## First find the executable
688 <        if (self.executable != ''):
689 <            exeWithPath = self.scram.findFile_(executable)
690 < #           print exeWithPath
691 <            if ( not exeWithPath ):
692 <                raise CrabException('User executable '+executable+' not found')
693 <
694 <            ## then check if it's private or not
695 <            if exeWithPath.find(swReleaseTop) == -1:
696 <                # the exe is private, so we must ship
697 <                common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
698 <                path = swArea+'/'
699 <                exe = string.replace(exeWithPath, path,'')
700 <                filesToBeTarred.append(exe)
701 <                pass
702 <            else:
703 <                # the exe is from release, we'll find it on WN
704 <                pass
705 <
706 <        ## Now get the libraries: only those in local working area
707 <        libDir = 'lib'
708 <        lib = swArea+'/' +libDir
709 <        common.logger.debug(5,"lib "+lib+" to be tarred")
710 <        if os.path.exists(lib):
711 <            filesToBeTarred.append(libDir)
712 <
713 <        ## Now check if module dir is present
714 <        moduleDir = 'module'
715 <        if os.path.isdir(swArea+'/'+moduleDir):
716 <            filesToBeTarred.append(moduleDir)
717 <
718 <        ## Now check if the Data dir is present
719 <        dataDir = 'src/Data/'
720 <        if os.path.isdir(swArea+'/'+dataDir):
721 <            filesToBeTarred.append(dataDir)
722 <
723 <        ## copy ProdAgent dir to swArea
724 <        cmd = '\cp -rf ' + os.environ['CRABDIR'] + '/ProdAgentApi ' + swArea
725 <        cmd_out = runCommand(cmd)
726 <        if cmd_out != '':
727 <            common.logger.message('ProdAgentApi directory could not be copied to local CMSSW project directory.')
728 <            common.logger.message('No FrameworkJobreport parsing is possible on the WorkerNode.')
729 <
730 <        ## Now check if the Data dir is present
731 <        paDir = 'ProdAgentApi'
732 <        if os.path.isdir(swArea+'/'+paDir):
733 <            filesToBeTarred.append(paDir)
734 <
735 <        ## Create the tar-ball
736 <        if len(filesToBeTarred)>0:
737 <            cwd = os.getcwd()
738 <            os.chdir(swArea)
739 <            tarcmd = 'tar zcvf ' + self.tgzNameWithPath + ' '
740 <            for line in filesToBeTarred:
741 <                tarcmd = tarcmd + line + ' '
742 <            cout = runCommand(tarcmd)
743 <            if not cout:
744 <                raise CrabException('Could not create tar-ball')
745 <            os.chdir(cwd)
746 <        else:
747 <            common.logger.debug(5,"No files to be to be tarred")
686 >        import tarfile
687 >        try: # create tar ball
688 >            tar = tarfile.open(self.tgzNameWithPath, "w:gz")
689 >            ## First find the executable
690 >            if (executable != ''):
691 >                exeWithPath = self.scram.findFile_(executable)
692 >                if ( not exeWithPath ):
693 >                    raise CrabException('User executable '+executable+' not found')
694 >    
695 >                ## then check if it's private or not
696 >                if exeWithPath.find(swReleaseTop) == -1:
697 >                    # the exe is private, so we must ship
698 >                    common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
699 >                    path = swArea+'/'
700 >                    exe = string.replace(exeWithPath, path,'')
701 >                    tar.add(path+exe,executable)
702 >                    pass
703 >                else:
704 >                    # the exe is from release, we'll find it on WN
705 >                    pass
706 >    
707 >            ## Now get the libraries: only those in local working area
708 >            libDir = 'lib'
709 >            lib = swArea+'/' +libDir
710 >            common.logger.debug(5,"lib "+lib+" to be tarred")
711 >            if os.path.exists(lib):
712 >                tar.add(lib,libDir)
713 >    
714 >            ## Now check if module dir is present
715 >            moduleDir = 'module'
716 >            module = swArea + '/' + moduleDir
717 >            if os.path.isdir(module):
718 >                tar.add(module,moduleDir)
719 >
720 >            ## Now check if any data dir(s) is present
721 >            swAreaLen=len(swArea)
722 >            for root, dirs, files in os.walk(swArea):
723 >                if "data" in dirs:
724 >                    common.logger.debug(5,"data "+root+"/data"+" to be tarred")
725 >                    tar.add(root+"/data",root[swAreaLen:]+"/data")
726 >
727 >            ## Add ProdAgent dir to tar
728 >            paDir = 'ProdAgentApi'
729 >            pa = os.environ['CRABDIR'] + '/' + 'ProdAgentApi'
730 >            if os.path.isdir(pa):
731 >                tar.add(pa,paDir)
732 >        
733 >            common.logger.debug(5,"Files added to "+self.tgzNameWithPath+" : "+str(tar.getnames()))
734 >            tar.close()
735 >        except :
736 >            raise CrabException('Could not create tar-ball')
737 >
738 >        ## check for tarball size
739 >        tarballinfo = os.stat(self.tgzNameWithPath)
740 >        if ( tarballinfo.st_size > self.MaxTarBallSize*1024*1024 ) :
741 >            raise CrabException('Input sandbox size of ' + str(float(tarballinfo.st_size)/1024.0/1024.0) + ' MB is larger than the allowed ' + str(self.MaxTarBallSize) + ' MB input sandbox limit and not supported by the used GRID submission system. Please make sure that no unnecessary files are in all data directories in your local CMSSW project area as they are automatically packed into the input sandbox.')
742 >
743 >        ## create tar-ball with ML stuff
744 >        self.MLtgzfile =  common.work_space.pathForTgz()+'share/MLfiles.tgz'
745 >        try:
746 >            tar = tarfile.open(self.MLtgzfile, "w:gz")
747 >            path=os.environ['CRABDIR'] + '/python/'
748 >            for file in ['report.py', 'DashboardAPI.py', 'Logger.py', 'ProcInfo.py', 'apmon.py', 'parseCrabFjr.py']:
749 >                tar.add(path+file,file)
750 >            common.logger.debug(5,"Files added to "+self.MLtgzfile+" : "+str(tar.getnames()))
751 >            tar.close()
752 >        except :
753 >            raise CrabException('Could not create ML files tar-ball')
754          
755          return
756          
# Line 757 | Line 817 | class Cmssw(JobType):
817          txt += '   exit 1 \n'
818          txt += 'fi \n'
819          txt += 'echo "CMSSW_VERSION =  '+self.version+'"\n'
820 +        txt += 'export SCRAM_ARCH='+self.executable_arch+'\n'
821          txt += 'cd '+self.version+'\n'
822          ### needed grep for bug in scramv1 ###
823 +        txt += scram+' runtime -sh\n'
824          txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
825 +        txt += 'echo $PATH\n'
826  
827          # Handle the arguments:
828          txt += "\n"
# Line 812 | Line 875 | class Cmssw(JobType):
875                  txt += 'sed "s#INPUTSKIPEVENTS#$SkipEvents#" pset_tmp_2.cfg > pset.cfg\n'
876              else:  # pythia like job
877                  if (self.sourceSeed):
878 +                    txt += 'FirstRun=${args[1]}\n'
879 +                    txt += 'echo "FirstRun: <$FirstRun>"\n'
880 +                    txt += 'sed "s#\<INPUTFIRSTRUN\>#$FirstRun#" $RUNTIME_AREA/'+pset+' > tmp_1.cfg\n'
881 +                else:
882 +                    txt += '# Copy untouched pset\n'
883 +                    txt += 'cp $RUNTIME_AREA/'+pset+' tmp_1.cfg\n'
884 +                if (self.sourceSeed):
885   #                    txt += 'Seed=$2\n'
886 <                    txt += 'Seed=${args[1]}\n'
886 >                    txt += 'Seed=${args[2]}\n'
887                      txt += 'echo "Seed: <$Seed>"\n'
888 <                    txt += 'sed "s#\<INPUT\>#$Seed#" $RUNTIME_AREA/'+pset+' > tmp.cfg\n'
888 >                    txt += 'sed "s#\<INPUT\>#$Seed#" tmp_1.cfg > tmp_2.cfg\n'
889                      if (self.sourceSeedVtx):
890   #                        txt += 'VtxSeed=$3\n'
891 <                        txt += 'VtxSeed=${args[2]}\n'
891 >                        txt += 'VtxSeed=${args[3]}\n'
892                          txt += 'echo "VtxSeed: <$VtxSeed>"\n'
893 <                        txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp.cfg > pset.cfg\n'
893 >                        txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp_2.cfg > pset.cfg\n'
894                      else:
895 <                        txt += 'mv tmp.cfg pset.cfg\n'
895 >                        txt += 'mv tmp_2.cfg pset.cfg\n'
896                  else:
897 <                    txt += '# Copy untouched pset\n'
898 <                    txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
897 >                    txt += 'mv tmp_1.cfg pset.cfg\n'
898 >                   # txt += '# Copy untouched pset\n'
899 >                   # txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
900  
901  
902          if len(self.additional_inbox_files) > 0:
# Line 850 | Line 921 | class Cmssw(JobType):
921              # txt += 'echo "****** end pset1.cfg ********"\n'
922          return txt
923  
924 <    def wsBuildExe(self, nj):
924 >    def wsBuildExe(self, nj=0):
925          """
926          Put in the script the commands to build an executable
927          or a library.
# Line 905 | Line 976 | class Cmssw(JobType):
976          """
977          
978      def executableName(self):
979 <        if self.pset == None: #CarlosDaniele
979 >        if self.scriptExe: #CarlosDaniele
980              return "sh "
981          else:
982              return self.executable
983  
984      def executableArgs(self):
985 <        if self.pset == None:#CarlosDaniele
985 >        if self.scriptExe:#CarlosDaniele
986              return   self.scriptExe + " $NJob"
987          else:
988              return " -p pset.cfg"
# Line 921 | Line 992 | class Cmssw(JobType):
992          Returns a list of filenames to be put in JDL input sandbox.
993          """
994          inp_box = []
995 <        # dict added to delete duplicate from input sandbox file list
996 <        seen = {}
995 >        # # dict added to delete duplicate from input sandbox file list
996 >        # seen = {}
997          ## code
998          if os.path.isfile(self.tgzNameWithPath):
999              inp_box.append(self.tgzNameWithPath)
1000 +        if os.path.isfile(self.MLtgzfile):
1001 +            inp_box.append(self.MLtgzfile)
1002          ## config
1003 <        if not self.pset is None: #CarlosDaniele
1004 <            inp_box.append(common.job_list[nj].configFilename())
1003 >        if not self.pset is None:
1004 >            inp_box.append(common.work_space.pathForTgz() + 'job/' + self.configFilename())
1005          ## additional input files
1006 <        #for file in self.additional_inbox_files:
1007 <        #    inp_box.append(common.work_space.cwdDir()+file)
1006 >        for file in self.additional_inbox_files:
1007 >            inp_box.append(file)
1008          return inp_box
1009  
1010      def outputSandbox(self, nj):
# Line 940 | Line 1013 | class Cmssw(JobType):
1013          """
1014          out_box = []
1015  
943        stdout=common.job_list[nj].stdout()
944        stderr=common.job_list[nj].stderr()
945
1016          ## User Declared output files
1017 <        for out in self.output_file:
1017 >        for out in (self.output_file+self.output_file_sandbox):
1018              n_out = nj + 1
1019              out_box.append(self.numberFile_(out,str(n_out)))
1020          return out_box
951        return []
1021  
1022      def prepareSteeringCards(self):
1023          """
# Line 964 | Line 1033 | class Cmssw(JobType):
1033          txt = '\n'
1034          txt += '# directory content\n'
1035          txt += 'ls \n'
1036 <        file_list = ''
1037 <        for fileWithSuffix in self.output_file:
1036 >
1037 >        for fileWithSuffix in (self.output_file+self.output_file_sandbox):
1038              output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
970            file_list=file_list+output_file_num+' '
1039              txt += '\n'
1040              txt += '# check output file\n'
1041              txt += 'ls '+fileWithSuffix+'\n'
1042              txt += 'ls_result=$?\n'
975            #txt += 'exe_result=$?\n'
1043              txt += 'if [ $ls_result -ne 0 ] ; then\n'
1044              txt += '   echo "ERROR: Problem with output file"\n'
978            #txt += '   echo "JOB_EXIT_STATUS = $exe_result"\n'
979            #txt += '   echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
980            #txt += '   dumpStatus $RUNTIME_AREA/$repo\n'
981            ### OLI_DANIELE
1045              if common.scheduler.boss_scheduler_name == 'condor_g':
1046                  txt += '    if [ $middleware == OSG ]; then \n'
1047                  txt += '        echo "prepare dummy output file"\n'
# Line 989 | Line 1052 | class Cmssw(JobType):
1052              txt += 'fi\n'
1053        
1054          txt += 'cd $RUNTIME_AREA\n'
992        file_list=file_list[:-1]
993        txt += 'file_list="'+file_list+'"\n'
1055          txt += 'cd $RUNTIME_AREA\n'
1056          ### OLI_DANIELE
1057          txt += 'if [ $middleware == OSG ]; then\n'  
# Line 1008 | Line 1069 | class Cmssw(JobType):
1069          txt += '    fi\n'
1070          txt += 'fi\n'
1071          txt += '\n'
1072 +
1073 +        file_list = ''
1074 +        ## Add to filelist only files to be possibly copied to SE
1075 +        for fileWithSuffix in self.output_file:
1076 +            output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
1077 +            file_list=file_list+output_file_num+' '
1078 +        file_list=file_list[:-1]
1079 +        txt += 'file_list="'+file_list+'"\n'
1080 +
1081          return txt
1082  
1083      def numberFile_(self, file, txt):
# Line 1028 | Line 1098 | class Cmssw(JobType):
1098          
1099          return result
1100  
1101 <    def getRequirements(self):
1101 >    def getRequirements(self, nj=[]):
1102          """
1103          return job requirements to add to jdl files
1104          """
# Line 1135 | Line 1205 | class Cmssw(JobType):
1205          txt += '       fi\n'
1206          txt += '   fi\n'
1207          txt += '   \n'
1138        txt += '   string=`cat /etc/redhat-release`\n'
1139        txt += '   echo $string\n'
1140        txt += '   if [[ $string = *alhalla* ]]; then\n'
1141        txt += '       echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1142        txt += '   elif [[ $string = *Enterprise* ]] || [[ $string = *cientific* ]]; then\n'
1143        txt += '       export SCRAM_ARCH=slc3_ia32_gcc323\n'
1144        txt += '       echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1145        txt += '   else\n'
1146        txt += '       echo "SET_CMS_ENV 10033 ==> ERROR OS unknown, LCG environment not initialized"\n'
1147        txt += '       echo "JOB_EXIT_STATUS = 10033"\n'
1148        txt += '       echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
1149        txt += '       dumpStatus $RUNTIME_AREA/$repo\n'
1150        txt += '       rm -f $RUNTIME_AREA/$repo \n'
1151        txt += '       echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1152        txt += '       echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1153        txt += '       exit 1\n'
1154        txt += '   fi\n'
1208          txt += '   echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1209          txt += '   echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1210          return txt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines