From 7a3b6dacebb30658ccae38280452a4659d3e4a09 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Fri, 30 Sep 2011 10:56:15 -0400 Subject: ROOT sucks and the TApplication object created by PyROOT interprets the contents of sys.argv whether you want it to or not. A simple hack is to blank out sys.argv around the point where you import ROOT. As an additional requirement, you have to actually use the ROOT module for something (even just looking up a class) in order for the TApplication to be initialized, so you can't just replace sys.argv with an empty array around the ROOT import. To ensure this is always done correctly, all Chroma modules that need ROOT should obtain it by: from chroma.rootimport import ROOT --- chroma/io/root.py | 3 ++- chroma/parabola.py | 3 ++- chroma/rootimport.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 chroma/rootimport.py diff --git a/chroma/io/root.py b/chroma/io/root.py index 55f7858..3fb7062 100644 --- a/chroma/io/root.py +++ b/chroma/io/root.py @@ -1,9 +1,10 @@ -import ROOT import os, os.path import shutil import numpy as np import chroma.event as event +from chroma.rootimport import ROOT + # Create .chroma directory if it doesn't exist chroma_dir = os.path.expanduser('~/.chroma') if not os.path.isdir(chroma_dir): diff --git a/chroma/parabola.py b/chroma/parabola.py index f4160fb..425f71b 100644 --- a/chroma/parabola.py +++ b/chroma/parabola.py @@ -1,7 +1,8 @@ import numpy as np import uncertainties from uncertainties import unumpy -import ROOT + +from chroma.rootimport import ROOT def build_design_matrix(x, y): y_invsigma = 1.0/unumpy.std_devs(y) diff --git a/chroma/rootimport.py b/chroma/rootimport.py new file mode 100644 index 0000000..6bcb6f6 --- /dev/null +++ b/chroma/rootimport.py @@ -0,0 +1,10 @@ +# TApplication is so incredibly annoying. +# STOP SNOOPING THE ARGUMENT LIST AND PRINTING BOGUS HELP MESSAGES!! +import sys +_argv = sys.argv +sys.argv = [] +import ROOT +# Have to do something with the module to get TApplication initialized +ROOT.TObject # This just fetches the class and does nothing else +sys.argv = _argv +del _argv -- cgit