Skip to content
Snippets Groups Projects
Commit 8f1462e7 authored by Walter Lampl's avatar Walter Lampl
Browse files

ComponentAccumulator: Add doc-strings for setPrivateTool and popPrivateTool,...

ComponentAccumulator: Add doc-strings for setPrivateTool and popPrivateTool, move check for dangling private tool(s) to __del__
parent 573fe6bf
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,9 @@ class ComponentAccumulator(object): ...@@ -51,6 +51,9 @@ class ComponentAccumulator(object):
raise RuntimeError("ComponentAccumulator was not merged!") raise RuntimeError("ComponentAccumulator was not merged!")
#log = logging.getLogger("ComponentAccumulator") #log = logging.getLogger("ComponentAccumulator")
#log.error("The ComponentAccumulator listed below was never merged!") #log.error("The ComponentAccumulator listed below was never merged!")
if self._privateTools is not None:
raise RuntimeError("Deleting a ComponentAccumulator with and dangling private tool(s)")
#pass #pass
...@@ -159,21 +162,28 @@ class ComponentAccumulator(object): ...@@ -159,21 +162,28 @@ class ComponentAccumulator(object):
return findSubSequence(self._sequence,sequenceName) return findSubSequence(self._sequence,sequenceName)
def setPrivateTools(self,privTool): def setPrivateTools(self,privTool):
"""Use this method to carry private AlgTool(s) to the caller when returning this ComponentAccumulator.
The method accepts either a single private AlgTool or a list of private AlgTools (typically assigned to ToolHandleArray)
"""
if self._privateTools is not None: if self._privateTools is not None:
raise ConfigurationError("This ComponentAccumulator holds already a private tool. Only one private tool is allowed") raise ConfigurationError("This ComponentAccumulator holds already a (list of) private tool. Only one (list of) private tool(s) is allowed")
if isinstance(privTool,collections.Sequence): if isinstance(privTool,collections.Sequence):
for t in privTool: for t in privTool:
if not isinstance(t,ConfigurableAlgTool): if not isinstance(t,ConfigurableAlgTool):
raise ConfigurationError("ComponentAccumulator.setPrivateTools accepts only configurableAlgTools or lists of ConfigurableAlgTools. Encountered %s in a list" % type(t)) raise ConfigurationError("ComponentAccumulator.setPrivateTools accepts only ConfigurableAlgTools or lists of ConfigurableAlgTools. Encountered %s in a list" % type(t))
else: else:
if not isinstance(privTool,ConfigurableAlgTool): if not isinstance(privTool,ConfigurableAlgTool):
raise ConfigurationError("ComponentAccumulator.setPrivateTools accepts only configurableAlgTools or lists of ConfigurableAlgTools. Encountered %s " % type(privTool)) raise ConfigurationError("ComponentAccumulator.setPrivateTools accepts only cCnfigurableAlgTools or lists of ConfigurableAlgTools. Encountered %s " % type(privTool))
self._privateTools=privTool self._privateTools=privTool
return return
def popPrivateTools(self): def popPrivateTools(self):
"""Get the (list of) private AlgTools from this CompoentAccumulator.
The CA will not keep any reference to the AlgTool.
"""
tool=self._privateTools tool=self._privateTools
self._privateTools=None self._privateTools=None
return tool return tool
...@@ -444,10 +454,6 @@ class ComponentAccumulator(object): ...@@ -444,10 +454,6 @@ class ComponentAccumulator(object):
if other is None: if other is None:
raise RuntimeError("merge called on object of type None: did you forget to return a CA from a config function?") raise RuntimeError("merge called on object of type None: did you forget to return a CA from a config function?")
privTool=self._privateTools or other._privateTools
if (privTool is not None):
raise RuntimeError("merge called on a ComponentAccumulator with and dangling private tool %s/%s" % (privTool.getType(),privTool.getName()))
if isinstance(other,collections.Sequence): if isinstance(other,collections.Sequence):
self._msg.error("Merge called with a: %s " % str(type(other)) + " of length: %d " % len(other)) self._msg.error("Merge called with a: %s " % str(type(other)) + " of length: %d " % len(other))
self._msg.error("where elements are of type : " + ", ".join([ str(type(x).__name__) for x in other]) ) self._msg.error("where elements are of type : " + ", ".join([ str(type(x).__name__) for x in other]) )
......
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