Skip to content

Instantly share code, notes, and snippets.

@wiso
Created May 9, 2017 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wiso/7d94702fce267c5ebe7c3412373e809f to your computer and use it in GitHub Desktop.
Save wiso/7d94702fce267c5ebe7c3412373e809f to your computer and use it in GitHub Desktop.
Simple wrapper to make Roofit workspace manipulation more safe with python
def safe_factory(func):
def wrapper(self, *args):
result = func(self, *args)
if not result:
raise ValueError('invalid factory input "%s"' % args)
return result
return wrapper
ROOT.RooWorkspace.factory = safe_factory(ROOT.RooWorkspace.factory)
def safe_decorator(func):
def wrapper(self, *args):
result = func(self, *args)
if not result:
raise ValueError('cannot find %s' % args[0])
return result
return wrapper
ROOT.RooWorkspace.data = safe_decorator(ROOT.RooWorkspace.data)
ROOT.RooWorkspace.obj = safe_decorator(ROOT.RooWorkspace.obj)
ROOT.RooWorkspace.var = safe_decorator(ROOT.RooWorkspace.var)
ROOT.RooWorkspace.pdf = safe_decorator(ROOT.RooWorkspace.pdf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment