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

Public Member Functions

def __init__ (self, name=Configurable.DefaultName)
 
def getHandle (self)
 
def getGaudiType (self)
 
def getGaudiHandle (self)
 
def getPrintTitle (self)
 
def setParent (self, parentName)
 
def getParent (self)
 
def getDirectParent (self)
 
def hasParent (self, parent)
 
def getJobOptName (self)
 
def isPublic (self)
 
def isInToolSvc (self)
 
def toStringProperty (self)
 
def __new__ (cls, *args, **kwargs)
 
def __new__ (self, name, bases, dct)
 
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 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 getFullName (self)
 
def getFullJobOptName (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 __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

 _jobOptName
 
 __children
 
 _name
 
 _flags
 

Static Private Attributes

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

Detailed Description

Definition at line 877 of file Configurable.py.

Constructor & Destructor Documentation

◆ __init__()

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

Reimplemented from python.Configurable.Configurable.

Definition at line 881 of file Configurable.py.

881  def __init__( self, name = Configurable.DefaultName ):
882  super( ConfigurableAlgTool, self ).__init__( name )
883  name = self.getName()
884  name = name[ name.find('/')+1 : ] # strips class, if any
885  self._jobOptName = name
886 

Member Function Documentation

◆ __bool__()

def python.Configurable.Configurable.__bool__ (   self)
inherited

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 
)
inherited

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 
)
inherited

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 
)
inherited

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 
)
inherited

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)
inherited

Definition at line 274 of file Configurable.py.

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

◆ __getstate__()

def python.Configurable.Configurable.__getstate__ (   self)
inherited

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 
)
inherited

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)
inherited

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)
inherited

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 
)
inherited

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 
)
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 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)
inherited

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 
)
inherited

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)
privateinherited

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)
privateinherited

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 
)
inherited

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)
privateinherited

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 
)
staticprivateinherited

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 
)
staticprivateinherited

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 
)
inherited

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 
)
inherited

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 
)
inherited

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)
inherited
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)
inherited

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)
inherited

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 
)
inherited

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 

◆ getDirectParent()

def python.Configurable.ConfigurableAlgTool.getDirectParent (   self)

Definition at line 931 of file Configurable.py.

931  def getDirectParent( self ):
932  parent = self.getParent()
933  dot = parent.rfind('.')
934  if dot != -1:
935  return parent[dot+1:]
936  else:
937  return parent
938 

◆ getFlattenedProperties()

def python.Configurable.Configurable.getFlattenedProperties (   self)
inherited

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)
inherited

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)
inherited

Definition at line 593 of file Configurable.py.

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

◆ getGaudiHandle()

def python.Configurable.ConfigurableAlgTool.getGaudiHandle (   self)

Definition at line 898 of file Configurable.py.

898  def getGaudiHandle( self ):
899  if self.isPublic():
900  return GaudiHandles.PublicToolHandle( self.toStringProperty() )
901  else:
902  return GaudiHandles.PrivateToolHandle( self.toStringProperty() )
903 

◆ getGaudiType()

def python.Configurable.ConfigurableAlgTool.getGaudiType (   self)

Definition at line 895 of file Configurable.py.

895  def getGaudiType( self ):
896  return 'AlgTool'
897 

◆ getHandle()

def python.Configurable.ConfigurableAlgTool.getHandle (   self)

Definition at line 887 of file Configurable.py.

887  def getHandle( self ):
888  # iAlgTool isn't useful, unless one knows for sure that the tool exists
889  try:
890  from GaudiPython.Bindings import iProperty
891  except ImportError:
892  from gaudimodule import iProperty
893  return iProperty( self.getJobOptName() )
894 

◆ getJobOptName()

def python.Configurable.ConfigurableAlgTool.getJobOptName (   self)

Reimplemented from python.Configurable.Configurable.

Definition at line 942 of file Configurable.py.

942  def getJobOptName( self ):
943  return self._jobOptName
944 

◆ getName()

def python.Configurable.Configurable.getName (   self)
inherited

Definition at line 580 of file Configurable.py.

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

◆ getParent()

def python.Configurable.ConfigurableAlgTool.getParent (   self)

Reimplemented from python.Configurable.Configurable.

Definition at line 924 of file Configurable.py.

924  def getParent( self ):
925  dot = self._jobOptName.rfind('.')
926  if dot != -1:
927  return self._jobOptName[:dot]
928  else:
929  return ""
930 

◆ getPrintTitle()

def python.Configurable.ConfigurableAlgTool.getPrintTitle (   self)

Reimplemented from python.Configurable.Configurable.

Definition at line 904 of file Configurable.py.

904  def getPrintTitle(self):
905  if self.isPublic():
906  pop = 'Public '
907  else:
908  pop = 'Private '
909  return pop + Configurable.getPrintTitle(self)
910 

◆ getProperties()

def python.Configurable.Configurable.getProperties (   self)
inherited

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)
inherited

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)
inherited

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)
inherited

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)
inherited

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)
inherited

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.ConfigurableAlgTool.hasParent (   self,
  parent 
)

Reimplemented from python.Configurable.Configurable.

Definition at line 939 of file Configurable.py.

939  def hasParent( self, parent ):
940  return self._jobOptName.startswith( parent + '.' )
941 

◆ isInToolSvc()

def python.Configurable.ConfigurableAlgTool.isInToolSvc (   self)

Definition at line 948 of file Configurable.py.

948  def isInToolSvc( self ):
949  return self.getParent() == 'ToolSvc'
950 

◆ isLocked()

def python.Configurable.Configurable.isLocked (   self)
inherited

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)
inherited

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.ConfigurableAlgTool.isPublic (   self)

Reimplemented from python.Configurable.Configurable.

Definition at line 945 of file Configurable.py.

945  def isPublic( self ):
946  return self.isInToolSvc()
947 

◆ lock()

def python.Configurable.Configurable.lock (   self)
inherited

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)
inherited

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 
)
inherited

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)
inherited

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 
)
inherited

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)
inherited

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 
)
inherited

Definition at line 608 of file Configurable.py.

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

◆ setParent()

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

Reimplemented from python.Configurable.Configurable.

Definition at line 911 of file Configurable.py.

911  def setParent( self, parentName ):
912 # print "ConfigurableAlgTool.setParent(%s@%x,%r)" % (self.getName(),id(self),parentName)
913 # print "Calling stack:"
914 # import traceback
915 # traceback.print_stack()
916  # propagate parent to AlgTools in children
917  for c in self.getAllChildren():
918  if isinstance(c,ConfigurableAlgTool): c.setParent( parentName )
919 
920  # update my own parent
921  self._jobOptName = parentName + '.' + self._jobOptName
922 
923 

◆ setup()

def python.Configurable.Configurable.setup (   self)
inherited

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 

◆ toStringProperty()

def python.Configurable.ConfigurableAlgTool.toStringProperty (   self)

Definition at line 951 of file Configurable.py.

951  def toStringProperty( self ):
952  # called on conversion to a string property for the jocat
953  return self.getType() + '/' + self.getName()
954 
955 

◆ unlock()

def python.Configurable.Configurable.unlock (   self)
inherited

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
privateinherited

Definition at line 212 of file Configurable.py.

◆ __hash__

python.Configurable.Configurable.__hash__ = object.__hash__
staticprivateinherited

Definition at line 807 of file Configurable.py.

◆ __slots__

dictionary python.Configurable.ConfigurableAlgTool.__slots__
staticprivate
Initial value:
= { '_jobOptName' : '', 'OutputLevel' : 0, \
'AuditTools' : 0, 'AuditInitialize' : 0, 'AuditFinalize' : 0 }

Definition at line 878 of file Configurable.py.

◆ _fInitOk

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

Definition at line 69 of file Configurable.py.

◆ _fInSetDefaults

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

Definition at line 66 of file Configurable.py.

◆ _fIsLocked

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

Definition at line 67 of file Configurable.py.

◆ _fIsPrinting

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

Definition at line 68 of file Configurable.py.

◆ _flags

python.Configurable.Configurable._flags
privateinherited

Definition at line 223 of file Configurable.py.

◆ _fSetupOk

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

Definition at line 70 of file Configurable.py.

◆ _jobOptName

python.Configurable.ConfigurableAlgTool._jobOptName
private

Definition at line 885 of file Configurable.py.

◆ _name

python.Configurable.Configurable._name
privateinherited

Definition at line 217 of file Configurable.py.

◆ _printOnce

int python.Configurable.Configurable._printOnce = 0
staticprivateinherited

Definition at line 83 of file Configurable.py.

◆ _useGlobalInstances

bool python.Configurable.Configurable._useGlobalInstances = True
staticprivateinherited

Definition at line 87 of file Configurable.py.

◆ allConfigurables

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

Definition at line 79 of file Configurable.py.

◆ indentUnit

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

Definition at line 62 of file Configurable.py.

◆ printHeaderPre

int python.Configurable.Configurable.printHeaderPre = 5
staticinherited

Definition at line 64 of file Configurable.py.

◆ printHeaderWidth

int python.Configurable.Configurable.printHeaderWidth = 100
staticinherited

Definition at line 63 of file Configurable.py.

◆ propertyNoValue

python.Configurable.Configurable.propertyNoValue
staticinherited

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
python.TestDriveDummies.properties
dictionary properties
Definition: TestDriveDummies.py:14
index
Definition: index.py:1
python.Bindings.__iter__
__iter__
Definition: Control/AthenaPython/python/Bindings.py:791
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.Utilities.clone
clone
Definition: Utilities.py:134
dumpTruth.getName
getName
Definition: dumpTruth.py:34
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
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.AppMgr.copyChild
copyChild
Definition: AppMgr.py:61
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
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:798
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: