Skip to content

WIP: Python type support for data handles

Frank Winklmeier requested to merge fwinkl/athena:gaudi_handle into master

Introduction

Implement Python type support for DataHandles (ReadHandleKey, WriteHandleKey, etc.). At the moment those are simply represented by their key value as strings:

>>> from AthExHive.AthExHiveConf import AlgB
>>> alg = AlgB()
>>> print(alg)
/***** Algorithm AlgB/AlgB *************************************************************************
[...]
|-Key_R1                     = 'StoreGateSvc+a1'
|-Key_W1                     = 'StoreGateSvc+a3'

However, handles carry additional information that is currently only accessible in C++. This MR makes this information also available in Python. Instead of implementing our own Python type hierarchy mirroring all of our (13 different!) C++ handle types, I decided to simply use the existing GaudiKernel.DataHandle. This could be re-discussed but is probably sufficient. The Python type is meant to be only used for inspection. For assigning a value to a handle, nothing changes, i.e. this continues to work via a plain string.

Implementation details

  • DataHandlePropertyProxy was added to manage the str->DataHandle conversion when assigning a value to a handle. This is 1:1 copy from Gaudi.
  • Override VarHandleKey::pythonRepr to write the proper Python representation during the Configurable generation.
  • Make VarHandleKeyProperty derive from DataHandleProperty. This is necessary in order for the property to be recognized as (data) handle in genconf.
  • A few unit tests had to be adapted as the property type is now correctly propagated by Gaudi. E.g. a WriteHandleKey property reports its type whereas it was VarHandleKey before. Note that WriteDecorHandleKey reports now as WriteHandleKey as well because our implementation leverages the declareProperty of its base.

Example

Python Configurable of AthExHive/HiveAlgB

>>> from AthExHive.AthExHiveConf import AlgB
>>> alg = AlgB()
>>> print(alg)
[...]
|-Key_R1                     = 'StoreGateSvc+a1'
|-Key_W1                     = 'StoreGateSvc+a3'
[...]

/***** Algorithm AlgB/AlgB *************************************************************************
|-Key_R1                     = DataHandle('StoreGateSvc+a1','R','HiveDataObj')
|-Key_W1                     = DataHandle('StoreGateSvc+a3','W','HiveDataObj')
[...]
>>> alg.Key_R1.type()
'HiveDataObj'
>>> alg.Key_R1.mode()
'R'
>>> alg.Key_R1.isCondition()
False

Dependencies

Requires: gaudi/Gaudi!1091 (merged), gaudi/Gaudi!1126 (merged), atlasexternals!740 (merged), !36693 (merged)

Edited by Frank Winklmeier

Merge request reports