32 Executes an analysis workflow.
34 The ``csworkflow`` script executes an analysis workflow defined in an
46 List of IRAF command line parameter strings of the form
52 An invalid number of command line arguments was provided.
55 self._init_cscript(self.__class__.__name__, ctools.__version__, argv)
71 xmlfile = self[
'inflow'].filename()
72 self.
_workflow = gammalib.GXml(xmlfile.url())
75 self._log_parameters(gammalib.TERSE)
84 workflow = self._workflow.element(
'workflow')
87 num_actors = workflow.elements(
'actor')
93 for i
in range(num_actors):
96 actor = workflow.element(
'actor', i)
100 output_parameters = []
105 name = actor.attribute(
'name')
106 tool = actor.attribute(
'tool')
109 if actor.elements(
'input') > 0:
110 actor_inputs = actor.element(
'input')
111 num_inputs = actor_inputs.elements(
'parameter')
112 for k
in range(num_inputs):
113 input_par = actor_inputs.element(
'parameter', k)
114 input_name = input_par.attribute(
'name')
115 input_value = input_par.attribute(
'value')
116 input_actor = input_par.attribute(
'actor')
117 parameter = {
'name': input_name, \
118 'value': input_value, \
119 'actor': input_actor}
120 input_parameters.append(parameter)
121 if input_actor !=
'':
122 if input_actor
not in input_actors:
123 input_actors.append(input_actor)
126 if actor.elements(
'output') > 0:
127 actor_output = actor.element(
'output')
128 num_outputs = actor_output.elements(
'parameter')
129 for k
in range(num_outputs):
130 output_par = actor_output.element(
'parameter', k)
131 output_name = output_par.attribute(
'name')
132 output_value = output_par.attribute(
'value')
133 output_actor = output_par.attribute(
'actor')
134 parameter = {
'name': output_name, \
135 'value': output_value, \
136 'actor': output_actor}
137 output_parameters.append(parameter)
138 if output_actor !=
'':
139 if output_actor
not in output_actors:
140 output_actors.append(output_actor)
143 num_inputs = len(input_actors)
147 status =
'waiting for input'
152 entry = {
'name': name,
154 'input_parameters': input_parameters,
155 'input_actors': input_actors,
156 'output_parameters': output_parameters,
157 'output_actors': output_actors,
161 self._actors.append(entry)
164 self._log_value(gammalib.NORMAL,
'Actor "%s"' % name, tool)
168 predecessors =
'none'
171 for k
in range(num_inputs):
174 predecessors +=
'"'+input_actors[k]+
'"'
177 self._log_value(gammalib.NORMAL,
178 gammalib.number(
' Predecessor', num_inputs),
195 if actor[
'status'] ==
'ready':
198 self._log_value(gammalib.NORMAL,
'Execute actor',
199 '"%s"' % actor[
'name'])
205 self._log_value(gammalib.NORMAL,
'Finished actor execution',
206 '"%s"' % actor[
'name'])
209 actor[
'status'] =
'finished'
220 if actor[
'status'] !=
'finished':
221 input_actors = actor[
'input_actors']
223 for input_actor
in input_actors:
225 if a[
'status'] !=
'finished':
229 actor[
'status'] =
'ready'
238 pars = actor[
'input_parameters']
240 self._log_value(gammalib.NORMAL,
' Input parameter',
'%s=%s' %
244 pars = actor[
'output_parameters']
246 self._log_value(gammalib.NORMAL,
' Output parameter',
'%s=%s' %
253 tool_eval =
'ctools.'+tool+
'()'
254 elif tool[:2] ==
'cs':
255 tool_eval =
'cscripts.'+tool+
'()'
262 tool = eval(tool_eval)
265 pars = actor[
'input_parameters']
267 app_par = tool[par[
'name']]
269 tool[par[
'name']] = app_par
272 pars = actor[
'output_parameters']
274 app_par = tool[par[
'name']]
276 tool[par[
'name']] = app_par
289 if (par[
'actor'] ==
''):
296 for output
in actor[
'output_parameters']:
297 if output[
'name'] == par[
'value']:
298 value = output[
'value']
302 msg =
'Parameter "'+par[
'value']+
'" is not an output '+ \
303 'parameter of actor "'+par[
'actor']+
'".'
304 raise RuntimeError(msg)
314 if actor[
'name'] == name:
318 msg =
'Actor "'+name+
'" not found.'
319 raise RuntimeError(msg)
336 self._log.header1(
'Parse workflow XML file')
342 self._log.header1(
'Execute workflow')
352 if __name__ ==
'__main__':