From 8c317cf4892395aa61c00fdf72f1cfd32b089db9 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Sat, 17 Sep 2011 16:50:04 -0400 Subject: .chroma directory is now used to build the ROOT shared library describing the event data structure. No more writing files to chroma package directory. --- chroma/io/root.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/chroma/io/root.py b/chroma/io/root.py index bb4b39a..55f7858 100644 --- a/chroma/io/root.py +++ b/chroma/io/root.py @@ -1,11 +1,26 @@ import ROOT -import os.path +import os, os.path +import shutil import numpy as np +import chroma.event as event + +# 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+'+') -ROOT.gROOT.ProcessLine('.L '+os.path.join(os.path.dirname(__file__), 'root.C')) -import ROOT -import chroma.event as event def tvector3_to_ndarray(vec): '''Convert a ROOT.TVector3 into a numpy np.float32 array''' -- cgit