<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _set_root(self, request):
 """Sets the root of the merkle tree, returning any head id used. Note: This method will fail if `_tree` has not been set Args: request (object):
 The parsed protobuf request object Returns: str: the state root of the head block used to specify the root Raises: ResponseFailed: Failed to set the root if the merkle tree """

        if request.state_root:
            root = request.state_root
        else:
            head = self._get_chain_head()
            root = head.state_root_hash

        try:
            self._tree.set_merkle_root(root)
        except KeyError as e:
            LOGGER.debug('Unable to find root "%s" in database', e)
            raise _ResponseFailed(self._status.NO_ROOT)

        return root