7 from __future__
import print_function
9 __author__ =
"Sebastien Binet"
19 if platform.system() ==
"Linux":
20 if lib[:3] !=
"lib": lib =
"lib"+lib
21 if lib[-3:] !=
".so": lib = lib+
".so"
26 'ElementLinkInt_p1' :
'ElementLink_p1<unsigned int>',
27 'basic_string<char>' :
'string',
28 'std::basic_string<char>' :
'string',
29 'vector<basic_string<char> >' :
'vector<string>',
31 'INavigable4MomentumCollection' :
'DataVector<INavigable4Momentum>',
32 'IParticleContainer' :
'DataVector<IParticle>',
36 'INavigable4MomentumCollection' :
'DataVector<INavigable4Momentum>',
37 'IParticleContainer' :
'DataVector<IParticle>',
41 'char',
'unsigned char',
'signed char',
43 'short int',
'short signed',
'short signed int',
44 'short',
'unsigned short',
'signed short',
45 'int',
'unsigned int',
52 'long signed',
'signed long',
72 _is_stl_sequence = re.compile (
r'std::(?P<ContType>.*?)'
73 r'<(?P<TemplateArg>.*?)'
74 r',\s*?std::allocator<\2> >')
75 _is_stl_mapping = re.compile (
r'std::map<'
76 r'(?P<TemplateArg1>.*?),\s*?'
77 r'(?P<TemplateArg2>.*?)'
78 r',\s*?std::allocator<\2> >')
85 """ return the OS-native name from an OS-indenpendent one """
87 if plat.count(
'linux')>0:
88 lib_prefix,lib_suffix =
'lib',
'.so'
90 lib_prefix,lib_suffix =
'',
'.dll'
91 elif plat ==
'darwin':
92 lib_prefix,lib_suffix =
'lib',
'.dylib'
94 raise RuntimeError (
"sorry platform [%s] is not (yet?) supported"%plat)
95 _sys_libname = libname
96 if not _sys_libname.startswith (lib_prefix):
97 _sys_libname =
''.
join([lib_prefix,_sys_libname])
98 if not _sys_libname.endswith (lib_suffix):
99 _sys_libname =
''.
join([_sys_libname, lib_suffix])
104 Helper method to load a library by its natural name, not the OS-native name.
105 But if the OS-native name is given, it is safely handled too.
107 >>> load_library ('AthenaServices')
108 >>> load_library ('AthenaServicesDict')
112 return ctypes.cdll.LoadLibrary (_sys_libname)
116 Helper function to find the (full)path to a library given its natural name.
117 @return None on failure
120 >>> find_library('AthenaServices')
121 '/afs/cern.ch/.../AtlasCore/[release]/InstallArea/.../libAthenaServices.so
132 if os.name !=
'posix':
133 raise RuntimeError(
'sorry OS [%s] is not supported' % os.name)
135 if 'LD_LIBRARY_PATH' in os.environ:
136 for d
in os.environ[
'LD_LIBRARY_PATH'].
split(os.pathsep):
137 lib = os.path.join(d, _sys_libname)
138 if os.path.exists(lib):
144 """helper function to reject rootcint libraries entries from rootmap
145 files (which appeared w/ ROOT v21/22)
146 It seems all of them (and on all platforms) are named like:
147 vector<char>: vector.dll
149 if libname ==
".dll":
151 pat = re.compile(
r'\w*?.dll')
152 return not (libname.startswith(
"lib"))
and \
153 not (pat.match (libname)
is None)
157 The repository of 'rootmap' files (location, content,...)
162 import PyUtils.RootUtils
as ru
163 ROOT = ru.import_root()
164 self.
_cxx = ROOT.Ath.DsoDb.instance()
168 kk = self.
_cxx.py_keys_from(cxx)
169 vv = self.
_cxx.py_vals_from(cxx)
170 for i
in range(kk.size()):
171 dd[kk[i]] =
list(vv[i])
197 dictDuplicates = dict_duplicates
202 pfDuplicates = pf_duplicates
204 def libs(self, detailed=False):
220 helper method to massage a typename into something understandable
224 typename = typename.replace(
', ',
',')
226 if typename
in _cpp_builtins:
229 if typename
in _aliases.keys():
230 t = _aliases[typename]
233 if _is_stl_sequence.match(typename):
236 _m = _is_stl_sequence.match(typename)
237 _m_type = _m.group(
'TemplateArg')
240 if _m_type.endswith(
'>'):
242 typename =
'std::%s<%s>' % (_m.group(
'ContType'),
245 typename = typename.replace(
'std::basic_string<char> ',
247 typename = typename.replace(
'std::basic_string<char>',
249 typename = typename.replace(
'std::',
'')
250 typename = typename.replace(
'> >',
'>->')
251 typename = typename.replace(
' >',
'>')
252 typename = typename.replace(
'>->',
'> >')
256 """helper method to massage a typename into something understandable
257 by reflex (which doesn't understand the same thing than rootmaps).
259 global _aliases,_typedefs
260 typename = typename.replace(
', ',
',')
262 if typename
in _cpp_builtins:
265 if typename
in _typedefs.keys():
266 t = _typedefs[typename]
269 if _is_stl_sequence.match(typename):
272 _m = _is_stl_sequence.match (typename)
273 _m_type = _m.group(
'TemplateArg')
275 _m_type = _to_rflx_name (_m_type.strip())
276 if _m_type.endswith(
'>'):
278 typename =
'std::%s<%s>' % (_m.group(
'ContType'), _m_type)
279 typename = typename.replace(
'std::string>',
280 'std::basic_string<char> >')
281 typename = typename.replace(
'std::string',
282 'std::basic_string<char>')
287 The repository of 'rootmap' files (location, content,...)
291 PluginNamespace =
"__pf__"
294 object.__init__(self)
299 import PyUtils.Logging
as _L
300 self.
msg = _L.logging.getLogger(
'DsoDb')
310 if not p.startswith(os.environ[
'ROOTSYS'])]
312 if not os.path.exists(path):
continue
315 dir_content = os.listdir(path)
319 dir_content = os.listdir(path)
320 except Exception
as err:
321 msg.warning(
"caught:\n%s", err)
322 if dir_content
is None:
323 msg.warning(
"could not run os.listdir on [%s]", path)
325 dsoFiles = [ f
for f
in dir_content
327 for dsoFile
in dsoFiles:
328 dsoFile = os.path.join( path, dsoFile )
329 if os.path.exists(dsoFile):
332 for line
in open(dsoFile,
'r'):
335 if len(line) <= 0
or line[0] ==
"#":
342 dsoKey, libName = line[0], line[1]
343 except Exception
as err:
345 'could not parse %s:%i', dsoFile, line_nbr
348 '(some) reflex-dicts may fail to be auto-loaded'
361 if dsoKey
not in db: db[dsoKey] =
list()
362 if _is_rootcint_dict (libName):
365 libName = os.path.join(path,
_libName(libName))
366 db[dsoKey].
append(libName)
373 s = os.linesep.join( [
374 "+--- %s ---" % self.
name,
375 "|nbr of lib components: %i" % len(self.
db.
keys()),
376 "|nbr of pf components: %i" % len(self.
pf.
keys()),
377 "|nbr of dso files: %i" % len(self.
dsoFiles),
378 "|nbr of known libs: %i" % len(self.
libs()),
379 "+-------------------------"
387 if len(db[k]) == 1:
continue
388 if pedantic: libs = db[k]
393 if os.path.basename(lib)
not in baseLibs:
395 baseLibs.add(os.path.basename(lib))
399 dups[k] = [ lib
for lib
in libs ]
409 if k
not in dups: dups[k] = []
410 dups[k] += [ lib
for lib
in dupDb[k]
411 if libName
not in os.path.basename(lib) ]
413 for k
in dups.keys():
418 return self.
__dups(self.
db, pedantic)
421 return self.
__dups(self.
pf, pedantic)
426 for db
in [self.
db, self.
pf]:
428 if libName
in [ os.path.basename(lib)
for lib
in db[k] ]:
430 caps = [ cap
for cap
in caps ]
433 print (
"::: ERROR: No such library [%s] in dsoDb !!" % libName)
434 raise ValueError (
"")
437 def libs(self, detailedDump = False):
438 if detailedDump: fct =
lambda x : x
439 else: fct = os.path.basename
441 for db
in [self.
pf, self.
db]:
445 libs = [ lib
for lib
in libs ]
451 for db
in [self.
pf, self.
db]:
453 if pedantic: libs = db[k]
458 if os.path.basename(lib)
not in baseLibs:
460 baseLibs.add(os.path.basename(lib))
463 d[k] = [ lib
for lib
in libs ]
468 helper method to massage a typename into something understandable
474 """helper method to massage a typename into something understandable
475 by reflex (which doesn't understand the same thing than rootmaps).