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