7 __author__ =
"Sebastien Binet"
17 if platform.system() ==
"Linux":
18 if lib[:3] !=
"lib": lib =
"lib"+lib
19 if lib[-3:] !=
".so": lib = lib+
".so"
24 'ElementLinkInt_p1' :
'ElementLink_p1<unsigned int>',
25 'basic_string<char>' :
'string',
26 'std::basic_string<char>' :
'string',
27 'vector<basic_string<char> >' :
'vector<string>',
29 'INavigable4MomentumCollection' :
'DataVector<INavigable4Momentum>',
30 'IParticleContainer' :
'DataVector<IParticle>',
34 'INavigable4MomentumCollection' :
'DataVector<INavigable4Momentum>',
35 'IParticleContainer' :
'DataVector<IParticle>',
39 'char',
'unsigned char',
'signed char',
41 'short int',
'short signed',
'short signed int',
42 'short',
'unsigned short',
'signed short',
43 'int',
'unsigned int',
50 'long signed',
'signed long',
70 _is_stl_sequence = re.compile (
r'std::(?P<ContType>.*?)'
71 r'<(?P<TemplateArg>.*?)'
72 r',\s*?std::allocator<\2> >')
73 _is_stl_mapping = re.compile (
r'std::map<'
74 r'(?P<TemplateArg1>.*?),\s*?'
75 r'(?P<TemplateArg2>.*?)'
76 r',\s*?std::allocator<\2> >')
83 """ return the OS-native name from an OS-indenpendent one """
85 if plat.count(
'linux')>0:
86 lib_prefix,lib_suffix =
'lib',
'.so'
88 lib_prefix,lib_suffix =
'',
'.dll'
89 elif plat ==
'darwin':
90 lib_prefix,lib_suffix =
'lib',
'.dylib'
92 raise RuntimeError (
"sorry platform [%s] is not (yet?) supported"%plat)
93 _sys_libname = libname
94 if not _sys_libname.startswith (lib_prefix):
95 _sys_libname =
''.
join([lib_prefix,_sys_libname])
96 if not _sys_libname.endswith (lib_suffix):
97 _sys_libname =
''.
join([_sys_libname, lib_suffix])
102 Helper method to load a library by its natural name, not the OS-native name.
103 But if the OS-native name is given, it is safely handled too.
105 >>> load_library ('AthenaServices')
106 >>> load_library ('AthenaServicesDict')
110 return ctypes.cdll.LoadLibrary (_sys_libname)
114 Helper function to find the (full)path to a library given its natural name.
115 @return None on failure
118 >>> find_library('AthenaServices')
119 '/afs/cern.ch/.../AtlasCore/[release]/InstallArea/.../libAthenaServices.so
130 if os.name !=
'posix':
131 raise RuntimeError(
'sorry OS [%s] is not supported' % os.name)
133 if 'LD_LIBRARY_PATH' in os.environ:
134 for d
in os.environ[
'LD_LIBRARY_PATH'].
split(os.pathsep):
135 lib = os.path.join(d, _sys_libname)
136 if os.path.exists(lib):
142 """helper function to reject rootcint libraries entries from rootmap
143 files (which appeared w/ ROOT v21/22)
144 It seems all of them (and on all platforms) are named like:
145 vector<char>: vector.dll
147 if libname ==
".dll":
149 pat = re.compile(
r'\w*?.dll')
150 return not (libname.startswith(
"lib"))
and \
151 not (pat.match (libname)
is None)
155 The repository of 'rootmap' files (location, content,...)
160 import PyUtils.RootUtils
as ru
161 ROOT = ru.import_root()
162 self.
_cxx = ROOT.Ath.DsoDb.instance()
166 kk = self.
_cxx.py_keys_from(cxx)
167 vv = self.
_cxx.py_vals_from(cxx)
168 for i
in range(kk.size()):
169 dd[kk[i]] =
list(vv[i])
195 dictDuplicates = dict_duplicates
200 pfDuplicates = pf_duplicates
202 def libs(self, detailed=False):
218 helper method to massage a typename into something understandable
222 typename = typename.replace(
', ',
',')
224 if typename
in _cpp_builtins:
227 if typename
in _aliases.keys():
228 t = _aliases[typename]
231 if _is_stl_sequence.match(typename):
234 _m = _is_stl_sequence.match(typename)
235 _m_type = _m.group(
'TemplateArg')
238 if _m_type.endswith(
'>'):
240 typename =
'std::%s<%s>' % (_m.group(
'ContType'),
243 typename = typename.replace(
'std::basic_string<char> ',
245 typename = typename.replace(
'std::basic_string<char>',
247 typename = typename.replace(
'std::',
'')
248 typename = typename.replace(
'> >',
'>->')
249 typename = typename.replace(
' >',
'>')
250 typename = typename.replace(
'>->',
'> >')
254 """helper method to massage a typename into something understandable
255 by reflex (which doesn't understand the same thing than rootmaps).
257 global _aliases,_typedefs
258 typename = typename.replace(
', ',
',')
260 if typename
in _cpp_builtins:
263 if typename
in _typedefs.keys():
264 t = _typedefs[typename]
267 if _is_stl_sequence.match(typename):
270 _m = _is_stl_sequence.match (typename)
271 _m_type = _m.group(
'TemplateArg')
273 _m_type = _to_rflx_name (_m_type.strip())
274 if _m_type.endswith(
'>'):
276 typename =
'std::%s<%s>' % (_m.group(
'ContType'), _m_type)
277 typename = typename.replace(
'std::string>',
278 'std::basic_string<char> >')
279 typename = typename.replace(
'std::string',
280 'std::basic_string<char>')
285 The repository of 'rootmap' files (location, content,...)
289 PluginNamespace =
"__pf__"
292 object.__init__(self)
297 import PyUtils.Logging
as _L
298 self.
msg = _L.logging.getLogger(
'DsoDb')
308 if not p.startswith(os.environ[
'ROOTSYS'])]
310 if not os.path.exists(path):
continue
313 dir_content = os.listdir(path)
317 dir_content = os.listdir(path)
318 except Exception
as err:
319 msg.warning(
"caught:\n%s", err)
320 if dir_content
is None:
321 msg.warning(
"could not run os.listdir on [%s]", path)
323 dsoFiles = [ f
for f
in dir_content
325 for dsoFile
in dsoFiles:
326 dsoFile = os.path.join( path, dsoFile )
327 if os.path.exists(dsoFile):
330 for line
in open(dsoFile,
'r'):
333 if len(line) <= 0
or line[0] ==
"#":
340 dsoKey, libName = line[0], line[1]
341 except Exception
as err:
343 'could not parse %s:%i', dsoFile, line_nbr
346 '(some) reflex-dicts may fail to be auto-loaded'
359 if dsoKey
not in db: db[dsoKey] =
list()
360 if _is_rootcint_dict (libName):
363 libName = os.path.join(path,
_libName(libName))
364 db[dsoKey].
append(libName)
371 s = os.linesep.join( [
372 "+--- %s ---" % self.
name,
373 "|nbr of lib components: %i" % len(self.
db.
keys()),
374 "|nbr of pf components: %i" % len(self.
pf.
keys()),
375 "|nbr of dso files: %i" % len(self.
dsoFiles),
376 "|nbr of known libs: %i" % len(self.
libs()),
377 "+-------------------------"
385 if len(db[k]) == 1:
continue
386 if pedantic: libs = db[k]
391 if os.path.basename(lib)
not in baseLibs:
393 baseLibs.add(os.path.basename(lib))
397 dups[k] = [ lib
for lib
in libs ]
407 if k
not in dups: dups[k] = []
408 dups[k] += [ lib
for lib
in dupDb[k]
409 if libName
not in os.path.basename(lib) ]
411 for k
in dups.keys():
416 return self.
__dups(self.
db, pedantic)
419 return self.
__dups(self.
pf, pedantic)
424 for db
in [self.
db, self.
pf]:
426 if libName
in [ os.path.basename(lib)
for lib
in db[k] ]:
428 caps = [ cap
for cap
in caps ]
431 print (
"::: ERROR: No such library [%s] in dsoDb !!" % libName)
432 raise ValueError (
"")
435 def libs(self, detailedDump = False):
436 if detailedDump: fct =
lambda x : x
437 else: fct = os.path.basename
439 for db
in [self.
pf, self.
db]:
443 libs = [ lib
for lib
in libs ]
449 for db
in [self.
pf, self.
db]:
451 if pedantic: libs = db[k]
456 if os.path.basename(lib)
not in baseLibs:
458 baseLibs.add(os.path.basename(lib))
461 d[k] = [ lib
for lib
in libs ]
466 helper method to massage a typename into something understandable
472 """helper method to massage a typename into something understandable
473 by reflex (which doesn't understand the same thing than rootmaps).