Commit b83dc3b3 authored by Niklas Stefan Nolte's avatar Niklas Stefan Nolte 🔥 Committed by Marco Clemencic
Browse files

add the possibility to ask for a Mode in a python datahandle

parent aeb156f0
......@@ -5,13 +5,14 @@ __doc__ = """The python module holding python bindings to DataObjectHandle"""
class DataObjectHandleBase(object):
__slots__ = ('Path', )
__slots__ = ('Path', 'Mode')
# define accessTypes
def __init__(self, path):
def __init__(self, path, mode='R'):
object.__init__(self)
self.Path = path
self.Mode = mode
def __eq__(self, other):
"""
......@@ -43,12 +44,15 @@ class DataObjectHandleBase(object):
def __add__(self, other):
path = ':'.join(i + other for i in self.Path.split(':'))
return DataObjectHandleBase(path)
return DataObjectHandleBase(path, self.Mode)
def __radd__(self, other):
path = ':'.join(other + i for i in self.Path.split(':'))
return DataObjectHandleBase(path)
return DataObjectHandleBase(path, self.Mode)
def __iadd__(self, other):
self.Path = ':'.join(i + other for i in self.Path.split(':'))
return self
def mode(self):
return self.Mode
......@@ -407,10 +407,11 @@ class DataObjectHandleBasePropertyProxy(PropertyProxy):
if value is None:
value = ''
mode = obj.__class__.getDefaultProperty(self.descr.__name__).mode()
if type(value) == str:
return DataObjectHandleBase(value)
return DataObjectHandleBase(value, mode)
elif isinstance(value, DataObjectHandleBase):
return DataObjectHandleBase(value.__str__())
return DataObjectHandleBase(value.__str__(), mode)
else:
raise ValueError("received an instance of %s, but %s expected" %
(type(value), 'str or DataObjectHandleBase'))
......
......@@ -109,7 +109,21 @@ DataObject* DataObjectHandleBase::fetch() const {
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(); }
......
......@@ -7,7 +7,7 @@ class MyAlg(ConfigurableAlgorithm):
__slots__ = {
'Text': 'some text',
'Int': 23,
'DataHandle': DataObjectHandleBase('Location')
'DataHandle': DataObjectHandleBase('Location', 'R')
}
def getDlls(self):
......@@ -34,13 +34,13 @@ def test_correct():
assert a.getValuedProperties() == {
'Int': 42,
'Text': 'value',
'DataHandle': DataObjectHandleBase('/Event/X')
'DataHandle': DataObjectHandleBase('/Event/X', 'R')
}
def test_str_from_datahandle():
a = MyAlg()
a.Text = DataObjectHandleBase('value')
a.Text = DataObjectHandleBase('value', 'R')
assert a.getProp('Text') == 'value'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment