| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# Configurable::ConfigurableUser Class Reference

Inheritance diagram for Configurable::ConfigurableUser:
[legend]
Collaboration diagram for Configurable::ConfigurableUser:
[legend]

List of all members.

## Public Member Functions
def | __init__
def | getGaudiType
def | getDlls
def | getHandle
def | __detach_used__
def | propagateProperty
def | propagateProperties
def | __apply_configuration__
def | applyConf
def | getUsedInstance
## Private Member Functions
def | __addActiveUseOf
def | __addPassiveUseOf
def | _instanceName
## Private Attributes
| _enabled
| __users__
| __used_instances__
## Static Private Attributes
dictionary | __slots__
list | __used_configurables__ = []
| list of ConfigurableUser classes this one is going to modify in the __apply_configuration__ method.
list | __queried_configurables__ = []
| list of ConfigurableUser classes this one is going to query in the __apply_configuration__ method

## Detailed Description

Definition at line 1112 of file Configurable.py.

## Member Function Documentation

def Configurable::ConfigurableUser::__init__ | ( |  | self,
|  |  | name = `Configurable.DefaultName`,
|  |  | _enabled = `True`,
|  |  | kwargs |
| ) |  |  |

Definition at line 1128 of file Configurable.py.

    01128                                                                                     :
    01129         super( ConfigurableUser, self ).__init__( name )
    01130         for n, v in kwargs.items():
    01131             setattr(self, n, v)
    01132         self._enabled = _enabled
    01133         self.__users__ = []
    01134
    01135         # Needed to retrieve the actual class if the declaration in __used_configurables__
    01136         # and  __queried_configurables__ is done with strings.
    01137         from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
    01138
    01139         # Set the list of users of the used configurables
    01140         #
    01141         self.__used_instances__ = []
    01142         for used in self.__used_configurables__:
    01143             # By default we want to use the default name of the instances
    01144             # for the used configurables
    01145             used_name = Configurable.DefaultName
    01146             # If the entry in the list is a tuple, we need a named instance
    01147             if type(used) is tuple:
    01148                 used, used_name = used # we re-set used to re-use the code below
    01149                 if not used_name:
    01150                     used_name = self._instanceName(used)
    01151             # Check is 'used' is a string or not
    01152             if type(used) is str:
    01153                 used_class = confDbGetConfigurable(used)
    01154             else:
    01155                 used_class = used
    01156             # Instantiate the configurable that we are going to use
    01157             try:
    01158                 inst = used_class(name = used_name, _enabled = False)
    01159             except AttributeError:
    01160                 # This cover the case where the used configurable is not a
    01161                 # ConfigurableUser instance, i.e. id doesn't have the attribute
    01162                 # '_enabled'.
    01163                 inst = used_class(name = used_name)
    01164             self.__addActiveUseOf(inst)
    01165         for queried in self.__queried_configurables__:
    01166             try:
    01167                 if type(queried) is str:
    01168                     queried = confDbGetConfigurable(used)
    01169                 inst = queried(_enabled = False)
    01170             except AttributeError:
    01171                 inst = queried()
    01172             self.__addPassiveUseOf(inst)
        def __addActiveUseOf(self, other):

def Configurable::ConfigurableUser::__addActiveUseOf | ( |  | self,
|  |  | other |
| ) |  |  | `[private]`

    Declare that we are going to modify the Configurable 'other' in our
    __apply_configuration__.

Definition at line 1173 of file Configurable.py.

    01173                                      :
    01174         """
    01175         Declare that we are going to modify the Configurable 'other' in our
    01176         __apply_configuration__.
    01177         """
    01178         self.__used_instances__.append(other)
    01179         if hasattr(other, "__users__"): # allow usage of plain Configurables
    01180             other.__users__.append(self)
        def __addPassiveUseOf(self, other):

def Configurable::ConfigurableUser::__addPassiveUseOf | ( |  | self,
|  |  | other |
| ) |  |  | `[private]`

    Declare that we are going to retrieve property values from the
    ConfigurableUser 'other' in our __apply_configuration__.

Definition at line 1181 of file Configurable.py.

    01181                                       :
    01182         """
    01183         Declare that we are going to retrieve property values from the
    01184         ConfigurableUser 'other' in our __apply_configuration__.
    01185         """
    01186         if not isinstance(other, ConfigurableUser):
    01187             raise Error("'%s': Cannot make passive use of '%s', it is not a ConfigurableUser" % (self.name(), other.name()))
    01188         other.__addActiveUseOf(self)
        def getGaudiType( self ):

def Configurable::ConfigurableUser::getGaudiType | ( |  | self | ) |

Definition at line 1189 of file Configurable.py.

    01189                             :
    01190         return 'User'
        def getDlls( self ):

def Configurable::ConfigurableUser::getDlls | ( |  | self | ) |

Definition at line 1191 of file Configurable.py.

    01191                        :
    01192         return None
        def getHandle( self ):

def Configurable::ConfigurableUser::getHandle | ( |  | self | ) |

Definition at line 1193 of file Configurable.py.

    01193                          :
    01194         return None
    01195
        def __detach_used__(self):

def Configurable::ConfigurableUser::__detach_used__ | ( |  | self | ) |

    Remove this ConfigurableUser instance from the users list of the used
    instances.

Definition at line 1196 of file Configurable.py.

    01196                              :
    01197         """
    01198         Remove this ConfigurableUser instance from the users list of the used
    01199         instances.
    01200         """
    01201         for used in self.__used_instances__:
    01202             if hasattr(used, "__users__"): # allow usage of plain Configurables
    01203                 used.__users__.remove(self)
    01204
        def propagateProperty(self, name, others = None, force = True):

def Configurable::ConfigurableUser::propagateProperty | ( |  | self,
|  |  | name,
|  |  | others = `None`,
|  |  | force = `True` |
| ) |  |  |

    Propagate the property 'name' (if set) to other configurables (if possible).
    'others' can be:
        None:
    propagate to all the entries in __used_configurables__
        a configurable instance:
    propagate only to it
        list of configurable instances:
    propagate to all of them.

    The logic is:
    - if the local property is set, the other property will be overwritten
    - local property not set and other set => keep other
    - local property not set and other not set => overwrite the default for
        ConfigurableUser instances and set the property for Configurables

Definition at line 1205 of file Configurable.py.

    01205                                                                   :
    01206         """
    01207         Propagate the property 'name' (if set) to other configurables (if possible).
    01208         'others' can be:
    01209             None:
    01210                 propagate to all the entries in __used_configurables__
    01211             a configurable instance:
    01212                 propagate only to it
    01213             list of configurable instances:
    01214                 propagate to all of them.
    01215
    01216
    01217         The logic is:
    01218         - if the local property is set, the other property will be overwritten
    01219         - local property not set and other set => keep other
    01220         - local property not set and other not set => overwrite the default for
    01221             ConfigurableUser instances and set the property for Configurables
    01222         """
    01223         # transform 'others' to a list of configurable instances
    01224         if others is None:
    01225             others = self.__used_instances__
    01226         elif type(others) not in [ list, tuple ] :
    01227             others = [ others ]
    01228         # these can be computed before the loop
    01229         local_is_set = self.isPropertySet(name)
    01230         value = self.getProp(name)
    01231         # loop over the others that do have 'name' in their slots
    01232         for other in [ o for o in others if name in o.__slots__ ]:
    01233             # If self property is set, use it
    01234             if local_is_set:
    01235                 if other.isPropertySet(name):
    01236                     log.warning("Property '%(prop)s' is set in both '%(self)s' and '%(other)s', using '%(self)s.%(prop)s'"%
    01237                                 { "self": self.name(),
    01238                                   "other": other.name(),
    01239                                   "prop": name } )
    01240                 other.setProp(name, value)
    01241             # If not, and other property also not set, propagate the default
    01242             elif not other.isPropertySet(name):
    01243                 if isinstance(other,ConfigurableUser):
    01244                     otherType = type(other._properties[name].getDefault())
    01245                     other._properties[name].setDefault(value)
    01246                     if otherType in [list, dict]:
    01247                         # Special case for list and dictionaries:
    01248                         # also set the property to the same value of the default (copy)
    01249                         other.setProp(name, otherType(value))
    01250                 else:
    01251                     other.setProp(name, value)
    01252             # If not set and other set, do nothing
    01253
        def propagateProperties(self, names = None, others = None, force = True):

def Configurable::ConfigurableUser::propagateProperties | ( |  | self,
|  |  | names = `None`,
|  |  | others = `None`,
|  |  | force = `True` |
| ) |  |  |

    Call propagateProperty for each property listed in 'names'.
    If 'names' is None, all the properties are propagated.

Definition at line 1254 of file Configurable.py.

    01254                                                                             :
    01255         """
    01256         Call propagateProperty for each property listed in 'names'.
    01257         If 'names' is None, all the properties are propagated.
    01258         """
    01259         if names is None:
    01260             # use all the non-private slots
    01261             names = [ p for p in self.__slots__ if not p.startswith("_") ]
    01262         for n in names:
    01263             self.propagateProperty(n, others, force)
    01264
        def __apply_configuration__(self):

def Configurable::ConfigurableUser::__apply_configuration__ | ( |  | self | ) |

    Function to be overridden to convert the high level configuration into a
    low level one.
    The default implementation calls applyConf, which is the method defined
    in some ConfigurableUser implementations.

Definition at line 1265 of file Configurable.py.

    01265                                      :
    01266         """
    01267         Function to be overridden to convert the high level configuration into a
    01268         low level one.
    01269         The default implementation calls applyConf, which is the method defined
    01270         in some ConfigurableUser implementations.
    01271         """
    01272         return self.applyConf()
    01273
        def applyConf( self ):

def Configurable::ConfigurableUser::applyConf | ( |  | self | ) |

    Function to be overridden to convert the high level configuration into a
    low level one.

Definition at line 1274 of file Configurable.py.

    01274                          :
    01275         """
    01276         Function to be overridden to convert the high level configuration into a
    01277         low level one.
    01278         """
    01279         pass
    01280
        def _instanceName(self, cls):

def Configurable::ConfigurableUser::_instanceName | ( |  | self,
|  |  | cls |
| ) |  |  | `[private]`

    Function used to define the name of the private instance of a given class
    name.
    This method is used when the __used_configurables_property__ declares the
    need of a private used configurable without specifying the name.

Definition at line 1281 of file Configurable.py.

    01281                                 :
    01282         """
    01283         Function used to define the name of the private instance of a given class
    01284         name.
    01285         This method is used when the __used_configurables_property__ declares the
    01286         need of a private used configurable without specifying the name.
    01287         """
    01288         if type(cls) is str:
    01289             clName = cls
    01290         else:
    01291             clName = cls.__name__
    01292         return "%s_%s" % (self.name(), clName)
    01293
        def getUsedInstance(self, name):

def Configurable::ConfigurableUser::getUsedInstance | ( |  | self,
|  |  | name |
| ) |  |  |

    Return the used instance with a given name.

Definition at line 1294 of file Configurable.py.

    01294                                    :
    01295         """
    01296         Return the used instance with a given name.
    01297         """
    01298         for i in self.__used_instances__:
    01299             if i.name() == name:
    01300                 if hasattr(i, "_enabled"):
    01301                     # ensure that the instances retrieved through the method are
    01302                     # enabled
    01303                     i._enabled = True
    01304                 return i
    01305         raise KeyError(name)
    01306
    01307 # list of callables to be called after all the __apply_configuration__ are called.
    postConfigActions = []

## Member Data Documentation

dictionary Configurable::ConfigurableUser::__slots__`[static, private]`

Initial value:

    { "__users__": [],
                      "__used_instances__": [],
                      "_enabled": True }

Reimplemented from Configurable::Configurable.

Definition at line 1113 of file Configurable.py.

list Configurable::ConfigurableUser::__used_configurables__ = []`[static, private]`

list of ConfigurableUser classes this one is going to modify in the __apply_configuration__ method.

The list may contain class objects, strings representing class objects or tuples with the class object (or a string) as first element and the instance name as second element. If the instance name is None or not present, the function _instanceName() is used to determine the name of the instance (the default implementation returns "<this name>_<other name>".

Definition at line 1124 of file Configurable.py.

list Configurable::ConfigurableUser::__queried_configurables__ = []`[static, private]`

list of ConfigurableUser classes this one is going to query in the __apply_configuration__ method

Definition at line 1127 of file Configurable.py.

Configurable::ConfigurableUser::_enabled`[private]`

Definition at line 1132 of file Configurable.py.

Configurable::ConfigurableUser::__users__`[private]`

Definition at line 1133 of file Configurable.py.

Configurable::ConfigurableUser::__used_instances__`[private]`

Definition at line 1141 of file Configurable.py.

The documentation for this class was generated from the following file:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r11/GaudiKernel/python/GaudiKernel/Configurable.py