<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _get_head_block(self, request):
 """Fetches the request specified head block, or the chain head. Note: This method will fail if `_block_store` has not been set Args: request (object):
 The parsed protobuf request object Returns: Block: the block object at the head of the requested chain Raises: ResponseFailed: Failed to retrieve a head block """

        if request.head_id:
            if self._id_regex.fullmatch(request.head_id) is None:
                LOGGER.debug('Invalid head id requested: %s', request.head_id)
                raise _ResponseFailed(self._status.NO_ROOT)
            try:
                return self._block_store[request.head_id]
            except KeyError as e:
                LOGGER.debug('Unable to find block "%s" in store', e)
                raise _ResponseFailed(self._status.NO_ROOT)

        else:
            return self._get_chain_head()