Source

mana-core-storegatebindings / python / Bindings.py

Full commit
# @file: StoreGateBindings/python/Bindings.py
# @author: Wim Lavrijsen <WLavrijsen@lbl.gov>
# @author: Sebastien Binet <binet@cern.ch>

### data
__version__ = "$Revision: 1.2 $"
__author__  = """
Wim Lavrijsen (WLavrijsen@lbl.gov),
Sebastien Binet (binet@cern.ch)
"""

from PyUtils.Decorators import memoize

### pythonizations for StoreGateSvc
def _setup():
    import PyCintex
    # StoreGate bindings from dictionary
    PyCintex.loadDictionary( "libAthenaPythonDict" )      # for clidsvc
    PyCintex.loadDictionary( "libStoreGateBindingsDict" ) # for storegatesvc

    # make sure the global C++ namespace has been created
    gbl = PyCintex.makeNamespace('')
    _ath= PyCintex.makeNamespace('AthenaInternal')
    
    global py_retrieve
    py_retrieve = PyCintex.gbl.AthenaInternal.retrieveObjectFromStore

    global py_record
    py_record   = PyCintex.gbl.AthenaInternal.recordObjectToStore

    # retrieve the StoreGateSvc class
    global StoreGate, StoreGateSvc
    StoreGateSvc = PyCintex.gbl.StoreGateSvc
    StoreGate    = PyCintex.gbl.StoreGate

    from AthenaPython.Pythonizations import py_svc

    @memoize
    def _get_klass_infos(klass):
        if isinstance(klass, str):
            klass = PyCintex.makeClass(klass)
        klassname = klass.__class__.__name__
        if klassname.endswith('_meta'): klassname = klassname[:-5]
        clidSvc = py_svc('ClassIDSvc', iface='IClassIDSvc')
        clid = clidSvc.clid(klassname)
        tname= clidSvc.typename(clid)
        return clid, tname

    # caching
    _makeNullPtr = PyCintex.libPyROOT.MakeNullPointer
    
    # add specialized retrieve method
    def retrieve( self, klass, key = None ):
        return py_retrieve( self, klass, key )
    StoreGateSvc.retrieve = retrieve

    # add specialized record method
    def record( self, obj, key ):
        return py_record( self, obj, key )
    StoreGateSvc.record = record

    # make dump print, rather than return string
    def dump( self ):
        print self.__class__._dump( self )
    StoreGateSvc._dump = StoreGateSvc.dump
    StoreGateSvc.dump  = dump

    # allow the use of the pythonized properties interface
    def __getattr__( self, attr ):
        try:                from GaudiPython.Bindings import iProperty
        except ImportError: from gaudimodule          import iProperty
        return getattr( iProperty("StoreGateSvc", self), attr )

    def __setattr__( self, attr, value ):
        try:                from GaudiPython.Bindings import iProperty
        except ImportError: from gaudimodule          import iProperty
        return setattr( iProperty("StoreGateSvc", self), attr, value )

    StoreGateSvc.__getattr__ = __getattr__
    StoreGateSvc.__setattr__ = __setattr__

    return

## execute method at module import
_setup()

## clean-up
del _setup