<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _master_tops(self):
        '''
        Evaluate master_tops locally
        '''
        if 'id' not in self.opts:
            log.error('Received call for external nodes without an id')
            return {}
        if not salt.utils.verify.valid_id(self.opts, self.opts['id']):
            return {}
        # Evaluate all configured master_tops interfaces

        grains = {}
        ret = {}

        if 'grains' in self.opts:
            grains = self.opts['grains']
        for fun in self.tops:
            if fun not in self.opts.get('master_tops', {}):
                continue
            try:
                ret.update(self.tops[fun](opts=self.opts, grains=grains))
            except Exception as exc:
                # If anything happens in the top generation, log it and move on
                log.error(
                    'Top function %s failed with error %s for minion %s',
                    fun, exc, self.opts['id']
                )
        return ret