def ws_contains(ws, key):
    """Check if RooWorkspace contains an object."""
    if isinstance(key, str):
        return bool(ws.obj(key))
    try:
        obj = ws.obj(key if isinstance(key, str) else key.GetName())
        return obj == key
    except Exception:
        return False