Skip to content
Snippets Groups Projects
Commit fa00bc57 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Add the possibility to ask for Mode in python data handle property (!845)

parents aeb156f0 b83dc3b3
No related branches found
No related tags found
No related merge requests found
...@@ -5,13 +5,14 @@ __doc__ = """The python module holding python bindings to DataObjectHandle""" ...@@ -5,13 +5,14 @@ __doc__ = """The python module holding python bindings to DataObjectHandle"""
class DataObjectHandleBase(object): class DataObjectHandleBase(object):
__slots__ = ('Path', ) __slots__ = ('Path', 'Mode')
# define accessTypes # define accessTypes
def __init__(self, path): def __init__(self, path, mode='R'):
object.__init__(self) object.__init__(self)
self.Path = path self.Path = path
self.Mode = mode
def __eq__(self, other): def __eq__(self, other):
""" """
...@@ -43,12 +44,15 @@ class DataObjectHandleBase(object): ...@@ -43,12 +44,15 @@ class DataObjectHandleBase(object):
def __add__(self, other): def __add__(self, other):
path = ':'.join(i + other for i in self.Path.split(':')) path = ':'.join(i + other for i in self.Path.split(':'))
return DataObjectHandleBase(path) return DataObjectHandleBase(path, self.Mode)
def __radd__(self, other): def __radd__(self, other):
path = ':'.join(other + i for i in self.Path.split(':')) path = ':'.join(other + i for i in self.Path.split(':'))
return DataObjectHandleBase(path) return DataObjectHandleBase(path, self.Mode)
def __iadd__(self, other): def __iadd__(self, other):
self.Path = ':'.join(i + other for i in self.Path.split(':')) self.Path = ':'.join(i + other for i in self.Path.split(':'))
return self return self
def mode(self):
return self.Mode
...@@ -407,10 +407,11 @@ class DataObjectHandleBasePropertyProxy(PropertyProxy): ...@@ -407,10 +407,11 @@ class DataObjectHandleBasePropertyProxy(PropertyProxy):
if value is None: if value is None:
value = '' value = ''
mode = obj.__class__.getDefaultProperty(self.descr.__name__).mode()
if type(value) == str: if type(value) == str:
return DataObjectHandleBase(value) return DataObjectHandleBase(value, mode)
elif isinstance(value, DataObjectHandleBase): elif isinstance(value, DataObjectHandleBase):
return DataObjectHandleBase(value.__str__()) return DataObjectHandleBase(value.__str__(), mode)
else: else:
raise ValueError("received an instance of %s, but %s expected" % raise ValueError("received an instance of %s, but %s expected" %
(type(value), 'str or DataObjectHandleBase')) (type(value), 'str or DataObjectHandleBase'))
......
...@@ -109,7 +109,21 @@ DataObject* DataObjectHandleBase::fetch() const { ...@@ -109,7 +109,21 @@ DataObject* DataObjectHandleBase::fetch() const {
std::string DataObjectHandleBase::toString() const { return objKey(); } std::string DataObjectHandleBase::toString() const { return objKey(); }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
std::string DataObjectHandleBase::pythonRepr() const { return "DataObjectHandleBase(\"" + toString() + "\")"; } std::string DataObjectHandleBase::pythonRepr() const {
std::string m;
switch ( mode() ) {
case Gaudi::DataHandle::Mode::Reader:
m = "R";
break;
case Gaudi::DataHandle::Mode::Writer:
m = "W";
break;
default:
m = "UNKNOWN";
break;
}
return "DataObjectHandleBase('" + toString() + "', '" + m + "')";
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void DataObjectHandleBase::fromString( const std::string& s ) { Gaudi::Parsers::parse( *this, s ).ignore(); } void DataObjectHandleBase::fromString( const std::string& s ) { Gaudi::Parsers::parse( *this, s ).ignore(); }
......
...@@ -7,7 +7,7 @@ class MyAlg(ConfigurableAlgorithm): ...@@ -7,7 +7,7 @@ class MyAlg(ConfigurableAlgorithm):
__slots__ = { __slots__ = {
'Text': 'some text', 'Text': 'some text',
'Int': 23, 'Int': 23,
'DataHandle': DataObjectHandleBase('Location') 'DataHandle': DataObjectHandleBase('Location', 'R')
} }
def getDlls(self): def getDlls(self):
...@@ -34,13 +34,13 @@ def test_correct(): ...@@ -34,13 +34,13 @@ def test_correct():
assert a.getValuedProperties() == { assert a.getValuedProperties() == {
'Int': 42, 'Int': 42,
'Text': 'value', 'Text': 'value',
'DataHandle': DataObjectHandleBase('/Event/X') 'DataHandle': DataObjectHandleBase('/Event/X', 'R')
} }
def test_str_from_datahandle(): def test_str_from_datahandle():
a = MyAlg() a = MyAlg()
a.Text = DataObjectHandleBase('value') a.Text = DataObjectHandleBase('value', 'R')
assert a.getProp('Text') == 'value' assert a.getProp('Text') == 'value'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment