Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Hadrien Benjamin Grasland
Gaudi
Commits
b83dc3b3
Commit
b83dc3b3
authored
Mar 06, 2019
by
Niklas Stefan Nolte
🔥
Committed by
Marco Clemencic
Mar 06, 2019
Browse files
add the possibility to ask for a Mode in a python datahandle
parent
aeb156f0
Changes
4
Hide whitespace changes
Inline
Side-by-side
GaudiKernel/python/GaudiKernel/DataObjectHandleBase.py
View file @
b83dc3b3
...
...
@@ -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
GaudiKernel/python/GaudiKernel/PropertyProxy.py
View file @
b83dc3b3
...
...
@@ -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'
))
...
...
GaudiKernel/src/Lib/DataObjectHandleBase.cpp
View file @
b83dc3b3
...
...
@@ -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
();
}
...
...
GaudiKernel/tests/nose/test_Configurables.py
View file @
b83dc3b3
...
...
@@ -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'
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment