The Gaudi Framework  v32r2 (46d42edc)
__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.
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]
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' +
70  ('.dylib' if sys.platform == 'darwin' else '.so'),
71  mode=ctypes.RTLD_GLOBAL)
72  gkl._py_Gaudi__Application__create.restype = ctypes.c_void_p
73  gkl._py_Gaudi__Application__run.argtypes = [ctypes.c_void_p]
74  gkl._py_Gaudi__Application__run.restype = ctypes.c_int
75  gkl._py_Gaudi__Application__delete.argtypes = [ctypes.c_void_p]
76 
77  c_opts = (c_opt_t * len(opts))()
78  for idx, item in enumerate(opts.items()):
79  c_opts[idx].key = item[0].encode('ascii')
80  c_opts[idx].value = item[1].encode('ascii')
81 
82  self._impl = _GaudiKernelLib._py_Gaudi__Application__create(
83  appType.encode('ascii'), c_opts, ctypes.c_long(len(c_opts)))
84 
85  @classmethod
86  def create(cls, appType, opts):
87  return cls(opts, appType=appType)
88 
89  def run(self):
90  return _GaudiKernelLib._py_Gaudi__Application__run(self._impl)
91 
92  def __del__(self):
93  _GaudiKernelLib._py_Gaudi__Application__delete(self._impl)
virtual int run()
Implement the application main logic:
Definition: Application.cpp:70
def __getattr__(self, name)
Definition: __init__.py:24
def __init__(self, opts, appType="Gaudi::Application")
Definition: __init__.py:63
def __del__(self)
Definition: __init__.py:92
def create(cls, appType, opts)
Definition: __init__.py:86
Gaudi application entry point.
Definition: __init__.py:62