All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiKernel.Configurable.ConfigurableUser Class Reference
Inheritance diagram for GaudiKernel.Configurable.ConfigurableUser:
Collaboration diagram for GaudiKernel.Configurable.ConfigurableUser:

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
 
def isApplicable
 
- Public Member Functions inherited from GaudiKernel.Configurable.Configurable
def __new__
 
def __init__
 
def __getstate__
 
def __getnewargs__
 
def __setstate__
 
def __len__
 
def __iter__
 
def __deepcopy__
 
def __iadd__
 
def __getattr__
 
def __setattr__
 
def __delattr__
 
def __nonzero__
 
def remove
 
def removeAll
 
def copyChild
 
def setParent
 
def getParent
 
def hasParent
 
def copyChildAndSetParent
 
def getChildren
 
def getTools
 
def children
 
def getAllChildren
 
def getSequence
 
def setup
 
def getProperties
 
def getValuedProperties
 
def properties
 
def getDefaultProperties
 
def getDefaultProperty
 
def getProp
 
def setProp
 
def isPropertySet
 
def getType
 
def getName
 
def name
 
def getJobOptName
 
def isPublic
 
def jobOptName
 
def getFullName
 
def getFullJobOptName
 
def getPrintTitle
 
def getTitleName
 
def setDefaults
 
def clone
 
def splitName
 
def addTool
 
def __repr__
 
def __str__
 

Private Member Functions

def __addActiveUseOf
 
def __addPassiveUseOf
 
def _instanceName
 

Private Attributes

 _enabled
 
 __users__
 
 _applied
 
 __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. More...
 
list __queried_configurables__ = []
 list of ConfigurableUser classes this one is going to query in the apply_configuration method More...
 

Additional Inherited Members

- Static Public Attributes inherited from GaudiKernel.Configurable.Configurable
string indentUnit = '| '
 
int printHeaderWidth = 100
 
int printHeaderPre = 5
 
dictionary allConfigurables = {}
 
dictionary configurableServices = {}
 

Detailed Description

Definition at line 1121 of file Configurable.py.

Constructor & Destructor Documentation

def GaudiKernel.Configurable.ConfigurableUser.__init__ (   self,
  name = Configurable.DefaultName,
  _enabled = True,
  kwargs 
)

Definition at line 1138 of file Configurable.py.

1139  def __init__( self, name = Configurable.DefaultName, _enabled = True, **kwargs ):
1140  super( ConfigurableUser, self ).__init__( name )
1141  for n, v in kwargs.items():
1142  setattr(self, n, v)
1143  self._enabled = _enabled
1144  self.__users__ = []
1145  self._applied = False
1146 
1147  # Needed to retrieve the actual class if the declaration in __used_configurables__
1148  # and __queried_configurables__ is done with strings.
1149  from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
1150 
1151  # Set the list of users of the used configurables
1152  #
1153  self.__used_instances__ = []
1154  for used in self.__used_configurables__:
1155  # By default we want to use the default name of the instances
1156  # for the used configurables
1157  used_name = Configurable.DefaultName
1158  # If the entry in the list is a tuple, we need a named instance
1159  if type(used) is tuple:
1160  used, used_name = used # we re-set used to re-use the code below
1161  if not used_name:
1162  used_name = self._instanceName(used)
1163  # Check is 'used' is a string or not
1164  if type(used) is str:
1165  used_class = confDbGetConfigurable(used)
1166  else:
1167  used_class = used
1168  # Instantiate the configurable that we are going to use
1169  try:
1170  inst = used_class(name = used_name, _enabled = False)
1171  except AttributeError:
1172  # This cover the case where the used configurable is not a
1173  # ConfigurableUser instance, i.e. id doesn't have the attribute
1174  # '_enabled'.
1175  inst = used_class(name = used_name)
1176  self.__addActiveUseOf(inst)
1177  for queried in self.__queried_configurables__:
1178  try:
1179  if type(queried) is str:
1180  queried = confDbGetConfigurable(used)
1181  inst = queried(_enabled = False)
1182  except AttributeError:
1183  inst = queried()
self.__addPassiveUseOf(inst)
list __queried_configurables__
list of ConfigurableUser classes this one is going to query in the apply_configuration method ...
list __used_configurables__
list of ConfigurableUser classes this one is going to modify in the apply_configuration method...
string type
Definition: gaudirun.py:126

Member Function Documentation

def GaudiKernel.Configurable.ConfigurableUser.__addActiveUseOf (   self,
  other 
)
private
Declare that we are going to modify the Configurable 'other' in our
__apply_configuration__.

Definition at line 1184 of file Configurable.py.

1185  def __addActiveUseOf(self, other):
1186  """
1187  Declare that we are going to modify the Configurable 'other' in our
1188  __apply_configuration__.
1189  """
1190  self.__used_instances__.append(other)
1191  if hasattr(other, "__users__"): # allow usage of plain Configurables
other.__users__.append(self)
def GaudiKernel.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 1192 of file Configurable.py.

1193  def __addPassiveUseOf(self, other):
1194  """
1195  Declare that we are going to retrieve property values from the
1196  ConfigurableUser 'other' in our __apply_configuration__.
1197  """
1198  if not isinstance(other, ConfigurableUser):
1199  raise Error("'%s': Cannot make passive use of '%s', it is not a ConfigurableUser" % (self.name(), other.name()))
other.__addActiveUseOf(self)
def GaudiKernel.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 1276 of file Configurable.py.

1277  def __apply_configuration__(self):
1278  """
1279  Function to be overridden to convert the high level configuration into a
1280  low level one.
1281  The default implementation calls applyConf, which is the method defined
1282  in some ConfigurableUser implementations.
1283  """
1284  return self.applyConf()
def GaudiKernel.Configurable.ConfigurableUser.__detach_used__ (   self)
Remove this ConfigurableUser instance from the users list of the used
instances.

Definition at line 1207 of file Configurable.py.

1208  def __detach_used__(self):
1209  """
1210  Remove this ConfigurableUser instance from the users list of the used
1211  instances.
1212  """
1213  for used in self.__used_instances__:
1214  if hasattr(used, "__users__"): # allow usage of plain Configurables
1215  used.__users__.remove(self)
def GaudiKernel.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 1292 of file Configurable.py.

1293  def _instanceName(self, cls):
1294  """
1295  Function used to define the name of the private instance of a given class
1296  name.
1297  This method is used when the __used_configurables_property__ declares the
1298  need of a private used configurable without specifying the name.
1299  """
1300  if type(cls) is str:
1301  clName = cls
1302  else:
1303  clName = cls.__name__
1304  return "%s_%s" % (self.name(), clName)
string type
Definition: gaudirun.py:126
def GaudiKernel.Configurable.ConfigurableUser.applyConf (   self)
Function to be overridden to convert the high level configuration into a
low level one.

Definition at line 1285 of file Configurable.py.

1286  def applyConf( self ):
1287  """
1288  Function to be overridden to convert the high level configuration into a
1289  low level one.
1290  """
1291  pass
def GaudiKernel.Configurable.ConfigurableUser.getDlls (   self)

Definition at line 1202 of file Configurable.py.

1203  def getDlls( self ):
return None
def GaudiKernel.Configurable.ConfigurableUser.getGaudiType (   self)

Definition at line 1200 of file Configurable.py.

1201  def getGaudiType( self ):
return 'User'
def GaudiKernel.Configurable.ConfigurableUser.getHandle (   self)

Definition at line 1204 of file Configurable.py.

1205  def getHandle( self ):
1206  return None
def GaudiKernel.Configurable.ConfigurableUser.getUsedInstance (   self,
  name 
)
Return the used instance with a given name.

Definition at line 1305 of file Configurable.py.

1306  def getUsedInstance(self, name):
1307  """
1308  Return the used instance with a given name.
1309  """
1310  for i in self.__used_instances__:
1311  if i.name() == name:
1312  if hasattr(i, "_enabled"):
1313  # ensure that the instances retrieved through the method are
1314  # enabled
1315  i._enabled = True
1316  return i
1317  raise KeyError(name)
def GaudiKernel.Configurable.ConfigurableUser.isApplicable (   self)
Return True is the instance can be "applied".

Definition at line 1318 of file Configurable.py.

1319  def isApplicable(self):
1320  '''
1321  Return True is the instance can be "applied".
1322  '''
1323  return (not self.__users__) and (not self._applied)
1324 
1325 
# list of callables to be called after all the __apply_configuration__ are called.
def GaudiKernel.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 1265 of file Configurable.py.

1266  def propagateProperties(self, names = None, others = None, force = True):
1267  """
1268  Call propagateProperty for each property listed in 'names'.
1269  If 'names' is None, all the properties are propagated.
1270  """
1271  if names is None:
1272  # use all the non-private slots
1273  names = [ p for p in self.__slots__ if not p.startswith("_") ]
1274  for n in names:
1275  self.propagateProperty(n, others, force)
def GaudiKernel.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 1216 of file Configurable.py.

1217  def propagateProperty(self, name, others = None, force = True):
1218  """
1219  Propagate the property 'name' (if set) to other configurables (if possible).
1220  'others' can be:
1221  None:
1222  propagate to all the entries in __used_configurables__
1223  a configurable instance:
1224  propagate only to it
1225  list of configurable instances:
1226  propagate to all of them.
1227 
1228 
1229  The logic is:
1230  - if the local property is set, the other property will be overwritten
1231  - local property not set and other set => keep other
1232  - local property not set and other not set => overwrite the default for
1233  ConfigurableUser instances and set the property for Configurables
1234  """
1235  # transform 'others' to a list of configurable instances
1236  if others is None:
1237  others = self.__used_instances__
1238  elif type(others) not in [ list, tuple ] :
1239  others = [ others ]
1240  # these can be computed before the loop
1241  local_is_set = self.isPropertySet(name)
1242  value = self.getProp(name)
1243  # loop over the others that do have 'name' in their slots
1244  for other in [ o for o in others if name in o.__slots__ ]:
1245  # If self property is set, use it
1246  if local_is_set:
1247  if other.isPropertySet(name):
1248  log.warning("Property '%(prop)s' is set in both '%(self)s' and '%(other)s', using '%(self)s.%(prop)s'"%
1249  { "self": self.name(),
1250  "other": other.name(),
1251  "prop": name } )
1252  other.setProp(name, value)
1253  # If not, and other property also not set, propagate the default
1254  elif not other.isPropertySet(name):
1255  if isinstance(other,ConfigurableUser):
1256  otherType = type(other._properties[name].getDefault())
1257  other._properties[name].setDefault(value)
1258  if otherType in [list, dict]:
1259  # Special case for list and dictionaries:
1260  # also set the property to the same value of the default (copy)
1261  other.setProp(name, otherType(value))
1262  else:
1263  other.setProp(name, value)
1264  # If not set and other set, do nothing
string type
Definition: gaudirun.py:126

Member Data Documentation

list GaudiKernel.Configurable.ConfigurableUser.__queried_configurables__ = []
staticprivate

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

Definition at line 1137 of file Configurable.py.

dictionary GaudiKernel.Configurable.ConfigurableUser.__slots__
staticprivate
Initial value:
1 = { "__users__": [],
2  "__used_instances__": [],
3  "_enabled": True,
4  "_applied": False }

Definition at line 1122 of file Configurable.py.

list GaudiKernel.Configurable.ConfigurableUser.__used_configurables__ = []
staticprivate

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></em><other name>".

Definition at line 1134 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser.__used_instances__
private

Definition at line 1152 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser.__users__
private

Definition at line 1143 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser._applied
private

Definition at line 1144 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser._enabled
private

Definition at line 1142 of file Configurable.py.


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