3 from __future__
import print_function
6 Collection of utilities to interface C++ code with Python via PyROOT.
8 This module requires ROOT.
17 from ROOTutils
import ROOT
22 """Make the ROOT C++ jit compiler read the specified header."""
23 ROOT.gROOT.ProcessLine(
'#include "%s"' % headerPath)
30 A class keeping track of the sources and where to look for them.
36 'LibEnvPath':
'LD_LIBRARY_PATH',
40 'LibSuffix':
'.dylib',
41 'LibEnvPath':
'DYLD_LIBRARY_PATH',
44 PlatformInfo = AllPlatformInfo[os.uname()[0]]
55 expPath = os.path.expandvars(path)
56 if not os.path.isdir(expPath):
58 "Warning: include path '%s'" % path,
59 (
" ( => '%s')" % expPath
if path != expPath
else ""),
65 self.includePaths.append(expPath)
69 self.
addIncPath(os.environ[varName], force=force)
75 self.
addIncPaths(*map((
lambda varName: os.environ[varName]), varNames))
77 def find(self, relPath, extraPaths = []):
82 expLibName = SourceCentral.expandLibraryName(libName)
84 SourceCentral.LibraryPaths() +
list(map(os.path.expandvars, extraPaths))
86 candidate = os.path.join(path, expLibName)
87 if os.path.exists(candidate):
return candidate
92 for path
in reversed(self.
includePaths +
list(map(os.path.expandvars, extraPaths))):
93 candidate = os.path.join(path, relPath)
94 if os.path.exists(candidate):
return candidate
98 def loadLibrary(self, relPath, extraPaths = [], force = False):
100 res = ROOT.gSystem.Load(expandedName)
101 if res == 0: self.
libraries[relPath] = expandedName
105 def loadHeader(self, headerRelPath, extraPaths = [], force = False):
106 try:
return self.
headers[headerRelPath]
107 except KeyError:
pass
108 headerPath = self.
findHeader(headerRelPath, extraPaths=extraPaths)
109 if not headerPath:
raise RuntimeError(
"Can't locate header file '%s'" % headerRelPath)
111 self.
headers[headerRelPath] = headerPath
118 Loads a C++ header from a UPS product.
121 * the specified relative path of the header is under the include directory
123 * the include directory path is set in a environment variable named with
124 the standard UPS pattern (`PRODUCTNAME_INC`)
125 * the header relative path starts with a directory that reflects the name
126 of the UPS product, `productname/relative/package/path/header.h`
128 For example, for a `headerRelPath` of `larcorealg/Geometry/GeometryCore.h`,
129 the full path must be represented by
130 `${LARCOREALG_INC}/larcorealg/Geometry/GeometryCore.h`, with the content
131 of `LARCOREALG_INC` variable being an absolute path.
142 def load(self, relPath, extraPaths = [], force = False):
147 return os.path.splitext(path)[-1]
in [ self.
PlatformInfo[
'LibSuffix'],
'' ]
150 if not name.startswith(
'lib'): name =
'lib' + name
152 if not name.endswith(LibSuffix): name += LibSuffix
158 return os.path.split(os.path.dirname(headerPath))[0]
162 return SourceCentral.packageNameFromHeaderPath(headerPath).upper() +
'_' + varSuffix
166 return os.getenv(SourceCentral.PlatformInfo[
'LibEnvPath']) \
167 .split(SourceCentral.PlatformInfo.get(
'LibEnvPathSep',
':'))
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def packageVarNameFromHeaderPath
def packageNameFromHeaderPath