Created
May 9, 2017 08:38
-
-
Save wiso/7d94702fce267c5ebe7c3412373e809f to your computer and use it in GitHub Desktop.
Simple wrapper to make Roofit workspace manipulation more safe with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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