7__doc__ =
"""Module containing a set of Python base classes for PyAthena"""
8__author__ =
"Sebastien Binet <binet@cern.ch>"
12__pseudo_all__ = [
'StatusCode',
23 """ return the OS-native name from an OS-indenpendent one """
26 if plat.count(
'linux')>0:
27 lib_prefix,lib_suffix =
'lib',
'.so'
29 lib_prefix,lib_suffix =
'',
'.dll'
30 elif plat ==
'darwin':
31 lib_prefix,lib_suffix =
'lib',
'.dylib'
33 raise RuntimeError (
"sorry platform [%s] is not (yet?) supported"%plat)
34 _sys_libname = libname
35 if not _sys_libname.startswith (lib_prefix):
36 _sys_libname =
''.join([lib_prefix,_sys_libname])
37 if not _sys_libname.endswith (lib_suffix):
38 _sys_libname =
''.join([_sys_libname, lib_suffix])
43 Helper method to load a library by its natural name, not the OS-native name.
44 But if the OS-native name is given, it is safely handled too. Note that there's
45 a problem on MacOSX, for which the OS-native name ends with .dylib, but for
46 which ATLAS builds .so libraries. Override the OS-native name (which should probably
47 be replaced by two attempts; one with the .dylib and the other with .so)
49 >>> load_library ('AthenaServices')
50 >>> load_library ('AthenaServicesDict')
53 from sys
import platform
54 if platform ==
'darwin':
55 _sys_libname = _sys_libname.replace(
'.dylib',
'.so')
57 return ctypes.cdll.LoadLibrary (_sys_libname)
61 Helper function to find the (full)path to a library given its natural name.
62 @return None on failure
65 >>> find_library('AthenaServices')
66 '/afs/cern.ch/.../AtlasCore/[release]/InstallArea/.../libAthenaServices.so
77 if os.name !=
'posix':
78 raise RuntimeError(
'sorry OS [%s] is not supported' % os.name)
80 if 'LD_LIBRARY_PATH' in os.environ:
81 for d
in os.environ[
'LD_LIBRARY_PATH'].
split(os.pathsep):
82 lib = os.path.join(d, _sys_libname)
83 if os.path.exists(lib):
89 Helper method to reload a python module by name.
90 This is useful in the usual following case:
91 >>> from Foo import MyAlg
92 >>> assert (not 'Foo' in dir())
93 >>> reload(Foo) # won't work
94 >>> PyAthena.reload_module ('Foo') # will work
95 >>> PyAthena.reload_module (Foo) # will work too
98 from importlib
import reload
99 if isinstance (modname, types.ModuleType):
100 modname = modname.__name__
101 if modname
in sys.modules:
102 return reload (sys.modules[modname])
103 raise ValueError(
'no module [%s] could be found'%modname)
106 """simple minded function to reload objects, methods and modules
109 >>> # edit and modify the execute methods of some PyAthena.Alg
110 ... # class, then load back that definition
111 >>> PyAthena.py_reload (alg1.execute, alg2.execute)
112 >>> PyAthena.py_reload (alg1.execute)
113 >>> alg1.execute() # will use the new definition
114 >>> theApp.nextEvent() # will also use the new definitions
115 ... # of both alg1 and alg2
118 from importlib
import reload
119 for i,arg
in enumerate(args):
120 if isinstance (arg, types.ModuleType):
123 elif isinstance (arg, types.StringType):
126 elif isinstance (arg, types.MethodType):
129 modname = arg.im_self.__class__.__module__
130 module = reload (sys.modules[modname])
132 klass = getattr (module, obj.__class__.__name__)
134 fct_name = arg.im_func.__name__
135 new_fct = getattr (klass, fct_name)
138 setattr (obj, fct_name,
139 new_fct.__get__(obj))
140 elif hasattr (arg,
'__class__'):
143 modname = arg.__class__.__module__
144 module = reload (sys.modules[modname])
146 klass = getattr (module, arg.__class__.__name__)
148 cfg_methods = dir(Configurable)
149 d = (k
for k
in dir(klass)
150 if not k.startswith(
'__')
and k
not in cfg_methods)
152 if not hasattr (arg, k):
153 v = getattr (klass, k)
156 except AttributeError:
159 setattr (arg, k, v.__get__(arg))
167 print (
"*** unhandled type: [%s] (arg #%i) ***" % (
type(arg),i))
172from AthenaPython
import PyAthenaComps
173from AthenaPython.Bindings
import _PyAthenaBindingsCatalog
as _pycat
178 """a helper class to allow easy retrieval of automatically generated
179 configurables (stolen from PyRoot)
182 types.ModuleType.__init__(self, module.__name__)
184 self.
__dict__[
'__doc__' ] = module.__doc__
185 self.
__dict__[
'__name__' ] = module.__name__
186 self.
__dict__[
'__file__' ] = module.__file__
188 from .Bindings
import py_svc
191 from .Bindings
import py_tool
194 from .Bindings
import py_alg
197 self.
__dict__ [
'load_library'] = load_library
198 self.
__dict__ [
'find_library'] = find_library
199 self.
__dict__ [
'reload_module'] = reload_module
200 self.
__dict__ [
'py_reload'] = py_reload
205 if k.startswith(
'__'):
206 return types.ModuleType.__getattribute__(self, k)
207 if k
in __pseudo_all__: v = getattr(PyAthenaComps, k)
208 else: v = _pycat.init(k)
209 object.__getattribute__(self,
'__dict__')[k] = v
213sys.modules[ __name__ ] =
ModuleFacade( sys.modules[ __name__ ] )
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
_get_native_libname(libname)
helpers