Skip to content

Instantly share code, notes, and snippets.

@cshimmin
Last active October 14, 2015 15:54
Show Gist options
  • Save cshimmin/9985307 to your computer and use it in GitHub Desktop.
Save cshimmin/9985307 to your computer and use it in GitHub Desktop.
Example of loading RootCore packages from python.
import sys, os
import ROOT as r
# prohibit root from hijacking command-line args
r.PyConfig.IgnoreCommandLineOptions = True
try:
ROOTCORE_PATH = os.environ['ROOTCOREDIR']
except KeyError:
print >>sys.stderr, "Warning! $ROOTCOREDIR env. variable is not set. Did you configure RootCore?"
ROOTCORE_PATH = None
''' Decorator for methods that should only be run once. '''
def run_once(f):
def wrapper(*args, **kwargs):
if not wrapper.has_run:
wrapper.has_run = True
return f(*args, **kwargs)
wrapper.has_run = False
return wrapper
'''
Call this method anytime you're going to use code that requires one of the
libraries managed by RootCore. You can call it as many times as you want;
the first one loads and subsequent calls will be a no-op.
'''
@run_once
def require_rootcore():
r.gROOT.ProcessLine('.x %s' % os.path.join(ROOTCORE_PATH, 'scripts', 'load_packages.C'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment