| The Gaudi Framework v32r1 (f65d50dc)

__init__.py
Go to the documentation of this file.
1 import os
2 import sys
3 import ctypes
4
5 __configurables_module_fullname__ = __name__ + '.Configurables'
6 __ignore_missing_configurables__ = False
7
8 # Small class that allows to access all the configurables as attributes of the
9 # instance.
10 # Used as module to allow code like
11 # @code
12 # from Gaudi.Configuration import Configurables
13 # Configurables.MyConf()
14 # @endcode
15
16
17 class _ConfigurablesModule(object):
18 # Initializes the instance
19 def __init__(self):
20 # If set to true, does not raise an AttributeError if the configurable is not found.
21 self.ignoreMissingConfigurables = False
22 self.__name__ = __configurables_module_fullname__
23
24 def __getattr__(self, name):
25 # trigger the load of the configurables database
26 from Gaudi.Configuration import confDbGetConfigurable, cfgDb
27 from Gaudi.CommonGaudiConfigurables import aliases
28 # return value
29 retval = None
30 # handle the special cases (needed for modules): __all__, __path__
31 if name == "__all__":
32 retval = cfgDb.keys()
33 elif name == "__path__":
34 raise AttributeError("'module' object has no attribute '__path__'")
35 elif name in cfgDb.keys(): # ignore private names
36 retval = confDbGetConfigurable(name)
37 elif name in aliases: # special case of aliases
38 retval = aliases[name]
39 elif self.ignoreMissingConfigurables:
40 import logging
41 logging.getLogger(__configurables_module_fullname__).warning(
42 'Configurable class %s not in database', name)
43 else:
44 # We raise an AttributeError exception if the configurable could not be found
45 # to respect the Python semantic.
46 raise AttributeError("module '%s' does not have attribute '%s'" %
47 (__configurables_module_fullname__, name))
48 return retval
49
50
51 # install the facade module instance as a module
52 Configurables = _ConfigurablesModule()
53 sys.modules[__configurables_module_fullname__] = Configurables
54
55 _GaudiKernelLib = None
56
57
58 class c_opt_t(ctypes.Structure):
59 _fields_ = [('key', ctypes.c_char_p), ('value', ctypes.c_char_p)]
60
61
62 class Application(object):
63 def __init__(self, opts, appType="Gaudi::Application"):
64 global _GaudiKernelLib
65 if _GaudiKernelLib is None:
66 # FIXME: note that we need PyDLL instead of CDLL if the calls to
67 # Python functions are not protected with the GIL.
68 gkl = _GaudiKernelLib = ctypes.PyDLL(
69 'libGaudiKernel.so', mode=ctypes.RTLD_GLOBAL)
70 gkl._py_Gaudi__Application__create.restype = ctypes.c_void_p
71 gkl._py_Gaudi__Application__run.argtypes = [ctypes.c_void_p]
72 gkl._py_Gaudi__Application__run.restype = ctypes.c_int
73 gkl._py_Gaudi__Application__delete.argtypes = [ctypes.c_void_p]
74
75 c_opts = (c_opt_t * len(opts))()
76 for idx, item in enumerate(opts.items()):
77 c_opts[idx].key, c_opts[idx].value = item
78
79 self._impl = _GaudiKernelLib._py_Gaudi__Application__create(
80 appType, c_opts, ctypes.c_long(len(c_opts)))
81
82 @classmethod
83 def create(cls, appType, opts):
84 return cls(opts, appType=appType)
85
86 def run(self):
87 return _GaudiKernelLib._py_Gaudi__Application__run(self._impl)
88
89 def __del__(self):
90 _GaudiKernelLib._py_Gaudi__Application__delete(self._impl)
Gaudi.Application::run
virtual int run()
Implement the application main logic:
Definition: Application.cpp:70
Gaudi._ConfigurablesModule.__name__
__name__
Definition: __init__.py:22
Gaudi._ConfigurablesModule
Definition: __init__.py:17
Gaudi._ConfigurablesModule.__getattr__
def __getattr__(self, name)
Definition: __init__.py:24
Gaudi.Application._impl
_impl
Definition: __init__.py:79
Gaudi.Configuration
Definition: Configuration.py:1
Gaudi.CommonGaudiConfigurables
Definition: CommonGaudiConfigurables.py:1
Gaudi.Application.__init__
def __init__(self, opts, appType="Gaudi::Application")
Definition: __init__.py:63
Gaudi.CommonGaudiConfigurables.cls
cls
Definition: CommonGaudiConfigurables.py:25
Gaudi._ConfigurablesModule.__init__
def __init__(self)
Definition: __init__.py:19
Gaudi.Application.__del__
def __del__(self)
Definition: __init__.py:89
Gaudi._ConfigurablesModule.ignoreMissingConfigurables
ignoreMissingConfigurables
Definition: __init__.py:21
Gaudi.Application.create
def create(cls, appType, opts)
Definition: __init__.py:83
Gaudi.Application
Gaudi application entry point.
Definition: __init__.py:62
Gaudi.c_opt_t
Definition: __init__.py:58