<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def root(self, cls=None, level=0):
 """ Returns the top-most HubComponent in the hierarchy. If `cls` is not None, then return the top-most attribute HubComponent that is an instance of class `cls`. For a fully-constructed track hub (and `cls=None`), this should return a a Hub object for every component in the hierarchy. """

        if cls is None:
            if self.parent is None:
                return self, level
        else:
            if isinstance(self, cls):
                if not isinstance(self.parent, cls):
                    return self, level

        if self.parent is None:
            return None, None

        return self.parent.root(cls, level - 1)