5 Collection of utilities to interface C++ code with Python via PyROOT.
7 This module requires ROOT.
16 from ROOTutils
import ROOT
21 """Make the ROOT C++ jit compiler read the specified header."""
22 ROOT.gROOT.ProcessLine(
'#include "%s"' % headerPath)
29 A class keeping track of the sources and where to look for them.
35 'LibEnvPath':
'LD_LIBRARY_PATH',
39 'LibSuffix':
'.dylib',
40 'LibEnvPath':
'DYLD_LIBRARY_PATH',
43 PlatformInfo = AllPlatformInfo[os.uname()[0]]
54 expPath = os.path.expandvars(path)
55 if not os.path.isdir(expPath):
56 print >>sys.stderr,
"Warning: include path '%s'" % path,
57 if path != expPath:
print >>sys.stderr,
" ( => '%s')" % expPath
58 print >>sys.stderr,
" does not exist."
60 self.includePaths.append(expPath)
64 self.
addIncPath(os.environ[varName], force=force)
70 self.
addIncPaths(*map((
lambda varName: os.environ[varName]), varNames))
72 def find(self, relPath, extraPaths = []):
77 expLibName = SourceCentral.expandLibraryName(libName)
79 SourceCentral.LibraryPaths() + map(os.path.expandvars, extraPaths)
81 candidate = os.path.join(path, expLibName)
82 if os.path.exists(candidate):
return candidate
87 for path
in reversed(self.
includePaths +
list(map(os.path.expandvars, extraPaths))):
88 candidate = os.path.join(path, relPath)
89 if os.path.exists(candidate):
return candidate
93 def loadLibrary(self, relPath, extraPaths = [], force = False):
95 res = ROOT.gSystem.Load(expandedName)
96 if res == 0: self.
libraries[relPath] = expandedName
100 def loadHeader(self, headerRelPath, extraPaths = [], force = False):
101 try:
return self.
headers[headerRelPath]
102 except KeyError:
pass
103 headerPath = self.
findHeader(headerRelPath, extraPaths=extraPaths)
104 if not headerPath:
raise RuntimeError(
"Can't locate header file '%s'" % headerRelPath)
106 self.
headers[headerRelPath] = headerPath
113 Loads a C++ header from a UPS product.
116 * the specified relative path of the header is under the include directory
118 * the include directory path is set in a environment variable named with
119 the standard UPS pattern (`PRODUCTNAME_INC`)
120 * the header relative path starts with a directory that reflects the name
121 of the UPS product, `productname/relative/package/path/header.h`
123 For example, for a `headerRelPath` of `larcorealg/Geometry/GeometryCore.h`,
124 the full path must be represented by
125 `${LARCOREALG_INC}/larcorealg/Geometry/GeometryCore.h`, with the content
126 of `LARCOREALG_INC` variable being an absolute path.
137 def load(self, relPath, extraPaths = [], force = False):
142 return os.path.splitext(path)[-1]
in [ self.
PlatformInfo[
'LibSuffix'],
'' ]
145 if not name.startswith(
'lib'): name =
'lib' + name
147 if not name.endswith(LibSuffix): name += LibSuffix
153 return os.path.split(os.path.dirname(headerPath))[0]
157 return SourceCentral.packageNameFromHeaderPath(headerPath).upper() +
'_' + varSuffix
161 return os.getenv(SourceCentral.PlatformInfo[
'LibEnvPath']) \
162 .split(SourceCentral.PlatformInfo.get(
'LibEnvPathSep',
':'))
def packageVarNameFromHeaderPath
def packageNameFromHeaderPath