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.73 by gutsche, Sun Apr 8 18:39:51 2007 UTC vs.
Revision 1.162 by spiga, Mon Mar 3 20:41:40 2008 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 + from BlackWhiteListParser import BlackWhiteListParser
6   import common
6 import PsetManipulator  
7 import DataDiscovery
8 import DataDiscovery_DBS2
9 import DataLocation
7   import Scram
8  
9 < import os, string, re, shutil, glob
9 > import os, string, glob
10  
11   class Cmssw(JobType):
12      def __init__(self, cfg_params, ncjobs):
13          JobType.__init__(self, 'CMSSW')
14          common.logger.debug(3,'CMSSW::__init__')
15  
16 <        # Marco.
16 >        self.argsList = []
17 >
18          self._params = {}
19          self.cfg_params = cfg_params
20 +        # init BlackWhiteListParser
21 +        self.blackWhiteListParser = BlackWhiteListParser(cfg_params)
22  
23 <        try:
24 <            self.MaxTarBallSize = float(self.cfg_params['EDG.maxtarballsize'])
25 <        except KeyError:
26 <            self.MaxTarBallSize = 100.0
23 >        self.MaxTarBallSize = float(self.cfg_params.get('EDG.maxtarballsize',9.5))
24  
25          # number of jobs requested to be created, limit obj splitting
26          self.ncjobs = ncjobs
27  
28          log = common.logger
29 <        
29 >
30          self.scram = Scram.Scram(cfg_params)
31          self.additional_inbox_files = []
32          self.scriptExe = ''
33          self.executable = ''
34          self.executable_arch = self.scram.getArch()
35          self.tgz_name = 'default.tgz'
36 +        self.additional_tgz_name = 'additional.tgz'
37          self.scriptName = 'CMSSW.sh'
38 <        self.pset = ''      #scrip use case Da  
38 >        self.pset = ''      #scrip use case Da
39          self.datasetPath = '' #scrip use case Da
40  
41          # set FJR file name
42          self.fjrFileName = 'crab_fjr.xml'
43  
44          self.version = self.scram.getSWVersion()
45 <        common.taskDB.setDict('codeVersion',self.version)
45 >
46 >        #
47 >        # Try to block creation in case of arch/version mismatch
48 >        #
49 >
50 > #        a = string.split(self.version, "_")
51 > #
52 > #        if int(a[1]) == 1 and (int(a[2]) < 5 and self.executable_arch.find('slc4') == 0):
53 > #            msg = "Warning: You are using %s version of CMSSW  with %s architecture. \n--> Did you compile your libraries with SLC3? Otherwise you can find some problems running on SLC4 Grid nodes.\n"%(self.version, self.executable_arch)
54 > #            common.logger.message(msg)
55 > #        if int(a[1]) == 1 and (int(a[2]) >= 5 and self.executable_arch.find('slc3') == 0):
56 > #            msg = "Error: CMS does not support %s with %s architecture"%(self.version, self.executable_arch)
57 > #            raise CrabException(msg)
58 > #
59 >
60          self.setParam_('application', self.version)
61  
62          ### collect Data cards
63  
64 <        ## get DBS mode
65 <        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)
61 <            if string.lower(tmp)=='none':
62 <                self.datasetPath = None
63 <                self.selectNoInput = 1
64 <            else:
65 <                self.datasetPath = tmp
66 <                self.selectNoInput = 0
67 <        except KeyError:
68 <            msg = "Error: datasetpath not defined "  
64 >        if not cfg_params.has_key('CMSSW.datasetpath'):
65 >            msg = "Error: datasetpath not defined "
66              raise CrabException(msg)
67 +        tmp =  cfg_params['CMSSW.datasetpath']
68 +        log.debug(6, "CMSSW::CMSSW(): datasetPath = "+tmp)
69 +        if string.lower(tmp)=='none':
70 +            self.datasetPath = None
71 +            self.selectNoInput = 1
72 +        else:
73 +            self.datasetPath = tmp
74 +            self.selectNoInput = 0
75  
76          # ML monitoring
77          # split dataset path style: /PreProdR3Minbias/SIM/GEN-SIM
# Line 74 | Line 79 | class Cmssw(JobType):
79              self.setParam_('dataset', 'None')
80              self.setParam_('owner', 'None')
81          else:
82 <            datasetpath_split = self.datasetPath.split("/")
83 <            self.setParam_('dataset', datasetpath_split[1])
84 <            self.setParam_('owner', datasetpath_split[-1])
82 >            ## SL what is supposed to fail here?
83 >            try:
84 >                datasetpath_split = self.datasetPath.split("/")
85 >                # standard style
86 >                self.setParam_('datasetFull', self.datasetPath)
87 >                self.setParam_('dataset', datasetpath_split[1])
88 >                self.setParam_('owner', datasetpath_split[2])
89 >            except:
90 >                self.setParam_('dataset', self.datasetPath)
91 >                self.setParam_('owner', self.datasetPath)
92  
93 <        self.setTaskid_()
82 <        self.setParam_('taskId', self.cfg_params['taskId'])
93 >        self.setParam_('taskId', common._db.queryTask('name')) ## new BL--DS
94  
95          self.dataTiers = []
96  
97          ## now the application
98 <        try:
99 <            self.executable = cfg_params['CMSSW.executable']
100 <            self.setParam_('exe', self.executable)
90 <            log.debug(6, "CMSSW::CMSSW(): executable = "+self.executable)
91 <            msg = "Default executable cmsRun overridden. Switch to " + self.executable
92 <            log.debug(3,msg)
93 <        except KeyError:
94 <            self.executable = 'cmsRun'
95 <            self.setParam_('exe', self.executable)
96 <            msg = "User executable not defined. Use cmsRun"
97 <            log.debug(3,msg)
98 <            pass
98 >        self.executable = cfg_params.get('CMSSW.executable','cmsRun')
99 >        self.setParam_('exe', self.executable)
100 >        log.debug(6, "CMSSW::CMSSW(): executable = "+self.executable)
101  
102 <        try:
101 <            self.pset = cfg_params['CMSSW.pset']
102 <            log.debug(6, "Cmssw::Cmssw(): PSet file = "+self.pset)
103 <            if self.pset.lower() != 'none' :
104 <                if (not os.path.exists(self.pset)):
105 <                    raise CrabException("User defined PSet file "+self.pset+" does not exist")
106 <            else:
107 <                self.pset = None
108 <        except KeyError:
102 >        if not cfg_params.has_key('CMSSW.pset'):
103              raise CrabException("PSet file missing. Cannot run cmsRun ")
104 +        self.pset = cfg_params['CMSSW.pset']
105 +        log.debug(6, "Cmssw::Cmssw(): PSet file = "+self.pset)
106 +        if self.pset.lower() != 'none' :
107 +            if (not os.path.exists(self.pset)):
108 +                raise CrabException("User defined PSet file "+self.pset+" does not exist")
109 +        else:
110 +            self.pset = None
111  
112          # output files
113          ## stuff which must be returned always via sandbox
# Line 116 | Line 117 | class Cmssw(JobType):
117          self.output_file_sandbox.append(self.fjrFileName)
118  
119          # other output files to be returned via sandbox or copied to SE
120 <        try:
121 <            self.output_file = []
122 <            tmp = cfg_params['CMSSW.output_file']
123 <            if tmp != '':
124 <                tmpOutFiles = string.split(cfg_params['CMSSW.output_file'],',')
125 <                log.debug(7, 'cmssw::cmssw(): output files '+str(tmpOutFiles))
126 <                for tmp in tmpOutFiles:
127 <                    tmp=string.strip(tmp)
127 <                    self.output_file.append(tmp)
128 <                    pass
129 <            else:
130 <                log.message("No output file defined: only stdout/err and the CRAB Framework Job Report will be available")
120 >        self.output_file = []
121 >        tmp = cfg_params.get('CMSSW.output_file',None)
122 >        if tmp :
123 >            tmpOutFiles = string.split(tmp,',')
124 >            log.debug(7, 'cmssw::cmssw(): output files '+str(tmpOutFiles))
125 >            for tmp in tmpOutFiles:
126 >                tmp=string.strip(tmp)
127 >                self.output_file.append(tmp)
128                  pass
129 <            pass
130 <        except KeyError:
131 <            log.message("No output file defined: only stdout/err and the CRAB Framework Job Report will be available")
135 <            pass
129 >        else:
130 >            log.message("No output file defined: only stdout/err and the CRAB Framework Job Report will be available\n")
131 >        pass
132  
133          # script_exe file as additional file in inputSandbox
134 <        try:
135 <            self.scriptExe = cfg_params['USER.script_exe']
136 <            if self.scriptExe != '':
137 <               if not os.path.isfile(self.scriptExe):
138 <                  msg ="ERROR. file "+self.scriptExe+" not found"
139 <                  raise CrabException(msg)
144 <               self.additional_inbox_files.append(string.strip(self.scriptExe))
145 <        except KeyError:
146 <            self.scriptExe = ''
134 >        self.scriptExe = cfg_params.get('USER.script_exe',None)
135 >        if self.scriptExe :
136 >           if not os.path.isfile(self.scriptExe):
137 >              msg ="ERROR. file "+self.scriptExe+" not found"
138 >              raise CrabException(msg)
139 >           self.additional_inbox_files.append(string.strip(self.scriptExe))
140  
141          #CarlosDaniele
142          if self.datasetPath == None and self.pset == None and self.scriptExe == '' :
# Line 151 | Line 144 | class Cmssw(JobType):
144             raise CrabException(msg)
145  
146          ## additional input files
147 <        try:
147 >        if cfg_params.has_key('USER.additional_input_files'):
148              tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
149              for tmp in tmpAddFiles:
150                  tmp = string.strip(tmp)
151                  dirname = ''
152                  if not tmp[0]=="/": dirname = "."
153 <                files = glob.glob(os.path.join(dirname, tmp))
153 >                files = []
154 >                if string.find(tmp,"*")>-1:
155 >                    files = glob.glob(os.path.join(dirname, tmp))
156 >                    if len(files)==0:
157 >                        raise CrabException("No additional input file found with this pattern: "+tmp)
158 >                else:
159 >                    files.append(tmp)
160                  for file in files:
161                      if not os.path.exists(file):
162                          raise CrabException("Additional input file not found: "+file)
163                      pass
164 <                    storedFile = common.work_space.shareDir()+file
165 <                    shutil.copyfile(file, storedFile)
166 <                    self.additional_inbox_files.append(string.strip(storedFile))
164 >                    # fname = string.split(file, '/')[-1]
165 >                    # storedFile = common.work_space.pathForTgz()+'share/'+fname
166 >                    # shutil.copyfile(file, storedFile)
167 >                    self.additional_inbox_files.append(string.strip(file))
168                  pass
169              pass
170              common.logger.debug(5,"Additional input files: "+str(self.additional_inbox_files))
171 <        except KeyError:
172 <            pass
173 <
174 <        # files per job
175 <        try:
176 <            if (cfg_params['CMSSW.files_per_jobs']):
177 <                raise CrabException("files_per_jobs no longer supported.  Quitting.")
178 <        except KeyError:
179 <            pass
171 >        pass
172  
173          ## Events per job
174 <        try:
174 >        if cfg_params.has_key('CMSSW.events_per_job'):
175              self.eventsPerJob =int( cfg_params['CMSSW.events_per_job'])
176              self.selectEventsPerJob = 1
177 <        except KeyError:
177 >        else:
178              self.eventsPerJob = -1
179              self.selectEventsPerJob = 0
180 <    
180 >
181          ## number of jobs
182 <        try:
182 >        if cfg_params.has_key('CMSSW.number_of_jobs'):
183              self.theNumberOfJobs =int( cfg_params['CMSSW.number_of_jobs'])
184              self.selectNumberOfJobs = 1
185 <        except KeyError:
185 >        else:
186              self.theNumberOfJobs = 0
187              self.selectNumberOfJobs = 0
188  
189 <        try:
189 >        if cfg_params.has_key('CMSSW.total_number_of_events'):
190              self.total_number_of_events = int(cfg_params['CMSSW.total_number_of_events'])
191              self.selectTotalNumberEvents = 1
192 <        except KeyError:
192 >        else:
193              self.total_number_of_events = 0
194              self.selectTotalNumberEvents = 0
195  
196 <        if self.pset != None: #CarlosDaniele
196 >        if self.pset != None: #CarlosDaniele
197               if ( (self.selectTotalNumberEvents + self.selectEventsPerJob + self.selectNumberOfJobs) != 2 ):
198                   msg = 'Must define exactly two of total_number_of_events, events_per_job, or number_of_jobs.'
199                   raise CrabException(msg)
# Line 210 | Line 202 | class Cmssw(JobType):
202                   msg = 'Must specify  number_of_jobs.'
203                   raise CrabException(msg)
204  
205 <        ## source seed for pythia
206 <        try:
207 <            self.sourceSeed = int(cfg_params['CMSSW.pythia_seed'])
208 <        except KeyError:
209 <            self.sourceSeed = None
210 <            common.logger.debug(5,"No seed given")
205 >        ## New method of dealing with seeds
206 >        self.incrementSeeds = []
207 >        self.preserveSeeds = []
208 >        if cfg_params.has_key('CMSSW.preserve_seeds'):
209 >            tmpList = cfg_params['CMSSW.preserve_seeds'].split(',')
210 >            for tmp in tmpList:
211 >                tmp.strip()
212 >                self.preserveSeeds.append(tmp)
213 >        if cfg_params.has_key('CMSSW.increment_seeds'):
214 >            tmpList = cfg_params['CMSSW.increment_seeds'].split(',')
215 >            for tmp in tmpList:
216 >                tmp.strip()
217 >                self.incrementSeeds.append(tmp)
218 >
219 >        ## Old method of dealing with seeds
220 >        ## FUTURE: This is for old CMSSW and old CRAB. Can throw exceptions after a couple of CRAB releases and then
221 >        ## remove
222 >        self.sourceSeed = cfg_params.get('CMSSW.pythia_seed',None)
223 >        if self.sourceSeed:
224 >          print "pythia_seed is a deprecated parameter. Use preserve_seeds or increment_seeds in the future.\n","Added to increment_seeds."
225 >          self.incrementSeeds.append('sourceSeed')
226 >
227 >        self.sourceSeedVtx = cfg_params.get('CMSSW.vtx_seed',None)
228 >        if self.sourceSeedVtx:
229 >          print "vtx_seed is a deprecated parameter. Use preserve_seeds or increment_seeds in the future.\n","Added to increment_seeds."
230 >          self.incrementSeeds.append('VtxSmeared')
231 >
232 >        self.sourceSeedG4 = cfg_params.get('CMSSW.g4_seed',None)
233 >        if self.sourceSeedG4:
234 >          print "g4_seed is a deprecated parameter. Use preserve_seeds or increment_seeds in the future.\n","Added to increment_seeds."
235 >          self.incrementSeeds.append('g4SimHits')
236 >
237 >        self.sourceSeedMix = cfg_params.get('CMSSW.mix_seed',None)
238 >        if self.sourceSeedMix:
239 >          print "mix_seed is a deprecated parameter. Use preserve_seeds or increment_seeds in the future.\n","Added to increment_seeds."
240 >          self.incrementSeeds.append('mix')
241 >
242 >        self.firstRun = cfg_params.get('CMSSW.first_run',None)
243  
220        try:
221            self.sourceSeedVtx = int(cfg_params['CMSSW.vtx_seed'])
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")
244          if self.pset != None: #CarlosDaniele
245 <            self.PsetEdit = PsetManipulator.PsetManipulator(self.pset) #Daniele Pset
245 >            import PsetManipulator as pp
246 >            PsetEdit = pp.PsetManipulator(self.pset) #Daniele Pset
247 >
248 >        # Copy/return
249 >
250 >        self.copy_data = int(cfg_params.get('USER.copy_data',0))
251 >        self.return_data = int(cfg_params.get('USER.return_data',0))
252  
253          #DBSDLS-start
254 <        ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
254 >        ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
255          self.maxEvents=0  # max events available   ( --> check the requested nb. of evts in Creator.py)
256          self.DBSPaths={}  # all dbs paths requested ( --> input to the site local discovery script)
257          self.jobDestination=[]  # Site destination(s) for each job (list of lists)
# Line 240 | Line 260 | class Cmssw(JobType):
260          blockSites = {}
261          if self.datasetPath:
262              blockSites = self.DataDiscoveryAndLocation(cfg_params)
263 <        #DBSDLS-end          
263 >        #DBSDLS-end
264  
265          self.tgzNameWithPath = self.getTarBall(self.executable)
266 <    
266 >
267          ## Select Splitting
268 <        if self.selectNoInput:
268 >        if self.selectNoInput:
269              if self.pset == None: #CarlosDaniele
270                  self.jobSplittingForScript()
271              else:
272                  self.jobSplittingNoInput()
273 <        else:
273 >        else:
274              self.jobSplittingByBlocks(blockSites)
275  
276          # modify Pset
277          if self.pset != None: #CarlosDaniele
278              try:
279 <                if (self.datasetPath): # standard job
280 <                    # allow to processa a fraction of events in a file
281 <                    self.PsetEdit.inputModule("INPUT")
282 <                    self.PsetEdit.maxEvent("INPUTMAXEVENTS")
283 <                    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) :
271 <                            self.PsetEdit.pythiaSeedVtx("INPUTVTX")
272 <                # add FrameworkJobReport to parameter-set
273 <                self.PsetEdit.addCrabFJR(self.fjrFileName)
274 <                self.PsetEdit.psetWriter(self.configFilename())
279 >                # Add FrameworkJobReport to parameter-set, set max events.
280 >                # Reset later for data jobs by writeCFG which does all modifications
281 >                PsetEdit.addCrabFJR(self.fjrFileName)
282 >                PsetEdit.maxEvent(self.eventsPerJob)
283 >                PsetEdit.psetWriter(self.configFilename())
284              except:
285                  msg='Error while manipuliating ParameterSet: exiting...'
286                  raise CrabException(msg)
287  
288      def DataDiscoveryAndLocation(self, cfg_params):
289  
290 +        import DataDiscovery
291 +        import DataLocation
292          common.logger.debug(10,"CMSSW::DataDiscoveryAndLocation()")
293  
294          datasetPath=self.datasetPath
295  
296          ## Contact the DBS
297 <        common.logger.message("Contacting DBS...")
297 >        common.logger.message("Contacting Data Discovery Services ...")
298          try:
299 <
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)
299 >            self.pubdata=DataDiscovery.DataDiscovery(datasetPath, cfg_params)
300              self.pubdata.fetchDBSInfo()
301  
302          except DataDiscovery.NotExistingDatasetError, ex :
# Line 301 | Line 308 | class Cmssw(JobType):
308          except DataDiscovery.DataDiscoveryError, ex:
309              msg = 'ERROR ***: failed Data Discovery in DBS :  %s'%ex.getErrorMessage()
310              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)
315        common.logger.message("Required data are :"+self.datasetPath)
311  
312          self.filesbyblock=self.pubdata.getFiles()
313          self.eventsbyblock=self.pubdata.getEventsPerBlock()
314          self.eventsbyfile=self.pubdata.getEventsPerFile()
315  
316          ## get max number of events
317 <        self.maxEvents=self.pubdata.getMaxEvents() ##  self.maxEvents used in Creator.py
323 <        common.logger.message("The number of available events is %s\n"%self.maxEvents)
317 >        self.maxEvents=self.pubdata.getMaxEvents() ##  self.maxEvents used in Creator.py
318  
325        common.logger.message("Contacting DLS...")
319          ## Contact the DLS and build a list of sites hosting the fileblocks
320          try:
321              dataloc=DataLocation.DataLocation(self.filesbyblock.keys(),cfg_params)
# Line 330 | Line 323 | class Cmssw(JobType):
323          except DataLocation.DataLocationError , ex:
324              msg = 'ERROR ***: failed Data Location in DLS \n %s '%ex.getErrorMessage()
325              raise CrabException(msg)
326 <        
326 >
327  
328          sites = dataloc.getSites()
329          allSites = []
# Line 340 | Line 333 | class Cmssw(JobType):
333                  allSites.append(oneSite)
334          allSites = self.uniquelist(allSites)
335  
336 <        common.logger.message("Sites ("+str(len(allSites))+") hosting part/all of dataset: "+str(allSites))
337 <        common.logger.debug(6, "List of Sites: "+str(allSites))
336 >        # screen output
337 >        common.logger.message("Requested dataset: " + datasetPath + " has " + str(self.maxEvents) + " events in " + str(len(self.filesbyblock.keys())) + " blocks.\n")
338 >
339          return sites
340 <    
340 >
341 >    def setArgsList(self, argsList):
342 >        self.argsList = argsList
343 >
344      def jobSplittingByBlocks(self, blockSites):
345          """
346          Perform job splitting. Jobs run over an integer number of files
# Line 393 | Line 390 | class Cmssw(JobType):
390              totalNumberOfJobs = 999999999
391          else :
392              totalNumberOfJobs = self.ncjobs
393 <            
393 >
394  
395          blocks = blockSites.keys()
396          blockCount = 0
# Line 403 | Line 400 | class Cmssw(JobType):
400          jobCount = 0
401          list_of_lists = []
402  
403 +        # list tracking which jobs are in which jobs belong to which block
404 +        jobsOfBlock = {}
405 +
406          # ---- Iterate over the blocks in the dataset until ---- #
407          # ---- we've met the requested total # of events    ---- #
408          while ( (eventsRemaining > 0) and (blockCount < numBlocksInDataset) and (jobCount < totalNumberOfJobs)):
409              block = blocks[blockCount]
410              blockCount += 1
411 <            
411 >            if block not in jobsOfBlock.keys() :
412 >                jobsOfBlock[block] = []
413 >
414              if self.eventsbyblock.has_key(block) :
415                  numEventsInBlock = self.eventsbyblock[block]
416                  common.logger.debug(5,'Events in Block File '+str(numEventsInBlock))
417 <            
417 >
418                  files = self.filesbyblock[block]
419                  numFilesInBlock = len(files)
420                  if (numFilesInBlock <= 0):
# Line 420 | Line 422 | class Cmssw(JobType):
422                  fileCount = 0
423  
424                  # ---- New block => New job ---- #
425 <                parString = "\\{"
425 >                parString = ""
426                  # counter for number of events in files currently worked on
427                  filesEventCount = 0
428                  # flag if next while loop should touch new file
429                  newFile = 1
430                  # job event counter
431                  jobSkipEventCount = 0
432 <            
432 >
433                  # ---- Iterate over the files in the block until we've met the requested ---- #
434                  # ---- total # of events or we've gone over all the files in this block  ---- #
435                  while ( (eventsRemaining > 0) and (fileCount < numFilesInBlock) and (jobCount < totalNumberOfJobs) ):
# Line 443 | Line 445 | class Cmssw(JobType):
445                              newFile = 0
446                          except KeyError:
447                              common.logger.message("File "+str(file)+" has unknown number of events: skipping")
448 <                        
448 >
449  
450                      # if less events in file remain than eventsPerJobRequested
451                      if ( filesEventCount - jobSkipEventCount < eventsPerJobRequested ) :
# Line 452 | Line 454 | class Cmssw(JobType):
454                              # end job using last file, use remaining events in block
455                              # close job and touch new file
456                              fullString = parString[:-2]
455                            fullString += '\\}'
457                              list_of_lists.append([fullString,str(-1),str(jobSkipEventCount)])
458                              common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(filesEventCount - jobSkipEventCount)+" events (last file in block).")
459                              self.jobDestination.append(blockSites[block])
460                              common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
461 +                            # fill jobs of block dictionary
462 +                            jobsOfBlock[block].append(jobCount+1)
463                              # reset counter
464                              jobCount = jobCount + 1
465                              totalEventCount = totalEventCount + filesEventCount - jobSkipEventCount
466                              eventsRemaining = eventsRemaining - filesEventCount + jobSkipEventCount
467                              jobSkipEventCount = 0
468                              # reset file
469 <                            parString = "\\{"
469 >                            parString = ""
470                              filesEventCount = 0
471                              newFile = 1
472                              fileCount += 1
# Line 475 | Line 478 | class Cmssw(JobType):
478                      elif ( filesEventCount - jobSkipEventCount == eventsPerJobRequested ) :
479                          # close job and touch new file
480                          fullString = parString[:-2]
478                        fullString += '\\}'
481                          list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
482                          common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
483                          self.jobDestination.append(blockSites[block])
484                          common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
485 +                        jobsOfBlock[block].append(jobCount+1)
486                          # reset counter
487                          jobCount = jobCount + 1
488                          totalEventCount = totalEventCount + eventsPerJobRequested
489                          eventsRemaining = eventsRemaining - eventsPerJobRequested
490                          jobSkipEventCount = 0
491                          # reset file
492 <                        parString = "\\{"
492 >                        parString = ""
493                          filesEventCount = 0
494                          newFile = 1
495                          fileCount += 1
496 <                        
496 >
497                      # if more events in file remain than eventsPerJobRequested
498                      else :
499                          # close job but don't touch new file
500                          fullString = parString[:-2]
498                        fullString += '\\}'
501                          list_of_lists.append([fullString,str(eventsPerJobRequested),str(jobSkipEventCount)])
502                          common.logger.debug(3,"Job "+str(jobCount+1)+" can run over "+str(eventsPerJobRequested)+" events.")
503                          self.jobDestination.append(blockSites[block])
504                          common.logger.debug(5,"Job "+str(jobCount+1)+" Destination: "+str(self.jobDestination[jobCount]))
505 +                        jobsOfBlock[block].append(jobCount+1)
506                          # increase counter
507                          jobCount = jobCount + 1
508                          totalEventCount = totalEventCount + eventsPerJobRequested
# Line 509 | Line 512 | class Cmssw(JobType):
512                          jobSkipEventCount = eventsPerJobRequested - (filesEventCount - jobSkipEventCount - self.eventsbyfile[file])
513                          # remove all but the last file
514                          filesEventCount = self.eventsbyfile[file]
515 <                        parString = "\\{"
513 <                        parString += '\\\"' + file + '\\\"\,'
515 >                        parString = '\\\"' + file + '\\\"\,'
516                      pass # END if
517                  pass # END while (iterate over files in the block)
518          pass # END while (iterate over blocks in the dataset)
519          self.ncjobs = self.total_number_of_jobs = jobCount
520          if (eventsRemaining > 0 and jobCount < totalNumberOfJobs ):
521              common.logger.message("Could not run on all requested events because some blocks not hosted at allowed sites.")
522 <        common.logger.message("\n"+str(jobCount)+" job(s) can run on "+str(totalEventCount)+" events.\n")
523 <        
522 >        common.logger.message(str(jobCount)+" job(s) can run on "+str(totalEventCount)+" events.\n")
523 >
524 >        # screen output
525 >        screenOutput = "List of jobs and available destination sites:\n\n"
526 >
527 >        # keep trace of block with no sites to print a warning at the end
528 >        noSiteBlock = []
529 >        bloskNoSite = []
530 >
531 >        blockCounter = 0
532 >        for block in blocks:
533 >            if block in jobsOfBlock.keys() :
534 >                blockCounter += 1
535 >                screenOutput += "Block %5i: jobs %20s: sites: %s\n" % (blockCounter,spanRanges(jobsOfBlock[block]),','.join(self.blackWhiteListParser.checkWhiteList(self.blackWhiteListParser.checkBlackList(blockSites[block],block),block)))
536 >                if len(self.blackWhiteListParser.checkWhiteList(self.blackWhiteListParser.checkBlackList(blockSites[block],block),block)) == 0:
537 >                    noSiteBlock.append( spanRanges(jobsOfBlock[block]) )
538 >                    bloskNoSite.append( blockCounter )
539 >
540 >        common.logger.message(screenOutput)
541 >        if len(noSiteBlock) > 0 and len(bloskNoSite) > 0:
542 >            msg = 'WARNING: No sites are hosting any part of data for block:\n                '
543 >            virgola = ""
544 >            if len(bloskNoSite) > 1:
545 >                virgola = ","
546 >            for block in bloskNoSite:
547 >                msg += ' ' + str(block) + virgola
548 >            msg += '\n               Related jobs:\n                 '
549 >            virgola = ""
550 >            if len(noSiteBlock) > 1:
551 >                virgola = ","
552 >            for range_jobs in noSiteBlock:
553 >                msg += str(range_jobs) + virgola
554 >            msg += '\n               will not be submitted and this block of data can not be analyzed!\n'
555 >            if self.cfg_params.has_key('EDG.se_white_list'):
556 >                msg += 'WARNING: SE White List: '+self.cfg_params['EDG.se_white_list']+'\n'
557 >                msg += '(Hint: By whitelisting you force the job to run at this particular site(s).\n'
558 >                msg += 'Please check if the dataset is available at this site!)\n'
559 >            if self.cfg_params.has_key('EDG.ce_white_list'):
560 >                msg += 'WARNING: CE White List: '+self.cfg_params['EDG.ce_white_list']+'\n'
561 >                msg += '(Hint: By whitelisting you force the job to run at this particular site(s).\n'
562 >                msg += 'Please check if the dataset is available at this site!)\n'
563 >
564 >            common.logger.message(msg)
565 >
566          self.list_of_args = list_of_lists
567          return
568  
# Line 527 | Line 571 | class Cmssw(JobType):
571          Perform job splitting based on number of event per job
572          """
573          common.logger.debug(5,'Splitting per events')
574 <        common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
575 <        common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
576 <        common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
574 >
575 >        if (self.selectEventsPerJob):
576 >            common.logger.message('Required '+str(self.eventsPerJob)+' events per job ')
577 >        if (self.selectNumberOfJobs):
578 >            common.logger.message('Required '+str(self.theNumberOfJobs)+' jobs in total ')
579 >        if (self.selectTotalNumberEvents):
580 >            common.logger.message('Required '+str(self.total_number_of_events)+' events in total ')
581  
582          if (self.total_number_of_events < 0):
583              msg='Cannot split jobs per Events with "-1" as total number of events'
# Line 538 | Line 586 | class Cmssw(JobType):
586          if (self.selectEventsPerJob):
587              if (self.selectTotalNumberEvents):
588                  self.total_number_of_jobs = int(self.total_number_of_events/self.eventsPerJob)
589 <            elif(self.selectNumberOfJobs) :  
589 >            elif(self.selectNumberOfJobs) :
590                  self.total_number_of_jobs =self.theNumberOfJobs
591 <                self.total_number_of_events =int(self.theNumberOfJobs*self.eventsPerJob)
591 >                self.total_number_of_events =int(self.theNumberOfJobs*self.eventsPerJob)
592  
593          elif (self.selectNumberOfJobs) :
594              self.total_number_of_jobs = self.theNumberOfJobs
595              self.eventsPerJob = int(self.total_number_of_events/self.total_number_of_jobs)
596 <
596 >
597          common.logger.debug(5,'N jobs  '+str(self.total_number_of_jobs))
598  
599          # is there any remainder?
# Line 561 | Line 609 | class Cmssw(JobType):
609          self.list_of_args = []
610          for i in range(self.total_number_of_jobs):
611              ## Since there is no input, any site is good
612 <           # self.jobDestination.append(["Any"])
613 <            self.jobDestination.append([""]) #must be empty to write correctly the xml
566 <            args=''
612 >            self.jobDestination.append([""]) #must be empty to write correctly the xml
613 >            args=[]
614              if (self.firstRun):
615 <                    ## pythia first run
616 <                #self.list_of_args.append([(str(self.firstRun)+str(i))])
617 <                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 <                    #                          ])
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))])
586 <                    args=args +str(',')+str(self.sourceSeed)+str(i)
587 <            else:
588 <                ## no random seed
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
615 >                ## pythia first run
616 >                args.append(str(self.firstRun)+str(i))
617 >            self.list_of_args.append(args)
618  
619          return
620  
# Line 621 | Line 643 | class Cmssw(JobType):
643          return
644  
645      def split(self, jobParams):
646 <
625 <        common.jobDB.load()
646 >
647          #### Fabio
648          njobs = self.total_number_of_jobs
649          arglist = self.list_of_args
650          # create the empty structure
651          for i in range(njobs):
652              jobParams.append("")
653 <        
653 >
654          for job in range(njobs):
655              jobParams[job] = arglist[job]
656 <            # print str(arglist[job])
657 <            # print jobParams[job]
658 <            common.jobDB.setArguments(job, jobParams[job])
656 >            job_ToSave ={}
657 >            job_ToSave['arguments']= str(jobParams[job])## new BL--DS
658 >            job_ToSave['dlsDestination']= self.jobDestination[job]## new BL--DS
659 >            common._db.updateJob_(job,job_ToSave)## new BL--DS
660              common.logger.debug(5,"Job "+str(job)+" Destination: "+str(self.jobDestination[job]))
639            common.jobDB.setDestination(job, self.jobDestination[job])
661  
641        common.jobDB.save()
662          return
663 <    
663 >
664      def getJobTypeArguments(self, nj, sched):
665          result = ''
666 <        for i in common.jobDB.arguments(nj):
666 >        jobs=[]
667 >        jobs.append(nj)
668 >        for i in common._db.queryJob('arguments',jobs):##  BL--DS
669              result=result+str(i)+" "
670          return result
671 <  
671 >
672      def numberOfJobs(self):
673          # Fabio
674          return self.total_number_of_jobs
# Line 655 | Line 677 | class Cmssw(JobType):
677          """
678          Return the TarBall with lib and exe
679          """
680 <        
680 >
681          # if it exist, just return it
682          #
683          # Marco. Let's start to use relative path for Boss XML files
# Line 678 | Line 700 | class Cmssw(JobType):
700          # print "swVersion = ", swVersion
701          swReleaseTop = self.scram.getReleaseTop_()
702          #print "swReleaseTop = ", swReleaseTop
703 <        
703 >
704          ## check if working area is release top
705          if swReleaseTop == '' or swArea == swReleaseTop:
706              return
# Line 687 | Line 709 | class Cmssw(JobType):
709          try: # create tar ball
710              tar = tarfile.open(self.tgzNameWithPath, "w:gz")
711              ## First find the executable
712 <            if (executable != ''):
712 >            if (self.executable != ''):
713                  exeWithPath = self.scram.findFile_(executable)
714                  if ( not exeWithPath ):
715                      raise CrabException('User executable '+executable+' not found')
716 <    
716 >
717                  ## then check if it's private or not
718                  if exeWithPath.find(swReleaseTop) == -1:
719                      # the exe is private, so we must ship
720                      common.logger.debug(5,"Exe "+exeWithPath+" to be tarred")
721                      path = swArea+'/'
722 <                    exe = string.replace(exeWithPath, path,'')
723 <                    tar.add(path+exe,executable)
722 >                    # distinguish case when script is in user project area or given by full path somewhere else
723 >                    if exeWithPath.find(path) >= 0 :
724 >                        exe = string.replace(exeWithPath, path,'')
725 >                        tar.add(path+exe,exe)
726 >                    else :
727 >                        tar.add(exeWithPath,os.path.basename(executable))
728                      pass
729                  else:
730                      # the exe is from release, we'll find it on WN
731                      pass
732 <    
732 >
733              ## Now get the libraries: only those in local working area
734              libDir = 'lib'
735              lib = swArea+'/' +libDir
736              common.logger.debug(5,"lib "+lib+" to be tarred")
737              if os.path.exists(lib):
738                  tar.add(lib,libDir)
739 <    
739 >
740              ## Now check if module dir is present
741              moduleDir = 'module'
742              module = swArea + '/' + moduleDir
# Line 724 | Line 750 | class Cmssw(JobType):
750                      common.logger.debug(5,"data "+root+"/data"+" to be tarred")
751                      tar.add(root+"/data",root[swAreaLen:]+"/data")
752  
753 <            ## Add ProdAgent dir to tar
754 <            paDir = 'ProdAgentApi'
755 <            pa = os.environ['CRABDIR'] + '/' + 'ProdAgentApi'
756 <            if os.path.isdir(pa):
757 <                tar.add(pa,paDir)
758 <        
753 >
754 >            ## Add ProdCommon dir to tar
755 >            prodcommonDir = 'ProdCommon'
756 >            prodcommonPath = os.environ['CRABDIR'] + '/' + 'ProdCommon'
757 >            if os.path.isdir(prodcommonPath):
758 >                tar.add(prodcommonPath,prodcommonDir)
759 >
760              common.logger.debug(5,"Files added to "+self.tgzNameWithPath+" : "+str(tar.getnames()))
761              tar.close()
762          except :
# Line 741 | Line 768 | class Cmssw(JobType):
768              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.')
769  
770          ## create tar-ball with ML stuff
771 <        self.MLtgzfile =  common.work_space.pathForTgz()+'share/MLfiles.tgz'
771 >        self.MLtgzfile =  common.work_space.pathForTgz()+'share/MLfiles.tgz'
772          try:
773              tar = tarfile.open(self.MLtgzfile, "w:gz")
774              path=os.environ['CRABDIR'] + '/python/'
775 <            for file in ['report.py', 'DashboardAPI.py', 'Logger.py', 'ProcInfo.py', 'apmon.py', 'parseCrabFjr.py']:
775 >            for file in ['report.py', 'DashboardAPI.py', 'Logger.py', 'ProcInfo.py', 'apmon.py', 'parseCrabFjr.py','writeCfg.py']:
776                  tar.add(path+file,file)
777              common.logger.debug(5,"Files added to "+self.MLtgzfile+" : "+str(tar.getnames()))
778              tar.close()
779          except :
780              raise CrabException('Could not create ML files tar-ball')
781 <        
781 >
782          return
783 <        
783 >
784 >    def additionalInputFileTgz(self):
785 >        """
786 >        Put all additional files into a tar ball and return its name
787 >        """
788 >        import tarfile
789 >        tarName=  common.work_space.pathForTgz()+'share/'+self.additional_tgz_name
790 >        tar = tarfile.open(tarName, "w:gz")
791 >        for file in self.additional_inbox_files:
792 >            tar.add(file,string.split(file,'/')[-1])
793 >        common.logger.debug(5,"Files added to "+self.additional_tgz_name+" : "+str(tar.getnames()))
794 >        tar.close()
795 >        return tarName
796 >
797      def wsSetupEnvironment(self, nj):
798          """
799          Returns part of a job script which prepares
800          the execution environment for the job 'nj'.
801          """
802          # Prepare JobType-independent part
803 <        txt = ''
804 <  
805 <        ## OLI_Daniele at this level  middleware already known
766 <
767 <        txt += 'if [ $middleware == LCG ]; then \n'
803 >        txt = '\n#Written by cms_cmssw::wsSetupEnvironment\n'
804 >        txt += 'echo ">>> setup environment"\n'
805 >        txt += 'if [ $middleware == LCG ]; then \n'
806          txt += self.wsSetupCMSLCGEnvironment_()
807          txt += 'elif [ $middleware == OSG ]; then\n'
808          txt += '    WORKING_DIR=`/bin/mktemp  -d $OSG_WN_TMP/cms_XXXXXXXXXXXX`\n'
809 <        txt += '    echo "Created working directory: $WORKING_DIR"\n'
810 <        txt += '    if [ ! -d $WORKING_DIR ] ;then\n'
811 <        txt += '        echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
812 <        txt += '        echo "JOB_EXIT_STATUS = 10016"\n'
813 <        txt += '        echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
814 <        txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
815 <        txt += '        rm -f $RUNTIME_AREA/$repo \n'
816 <        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
817 <        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
780 <        txt += '        exit 1\n'
809 >        txt += '    if [ ! $? == 0 ] ;then\n'
810 >        #txt += '        echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
811 >        #txt += '        echo "JOB_EXIT_STATUS = 10016"\n'
812 >        #txt += '        echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
813 >        #txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
814 >        #txt += '        exit 1\n'
815 >        txt += '        echo "ERROR ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
816 >        txt += '        job_exit_code=10016\n'
817 >        txt += '        func_exit\n'
818          txt += '    fi\n'
819 +        txt += '    echo ">>> Created working directory: $WORKING_DIR"\n'
820          txt += '\n'
821          txt += '    echo "Change to working directory: $WORKING_DIR"\n'
822          txt += '    cd $WORKING_DIR\n'
823 <        txt += self.wsSetupCMSOSGEnvironment_()
823 >        txt += '    echo ">>> current directory (WORKING_DIR): $WORKING_DIR"\n'
824 >        txt += self.wsSetupCMSOSGEnvironment_()
825 >        #txt += '    echo "### Set SCRAM ARCH to ' + self.executable_arch + ' ###"\n'
826 >        #txt += '    export SCRAM_ARCH='+self.executable_arch+'\n'
827          txt += 'fi\n'
828  
829          # Prepare JobType-specific part
830          scram = self.scram.commandName()
831          txt += '\n\n'
832 <        txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
832 >        txt += 'echo ">>> specific cmssw setup environment:"\n'
833 >        txt += 'echo "CMSSW_VERSION =  '+self.version+'"\n'
834          txt += scram+' project CMSSW '+self.version+'\n'
835          txt += 'status=$?\n'
836          txt += 'if [ $status != 0 ] ; then\n'
837 <        txt += '   echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
838 <        txt += '   echo "JOB_EXIT_STATUS = 10034"\n'
839 <        txt += '   echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
840 <        txt += '   dumpStatus $RUNTIME_AREA/$repo\n'
841 <        txt += '   rm -f $RUNTIME_AREA/$repo \n'
842 <        txt += '   echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
801 <        txt += '   echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
802 <        ## OLI_Daniele
837 >        #txt += '    echo "SET_EXE_ENV 10034 ==>ERROR CMSSW '+self.version+' not found on `hostname`" \n'
838 >        #txt += '    echo "JOB_EXIT_STATUS = 10034"\n'
839 >        #txt += '    echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
840 >        #txt += '    dumpStatus $RUNTIME_AREA/$repo\n'
841 >        txt += '    echo "ERROR ==> CMSSW '+self.version+' not found on `hostname`" \n'
842 >        txt += '    job_exit_code=10034\n'
843          txt += '    if [ $middleware == OSG ]; then \n'
804        txt += '        echo "Remove working directory: $WORKING_DIR"\n'
844          txt += '        cd $RUNTIME_AREA\n'
845 +        txt += '        echo ">>> current directory (RUNTIME_AREA): $RUNTIME_AREA"\n'
846 +        txt += '        echo ">>> Remove working directory: $WORKING_DIR"\n'
847          txt += '        /bin/rm -rf $WORKING_DIR\n'
848          txt += '        if [ -d $WORKING_DIR ] ;then\n'
849 <        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'
850 <        txt += '            echo "JOB_EXIT_STATUS = 10018"\n'
851 <        txt += '            echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
852 <        txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
853 <        txt += '            rm -f $RUNTIME_AREA/$repo \n'
854 <        txt += '            echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
814 <        txt += '            echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
849 >        #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'
850 >        #txt += '            echo "JOB_EXIT_STATUS = 10018"\n'
851 >        #txt += '            echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
852 >        #txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
853 >        txt += '            echo "ERROR ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after CMSSW CMSSW_0_6_1 not found on `hostname`"\n'
854 >        txt += '        if [ -d $WORKING_DIR ] ;then\n'
855          txt += '        fi\n'
856          txt += '    fi \n'
857 <        txt += '   exit 1 \n'
857 >        #txt += '    exit 1 \n'
858 >        txt += '    fi \n'
859          txt += 'fi \n'
819        txt += 'echo "CMSSW_VERSION =  '+self.version+'"\n'
820        txt += 'export SCRAM_ARCH='+self.executable_arch+'\n'
860          txt += 'cd '+self.version+'\n'
861 +        ########## FEDE FOR DBS2 ######################
862 +        txt += 'SOFTWARE_DIR=`pwd`\n'
863 +        txt += 'echo ">>> current directory (SOFTWARE_DIR): $SOFTWARE_DIR" \n'
864 +        ###############################################
865          ### needed grep for bug in scramv1 ###
823        txt += scram+' runtime -sh\n'
866          txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
825        txt += 'echo $PATH\n'
826
867          # Handle the arguments:
868          txt += "\n"
869          txt += "## number of arguments (first argument always jobnumber)\n"
870          txt += "\n"
871 < #        txt += "narg=$#\n"
832 <        txt += "if [ $nargs -lt 2 ]\n"
871 >        txt += "if [ $nargs -lt "+str(len(self.argsList[nj].split()))+" ]\n"
872          txt += "then\n"
873 <        txt += "    echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$nargs+ \n"
874 <        txt += '    echo "JOB_EXIT_STATUS = 50113"\n'
875 <        txt += '    echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
876 <        txt += '    dumpStatus $RUNTIME_AREA/$repo\n'
877 <        txt += '    rm -f $RUNTIME_AREA/$repo \n'
878 <        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
840 <        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
841 <        ## OLI_Daniele
873 >        #txt += "    echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$nargs+ \n"
874 >        #txt += '    echo "JOB_EXIT_STATUS = 50113"\n'
875 >        #txt += '    echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
876 >        #txt += '    dumpStatus $RUNTIME_AREA/$repo\n'
877 >        txt += "    echo 'ERROR ==> Too few arguments' +$nargs+ \n"
878 >        txt += '    job_exit_code=50113\n'
879          txt += '    if [ $middleware == OSG ]; then \n'
843        txt += '        echo "Remove working directory: $WORKING_DIR"\n'
880          txt += '        cd $RUNTIME_AREA\n'
881 +        txt += '        echo ">>> current directory (RUNTIME_AREA): $RUNTIME_AREA"\n'
882 +        txt += '        echo ">>> Remove working directory: $WORKING_DIR"\n'
883          txt += '        /bin/rm -rf $WORKING_DIR\n'
884          txt += '        if [ -d $WORKING_DIR ] ;then\n'
885 <        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'
886 <        txt += '            echo "JOB_EXIT_STATUS = 50114"\n'
887 <        txt += '            echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
888 <        txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
889 <        txt += '            rm -f $RUNTIME_AREA/$repo \n'
890 <        txt += '            echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
853 <        txt += '            echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
885 >        #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'
886 >        #txt += '            echo "JOB_EXIT_STATUS = 50114"\n'
887 >        #txt += '            echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
888 >        #txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
889 >        txt += '            echo "ERROR ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Too few arguments for CRAB job wrapper"\n'
890 >        txt += '            job_exit_code=50114\n'
891          txt += '        fi\n'
892 <        txt += '    fi \n'
893 <        txt += "    exit 1\n"
892 >        txt += '    fi\n'
893 >        #txt += "    exit 1\n"
894 >        txt += "    func_exit\n"
895          txt += "fi\n"
896          txt += "\n"
897  
898          # Prepare job-specific part
899          job = common.job_list[nj]
900 +        ### FEDE FOR DBS OUTPUT PUBLICATION
901 +        if (self.datasetPath):
902 +            txt += '\n'
903 +            txt += 'DatasetPath='+self.datasetPath+'\n'
904 +
905 +            datasetpath_split = self.datasetPath.split("/")
906 +
907 +            txt += 'PrimaryDataset='+datasetpath_split[1]+'\n'
908 +            txt += 'DataTier='+datasetpath_split[2]+'\n'
909 +            txt += 'ApplicationFamily=cmsRun\n'
910 +
911 +        else:
912 +            txt += 'DatasetPath=MCDataTier\n'
913 +            txt += 'PrimaryDataset=null\n'
914 +            txt += 'DataTier=null\n'
915 +            txt += 'ApplicationFamily=MCDataTier\n'
916          if self.pset != None: #CarlosDaniele
917              pset = os.path.basename(job.configFilename())
918              txt += '\n'
919 +            txt += 'cp  $RUNTIME_AREA/'+pset+' .\n'
920              if (self.datasetPath): # standard job
921 <                #txt += 'InputFiles=$2\n'
922 <                txt += 'InputFiles=${args[1]}\n'
923 <                txt += 'MaxEvents=${args[2]}\n'
869 <                txt += 'SkipEvents=${args[3]}\n'
921 >                txt += 'InputFiles=${args[1]}; export InputFiles\n'
922 >                txt += 'MaxEvents=${args[2]}; export MaxEvents\n'
923 >                txt += 'SkipEvents=${args[3]}; export SkipEvents\n'
924                  txt += 'echo "Inputfiles:<$InputFiles>"\n'
871                txt += 'sed "s#{\'INPUT\'}#$InputFiles#" $RUNTIME_AREA/'+pset+' > pset_tmp_1.cfg\n'
925                  txt += 'echo "MaxEvents:<$MaxEvents>"\n'
873                txt += 'sed "s#INPUTMAXEVENTS#$MaxEvents#" pset_tmp_1.cfg > pset_tmp_2.cfg\n'
926                  txt += 'echo "SkipEvents:<$SkipEvents>"\n'
875                txt += 'sed "s#INPUTSKIPEVENTS#$SkipEvents#" pset_tmp_2.cfg > pset.cfg\n'
927              else:  # pythia like job
928 <                if (self.sourceSeed):
929 <                    txt += 'FirstRun=${args[1]}\n'
928 >                txt += 'PreserveSeeds='  + ','.join(self.preserveSeeds)  + '; export PreserveSeeds\n'
929 >                txt += 'IncrementSeeds=' + ','.join(self.incrementSeeds) + '; export IncrementSeeds\n'
930 >                txt += 'echo "PreserveSeeds: <$PreserveSeeds>"\n'
931 >                txt += 'echo "IncrementSeeds:<$IncrementSeeds>"\n'
932 >                if (self.firstRun):
933 >                    txt += 'FirstRun=${args[1]}; export FirstRun\n'
934                      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[2]}\n'
887                    txt += 'echo "Seed: <$Seed>"\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[3]}\n'
892                        txt += 'echo "VtxSeed: <$VtxSeed>"\n'
893                        txt += 'sed "s#INPUTVTX#$VtxSeed#" tmp_2.cfg > pset.cfg\n'
894                    else:
895                        txt += 'mv tmp_2.cfg pset.cfg\n'
896                else:
897                    txt += 'mv tmp_1.cfg pset.cfg\n'
898                   # txt += '# Copy untouched pset\n'
899                   # txt += 'cp $RUNTIME_AREA/'+pset+' pset.cfg\n'
935  
936 +            txt += 'mv -f '+pset+' pset.cfg\n'
937  
938          if len(self.additional_inbox_files) > 0:
939 <            for file in self.additional_inbox_files:
940 <                relFile = file.split("/")[-1]
941 <                txt += 'if [ -e $RUNTIME_AREA/'+relFile+' ] ; then\n'
942 <                txt += '   cp $RUNTIME_AREA/'+relFile+' .\n'
907 <                txt += '   chmod +x '+relFile+'\n'
908 <                txt += 'fi\n'
909 <            pass
939 >            txt += 'if [ -e $RUNTIME_AREA/'+self.additional_tgz_name+' ] ; then\n'
940 >            txt += '  tar xzvf $RUNTIME_AREA/'+self.additional_tgz_name+'\n'
941 >            txt += 'fi\n'
942 >            pass
943  
944          if self.pset != None: #CarlosDaniele
912            txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
913        
945              txt += '\n'
946              txt += 'echo "***** cat pset.cfg *********"\n'
947              txt += 'cat pset.cfg\n'
948              txt += 'echo "****** end pset.cfg ********"\n'
949              txt += '\n'
950 <            # txt += 'echo "***** cat pset1.cfg *********"\n'
951 <            # txt += 'cat pset1.cfg\n'
952 <            # txt += 'echo "****** end pset1.cfg ********"\n'
950 >            ### FEDE FOR DBS OUTPUT PUBLICATION
951 >            txt += 'PSETHASH=`EdmConfigHash < pset.cfg` \n'
952 >            txt += 'echo "PSETHASH = $PSETHASH" \n'
953 >            ##############
954 >            txt += '\n'
955          return txt
956  
957      def wsBuildExe(self, nj=0):
# Line 927 | Line 960 | class Cmssw(JobType):
960          or a library.
961          """
962  
963 <        txt = ""
963 >        txt = '\n#Written by cms_cmssw::wsBuildExe\n'
964  
965          if os.path.isfile(self.tgzNameWithPath):
966 <            txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
966 >            txt += 'echo ">>> tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+' :" \n'
967              txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
968              txt += 'untar_status=$? \n'
969              txt += 'if [ $untar_status -ne 0 ]; then \n'
970 <            txt += '   echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
971 <            txt += '   echo "JOB_EXIT_STATUS = $untar_status" \n'
972 <            txt += '   echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
970 >            #txt += '   echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
971 >            #txt += '   echo "JOB_EXIT_STATUS = $untar_status" \n'
972 >            #txt += '   echo "JobExitCode=$untar_status" | tee -a $RUNTIME_AREA/$repo\n'
973 >            txt += '   echo "ERROR ==> Untarring .tgz file failed"\n'
974 >            txt += '   job_exit_code=$untar_status\n'
975 >            txt += '   echo "JobExitCode=$untar_status" >> $RUNTIME_AREA/$repo\n'
976              txt += '   if [ $middleware == OSG ]; then \n'
941            txt += '       echo "Remove working directory: $WORKING_DIR"\n'
977              txt += '       cd $RUNTIME_AREA\n'
978 +            txt += '        echo ">>> current directory (RUNTIME_AREA): $RUNTIME_AREA"\n'
979 +            txt += '        echo ">>> Remove working directory: $WORKING_DIR"\n'
980              txt += '       /bin/rm -rf $WORKING_DIR\n'
981              txt += '       if [ -d $WORKING_DIR ] ;then\n'
982 <            txt += '           echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
983 <            txt += '           echo "JOB_EXIT_STATUS = 50999"\n'
984 <            txt += '           echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
985 <            txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
986 <            txt += '           rm -f $RUNTIME_AREA/$repo \n'
987 <            txt += '           echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
951 <            txt += '           echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
982 >            #txt += '           echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
983 >            #txt += '           echo "JOB_EXIT_STATUS = 50999"\n'
984 >            #txt += '           echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
985 >            #txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
986 >            txt += '           echo "ERROR ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
987 >            txt += '           job_exit_code=50999\n'
988              txt += '       fi\n'
989              txt += '   fi \n'
990              txt += '   \n'
991 <            txt += '   exit 1 \n'
991 >            #txt += '   exit 1 \n'
992 >            txt += '   func_exit\n'
993              txt += 'else \n'
994              txt += '   echo "Successful untar" \n'
995              txt += 'fi \n'
996              txt += '\n'
997 <            txt += 'echo "Include ProdAgentApi in PYTHONPATH"\n'
997 >            #### Removed ProdAgent API dependencies
998 >            txt += 'echo ">>> Include ProdCommon in PYTHONPATH:"\n'
999              txt += 'if [ -z "$PYTHONPATH" ]; then\n'
1000 <            txt += '   export PYTHONPATH=ProdAgentApi\n'
1000 >            #### FEDE FOR DBS OUTPUT PUBLICATION
1001 >            txt += '   export PYTHONPATH=$SOFTWARE_DIR/ProdCommon\n'
1002              txt += 'else\n'
1003 <            txt += '   export PYTHONPATH=ProdAgentApi:${PYTHONPATH}\n'
1003 >            txt += '   export PYTHONPATH=$SOFTWARE_DIR/ProdCommon:${PYTHONPATH}\n'
1004 >            txt += 'echo "PYTHONPATH=$PYTHONPATH"\n'
1005 >            ###################
1006              txt += 'fi\n'
1007              txt += '\n'
1008  
1009              pass
1010 <        
1010 >
1011          return txt
1012  
1013      def modifySteeringCards(self, nj):
1014          """
1015 <        modify the card provided by the user,
1015 >        modify the card provided by the user,
1016          writing a new card into share dir
1017          """
1018 <        
1018 >
1019      def executableName(self):
1020          if self.scriptExe: #CarlosDaniele
1021              return "sh "
# Line 982 | Line 1023 | class Cmssw(JobType):
1023              return self.executable
1024  
1025      def executableArgs(self):
1026 +        # FUTURE: This function tests the CMSSW version. Can be simplified as we drop support for old versions
1027          if self.scriptExe:#CarlosDaniele
1028              return   self.scriptExe + " $NJob"
1029 <        else:
1030 <            return " -p pset.cfg"
1029 >        else:
1030 >            version_array = self.scram.getSWVersion().split('_')
1031 >            major = 0
1032 >            minor = 0
1033 >            try:
1034 >                major = int(version_array[1])
1035 >                minor = int(version_array[2])
1036 >            except:
1037 >                msg = "Cannot parse CMSSW version string: " + "_".join(version_array) + " for major and minor release number!"
1038 >                raise CrabException(msg)
1039 >
1040 >            ex_args = ""
1041 >
1042 >            # Framework job report
1043 >            if major >= 1 and minor >= 5 :
1044 >                ex_args += " -j " + self.fjrFileName
1045 >
1046 >            # Type of cfg file
1047 >            if major >= 2 :
1048 >                ex_args += " -p pset.pycfg"
1049 >            else:
1050 >                ex_args += " -p pset.cfg"
1051 >            return ex_args
1052  
1053      def inputSandbox(self, nj):
1054          """
# Line 1003 | Line 1066 | class Cmssw(JobType):
1066          if not self.pset is None:
1067              inp_box.append(common.work_space.pathForTgz() + 'job/' + self.configFilename())
1068          ## additional input files
1069 <        for file in self.additional_inbox_files:
1070 <            inp_box.append(file)
1069 >        tgz = self.additionalInputFileTgz()
1070 >        inp_box.append(tgz)
1071          return inp_box
1072  
1073      def outputSandbox(self, nj):
# Line 1015 | Line 1078 | class Cmssw(JobType):
1078  
1079          ## User Declared output files
1080          for out in (self.output_file+self.output_file_sandbox):
1081 <            n_out = nj + 1
1081 >            n_out = nj + 1
1082              out_box.append(self.numberFile_(out,str(n_out)))
1083          return out_box
1084  
# Line 1030 | Line 1093 | class Cmssw(JobType):
1093          Returns part of a job script which renames the produced files.
1094          """
1095  
1096 <        txt = '\n'
1097 <        txt += '# directory content\n'
1096 >        txt = '\n#Written by cms_cmssw::wsRenameOutput\n'
1097 >        txt += 'echo ">>> current directory (SOFTWARE_DIR): $SOFTWARE_DIR" \n'
1098 >        txt += 'echo ">>> current directory content:"\n'
1099          txt += 'ls \n'
1100 +        txt += '\n'
1101  
1102 <        for fileWithSuffix in (self.output_file+self.output_file_sandbox):
1102 >        #txt += 'output_exit_status=0\n'
1103 >
1104 >        for fileWithSuffix in (self.output_file_sandbox):
1105              output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
1106              txt += '\n'
1107              txt += '# check output file\n'
1108 <            txt += 'ls '+fileWithSuffix+'\n'
1109 <            txt += 'ls_result=$?\n'
1110 <            txt += 'if [ $ls_result -ne 0 ] ; then\n'
1111 <            txt += '   echo "ERROR: Problem with output file"\n'
1112 <            if common.scheduler.boss_scheduler_name == 'condor_g':
1108 >            txt += 'if [ -e ./'+fileWithSuffix+' ] ; then\n'
1109 >            txt += '    mv '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
1110 >            txt += '    ln -s $RUNTIME_AREA/'+output_file_num+' $RUNTIME_AREA/'+fileWithSuffix+'\n'
1111 >            txt += 'else\n'
1112 >            #txt += '    exit_status=60302\n'
1113 >            #txt += '    echo "ERROR: Output file '+fileWithSuffix+' not found"\n'
1114 >            txt += '    echo "WARNING: Output file '+fileWithSuffix+' not found"\n'
1115 >            txt += '    job_exit_code=60302\n'
1116 >            if common.scheduler.name().upper() == 'CONDOR_G':
1117                  txt += '    if [ $middleware == OSG ]; then \n'
1118                  txt += '        echo "prepare dummy output file"\n'
1119                  txt += '        echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
1120                  txt += '    fi \n'
1050            txt += 'else\n'
1051            txt += '   cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
1121              txt += 'fi\n'
1053      
1054        txt += 'cd $RUNTIME_AREA\n'
1055        txt += 'cd $RUNTIME_AREA\n'
1056        ### OLI_DANIELE
1057        txt += 'if [ $middleware == OSG ]; then\n'  
1058        txt += '    cd $RUNTIME_AREA\n'
1059        txt += '    echo "Remove working directory: $WORKING_DIR"\n'
1060        txt += '    /bin/rm -rf $WORKING_DIR\n'
1061        txt += '    if [ -d $WORKING_DIR ] ;then\n'
1062        txt += '        echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
1063        txt += '        echo "JOB_EXIT_STATUS = 60999"\n'
1064        txt += '        echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
1065        txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
1066        txt += '        rm -f $RUNTIME_AREA/$repo \n'
1067        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1068        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1069        txt += '    fi\n'
1070        txt += 'fi\n'
1071        txt += '\n'
1122  
1123 <        file_list = ''
1074 <        ## Add to filelist only files to be possibly copied to SE
1075 <        for fileWithSuffix in self.output_file:
1123 >        for fileWithSuffix in (self.output_file):
1124              output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
1125 <            file_list=file_list+output_file_num+' '
1126 <        file_list=file_list[:-1]
1127 <        txt += 'file_list="'+file_list+'"\n'
1125 >            txt += '\n'
1126 >            txt += '# check output file\n'
1127 >            txt += 'if [ -e ./'+fileWithSuffix+' ] ; then\n'
1128 >            if (self.copy_data == 1):  # For OSG nodes, file is in $WORKING_DIR, should not be moved to $RUNTIME_AREA
1129 >                txt += '    mv '+fileWithSuffix+' '+output_file_num+'\n'
1130 >                txt += '    ln -s `pwd`/'+output_file_num+' $RUNTIME_AREA/'+fileWithSuffix+'\n'
1131 >            else:
1132 >                txt += '    mv '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
1133 >                txt += '    ln -s $RUNTIME_AREA/'+output_file_num+' $RUNTIME_AREA/'+fileWithSuffix+'\n'
1134 >            txt += 'else\n'
1135 >            #txt += '    exit_status=60302\n'
1136 >            #txt += '    echo "ERROR: Output file '+fileWithSuffix+' not found"\n'
1137 >            #txt += '    echo "JOB_EXIT_STATUS = $exit_status"\n'
1138 >            #txt += '    output_exit_status=$exit_status\n'
1139 >            txt += '    job_exit_code=60302\n'
1140 >            txt += '    echo "WARNING: Output file '+fileWithSuffix+' not found"\n'
1141 >            if common.scheduler.name().upper() == 'CONDOR_G':
1142 >                txt += '    if [ $middleware == OSG ]; then \n'
1143 >                txt += '        echo "prepare dummy output file"\n'
1144 >                txt += '        echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
1145 >                txt += '    fi \n'
1146 >            txt += 'fi\n'
1147 >        file_list = []
1148 >        for fileWithSuffix in (self.output_file):
1149 >             file_list.append(self.numberFile_(fileWithSuffix, '$NJob'))
1150  
1151 +        txt += 'file_list="'+string.join(file_list,' ')+'"\n'
1152 +        txt += '\n'
1153 +        txt += 'echo ">>> current directory (SOFTWARE_DIR): $SOFTWARE_DIR" \n'
1154 +        txt += 'echo ">>> current directory content:"\n'
1155 +        txt += 'ls \n'
1156 +        txt += '\n'
1157 +        txt += 'cd $RUNTIME_AREA\n'
1158 +        txt += 'echo ">>> current directory (RUNTIME_AREA):  $RUNTIME_AREA"\n'
1159          return txt
1160  
1161      def numberFile_(self, file, txt):
# Line 1088 | Line 1166 | class Cmssw(JobType):
1166          # take away last extension
1167          name = p[0]
1168          for x in p[1:-1]:
1169 <           name=name+"."+x
1169 >            name=name+"."+x
1170          # add "_txt"
1171          if len(p)>1:
1172 <          ext = p[len(p)-1]
1173 <          result = name + '_' + txt + "." + ext
1172 >            ext = p[len(p)-1]
1173 >            result = name + '_' + txt + "." + ext
1174          else:
1175 <          result = name + '_' + txt
1176 <        
1175 >            result = name + '_' + txt
1176 >
1177          return result
1178  
1179      def getRequirements(self, nj=[]):
1180          """
1181 <        return job requirements to add to jdl files
1181 >        return job requirements to add to jdl files
1182          """
1183          req = ''
1184          if self.version:
1185              req='Member("VO-cms-' + \
1186                   self.version + \
1187                   '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
1188 +        ## SL add requirement for OS version only if SL4
1189 +        #reSL4 = re.compile( r'slc4' )
1190 +        if self.executable_arch: # and reSL4.search(self.executable_arch):
1191 +            req+=' && Member("VO-cms-' + \
1192 +                 self.executable_arch + \
1193 +                 '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
1194  
1195          req = req + ' && (other.GlueHostNetworkAdapterOutboundIP)'
1196 +        if common.scheduler.name() == "glitecoll":
1197 +            req += ' && other.GlueCEStateStatus == "Production" '
1198  
1199          return req
1200  
# Line 1116 | Line 1202 | class Cmssw(JobType):
1202          """ return the config filename """
1203          return self.name()+'.cfg'
1204  
1119    ### OLI_DANIELE
1205      def wsSetupCMSOSGEnvironment_(self):
1206          """
1207          Returns part of a job script which is prepares
1208          the execution environment and which is common for all CMS jobs.
1209          """
1210 <        txt = '\n'
1211 <        txt += '   echo "### SETUP CMS OSG  ENVIRONMENT ###"\n'
1212 <        txt += '   if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
1213 <        txt += '      # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
1214 <        txt += '       source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
1215 <        txt += '   elif [ -f $OSG_APP/cmssoft/cms/cmsset_default.sh ] ;then\n'
1210 >        txt = '\n#Written by cms_cmssw::wsSetupCMSOSGEnvironment_\n'
1211 >        txt += '    echo ">>> setup CMS OSG environment:"\n'
1212 >        txt += '    echo "set SCRAM ARCH to ' + self.executable_arch + '"\n'
1213 >        txt += '    export SCRAM_ARCH='+self.executable_arch+'\n'
1214 >        txt += '    echo "SCRAM_ARCH = $SCRAM_ARCH"\n'
1215 >        txt += '    if [ -f $OSG_APP/cmssoft/cms/cmsset_default.sh ] ;then\n'
1216          txt += '      # Use $OSG_APP/cmssoft/cms/cmsset_default.sh to setup cms software\n'
1217 <        txt += '       source $OSG_APP/cmssoft/cms/cmsset_default.sh '+self.version+'\n'
1218 <        txt += '   else\n'
1219 <        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'
1220 <        txt += '       echo "JOB_EXIT_STATUS = 10020"\n'
1221 <        txt += '       echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1222 <        txt += '       dumpStatus $RUNTIME_AREA/$repo\n'
1223 <        txt += '       rm -f $RUNTIME_AREA/$repo \n'
1224 <        txt += '       echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1225 <        txt += '       echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1226 <        txt += '       exit 1\n'
1227 <        txt += '\n'
1228 <        txt += '       echo "Remove working directory: $WORKING_DIR"\n'
1229 <        txt += '       cd $RUNTIME_AREA\n'
1230 <        txt += '       /bin/rm -rf $WORKING_DIR\n'
1231 <        txt += '       if [ -d $WORKING_DIR ] ;then\n'
1232 <        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'
1233 <        txt += '            echo "JOB_EXIT_STATUS = 10017"\n'
1234 <        txt += '            echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
1235 <        txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
1236 <        txt += '            rm -f $RUNTIME_AREA/$repo \n'
1152 <        txt += '            echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1153 <        txt += '            echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1154 <        txt += '       fi\n'
1217 >        txt += '        source $OSG_APP/cmssoft/cms/cmsset_default.sh '+self.version+'\n'
1218 >        txt += '    else\n'
1219 >        #txt += '        echo "SET_CMS_ENV 10020 ==> ERROR $OSG_APP/cmssoft/cms/cmsset_default.sh file not found"\n'
1220 >        #txt += '        echo "JOB_EXIT_STATUS = 10020"\n'
1221 >        #txt += '        echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1222 >        #txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
1223 >        txt += '        echo "ERROR ==> $OSG_APP/cmssoft/cms/cmsset_default.sh file not found"\n'
1224 >        txt += '        job_exit_code=10020\n'
1225 >        txt += '        cd $RUNTIME_AREA\n'
1226 >        txt += '        echo ">>> current directory (RUNTIME_AREA): $RUNTIME_AREA"\n'
1227 >        txt += '        echo ">>> Remove working directory: $WORKING_DIR"\n'
1228 >        txt += '        /bin/rm -rf $WORKING_DIR\n'
1229 >        txt += '        if [ -d $WORKING_DIR ] ;then\n'
1230 >        #txt += '            echo "SET_CMS_ENV 10017 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after $OSG_APP/cmssoft/cms/cmsset_default.sh file not found"\n'
1231 >        #txt += '            echo "JOB_EXIT_STATUS = 10017"\n'
1232 >        #txt += '            echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
1233 >        #txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
1234 >        txt += '            echo "ERROR ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after $OSG_APP/cmssoft/cms/cmsset_default.sh file not found"\n'
1235 >        txt += '            job_exit_code=10017\n'
1236 >        txt += '        fi\n'
1237          txt += '\n'
1238 <        txt += '       exit 1\n'
1239 <        txt += '   fi\n'
1238 >        #txt += '        exit 1\n'
1239 >        txt += '        func_exit\n'
1240 >        txt += '    fi\n'
1241          txt += '\n'
1242 <        txt += '   echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1243 <        txt += '   echo " END SETUP CMS OSG  ENVIRONMENT "\n'
1242 >        txt += '    echo "==> setup cms environment ok"\n'
1243 >        txt += '    echo "SCRAM_ARCH = $SCRAM_ARCH"\n'
1244  
1245          return txt
1246 <
1246 >
1247      ### OLI_DANIELE
1248      def wsSetupCMSLCGEnvironment_(self):
1249          """
1250          Returns part of a job script which is prepares
1251          the execution environment and which is common for all CMS jobs.
1252          """
1253 <        txt  = '   \n'
1254 <        txt += '   echo " ### SETUP CMS LCG  ENVIRONMENT ### "\n'
1255 <        txt += '   if [ ! $VO_CMS_SW_DIR ] ;then\n'
1256 <        txt += '       echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
1257 <        txt += '       echo "JOB_EXIT_STATUS = 10031" \n'
1258 <        txt += '       echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
1259 <        txt += '       dumpStatus $RUNTIME_AREA/$repo\n'
1260 <        txt += '       rm -f $RUNTIME_AREA/$repo \n'
1261 <        txt += '       echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1262 <        txt += '       echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1263 <        txt += '       exit 1\n'
1264 <        txt += '   else\n'
1265 <        txt += '       echo "Sourcing environment... "\n'
1266 <        txt += '       if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1267 <        txt += '           echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1268 <        txt += '           echo "JOB_EXIT_STATUS = 10020"\n'
1269 <        txt += '           echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1270 <        txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
1271 <        txt += '           rm -f $RUNTIME_AREA/$repo \n'
1272 <        txt += '           echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1273 <        txt += '           echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1274 <        txt += '           exit 1\n'
1275 <        txt += '       fi\n'
1276 <        txt += '       echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1277 <        txt += '       source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1278 <        txt += '       result=$?\n'
1279 <        txt += '       if [ $result -ne 0 ]; then\n'
1280 <        txt += '           echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1281 <        txt += '           echo "JOB_EXIT_STATUS = 10032"\n'
1282 <        txt += '           echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1283 <        txt += '           dumpStatus $RUNTIME_AREA/$repo\n'
1284 <        txt += '           rm -f $RUNTIME_AREA/$repo \n'
1285 <        txt += '           echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1286 <        txt += '           echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1287 <        txt += '           exit 1\n'
1288 <        txt += '       fi\n'
1289 <        txt += '   fi\n'
1290 <        txt += '   \n'
1291 <        txt += '   echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1292 <        txt += '   echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1253 >        txt = '\n#Written by cms_cmssw::wsSetupCMSLCGEnvironment_\n'
1254 >        txt += '    echo ">>> setup CMS LCG environment:"\n'
1255 >        txt += '    echo "set SCRAM ARCH and BUILD_ARCH to ' + self.executable_arch + ' ###"\n'
1256 >        txt += '    export SCRAM_ARCH='+self.executable_arch+'\n'
1257 >        txt += '    export BUILD_ARCH='+self.executable_arch+'\n'
1258 >        txt += '    if [ ! $VO_CMS_SW_DIR ] ;then\n'
1259 >        #txt += '        echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
1260 >        #txt += '        echo "JOB_EXIT_STATUS = 10031" \n'
1261 >        #txt += '        echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
1262 >        #txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
1263 >        #txt += '        exit 1\n'
1264 >        txt += '        echo "ERROR ==> CMS software dir not found on WN `hostname`"\n'
1265 >        txt += '        job_exit_code=10031\n'
1266 >        txt += '        func_exit\n'
1267 >        txt += '    else\n'
1268 >        txt += '        echo "Sourcing environment... "\n'
1269 >        txt += '        if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1270 >        #txt += '            echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1271 >        #txt += '            echo "JOB_EXIT_STATUS = 10020"\n'
1272 >        #txt += '            echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1273 >        #txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
1274 >        #txt += '            exit 1\n'
1275 >        txt += '            echo "ERROR ==> cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1276 >        txt += '            job_exit_code=10020\n'
1277 >        txt += '            func_exit\n'
1278 >        txt += '        fi\n'
1279 >        txt += '        echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1280 >        txt += '        source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1281 >        txt += '        result=$?\n'
1282 >        txt += '        if [ $result -ne 0 ]; then\n'
1283 >        #txt += '            echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1284 >        #txt += '            echo "JOB_EXIT_STATUS = 10032"\n'
1285 >        #txt += '            echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1286 >        #txt += '            dumpStatus $RUNTIME_AREA/$repo\n'
1287 >        #txt += '            exit 1\n'
1288 >        txt += '            echo "ERROR ==> problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1289 >        txt += '            job_exit_code=10032\n'
1290 >        txt += '            func_exit\n'
1291 >        txt += '        fi\n'
1292 >        txt += '    fi\n'
1293 >        txt += '    \n'
1294 >        txt += '    echo "==> setup cms environment ok"\n'
1295 >        return txt
1296 >
1297 >    ### FEDE FOR DBS OUTPUT PUBLICATION
1298 >    def modifyReport(self, nj):
1299 >        """
1300 >        insert the part of the script that modifies the FrameworkJob Report
1301 >        """
1302 >
1303 >        txt = '\n#Written by cms_cmssw::modifyReport\n'
1304 >        try:
1305 >            publish_data = int(self.cfg_params['USER.publish_data'])
1306 >        except KeyError:
1307 >            publish_data = 0
1308 >        if (publish_data == 1):
1309 >            
1310 >            txt += 'if [ $copy_exit_status -eq 0 ]; then\n'
1311 >            txt += '    echo ">>> Modify Job Report:" \n'
1312 >            txt += '    chmod a+x $SOFTWARE_DIR/ProdCommon/ProdCommon/FwkJobRep/ModifyJobReport.py\n'
1313 >            #txt += '    if [ -z "$SE" ]; then\n'
1314 >            #txt += '        SE="" \n'
1315 >            #txt += '    fi \n'
1316 >            #txt += '    if [ -z "$SE_PATH" ]; then\n'
1317 >            #txt += '        SE_PATH="" \n'
1318 >            #txt += '    fi \n'
1319 >            txt += '    echo "SE = $SE"\n'
1320 >            txt += '    echo "SE_PATH = $SE_PATH"\n'
1321 >
1322 >            processedDataset = self.cfg_params['USER.publish_data_name']
1323 >            txt += '    ProcessedDataset='+processedDataset+'\n'
1324 >            #txt += '    if [ "$SE_PATH" == "" ]; then\n'
1325 >            #txt += '        FOR_LFN=/copy_problems/ \n'
1326 >            #txt += '    else \n'
1327 >            #txt += '        tmp=`echo $SE_PATH | awk -F \'store\' \'{print$2}\'` \n'
1328 >            #txt += '        FOR_LFN=/store$tmp \n'
1329 >            #txt += '    fi \n'
1330 >            txt += '    tmp=`echo $SE_PATH | awk -F \'store\' \'{print$2}\'` \n'
1331 >            txt += '    FOR_LFN=/store$tmp \n'
1332 >            txt += '    echo "ProcessedDataset = $ProcessedDataset"\n'
1333 >            txt += '    echo "FOR_LFN = $FOR_LFN" \n'
1334 >            txt += '    echo "CMSSW_VERSION = $CMSSW_VERSION"\n\n'
1335 >            txt += '    echo "$SOFTWARE_DIR/ProdCommon/ProdCommon/FwkJobRep/ModifyJobReport.py crab_fjr_$NJob.xml $NJob $FOR_LFN $PrimaryDataset $DataTier $ProcessedDataset $ApplicationFamily $executable $CMSSW_VERSION $PSETHASH $SE $SE_PATH"\n'
1336 >            txt += '    $SOFTWARE_DIR/ProdCommon/ProdCommon/FwkJobRep/ModifyJobReport.py crab_fjr_$NJob.xml $NJob $FOR_LFN $PrimaryDataset $DataTier $ProcessedDataset $ApplicationFamily $executable $CMSSW_VERSION $PSETHASH $SE $SE_PATH\n'
1337 >
1338 >            txt += '    modifyReport_result=$?\n'
1339 >            txt += '    if [ $modifyReport_result -ne 0 ]; then\n'
1340 >            txt += '        modifyReport_result=70500\n'
1341 >            txt += '        job_exit_code=$modifyReport_result\n'
1342 >            txt += '        echo "ModifyReportResult=$modifyReport_result" | tee -a $RUNTIME_AREA/$repo\n'
1343 >            txt += '        echo "WARNING: Problem with ModifyJobReport"\n'
1344 >            txt += '    else\n'
1345 >            txt += '        mv NewFrameworkJobReport.xml crab_fjr_$NJob.xml\n'
1346 >            txt += '    fi\n'
1347 >            txt += 'fi\n'
1348 >        return txt
1349 >
1350 >    def cleanEnv(self):
1351 >        txt = '\n#Written by cms_cmssw::cleanEnv\n'
1352 >        txt += 'if [ $middleware == OSG ]; then\n'
1353 >        txt += '    cd $RUNTIME_AREA\n'
1354 >        txt += '    echo ">>> current directory (RUNTIME_AREA): $RUNTIME_AREA"\n'
1355 >        txt += '    echo ">>> Remove working directory: $WORKING_DIR"\n'
1356 >        txt += '    /bin/rm -rf $WORKING_DIR\n'
1357 >        txt += '    if [ -d $WORKING_DIR ] ;then\n'
1358 >        #txt += '        echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
1359 >        #txt += '        echo "JOB_EXIT_STATUS = 60999"\n'
1360 >        #txt += '        echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
1361 >        #txt += '        dumpStatus $RUNTIME_AREA/$repo\n'
1362 >        txt += '        echo "ERROR ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
1363 >        txt += '        job_exit_code=60999\n'
1364 >        txt += '        func_exit\n'
1365 >        txt += '    fi\n'
1366 >        txt += 'fi\n'
1367 >        txt += '\n'
1368          return txt
1369  
1370      def setParam_(self, param, value):
# Line 1215 | Line 1373 | class Cmssw(JobType):
1373      def getParams(self):
1374          return self._params
1375  
1218    def setTaskid_(self):
1219        self._taskId = self.cfg_params['taskId']
1220        
1221    def getTaskid(self):
1222        return self._taskId
1223
1224 #######################################################################
1376      def uniquelist(self, old):
1377          """
1378          remove duplicates from a list
# Line 1230 | Line 1381 | class Cmssw(JobType):
1381          for e in old:
1382              nd[e]=0
1383          return nd.keys()
1384 +
1385 +
1386 +    def checkOut(self, limit):
1387 +        """
1388 +        check the dimension of the output files
1389 +        """
1390 +        txt = '\n#Written by cms_cmssw::checkOut\n'
1391 +        txt += 'echo ">>> Starting output sandbox limit check :"\n'
1392 +        listOutFiles = []
1393 +        txt += 'stdoutFile=`ls *stdout` \n'
1394 +        txt += 'stderrFile=`ls *stderr` \n'
1395 +        if (self.return_data == 1):
1396 +            for file in (self.output_file+self.output_file_sandbox):
1397 +                listOutFiles.append(self.numberFile_(file, '$NJob'))
1398 +            listOutFiles.append('$stdoutFile')
1399 +            listOutFiles.append('$stderrFile')
1400 +        else:
1401 +            for file in (self.output_file_sandbox):
1402 +                listOutFiles.append(self.numberFile_(file, '$NJob'))
1403 +            listOutFiles.append('$stdoutFile')
1404 +            listOutFiles.append('$stderrFile')
1405 +
1406 +        txt += 'echo "output files: '+string.join(listOutFiles,' ')+'"\n'
1407 +        txt += 'filesToCheck="'+string.join(listOutFiles,' ')+'"\n'
1408 +        txt += 'ls -gGhrta;\n'
1409 +        txt += 'sum=0;\n'
1410 +        txt += 'for file in $filesToCheck ; do\n'
1411 +        txt += '    if [ -e $file ]; then\n'
1412 +        txt += '        tt=`ls -gGrta $file | awk \'{ print $3 }\'`\n'
1413 +        txt += '        sum=`expr $sum + $tt`\n'
1414 +        txt += '    else\n'
1415 +        txt += '        echo "WARNING: output file $file not found!"\n'
1416 +        txt += '    fi\n'
1417 +        txt += 'done\n'
1418 +        txt += 'echo "Total Output dimension: $sum";\n'
1419 +        txt += 'limit='+str(limit)+';\n'
1420 +        txt += 'echo "WARNING: output files size limit is set to: $limit";\n'
1421 +        txt += 'if [ $limit -lt $sum ]; then\n'
1422 +        txt += '    echo "WARNING: output files have to big size - something will be lost;"\n'
1423 +        txt += '    echo "         checking the output file sizes..."\n'
1424 +        txt += '    tot=0;\n'
1425 +        txt += '    for filefile in $filesToCheck ; do\n'
1426 +        txt += '        dimFile=`ls -gGrta $filefile | awk \'{ print $3 }\';`\n'
1427 +        txt += '        tot=`expr $tot + $tt`;\n'
1428 +        txt += '        if [ $limit -lt $dimFile ]; then\n'
1429 +        txt += '            echo "deleting file: $filefile";\n'
1430 +        txt += '            rm -f $filefile\n'
1431 +        txt += '        elif [ $limit -lt $tot ]; then\n'
1432 +        txt += '            echo "deleting file: $filefile";\n'
1433 +        txt += '            rm -f $filefile\n'
1434 +        txt += '        else\n'
1435 +        txt += '            echo "saving file: $filefile"\n'
1436 +        txt += '        fi\n'
1437 +        txt += '    done\n'
1438 +
1439 +        txt += '    ls -agGhrt\n'
1440 +        txt += '    echo "WARNING: output files are too big in dimension: can not put in the output_sandbox."\n'
1441 +        #txt += '    echo "JOB_EXIT_STATUS = 70000"\n'
1442 +        #txt += '    exit_status=70000\n'
1443 +        txt += '    job_exit_code=70000\n'
1444 +        txt += 'else\n'
1445 +        txt += '    echo "Total Output dimension $sum is fine."\n'
1446 +        txt += 'fi\n'
1447 +        txt += 'echo "Ending output sandbox limit check"\n'
1448 +        return txt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines