def submit(self, sample):
        cleanup = [] # not so much to clean up any more

        result = {'stdout': 'Not run'}

        try:
            sample.set_curr_dataset(self.dataset)
        except KeyError:
            print "\033[1m warning: \033[0m sample %s not submitted, doesn't have dataset %s" % (sample.name, self.dataset)
            return result

        cfg_fn, cfg = self.cfg(sample)
        pset_orig_fn, pset_fn, pset = self.pset(sample)

        assert pset_fn.endswith('.py')
        cleanup.append(pset_fn + 'c')

        if not self.testing:
            working_dir = os.path.join(cfg.General.workArea, 'crab_' + cfg.General.requestName)
            new_working_dir = os.path.join(cfg.General.workArea, 'crab_' + sample.name)

            if not os.path.isdir(working_dir) and not os.path.isdir(new_working_dir):
                success, nretries = False, 10
                while not success and nretries:
                    result = crab_command('submit', config = cfg)
                    should_retry = result.get('status', '') == 'HTTPException' and result.has_key('HTTPException')
                    if should_retry:
                        nretries -= 1
                        print sample.name, 'crapped out with HTTPException,', nretries, 'tries left'
                        shutil.rmtree(working_dir)
                    else:
                        open(os.path.join(working_dir, 'cs_ex'), 'wt').write(self.ex_str)
                        success = True

                if success:
                    # The requestName contains the full batch_name so the entries in dashboard
                    # are distinguishable, but once the job is submitted the local directory
                    # name can be changed back to just having the sample name.
                    shutil.move(working_dir, new_working_dir)
                else:
                    print '\033[1m warning: \033[0m sample %s not submitted, nretries exceeded' % (sample.name)
            else:
                print '\033[1m warning: \033[0m sample %s not submitted, directory %s already exists' % (sample.name, working_dir)

            if cleanup:
                os.system('rm -f %s' % ' '.join(cleanup))
        else:
            print 'in testing mode, not submitting anything.'
            diff_out, diff_ret = popen('diff -uN %s %s' % (self.pset_template_fn, pset_orig_fn), return_exit_code=True)
            if diff_ret != 0:
                print '.py diff:\n---------'
                print diff_out
                raw_input('continue?')
                print
            print 'crab.cfg:\n---------'
            print open(cfg_fn).read()
            raw_input('continue?')
            print '\n'

        return result
Exemple #2
0
    def pset(self, sample):
        pset = open(self.pset_template_fn).read()
        if self.pset_modifier is not None:
            ret = self.pset_modifier(sample)
            if type(ret) != tuple:
                to_add = ret
                to_replace = []
            else:
                to_add, to_replace = ret
            for a,b,err in to_replace:
                if pset.find(a) < 0:
                    raise ValueError(err)
                pset = pset.replace(a,b)
            if to_add:
                pset += '\n' + '\n'.join(to_add) + '\n'

        pset_fn = self.pset_fn_pattern % sample
        pset_orig_fn = pset_fn.replace('.py', '_orig.py')

        extra = ''
        if self.modify_pset_hash:
            extra += '\nprocess.dummyForPsetHash = cms.PSet(dummy = cms.string(%r))' % (str(datetime.now()) + sample.dataset)
        extra += "\nopen(%r, 'wt').write(process.dumpPython())" % pset_fn
        open(pset_orig_fn, 'wt').write(pset + extra)

        out = popen('python %s' % pset_orig_fn)
        open(pset_orig_fn, 'wt').write(pset)

        return pset_orig_fn, pset_fn, pset
Exemple #3
0
    def submit(self, sample):
        cleanup = [] # not so much to clean up any more

        result = {'stdout': 'Not run'}

        try:
            sample.set_curr_dataset(self.dataset)
        except KeyError:
            print "\033[1m warning: \033[0m sample %s not submitted, doesn't have dataset %s" % (sample.name, self.dataset)
            return result

        cfg_fn, cfg = self.cfg(sample)
        pset_orig_fn, pset_fn, pset = self.pset(sample)

        assert pset_fn.endswith('.py')
        cleanup.append(pset_fn + 'c')

        if not self.testing:
            working_dir = os.path.join(cfg.General.workArea, 'crab_' + cfg.General.requestName)

            if not os.path.isdir(working_dir):
                result = crab_command('submit', config = cfg)
            else:
                print '\033[1m warning: \033[0m sample %s not submitted, directory %s already exists' % (sample.name, working_dir)

            if cleanup:
                os.system('rm -f %s' % ' '.join(cleanup))
        else:
            print 'in testing mode, not submitting anything.'
            diff_out, diff_ret = popen('diff -uN %s %s' % (self.pset_template_fn, pset_orig_fn), return_exit_code=True)
            if diff_ret != 0:
                print '.py diff:\n---------'
                print diff_out
                raw_input('continue?')
                print
            print 'crab.cfg:\n---------'
            print open(cfg_fn).read()
            raw_input('continue?')
            print '\n'

        return result
    def pset(self, sample):
        pset = open(self.pset_template_fn).read()
        if self.pset_modifier is not None:
            ret = self.pset_modifier(sample)
            if type(ret) != tuple:
                to_add = ret
                to_replace = []
            else:
                to_add, to_replace = ret
            for a, b, err in to_replace:
                if pset.find(a) < 0:
                    raise ValueError(err)
                pset = pset.replace(a, b)
            if to_add:
                pset += '\n' + '\n'.join(to_add) + '\n'

        pset_fn = self.pset_fn_pattern % sample
        pset_orig_fn = pset_fn.replace('.py', '_orig.py')

        extra = ''
        if self.modify_pset_hash:
            extra += '\nprocess.dummyForPsetHash = cms.PSet(dummy = cms.string(%r))' % (
                str(datetime.now()) + sample.dataset)
        extra += "\nopen(%r, 'wt').write(process.dumpPython())\n" % pset_fn
        open(pset_orig_fn, 'wt').write(pset + extra)

        out, ret = popen('python %s' % pset_orig_fn, return_exit_code=True)
        if ret:
            print '\nproblem in dumpPython, output:'
            print out
            raise RuntimeError('problem evaluating original pset')

        # handle problem with crap done by RecoEgamma.ElectronIdentification.Identification/mvaElectronID_Fall17_iso_V1_cff
        # fixed in dumpPython in 10_2_X
        pset_new = open(pset_fn).read()
        open(pset_fn,
             'wt').write('inf, nan = float("inf"), float("nan")\n' + pset_new)

        open(pset_orig_fn, 'wt').write(pset)

        return pset_orig_fn, pset_fn, pset
    def pset(self, sample):
        pset = open(self.pset_template_fn).read()
        if self.pset_modifier is not None:
            ret = self.pset_modifier(sample)
            if type(ret) != tuple:
                to_add = ret
                to_replace = []
            else:
                to_add, to_replace = ret
            for a,b,err in to_replace:
                if pset.find(a) < 0:
                    raise ValueError(err)
                pset = pset.replace(a,b)
            if to_add:
                pset += '\n' + '\n'.join(to_add) + '\n'

        pset_fn = self.pset_fn_pattern % sample
        pset_orig_fn = pset_fn.replace('.py', '_orig.py')

        extra = ''
        if self.modify_pset_hash:
            extra += '\nprocess.dummyForPsetHash = cms.PSet(dummy = cms.string(%r))' % (str(datetime.now()) + sample.dataset)
        extra += "\nopen(%r, 'wt').write(process.dumpPython())\n" % pset_fn
        open(pset_orig_fn, 'wt').write(pset + extra)

        out, ret = popen('python %s' % pset_orig_fn, return_exit_code=True)
        if ret:
            print '\nproblem in dumpPython, output:'
            print out
            raise RuntimeError('problem evaluating original pset')

        # handle problem with crap done by RecoEgamma.ElectronIdentification.Identification/mvaElectronID_Fall17_iso_V1_cff
        # fixed in dumpPython in 10_2_X
        pset_new = open(pset_fn).read()
        open(pset_fn, 'wt').write('inf, nan = float("inf"), float("nan")\n' + pset_new)

        open(pset_orig_fn, 'wt').write(pset)

        return pset_orig_fn, pset_fn, pset
    def submit(self, sample):
        cleanup = []  # not so much to clean up any more

        result = {'stdout': 'Not run'}

        try:
            sample.set_curr_dataset(self.dataset)
        except KeyError:
            print "\033[1m warning: \033[0m sample %s not submitted, doesn't have dataset %s" % (
                sample.name, self.dataset)
            return result

        cfg_fn, cfg = self.cfg(sample)
        pset_orig_fn, pset_fn, pset = self.pset(sample)

        assert pset_fn.endswith('.py')
        cleanup.append(pset_fn + 'c')

        if not self.testing:
            working_dir = os.path.join(cfg.General.workArea,
                                       'crab_' + cfg.General.requestName)
            new_working_dir = os.path.join(cfg.General.workArea,
                                           'crab_' + sample.name)

            if not os.path.isdir(working_dir) and not os.path.isdir(
                    new_working_dir):
                success, nretries = False, 10
                while not success and nretries:
                    result = crab_command('submit', config=cfg)
                    should_retry = result.get(
                        'status', '') == 'HTTPException' and result.has_key(
                            'HTTPException')
                    if should_retry:
                        nretries -= 1
                        print sample.name, 'crapped out with HTTPException,', nretries, 'tries left'
                        shutil.rmtree(working_dir)
                    else:
                        open(os.path.join(working_dir, 'cs_ex'),
                             'wt').write(self.ex_str)
                        success = True

                if success:
                    # The requestName contains the full batch_name so the entries in dashboard
                    # are distinguishable, but once the job is submitted the local directory
                    # name can be changed back to just having the sample name.
                    shutil.move(working_dir, new_working_dir)
                else:
                    print '\033[1m warning: \033[0m sample %s not submitted, nretries exceeded' % (
                        sample.name)
            else:
                print '\033[1m warning: \033[0m sample %s not submitted, directory %s already exists' % (
                    sample.name, working_dir)

            if cleanup:
                os.system('rm -f %s' % ' '.join(cleanup))
        else:
            print 'in testing mode, not submitting anything.'
            diff_out, diff_ret = popen('diff -uN %s %s' %
                                       (self.pset_template_fn, pset_orig_fn),
                                       return_exit_code=True)
            if diff_ret != 0:
                print '.py diff:\n---------'
                print diff_out
                raw_input('continue?')
                print
            print 'crab.cfg:\n---------'
            print open(cfg_fn).read()
            raw_input('continue?')
            print '\n'

        return result