def method_file_cd(f):
    """
    A decorator to cd back to the original directory where this object was
    created (useful for any calls to TObject.Write).
    This function can decorate methods.
    """
    @wraps(f)
    def wrapper(self, *args, **kwargs):
        with preserve_current_directory():
            self.GetDirectory().cd()
            return f(self, *args, **kwargs)
    return wrapper