ATLAS Offline Software
Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
python.Configurable.Configurable Class Reference
Inheritance diagram for python.Configurable.Configurable:
Collaboration diagram for python.Configurable.Configurable:

Classes

class  DefaultCollector
 
class  DefaultName
 

Public Member Functions

def __new__ (cls, *args, **kwargs)
 
def __init__ (self, name=DefaultName)
 
def __getstate__ (self)
 
def __setstate__ (self, dct)
 
def __getnewargs__ (self)
 
def __len__ (self)
 
def __iter__ (self)
 
def __deepcopy__ (self, memo)
 
def __iadd__ (self, configs, descr=None, index=None)
 
def __getattr__ (self, attr)
 
def __delattr__ (self, attr)
 
def remove (self, items)
 
def removeAll (self)
 
def clone (self, newname)
 
def copyChild (self, child)
 
def setParent (self, parentName)
 
def getParent (self)
 
def hasParent (self, parent)
 
def copyChildAndSetParent (self, cfg, parent)
 
def getChildren (self)
 
def overwriteChild (self, idx, newChild)
 
def getAllChildren (self)
 
def getSequence (self)
 
def setup (self)
 
def lock (self)
 
def unlock (self)
 
def isLocked (self)
 
def isPrinting (self)
 
def getProperties (self)
 
def getValuedProperties (self)
 
def properties (self)
 
def getDefaultProperties (cls)
 
def getDefaultProperty (cls, name)
 
def getType (cls)
 
def getName (self)
 
def name (self)
 
def getJobOptName (self)
 
def isPublic (self)
 
def getFullName (self)
 
def getFullJobOptName (self)
 
def getPrintTitle (self)
 
def getTitleName (self)
 
def setDefaults (cls, handle)
 
def __repr__ (self)
 
def __str__ (self, indent=0, headerLastIndentUnit=indentUnit)
 
def getFlattenedProperties (self)
 
def getStrDescriptor (self)
 
def __eq__ (self, rhs)
 
def __ne__ (self, rhs)
 
def __bool__ (self)
 
def __new__ (self, name, bases, dct)
 
def __call__ (cls, *args, **kwargs)
 

Static Public Attributes

 propertyNoValue
 
string indentUnit = '| '
 
int printHeaderWidth = 100
 
int printHeaderPre = 5
 
 allConfigurables = weakref.WeakValueDictionary()
 

Private Member Functions

def _isInSetDefaults (self)
 
def __setupDlls (self)
 
def __setupDefaults (self)
 

Static Private Member Functions

def _printHeader (indentStr, title)
 
def _printFooter (indentStr, title)
 

Private Attributes

 __children
 
 _name
 
 _flags
 

Static Private Attributes

int _fInSetDefaults = 0x01
 
int _fIsLocked = 0x02
 
int _fIsPrinting = 0x04
 
int _fInitOk = 0x08
 
int _fSetupOk = 0x10
 
tuple __slots__
 
int _printOnce = 0
 
bool _useGlobalInstances = True
 
 __hash__ = object.__hash__
 

Detailed Description

Base class for Gaudi components that implement the IProperty interface.
   Provides most of the boilerplate code, but the actual useful classes
   are its derived ConfigurableAlgorithm, ConfigurableService, and
   ConfigurableAlgTool.

Definition at line 47 of file Configurable.py.

Constructor & Destructor Documentation

◆ __init__()

def python.Configurable.Configurable.__init__ (   self,
  name = DefaultName 
)

Reimplemented in python.Configurable.ConfigurableAuditor, python.Configurable.ConfigurableAlgTool, and python.Configurable.ConfigurableAlgorithm.

Definition at line 203 of file Configurable.py.

203  def __init__( self, name = DefaultName ):
204  # check class readiness, all required overloads should be there now
205  klass = self.__class__
206 
207  # this is an abstract class
208  if klass == Configurable:
209  raise TypeError( "%s is an ABC and can not be instantiated" % str(Configurable))
210 
211  # for using this Configurable as a (Gaudi) sequence
212  self.__children = []
213 
214  # know who we are
215  if name == Configurable.DefaultName:
216  if hasattr( self.__class__, 'DefaultedName' ):
217  self._name = self.__class__.DefaultedName
218  else:
219  self._name = self.getType()
220  else:
221  self._name = name
222 
223  self._flags = 0
224 
225  # set to True when collecting defaults, False otherwise
226  self._flags &= ~self._fInSetDefaults
227 
228  # set to True when locked, False otherwise
229  self._flags &= ~self._fIsLocked
230 
231  # set to True when inside __str__ (volatile - not stored on file)
232  self._flags &= ~self._fIsPrinting
233 
234  # for later, in case __init__ itself is overridden
235  self._flags |= self._fInitOk
236 
237  # for debugging purposes (temporary (?))
238  self._flags &= ~self._fSetupOk
239 

Member Function Documentation

◆ __bool__()

def python.Configurable.Configurable.__bool__ (   self)

Definition at line 809 of file Configurable.py.

809  def __bool__ (self):
810  return True
811 

◆ __call__()

def python.ConfigurableMeta.ConfigurableMeta.__call__ (   cls,
args,
**  kwargs 
)
inherited
To Gaudi, any object with the same type/name is the same object. Hence,
   this is mimicked in the configuration: instantiating a new Configurable
   of a type with the same name will return the same instance.

Definition at line 95 of file ConfigurableMeta.py.

95  def __call__( cls, *args, **kwargs ):
96  """To Gaudi, any object with the same type/name is the same object. Hence,
97  this is mimicked in the configuration: instantiating a new Configurable
98  of a type with the same name will return the same instance."""
99 
100  # Get the instance: `singleton' logic needs to be in __new__, not here,
101  # for compatibililty with pickling.)
102  cfg = cls.__new__( cls, *args, **kwargs )
103 
104  # Initialize the object, if not done already.
105  if cfg and ( not hasattr(cfg, '_fInitOk') or not cfg._fInitOk ):
106  cls.__init__( cfg, *args, **kwargs )
107 
108  return cfg

◆ __deepcopy__()

def python.Configurable.Configurable.__deepcopy__ (   self,
  memo 
)

Reimplemented in python.Configurable.ConfigurableService, and python.Configurable.ConfigurableAlgorithm.

Definition at line 285 of file Configurable.py.

285  def __deepcopy__( self, memo ):
286  newconf = object.__new__( self.__class__ )
287  self.__class__.__init__( newconf, self.getName() )
288 
289  for proxy in self._properties.values():
290  try:
291  proxy.__set__( newconf, proxy.__get__( self ) )
292  except AttributeError:
293  pass # means property was not set for self
294 
295  for c in self.__children:
296  newconf += c # processes proper copy semantics
297 
298  return newconf
299 

◆ __delattr__()

def python.Configurable.Configurable.__delattr__ (   self,
  attr 
)

Definition at line 348 of file Configurable.py.

348  def __delattr__( self, attr ):
349  # remove as property, otherwise try as child
350  try:
351  # remove history etc., then reset to default (in case set before)
352  prop = self._properties[ attr ]
353  prop.__delete__( self )
354  prop.__set__( self, prop.default )
355  return # reaches here? was property: done now
356  except KeyError:
357  pass
358 
359  # otherwise, remove child, if one is so named
360  for c in self.__children:
361  if c.getName() == attr:
362  self.__children.remove( c )
363 
364  # potentially, there are left over caches (certain user derived classes)
365  try:
366  del self.__dict__[ attr ]
367  except (AttributeError,KeyError):
368  pass
369 

◆ __eq__()

def python.Configurable.Configurable.__eq__ (   self,
  rhs 
)

Definition at line 792 of file Configurable.py.

792  def __eq__(self,rhs):
793  # Check identity first
794  if self is rhs: return True
795  # Avoid comparing against None...
796  if not rhs: return False
797  # Class check
798  if not isinstance(rhs,Configurable): return False
799  # Type/Name check
800  if self.getFullName() != rhs.getFullName(): return False
801  # If identical types and names, then go the whole hog and test children
802  # Could be sped up by testing property by property...
803  return self.getStrDescriptor() == rhs.getStrDescriptor()

◆ __getattr__()

def python.Configurable.Configurable.__getattr__ (   self,
  attr 
)

Definition at line 339 of file Configurable.py.

339  def __getattr__( self, attr ): # until ToolProperties exist ...
340  if attr[0] == "_":
341  return super( Configurable, self ).__getattribute__(attr)
342  for c in self.__children:
343  if c.getName() == attr:
344  return c
345 
346  raise AttributeError( "'%s' object has no attribute '%s'" % (self.__class__,attr) )
347 

◆ __getnewargs__()

def python.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 274 of file Configurable.py.

274  def __getnewargs__( self ):
275  return (self._name,)
276 

◆ __getstate__()

def python.Configurable.Configurable.__getstate__ (   self)

Definition at line 241 of file Configurable.py.

241  def __getstate__( self ):
242  d = {}
243  for name, proxy in self._properties.items():
244  try:
245  d[ name ] = proxy.__get__( self )
246  except AttributeError:
247  pass
248 
249  d[ '_Configurable__children' ] = self.__children
250  d[ '_name' ] = self._name
251  if hasattr(self, '_jobOptName'):
252  d[ '_jobOptName' ] = self.getJobOptName()
253  d[ '_fIsLocked' ] = self.isLocked()
254 
255  return d
256 

◆ __iadd__()

def python.Configurable.Configurable.__iadd__ (   self,
  configs,
  descr = None,
  index = None 
)

Definition at line 301 of file Configurable.py.

301  def __iadd__( self, configs, descr = None, index = None ):
302  if self.isLocked():
303  raise RuntimeError( f"cannot add children to locked configurable {self.getJobOptName()}" )
304 
305  if not type(configs) in (list,tuple):
306  configs = ( configs, )
307 
308  joname = self.getJobOptName()
309 
310  for cfg in configs:
311  # prevent type mismatches
312  if not isinstance( cfg, Configurable ):
313  raise TypeError( "'%s' is not a Configurable" % str(cfg) )
314 
315  cc = self.copyChildAndSetParent( cfg, joname )
316 
317  # filters dupes; usually "ok" (backdoor should catch them)
318  ccjo = cc.getJobOptName()
319  for c in self.__children:
320  if c.getJobOptName() == ccjo:
321  log.debug( 'attempt to add a duplicate (%s.%s) ... dupe ignored', joname or self.name(), ccjo )
322  break
323  else:
324  if index is None:
325  self.__children.append( cc )
326  else:
327  self.__children.insert( index, cc )
328 
329  try:
330  if descr: # support for tool properties
331  descr.__set__( self, cc )
332  else:
333  setattr( self, cc.getName(), cc )
334  except AttributeError:
335  pass # to allow free addition of tools/subalgorithms
336 
337  return self
338 

◆ __iter__()

def python.Configurable.Configurable.__iter__ (   self)

Definition at line 281 of file Configurable.py.

281  def __iter__( self ):
282  return iter( self.__children )
283 

◆ __len__()

def python.Configurable.Configurable.__len__ (   self)

Definition at line 278 of file Configurable.py.

278  def __len__( self ):
279  return len( self.__children )
280 

◆ __ne__()

def python.Configurable.Configurable.__ne__ (   self,
  rhs 
)

Definition at line 804 of file Configurable.py.

804  def __ne__(self,rhs):
805  return (not self.__eq__(rhs))
806 

◆ __new__() [1/2]

def python.Configurable.Configurable.__new__ (   cls,
args,
**  kwargs 
)
To Gaudi, any object with the same type/name is the same object. Hence,
   this is mimicked in the configuration: instantiating a new Configurable
   of a type with the same name will return the same instance.

Definition at line 89 of file Configurable.py.

89  def __new__ ( cls, *args, **kwargs ):
90  """To Gaudi, any object with the same type/name is the same object. Hence,
91  this is mimicked in the configuration: instantiating a new Configurable
92  of a type with the same name will return the same instance."""
93 
94  # try to get the name of the Configurable (having a name is compulsory)
95  if 'name' in kwargs:
96  # simple keyword (by far the easiest)
97  name = kwargs[ 'name' ]
98  elif 'name' in cls.__init__.__code__.co_varnames:
99  # either positional in args, or default
100  index = list(cls.__init__.__code__.co_varnames).index( 'name' )
101  try:
102  # var names index is offset by one as __init__ is to be called with self
103  name = args[ index - 1 ]
104  except IndexError:
105  # retrieve default value, then
106  name = cls.__init__.__defaults__[ index - (len(args)+1) ]
107  else:
108  # positional index is assumed (will work most of the time)
109  try:
110  name = args[1] # '0' is for self
111  except (IndexError,TypeError):
112  raise TypeError( 'no "name" argument while instantiating "%s"' % cls.__name__ )
113 
114  if name == Configurable.DefaultName:
115  # select either conventional name, or the type of the class
116  if hasattr( cls, 'DefaultedName' ):
117  name = cls.DefaultedName
118  else:
119  name = cls.getType()
120  elif not name or type(name) is not str:
121  # unnamed, highly specialized user code, etc. ... unacceptable
122  raise TypeError( 'could not retrieve name from %s.__init__ arguments' % cls.__name__ )
123 
124  # close backdoor access to otherwise private subalgs/tools
125  if 0 <= name.find( '.' ):
126  raise NameError( '"%s": Gaudi name indexing with "." to private configurables not '
127  'allowed, as it leads to uncheckable backdoors' % name )
128 
129  if 0 <= name.find( '/' ):
130  raise NameError( '"%s": type separator "/" no allowed in component name, '
131  'typename is derived from configurable instead' % name )
132 
133  if cls._useGlobalInstances:
134  # ordinary recycle case
135  try:
136  conf = cls.configurables[ name ]
137 
138  # initialize additional properties, if any
139  for n,v in kwargs.items():
140  try:
141  setattr( conf, n, v )
142  except AttributeError as originalAttributeError:
143 
144  # now for a completely different can of worms ...
145  acceptableKeyWord = False
146 
147  # little helper
148  def flat( classtree ):
149  if isinstance( classtree, list ) or isinstance( classtree, tuple ):
150  return [ j for i in classtree for j in flat( i ) ]
151  else:
152  return [ classtree ]
153 
154  # the following attempts to figure out if the missing attribute
155  # is in fact an acceptable formal function argument to __init__,
156  import inspect
157  allclasses = flat( inspect.getclasstree( [ conf.__class__ ] ) )
158  for confklass in allclasses:
159  try:
160  # the following may result in the same init tried several
161  # times, but we shouldn't be in this loop too often anyway
162  if n in confklass.__init__.__code__.co_varnames:
163  acceptableKeyWord = True
164  break
165  except AttributeError:
166  pass
167 
168  # raising here will break the usage of keywords in __init__, but
169  # there don't appear to be such cases in ATLAS yet ...
170  if not acceptableKeyWord:
171  raise originalAttributeError
172  return conf
173  except KeyError:
174  pass
175  else:
176  #Run 3 style config
177  #Uncomment this line to verify that RecExCommon doesn't use that
178  #print "Run 3 style config"
179  pass #end if not new configuration approach
180  # still here: create a new instance ...
181  conf = object.__new__( cls )
182 
183  # ... python convention says to silently return, if __new__ fails ...
184  if conf is None:
185  return
186 
187  # ... initialize it
188  cls.__init__( conf, *args, **kwargs )
189 
190  # update normal, per-class cache
191  if cls._useGlobalInstances:
192  cls.configurables[ name ] = conf
193 
194  # update generics super-cache
195  if name in cls.allConfigurables and conf.getType() != cls.allConfigurables[ name ].getType():
196  raise TypeError( 'attempt to redefine type of "%s" (was: %s, new: %s)' %
197  (name,cls.allConfigurables[ name ].getType(), conf.getType()) )
198  cls.allConfigurables[ name ] = conf
199 
200  return conf
201 

◆ __new__() [2/2]

def python.ConfigurableMeta.ConfigurableMeta.__new__ (   self,
  name,
  bases,
  dct 
)
inherited

Definition at line 27 of file ConfigurableMeta.py.

27  def __new__( self, name, bases, dct ):
28  # enforce use of classmethod for getType() and setDefaults()
29  if 'getType' in dct and not isinstance( dct[ 'getType' ], classmethod ):
30  dct[ 'getType' ] = classmethod( dct[ 'getType' ] )
31 
32  if 'setDefaults' in dct and not isinstance( dct[ 'setDefaults' ], classmethod ):
33  dct[ 'setDefaults' ] = classmethod( dct[ 'setDefaults' ] )
34 
35  # collect what are properties (basically, any public name; C++ variables
36  # shouldn't start with an '_' because of portability constraints, hence
37  # it is safe to assume that any such vars are python private ones)
38  newclass = type.__new__( self, name, bases, dct )
39 
40  if 'AthenaCommon' not in newclass.__module__:
41  # check for required methods and the right number of arguments
42  # meths = { 'getServices' : 1, # retrieve list of services to configure
43  meths = { 'getDlls' : 1, # provide list of Dlls to load
44  'getGaudiType' : 1, # return string describing component class
45  'getHandle' : 1, # provide access to C++ side component instance
46  'getType' : 1 } # return the type of the actual C++ component
47 
48  for meth, nArgs in meths.items():
49  try:
50  f = getattr( newclass, meth )
51  except AttributeError:
52  raise NotImplementedError("%s is missing in class %s" % (meth,str(newclass)))
53 
54  # in addition, verify the number of arguments w/o defaults
55  nargcount = f.__code__.co_argcount
56  dflts = f.__defaults__
57  ndefaults = dflts and len(dflts) or 0
58  if not nargcount - ndefaults <= nArgs <= nargcount:
59  raise TypeError("%s.%s requires exactly %d arguments" % (newclass,meth,nArgs))
60 
61  # cache references of instances by name for duplicate removal
62  newclass.configurables = weakref.WeakValueDictionary()
63 
64  # loop over slots, which are all assumed to be properties, create proxies, defaults
65  properties = {}
66  slots = dct.get( '__slots__' )
67  if slots:
68  props = [ x for x in slots if x[0] != '_' ]
69  propDict = dct.get('_propertyDocDct')
70  for prop in props:
71  docString = propDict and propDict.get(prop)
72  if type(slots) is dict:
73  default = slots[prop]
74  else:
75  default = None
76  proxy = PropertyProxy.PropertyProxyFactory(
77  getattr( newclass, prop ), docString, default )
78 
79  properties[ prop ] = proxy
80  setattr( newclass, prop, proxy )
81 
82  # complete set of properties includes those from base classes
83  for base in bases:
84  try:
85  bprops = base._properties.copy()
86  bprops.update( properties )
87  properties = bprops
88  except AttributeError:
89  pass
90 
91  newclass._properties = properties
92 
93  return newclass
94 

◆ __repr__()

def python.Configurable.Configurable.__repr__ (   self)

Definition at line 646 of file Configurable.py.

646  def __repr__( self ):
647  return '<%s at %s>' % (self.getFullJobOptName(),hex(id(self)))
648 

◆ __setstate__()

def python.Configurable.Configurable.__setstate__ (   self,
  dct 
)

Definition at line 257 of file Configurable.py.

257  def __setstate__( self, dct ):
258  # flags are set to neutral, not from pickle except for lockedness
259  self._flags = 0
260  self._flags |= self._fInitOk
261  self._flags &= ~self._fInSetDefaults
262  if '_fIsLocked' in dct:
263  if dct[ '_fIsLocked' ]:
264  self._flags &= self._fIsLocked
265  else:
266  self._flags &= ~self._fIsLocked
267  del dct['_fIsLocked']
268  self._flags &= ~self._fIsPrinting
269  for (n, v) in dct.items():
270  setattr( self, n, v )
271 
272  return
273 

◆ __setupDefaults()

def python.Configurable.Configurable.__setupDefaults (   self)
private

Definition at line 625 of file Configurable.py.

625  def __setupDefaults( self ):
626  # set handle defaults flags to inform __setattr__ that it is being
627  # called during setDefaults of the concrete Configurable
628  self._flags |= self._fInSetDefaults
629  self.setDefaults( self )
630  self._flags &= ~self._fInSetDefaults
631 

◆ __setupDlls()

def python.Configurable.Configurable.__setupDlls (   self)
private

Definition at line 614 of file Configurable.py.

614  def __setupDlls( self ):
615  dlls = self.getDlls()
616  if not dlls:
617  dlls = []
618  elif isinstance(dlls, str):
619  dlls = [ dlls ]
620 
621  from AthenaCommon.AppMgr import theApp
622  dlls = filter( lambda d: d not in theApp.Dlls, dlls )
623  if dlls: theApp.Dlls += dlls
624 

◆ __str__()

def python.Configurable.Configurable.__str__ (   self,
  indent = 0,
  headerLastIndentUnit = indentUnit 
)

Definition at line 649 of file Configurable.py.

649  def __str__( self, indent = 0, headerLastIndentUnit=indentUnit ):
650  global log # to print some info depending on output level
651 
652  def _sorted_repr_set(value):
653  """Helper to print sorted set representation"""
654  return "{" + repr(sorted(value))[1:-1] + "}" if value else "set()"
655 
656  indentStr = indent*Configurable.indentUnit
657  # print header
658  title = self.getPrintTitle()
659 
660  # if run under WARNING and hight only, stick with title
661  if logging.WARNING <= log.level:
662  if not Configurable._printOnce:
663  Configurable._printOnce = 1
664  return "Reduced Configurable printout; change log level for more details, e.g.:\n import AthenaCommon.Configurable as Configurable\n Configurable.log.setLevel( INFO )\n" + title
665  else:
666  return title
667 
668  # avoid auto-setting private AlgTools while doing printout
669  self._flags |= self._fIsPrinting
670 
671  # print line to easily see start-of-configurable
672  if indent > 0:
673  headerIndent = (indent-1)*Configurable.indentUnit + headerLastIndentUnit
674  else:
675  headerIndent = ''
676  rep = Configurable._printHeader( headerIndent, title )
677  rep += os.linesep
678  # print own properties
679  props = self.getProperties()
680  defs = self.getDefaultProperties()
681  if not props:
682  rep += indentStr + '|-<no properties>' + os.linesep
683  else:
684  # get property name with
685  nameWidth = 0
686  for p in props.keys():
687  nameWidth=max(nameWidth,len(p))
688  propNames = sorted(props.keys())
689  for p in propNames:
690  v = props[p]
691  # start with indent and property name
692  prefix = indentStr + '|-%-*s' % (nameWidth,p)
693  # add memory address for debugging (not for defaults)
694  if log.isEnabledFor( logging.DEBUG ):
695  if v != Configurable.propertyNoValue:
696  address = ' @%11s' % hex(id(v))
697  else:
698  address = 13*' '
699  prefix += address
700  # add value and default
701  default = defs.get(p)
702 
703  if not isinstance(v,MutableSequence) and v == Configurable.propertyNoValue:
704  # show default value as value, and no extra 'default'
705  strVal = repr(default)
706  strDef = None
707  else:
708  # convert configurable to handle
709  if isinstance(v,Configurable):
710  vv = v.getGaudiHandle()
711  else:
712  vv = v
713  if isinstance(vv,(GaudiHandles.GaudiHandle,
714  GaudiHandles.GaudiHandleArray,
715  DataHandle.DataHandle)):
716  strVal = repr(vv)
717  strDef = repr(default.toStringProperty())
718  if strDef == repr(vv.toStringProperty()):
719  strDef = None
720  elif isinstance(vv, set):
721  strVal = _sorted_repr_set(vv)
722  strDef = _sorted_repr_set(default)
723  else:
724  strVal = repr(vv)
725  strDef = repr(default)
726  # add the value
727  line = prefix + ' = ' + strVal
728  # add default if present
729  if strDef is not None:
730  # put default on new line if too big
731  if len(line) + len(strDef) > Configurable.printHeaderWidth:
732  line += os.linesep + indentStr + '| ' + (len(prefix)-len(indentStr)-3)*' '
733  line += ' (default: %s)' % (strDef,)
734  # add the line to the total string
735  rep += line + os.linesep
736 
737  # print configurables + their properties, or loop over sequence
738  childNotToSort = []
739  childToSort = []
740  for c in self.getAllChildren():
741  if isinstance(c, ConfigurableAlgorithm): childNotToSort.append(c)
742  else: childToSort.append(c)
743  # sort the non-algs
744  childToSort.sort(key=lambda x : x.getName())
745  for cfg in childToSort + childNotToSort:
746  rep += cfg.__str__( indent + 1, '|=' ) + os.linesep
747 
748  # print line to easily see end-of-configurable. Note: No linesep!
749  rep += Configurable._printFooter( indentStr, title )
750 
751  self._flags &= ~self._fIsPrinting
752  return rep
753 
754  # hash method for set/dict operations
755  # first attempt, assuming need to recurse into child properties
756  # if too much overhead, could attempt to cache with python
757  # properties, but hard to propagate changes upwards to parents
758 

◆ _isInSetDefaults()

def python.Configurable.Configurable._isInSetDefaults (   self)
private

Definition at line 611 of file Configurable.py.

611  def _isInSetDefaults( self ):
612  return self._flags & self._fInSetDefaults
613 

◆ _printFooter()

def python.Configurable.Configurable._printFooter (   indentStr,
  title 
)
staticprivate

Definition at line 640 of file Configurable.py.

640  def _printFooter( indentStr, title ):
641  preLen = Configurable.printHeaderPre
642  postLen = Configurable.printHeaderWidth - preLen - 12 - len(title)# - len(indentStr)
643  postLen = max(preLen,postLen)
644  return indentStr + '\\%s (End of %s) %s' % (preLen*'-',title,postLen*'-')
645 

◆ _printHeader()

def python.Configurable.Configurable._printHeader (   indentStr,
  title 
)
staticprivate

Definition at line 633 of file Configurable.py.

633  def _printHeader( indentStr, title ):
634  preLen = Configurable.printHeaderPre
635  postLen = Configurable.printHeaderWidth - preLen - 3 - len(title)# - len(indentStr)
636  postLen = max(preLen,postLen)
637  return indentStr + '/%s %s %s' % (preLen*'*',title,postLen*'*')
638 

◆ clone()

def python.Configurable.Configurable.clone (   self,
  newname 
)

Definition at line 380 of file Configurable.py.

380  def clone( self, newname ):
381  if newname == self.getName():
382  log.error( 'not cloning %s, because new name given is same as old name', self.getName() )
383  return None
384 
385  return self.__class__( newname, **self.getValuedProperties() )
386 

◆ copyChild()

def python.Configurable.Configurable.copyChild (   self,
  child 
)

Reimplemented in python.Configurable.ConfigurableService.

Definition at line 388 of file Configurable.py.

388  def copyChild( self, child ):
389  return copy.deepcopy( child )
390 

◆ copyChildAndSetParent()

def python.Configurable.Configurable.copyChildAndSetParent (   self,
  cfg,
  parent 
)

Definition at line 400 of file Configurable.py.

400  def copyChildAndSetParent(self,cfg,parent):
401  cc = self.copyChild( cfg )
402 
403  if hasattr( cc, 'setParent' ) and parent:
404  cc.setParent( parent )
405 
406  return cc
407 

◆ getAllChildren()

def python.Configurable.Configurable.getAllChildren (   self)
Get all (private) configurable children, both explicit ones (added with +=)
and the ones in the private GaudiHandle properties

Definition at line 414 of file Configurable.py.

414  def getAllChildren( self ):
415  """Get all (private) configurable children, both explicit ones (added with +=)
416  and the ones in the private GaudiHandle properties"""
417  childs = []
418  # add private configurable properties (also inside handles)
419  for proxy in self._properties.values():
420  try:
421  c = proxy.__get__( self )
422  except AttributeError:
423  pass
424  else:
425  if isinstance(c,Configurable) and not c.isPublic():
426  childs.append(c)
427  elif isinstance(c,GaudiHandles.GaudiHandle):
428  try:
429  conf = c.configurable
430  except AttributeError:
431  pass
432  else:
433  if not conf.isPublic():
434  childs.append(conf)
435  elif isinstance(c,GaudiHandles.GaudiHandleArray):
436  # only setup private arrays
437  if not c.isPublic():
438  for ci in c:
439  if isinstance(ci,Configurable):
440  childs.append(ci)
441  else:
442  try:
443  conf = ci.configurable
444  except AttributeError:
445  pass
446  else:
447  childs.append(conf)
448 
449  # add explicit children
450  childs += self.__children
451  return childs
452 

◆ getChildren()

def python.Configurable.Configurable.getChildren (   self)

Definition at line 408 of file Configurable.py.

408  def getChildren( self ):
409  return self.__children[:] # read only
410 

◆ getDefaultProperties()

def python.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 544 of file Configurable.py.

544  def getDefaultProperties( cls ):
545 
546  # user provided defaults
547  c = Configurable.DefaultCollector()
548  cls.setDefaults( c )
549 
550  # defaults from C++
551  for k,v in cls._properties.items():
552  if k not in c.__dict__ and hasattr( v, 'default' ):
553  c.__dict__[ k ] = v.default
554 
555  return c.__dict__
556 

◆ getDefaultProperty()

def python.Configurable.Configurable.getDefaultProperty (   cls,
  name 
)

Definition at line 558 of file Configurable.py.

558  def getDefaultProperty( cls, name ):
559 
560  # user provided defaults
561  c = Configurable.DefaultCollector()
562  cls.setDefaults( c )
563 
564  if name in c.__dict__:
565  return c.__dict__[ name ]
566 
567  # defaults from C++
568  try:
569  v = cls._properties[name]
570  if hasattr( v, 'default' ):
571  return v.default
572  except KeyError:
573  pass
574 
575  return None
576 

◆ getFlattenedProperties()

def python.Configurable.Configurable.getFlattenedProperties (   self)

Definition at line 759 of file Configurable.py.

759  def getFlattenedProperties(self):
760  self._flags |= self._fIsPrinting
761  properties = self.getValuedProperties()
762  propstr = ""
763  for key,val in sorted(properties.items()):
764  if isinstance(val,GaudiHandles.PublicToolHandle) or isinstance(val,GaudiHandles.PrivateToolHandle):
765  propstr += val.getFullName()
766  elif isinstance(val,Configurable):
767  propstr += "({0}:{1})".format(key,val.getFlattenedProperties())
768  elif isinstance(val,GaudiHandles.PublicToolHandleArray) or isinstance(val,GaudiHandles.PrivateToolHandleArray):
769  for th in val:
770  # Handle ToolHandles that have just been set as strings(?)
771  if isinstance(th,Configurable):
772  propstr += "({0}:{1}".format(th.getFullName(), th.getFlattenedProperties())
773  else:
774  propstr += th.getFullName()
775  else:
776  propstr += "({0}:{1})".format(key,str(val))
777  self._flags &= ~self._fIsPrinting
778  return propstr
779 

◆ getFullJobOptName()

def python.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 596 of file Configurable.py.

596  def getFullJobOptName( self ):
597  return "%s/%s" % (self.getType(),self.getJobOptName() or self.getName())
598 

◆ getFullName()

def python.Configurable.Configurable.getFullName (   self)

Definition at line 593 of file Configurable.py.

593  def getFullName( self ) :
594  return str( self.getType() + '/' + self.getName() )
595 

◆ getJobOptName()

def python.Configurable.Configurable.getJobOptName (   self)

Reimplemented in python.Configurable.ConfigurableAuditor, python.Configurable.ConfigurableAlgTool, and python.Configurable.ConfigurableAlgorithm.

Definition at line 586 of file Configurable.py.

586  def getJobOptName( self ): # full hierachical name
587  return self.getName()
588 

◆ getName()

def python.Configurable.Configurable.getName (   self)

Definition at line 580 of file Configurable.py.

580  def getName( self ):
581  return self._name
582 

◆ getParent()

def python.Configurable.Configurable.getParent (   self)

Reimplemented in python.Configurable.ConfigurableAlgTool.

Definition at line 394 of file Configurable.py.

394  def getParent( self ):
395  return ""
396 

◆ getPrintTitle()

def python.Configurable.Configurable.getPrintTitle (   self)

Reimplemented in python.Configurable.ConfigurableAlgTool.

Definition at line 599 of file Configurable.py.

599  def getPrintTitle(self):
600  return self.getGaudiType() + ' ' + self.getTitleName()
601 

◆ getProperties()

def python.Configurable.Configurable.getProperties (   self)

Definition at line 515 of file Configurable.py.

515  def getProperties( self ):
516  props = {}
517  for name, proxy in self._properties.items():
518  try:
519  props[ name ] = proxy.__get__( self )
520  except AttributeError:
521  props[ name ] = Configurable.propertyNoValue
522 
523  return props
524 

◆ getSequence()

def python.Configurable.Configurable.getSequence (   self)

Definition at line 453 of file Configurable.py.

453  def getSequence( self ):
454  elems = []
455  for c in self.__children:
456  elems.append( c.getFullName() )
457  return elems
458 

◆ getStrDescriptor()

def python.Configurable.Configurable.getStrDescriptor (   self)

Definition at line 780 of file Configurable.py.

780  def getStrDescriptor(self):
781 
782  descr = ""
783  if hasattr( self,"_name" ):
784  propstr = self.getFlattenedProperties()
785  descr = (self.getFullName(), propstr)
786  else: # Not yet initialised?
787  descr = self.getType()
788 
789  return descr
790 

◆ getTitleName()

def python.Configurable.Configurable.getTitleName (   self)

Definition at line 602 of file Configurable.py.

602  def getTitleName( self ):
603  if log.isEnabledFor( logging.DEBUG ):
604  return self.getFullJobOptName()
605  else:
606  return self.getFullName()
607 

◆ getType()

def python.Configurable.Configurable.getType (   cls)

Reimplemented in python.AppMgr.AthServiceManager.

Definition at line 577 of file Configurable.py.

577  def getType( cls ):
578  return cls.__name__
579 

◆ getValuedProperties()

def python.Configurable.Configurable.getValuedProperties (   self)

Definition at line 525 of file Configurable.py.

525  def getValuedProperties( self ):
526  props = {}
527  for name, proxy in self._properties.items():
528  try:
529  value = proxy.__get__( self )
530  if hasattr(value, 'getFullName') :
531  value = value.getFullName()
532  elif type(value) is list and len(value) > 0 and hasattr(value[0], 'getFullName'):
533  value = [ i.getFullName() for i in value ]
534  props[ name ] = value
535  except AttributeError:
536  pass
537 
538  return props
539 

◆ hasParent()

def python.Configurable.Configurable.hasParent (   self,
  parent 
)

Reimplemented in python.Configurable.ConfigurableAlgTool.

Definition at line 397 of file Configurable.py.

397  def hasParent( self, parent ):
398  return False
399 

◆ isLocked()

def python.Configurable.Configurable.isLocked (   self)

Definition at line 507 of file Configurable.py.

507  def isLocked( self ):
508  # check whether this configurable is currently locked
509  return self._flags & self._fIsLocked
510 

◆ isPrinting()

def python.Configurable.Configurable.isPrinting (   self)

Definition at line 511 of file Configurable.py.

511  def isPrinting( self ):
512  # check whether this configurable is currently being printed (see PropertyProxy.py)
513  return self._flags & self._fIsPrinting
514 

◆ isPublic()

def python.Configurable.Configurable.isPublic (   self)

Reimplemented in python.Configurable.ConfigurableAlgTool.

Definition at line 589 of file Configurable.py.

589  def isPublic( self ):
590  return True
591 

◆ lock()

def python.Configurable.Configurable.lock (   self)

Definition at line 487 of file Configurable.py.

487  def lock( self ):
488  # prevent any further changes, unless unlocked
489  self._flags |= self._fIsLocked
490 
491  # same for any of its private ToolHandle properties
492  for k, v in self.getProperties().items():
493  if isinstance( v, Configurable ):
494  v.lock()
495 
496  # leave children alone ... most likely are public (and can't check otherwise)
497 

◆ name()

def python.Configurable.Configurable.name (   self)

Definition at line 583 of file Configurable.py.

583  def name( self ):
584  return self.getName()
585 

◆ overwriteChild()

def python.Configurable.Configurable.overwriteChild (   self,
  idx,
  newChild 
)

Definition at line 411 of file Configurable.py.

411  def overwriteChild( self, idx, newChild ):
412  self.__children[idx] = newChild
413 

◆ properties()

def python.Configurable.Configurable.properties (   self)

Definition at line 540 of file Configurable.py.

540  def properties( self ):
541  return self.getProperties() # compatibility
542 

◆ remove()

def python.Configurable.Configurable.remove (   self,
  items 
)

Definition at line 370 of file Configurable.py.

370  def remove( self, items ):
371  if not isinstance(items, (list, tuple)):
372  items = [ items ]
373 
374  self.__children = [ e for e in self.__children if e not in items ]
375 

◆ removeAll()

def python.Configurable.Configurable.removeAll (   self)

Definition at line 376 of file Configurable.py.

376  def removeAll( self ):
377  self.remove( self.__children )
378 

◆ setDefaults()

def python.Configurable.Configurable.setDefaults (   cls,
  handle 
)

Definition at line 608 of file Configurable.py.

608  def setDefaults( cls, handle ):
609  pass
610 

◆ setParent()

def python.Configurable.Configurable.setParent (   self,
  parentName 
)

Reimplemented in python.Configurable.ConfigurableAlgTool.

Definition at line 391 of file Configurable.py.

391  def setParent( self, parentName ):
392  pass
393 

◆ setup()

def python.Configurable.Configurable.setup (   self)

Reimplemented in python.AppMgr.AthServiceManager.

Definition at line 459 of file Configurable.py.

459  def setup( self ):
460  # make sure base class init has been called
461  if not hasattr(self,'_fInitOk') or not self._fInitOk:
462  # could check more, but this is the only explanation
463  raise TypeError("Configurable.__init__ not called in %s override" % self.__class__.__name__)
464 
465  # setup self: this collects all values on the python side
466  self.__setupDlls()
467  self.__setupDefaults()
468 
469  # setup children
470  for c in self.getAllChildren():
471  c.setup()
472 
473  # now get handle to work with for moving properties into the catalogue
474  handle = self.getHandle()
475  if not handle:
476  log.debug( 'no handle for %s: not transporting properties', self._name )
477  return # allowed, done early
478 
479  # pass final set of properties on to handle on the C++ side or JobOptSvc
480  for name in self._properties.keys():
481  if hasattr( self, name ): # means property has python-side value/default
482  setattr( handle, name, getattr(self,name) )
483 
484  # for debugging purposes
485  self._flags |= self._fSetupOk
486 

◆ unlock()

def python.Configurable.Configurable.unlock (   self)

Definition at line 498 of file Configurable.py.

498  def unlock( self ):
499  # allow again changes to be made
500  import sys, traceback
501  stack = traceback.extract_stack( sys._getframe(1), 1 )
502  log.warning( 'unlock() called on configurable "%s" in %s', self.getJobOptName(), stack[0][0] )
503  self._flags &= ~self._fIsLocked
504 
505  # note that unlock() does not unlock the children; do that individually
506 

Member Data Documentation

◆ __children

python.Configurable.Configurable.__children
private

Definition at line 212 of file Configurable.py.

◆ __hash__

python.Configurable.Configurable.__hash__ = object.__hash__
staticprivate

Definition at line 807 of file Configurable.py.

◆ __slots__

tuple python.Configurable.Configurable.__slots__
staticprivate
Initial value:
= (
'__weakref__', # required for dealing with weak references
'__children', # controlled components, e.g. private AlgTools
'_name', # the (unqualified) component name
'_flags', # see list of flags above
)

Definition at line 72 of file Configurable.py.

◆ _fInitOk

int python.Configurable.Configurable._fInitOk = 0x08
staticprivate

Definition at line 69 of file Configurable.py.

◆ _fInSetDefaults

int python.Configurable.Configurable._fInSetDefaults = 0x01
staticprivate

Definition at line 66 of file Configurable.py.

◆ _fIsLocked

int python.Configurable.Configurable._fIsLocked = 0x02
staticprivate

Definition at line 67 of file Configurable.py.

◆ _fIsPrinting

int python.Configurable.Configurable._fIsPrinting = 0x04
staticprivate

Definition at line 68 of file Configurable.py.

◆ _flags

python.Configurable.Configurable._flags
private

Definition at line 223 of file Configurable.py.

◆ _fSetupOk

int python.Configurable.Configurable._fSetupOk = 0x10
staticprivate

Definition at line 70 of file Configurable.py.

◆ _name

python.Configurable.Configurable._name
private

Definition at line 217 of file Configurable.py.

◆ _printOnce

int python.Configurable.Configurable._printOnce = 0
staticprivate

Definition at line 83 of file Configurable.py.

◆ _useGlobalInstances

bool python.Configurable.Configurable._useGlobalInstances = True
staticprivate

Definition at line 87 of file Configurable.py.

◆ allConfigurables

python.Configurable.Configurable.allConfigurables = weakref.WeakValueDictionary()
static

Definition at line 79 of file Configurable.py.

◆ indentUnit

string python.Configurable.Configurable.indentUnit = '| '
static

Definition at line 62 of file Configurable.py.

◆ printHeaderPre

int python.Configurable.Configurable.printHeaderPre = 5
static

Definition at line 64 of file Configurable.py.

◆ printHeaderWidth

int python.Configurable.Configurable.printHeaderWidth = 100
static

Definition at line 63 of file Configurable.py.

◆ propertyNoValue

python.Configurable.Configurable.propertyNoValue
static

Definition at line 61 of file Configurable.py.


The documentation for this class was generated from the following file:
max
#define max(a, b)
Definition: cfImp.cxx:41
vtune_athena.format
format
Definition: vtune_athena.py:14
index
Definition: index.py:1
python.Bindings.__iter__
__iter__
Definition: Control/AthenaPython/python/Bindings.py:783
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.Utilities.clone
clone
Definition: Utilities.py:134
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:797
covarianceTool.filter
filter
Definition: covarianceTool.py:514
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.JsonUtils.properties
properties
Definition: JsonUtils.py:96
python.AppMgr.copyChild
copyChild
Definition: AppMgr.py:60
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
str
Definition: BTagTrackIpAccessor.cxx:11
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
python.AnaAlgSequence.getFullName
def getFullName(comp)
Definition: AnaAlgSequence.py:12
python.setup
def setup()
Definition: Control/Hephaestus/python/__init__.py:9
Ringer::getType
T getType(const char *cStr)
Return Ringer enumeration of type T identifying string type: