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

return the just-added tool from addTool

augment addTool to return the tool it just added.
This allows one to write:
```python
myToolWithName = myalg.addTool(tool_conf2,"ToolWithName")
myToolWithName.String = "xyz"
```
instead of 
```python
myalg.addTool(tool_conf2,"ToolWithName")
myalg.ToolWithName.String = "xyz"
```
which requires one to duplicate the "ToolWithName" -- once as string, and
once as attribute, but only rarely does anybody use getattr for the 2nd
case to just avoid the duplication.

Of course, one could write 
```python
myalg.addTool(tool_conf2,"ToolWithName", String="xyz")
```
or even pass in a complete dictionary with **, but the configuration of
the tool isn't necessarily complete at the time of creation of its
configurable.

Fixes GAUDI-1162.
See merge request !87
parents ce142973 4f512ebd
No related branches found
No related tags found
No related merge requests found
...@@ -36,9 +36,14 @@ tool_conf2 = MyTool( 'MyTool_conf2', ...@@ -36,9 +36,14 @@ tool_conf2 = MyTool( 'MyTool_conf2',
OutputLevel = INFO ) OutputLevel = INFO )
myalg.addTool(tool_conf2,"ToolWithName") myToolWithName = myalg.addTool(tool_conf2,"ToolWithName")
myalg.ToolWithName.String = "abc" myalg.ToolWithName.String = "xyz"
assert myToolWithName.String == "xyz"
assert myalg.ToolWithName == myToolWithName
myToolWithName.String = "abc"
mygalg = MyGaudiAlgorithm('MyGaudiAlg') mygalg = MyGaudiAlgorithm('MyGaudiAlg')
mygalg.PrivToolHandle.String = "Is a private tool" mygalg.PrivToolHandle.String = "Is a private tool"
......
...@@ -786,6 +786,7 @@ class Configurable( object ): ...@@ -786,6 +786,7 @@ class Configurable( object ):
if name in self.__slots__: if name in self.__slots__:
# this is to avoid that the property hides the tool # this is to avoid that the property hides the tool
setattr(self,name,self.__tools[name]) setattr(self,name,self.__tools[name])
return self.__tools[name]
def _isInSetDefaults( self ): def _isInSetDefaults( self ):
return self._inSetDefaults return self._inSetDefaults
......
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