Package Ganga :: Package Utility :: Module root
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Utility.root

  1  ############################################################################### 
  2  # Ganga Project. http://cern.ch/ganga 
  3  # 
  4  # $Id: root.py,v 1.1 2008-07-17 16:41:01 moscicki Exp $ 
  5  ############################################################################### 
  6   
  7  from Ganga.Utility.Config import getConfig, ConfigError 
  8  from commands import getstatusoutput     
  9  import Ganga.Utility.logging 
 10   
 11  # 
 12  #       MOVED to Ganga/Lib/Root/Root.py 
 13  # 
 14  #config.setDefaultOptions({'location':'/afs/cern.ch/sw/lcg/external/root', 
 15  #                          'version':'5.14.00d', 
 16  #                          'arch':'slc3_ia32_gcc323', 
 17  #                          'path':'', 
 18  #                          'pythonhome':sys.prefix, 
 19  #                          'pythonversion':''}) 
 20   
21 -def getrootsys(version = None, arch = None):
22 rootsys = "" 23 try: 24 configroot = getConfig('ROOT') 25 if version == None: 26 rootver = configroot['version'] 27 else: 28 rootver = str(version) 29 if arch == None: 30 rootarch = configroot['arch'] 31 else: 32 rootarch = str(arch) 33 if configroot['path']!="": 34 rootsys = configroot['path']+"/" 35 else: 36 rootsys = configroot['location']+"/"+rootver+"/"+rootarch+"/root/" 37 except ConfigError: 38 pass 39 logger.debug("ROOTSYS: %s", rootsys) 40 41 return rootsys
42
43 -def getenvrootsys():
44 """Determine and return $ROOTSYS environment variable""" 45 import os 46 try: 47 rootsys = os.environ['ROOTSYS'] 48 except KeyError: 49 rootsys="" 50 return rootsys
51
52 -def getpythonhome(arch = None, pythonversion=None):
53 """Looks for the PYTHONHOME for the particular version and arch""" 54 pythonhome = '' 55 try: 56 #returns a copy 57 configroot = getConfig('ROOT').getEffectiveOptions() 58 if arch != None: 59 configroot['arch'] = arch 60 if pythonversion != None: 61 configroot['pythonversion'] = pythonversion 62 #allow other Root variables to be used in the definition 63 pythonhome = configroot['pythonhome'] 64 #supports ${foo} type variable expansion 65 for k in configroot.keys(): 66 pythonhome = pythonhome.replace('${%s}' % k, configroot[k]) 67 except ConfigError: 68 pass 69 logger.debug('PYTHONHOME: %s', pythonhome) 70 return pythonhome
71
72 -def getenvpythonhome():
73 """Deterimin the PYTHONHOME environment variable""" 74 import os 75 pythonhome = '' 76 try: 77 pythonhome = os.environ['PYTHONHOME'] 78 except KeyError: 79 pass 80 return pythonhome
81
82 -def getconfrootsys():
83 """Determine and return ROOTSYS from ganga configuration""" 84 return Ganga.Utility.root.getrootsys()
85
86 -def getrootprefix(rootsys = None):
87 """Determine ROOT path and return prefix, 88 emtpy if ROOT is not found in path or ERROR, 89 else ROOTSYS+LD_LIBRARY_PATH+prefix 90 """ 91 rc = 0 92 if rootsys == None: 93 rootsys = Ganga.Utility.root.getconfrootsys() 94 if rootsys=="": 95 rootsys = Ganga.Utility.root.getenvrootsys() 96 if rootsys=="": 97 logger.error("No proper ROOT setup") 98 rc = 1 99 100 rootprefix = "ROOTSYS="+rootsys+" LD_LIBRARY_PATH="+rootsys+"/lib:$LD_LIBRARY_PATH "+rootsys+"/bin/" 101 logger.debug("ROOTPREFIX: %s", rootprefix) 102 103 return rc, rootprefix
104
105 -def checkrootprefix(rootsys = None):
106 """Check if rootprefix variable holds valid values""" 107 108 rc, rootprefix = Ganga.Utility.root.getrootprefix(rootsys) 109 110 cmdtest = rootprefix + "root-config --version" 111 rc, out = getstatusoutput(cmdtest) 112 if (rc!=0): 113 logger.error("No proper ROOT setup") 114 logger.error("%s", out) 115 return 1 116 else: 117 logger.info("ROOT Version: %s", out) 118 return 0
119 120 121 logger = Ganga.Utility.logging.getLogger() 122 123 # $Log: not supported by cvs2svn $ 124 # Revision 1.8.24.1 2007/10/12 13:56:28 moscicki 125 # merged with the new configuration subsystem 126 # 127 # Revision 1.8.26.1 2007/10/09 13:46:22 roma 128 # Migration to new Config 129 # 130 # Revision 1.8 2007/04/13 11:26:28 moscicki 131 # root version upgrade to 5.14.00d from Will 132 # 133 # Revision 1.7 2007/04/12 10:22:55 moscicki 134 # root version upgrade to 5.14.00b from Will 135 # 136 # Revision 1.6 2007/03/14 12:15:14 moscicki 137 # patches from Will 138 # 139 # Revision 1.5 2006/08/08 14:07:45 moscicki 140 # config fixes from U.Egede 141 # 142 # Revision 1.4 2006/08/01 10:05:59 moscicki 143 # changes from Ulrik 144 # 145 # Revision 1.3 2006/06/21 11:50:23 moscicki 146 # johannes elmsheuser: 147 # 148 # * more modular design and a few extentions 149 # * get $ROOTSYS from configuration or environment 150 # 151 # Revision 1.1 2006/06/13 08:46:56 moscicki 152 # support for ROOT 153 # 154