summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2011-09-30 10:56:15 -0400
committerStan Seibert <stan@mtrr.org>2011-09-30 10:56:15 -0400
commit7a3b6dacebb30658ccae38280452a4659d3e4a09 (patch)
treed33a883cde2ffd90fc337620c8f2362db09a932c
parentda2d77605c814c0ce4bfd8c08ec742a275d856af (diff)
downloadchroma-7a3b6dacebb30658ccae38280452a4659d3e4a09.tar.gz
chroma-7a3b6dacebb30658ccae38280452a4659d3e4a09.tar.bz2
chroma-7a3b6dacebb30658ccae38280452a4659d3e4a09.zip
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
-rw-r--r--chroma/io/root.py3
-rw-r--r--chroma/parabola.py3
-rw-r--r--chroma/rootimport.py10
3 files changed, 14 insertions, 2 deletions
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