The Gaudi Framework  v33r0 (d5ea422b)
__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 
34  def __getattr__(self, name):
35  # trigger the load of the configurables database
36  from Gaudi.Configuration import confDbGetConfigurable, cfgDb
37  from Gaudi.CommonGaudiConfigurables import aliases
38  # return value
39  retval = None
40  # handle the special cases (needed for modules): __all__, __path__
41  if name == "__all__":
42  retval = cfgDb.keys()
43  elif name == "__path__":
44  raise AttributeError("'module' object has no attribute '__path__'")
45  elif name in cfgDb.keys(): # ignore private names
46  retval = confDbGetConfigurable(name)
47  elif name in aliases: # special case of aliases
48  retval = aliases[name]
50  import logging
51  logging.getLogger(__configurables_module_fullname__).warning(
52  'Configurable class %s not in database', name)
53  else:
54  # We raise an AttributeError exception if the configurable could not be found
55  # to respect the Python semantic.
56  raise AttributeError("module '%s' does not have attribute '%s'" %
57  (__configurables_module_fullname__, name))
58  return retval
59 
60 
61 # install the facade module instance as a module
62 Configurables = _ConfigurablesModule()
63 sys.modules[__configurables_module_fullname__] = Configurables
64 
65 _GaudiKernelLib = None
66 
67 
68 class c_opt_t(ctypes.Structure):
69  _fields_ = [('key', ctypes.c_char_p), ('value', ctypes.c_char_p)]
70 
71 
72 class Application(object):
73  def __init__(self, opts, appType="Gaudi::Application"):
74  global _GaudiKernelLib
75  if _GaudiKernelLib is None:
76  # FIXME: note that we need PyDLL instead of CDLL if the calls to
77  # Python functions are not protected with the GIL.
78  gkl = _GaudiKernelLib = ctypes.PyDLL(
79  'libGaudiKernel' +
80  ('.dylib' if sys.platform == 'darwin' else '.so'),
81  mode=ctypes.RTLD_GLOBAL)
82  gkl._py_Gaudi__Application__create.restype = ctypes.c_void_p
83  gkl._py_Gaudi__Application__run.argtypes = [ctypes.c_void_p]
84  gkl._py_Gaudi__Application__run.restype = ctypes.c_int
85  gkl._py_Gaudi__Application__delete.argtypes = [ctypes.c_void_p]
86 
87  c_opts = (c_opt_t * len(opts))()
88  for idx, item in enumerate(opts.items()):
89  c_opts[idx].key = item[0].encode('ascii')
90  c_opts[idx].value = item[1].encode('ascii')
91 
92  self._impl = _GaudiKernelLib._py_Gaudi__Application__create(
93  appType.encode('ascii'), c_opts, ctypes.c_long(len(c_opts)))
94 
95  @classmethod
96  def create(cls, appType, opts):
97  return cls(opts, appType=appType)
98 
99  def run(self):
100  return _GaudiKernelLib._py_Gaudi__Application__run(self._impl)
101 
102  def __del__(self):
103  _GaudiKernelLib._py_Gaudi__Application__delete(self._impl)
virtual int run()
Implement the application main logic:
Definition: Application.cpp:80
def __getattr__(self, name)
Definition: __init__.py:34
def __init__(self, opts, appType="Gaudi::Application")
Definition: __init__.py:73
def __del__(self)
Definition: __init__.py:102
def create(cls, appType, opts)
Definition: __init__.py:96
Gaudi application entry point.
Definition: __init__.py:72