From bbad0212924f725085c63d4a9133a9d73110f11a Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Fri, 30 Sep 2011 11:30:52 -0400 Subject: Test if root.C classes have been loaded before loading in root.py. Prevents printed warnings when the user already has a .rootlogon.C to load the Chroma ROOT classes. --- chroma/io/root.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/chroma/io/root.py b/chroma/io/root.py index 3fb7062..b74a887 100644 --- a/chroma/io/root.py +++ b/chroma/io/root.py @@ -5,22 +5,24 @@ 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): - if os.path.exists(chroma_dir): - raise Exception('$HOME/.chroma file exists where directory should be') - else: - os.mkdir(chroma_dir) -# Check if latest ROOT file is present -package_root_C = os.path.join(os.path.dirname(__file__), 'root.C') -home_root_C = os.path.join(chroma_dir, 'root.C') -if not os.path.exists(home_root_C) or \ - os.stat(package_root_C).st_mtime > os.stat(home_root_C).st_mtime: - shutil.copy2(src=package_root_C, dst=home_root_C) -# Import this C file for access to data structure -ROOT.gROOT.ProcessLine('.L '+home_root_C+'+') - +# Check if we have already imported the ROOT class due to a user's +# rootlogon.C script +if not hasattr(ROOT, 'Vertex') or not hasattr(ROOT, 'Channel'): + # Create .chroma directory if it doesn't exist + chroma_dir = os.path.expanduser('~/.chroma') + if not os.path.isdir(chroma_dir): + if os.path.exists(chroma_dir): + raise Exception('$HOME/.chroma file exists where directory should be') + else: + os.mkdir(chroma_dir) + # Check if latest ROOT file is present + package_root_C = os.path.join(os.path.dirname(__file__), 'root.C') + home_root_C = os.path.join(chroma_dir, 'root.C') + if not os.path.exists(home_root_C) or \ + os.stat(package_root_C).st_mtime > os.stat(home_root_C).st_mtime: + shutil.copy2(src=package_root_C, dst=home_root_C) + # Import this C file for access to data structure + ROOT.gROOT.ProcessLine('.L '+home_root_C+'+') def tvector3_to_ndarray(vec): -- cgit