]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/ForEachLoop.cxx
Salome HOME
Issue EDF13268 - link from list[pyobj] inside ForEachLoop to list[pyobj] outside...
[modules/yacs.git] / src / engine / ForEachLoop.cxx
1 // Copyright (C) 2006-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ForEachLoop.hxx"
21 #include "TypeCode.hxx"
22 #include "Visitor.hxx"
23 #include "ComposedNode.hxx"
24 #include "Executor.hxx"
25 #include "AutoLocker.hxx"
26
27 #include <iostream>
28 #include <iomanip>
29 #include <sstream>
30 #include <algorithm>    // std::replace_if
31
32 //#define _DEVDEBUG_
33 #include "YacsTrace.hxx"
34
35 using namespace YACS::ENGINE;
36 using namespace std;
37
38 /*! \class YACS::ENGINE::ForEachLoop
39  *  \brief Loop node for parametric calculation
40  *
41  *  \ingroup Nodes
42  */
43
44 const char FakeNodeForForEachLoop::NAME[]="thisIsAFakeNode";
45
46 const char SplitterNode::NAME_OF_SEQUENCE_INPUT[]="SmplsCollection";
47
48 const char ForEachLoop::NAME_OF_SPLITTERNODE[]="splitter";
49
50 const int ForEachLoop::NOT_RUNNING_BRANCH_ID=-1;
51
52 const char ForEachLoop::INTERCEPTOR_STR[]="_interceptor";
53
54 InterceptorInputPort::InterceptorInputPort(const std::string& name, Node *node, TypeCode* type):AnyInputPort(name,node,type),
55                                                                                                 DataPort(name,node,type),Port(node),
56                                                                                                 _repr(0)
57 {
58 }
59
60 InterceptorInputPort::InterceptorInputPort(const  InterceptorInputPort& other, Node *newHelder):AnyInputPort(other,newHelder),DataPort(other,newHelder),
61                                                                                                 Port(other,newHelder),
62                                                                                                 _repr(0)
63 {
64 }
65
66 void InterceptorInputPort::getAllRepresentants(std::set<InPort *>& repr) const
67 {
68   set<InPort *> ports=_repr->edSetInPort();
69   for(set<InPort *>::iterator iter=ports.begin();iter!=ports.end();iter++)
70     (*iter)->getAllRepresentants(repr);
71 }
72
73 InputPort *InterceptorInputPort::clone(Node *newHelder) const
74 {
75   return new InterceptorInputPort(*this,newHelder);
76 }
77
78 void InterceptorInputPort::setRepr(AnySplitOutputPort *repr)
79 {
80   _repr=repr;
81 }
82
83 bool AnySplitOutputPort::decrRef()
84 {
85   return (--_cnt==0);
86 }
87
88 void AnySplitOutputPort::incrRef() const
89 {
90   _cnt++;
91 }
92
93 AnySplitOutputPort::AnySplitOutputPort(const std::string& name, Node *node, TypeCode *type):OutputPort(name,node,type),
94                                                                                             DataPort(name,node,type),Port(node),
95                                                                                             _repr(0),_intercptr(0),_cnt(1)
96 {
97 }
98
99 AnySplitOutputPort::AnySplitOutputPort(const AnySplitOutputPort& other, Node *newHelder):OutputPort(other,newHelder),
100                                                                                          DataPort(other,newHelder),
101                                                                                          Port(other,newHelder),
102                                                                                          _repr(0),_intercptr(0),_cnt(1)
103 {
104 }
105
106 bool AnySplitOutputPort::addInPort(InPort *inPort) throw(YACS::Exception)
107 {
108   bool ret=OutputPort::addInPort(inPort);
109   if(_repr)
110     _repr->addInPort(_intercptr);
111   return ret;
112 }
113
114 void AnySplitOutputPort::getAllRepresented(std::set<OutPort *>& represented) const
115 {
116   if(!_repr)
117     OutPort::getAllRepresented(represented);
118   else
119     _repr->getAllRepresented(represented);
120 }
121
122 int AnySplitOutputPort::removeInPort(InPort *inPort, bool forward) throw(YACS::Exception)
123 {
124   bool ret=OutputPort::removeInPort(inPort,forward);
125   if(_repr)
126     if(_setOfInputPort.empty())
127       _repr->removeInPort(_intercptr,forward);
128   return ret;
129 }
130
131 void AnySplitOutputPort::addRepr(OutPort *repr, InterceptorInputPort *intercptr)
132 {
133   _repr=repr;
134   _intercptr=intercptr;
135 }
136
137 OutputPort *AnySplitOutputPort::clone(Node *newHelder) const
138 {
139   return new AnySplitOutputPort(*this,newHelder);
140 }
141
142 SeqAnyInputPort::SeqAnyInputPort(const std::string& name, Node *node, TypeCodeSeq* type):AnyInputPort(name,node,type),DataPort(name,node,type),Port(node)
143 {
144   _type->decrRef();
145 }
146
147 SeqAnyInputPort::SeqAnyInputPort(const  SeqAnyInputPort& other, Node *newHelder):AnyInputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder)
148 {
149 }
150
151 InputPort *SeqAnyInputPort::clone(Node *newHelder) const
152 {
153   return new SeqAnyInputPort(*this,newHelder);
154 }
155
156 unsigned SeqAnyInputPort::getNumberOfElements() const
157 {
158   const SequenceAny * valCsted=(const SequenceAny *) _value;
159   if (valCsted) return valCsted->size();
160   return 0;
161 }
162
163 Any *SeqAnyInputPort::getValueAtRank(int i) const
164 {
165   const SequenceAny * valCsted=(const SequenceAny *) _value;
166   AnyPtr ret=(*valCsted)[i];
167   ret->incrRef();
168   return ret;
169 }
170
171 std::string SeqAnyInputPort::dump()
172 {
173   stringstream xmldump;
174   int nbElem = getNumberOfElements();
175   xmldump << "<value><array><data>" << endl;
176   for (int i = 0; i < nbElem; i++)
177     {
178       Any *val = getValueAtRank(i);
179       switch (val->getType()->kind())
180         {
181         case Double:
182           xmldump << "<value><double>" << setprecision(16) << val->getDoubleValue() << "</double></value>" << endl;
183           break;
184         case Int:
185           xmldump << "<value><int>" << val->getIntValue() << "</int></value>" << endl;
186           break;
187         case Bool:
188           xmldump << "<value><boolean>" << val->getBoolValue() << "</boolean></value>" << endl;
189           break;
190         case String:
191           xmldump << "<value><string>" << val->getStringValue() << "</string></value>" << endl;
192           break;
193         case Objref:
194           xmldump << "<value><objref>" << val->getStringValue() << "</objref></value>" << endl;
195           break;
196         default:
197           xmldump << "<value><error> NO_SERIALISATION_AVAILABLE </error></value>" << endl;
198           break;
199         }
200     }
201   xmldump << "</data></array></value>" << endl;
202   return xmldump.str();
203 }
204
205 SplitterNode::SplitterNode(const std::string& name, TypeCode *typeOfData, 
206                            ForEachLoop *father):ElementaryNode(name),
207                                                 _dataPortToDispatch(NAME_OF_SEQUENCE_INPUT,
208                                                                     this,(TypeCodeSeq *)TypeCode::sequenceTc("","",typeOfData))
209 {
210   _father=father;
211 }
212
213 SplitterNode::SplitterNode(const SplitterNode& other, ForEachLoop *father):ElementaryNode(other,father),
214                                                                            _dataPortToDispatch(other._dataPortToDispatch,this)
215 {
216 }
217
218 InputPort *SplitterNode::getInputPort(const std::string& name) const throw(YACS::Exception)
219 {
220   if(name==NAME_OF_SEQUENCE_INPUT)
221     return (InputPort *)&_dataPortToDispatch;
222   else
223     return ElementaryNode::getInputPort(name);
224 }
225
226 Node *SplitterNode::simpleClone(ComposedNode *father, bool editionOnly) const
227 {
228   return new SplitterNode(*this,(ForEachLoop *)father);
229 }
230
231 unsigned SplitterNode::getNumberOfElements() const
232 {
233   return _dataPortToDispatch.getNumberOfElements();
234 }
235
236 void SplitterNode::execute()
237 {
238   //Nothing : should never been called elsewhere big problem...
239 }
240
241 void SplitterNode::init(bool start)
242 {
243   ElementaryNode::init(start);
244   _dataPortToDispatch.exInit(start);
245 }
246
247 void SplitterNode::putSplittedValueOnRankTo(int rankInSeq, int branch, bool first)
248 {
249   Any *valueToDispatch=_dataPortToDispatch.getValueAtRank(rankInSeq);
250   ForEachLoop *fatherTyped=(ForEachLoop *)_father;
251   fatherTyped->putValueOnBranch(valueToDispatch,branch,first);
252   valueToDispatch->decrRef();
253 }
254
255 FakeNodeForForEachLoop::FakeNodeForForEachLoop(ForEachLoop *loop, bool normalFinish):ElementaryNode(NAME),
256                                                                                      _loop(loop),
257                                                                                      _normalFinish(normalFinish)
258 {
259   _state=YACS::TOACTIVATE;
260   _father=_loop->getFather();
261 }
262
263 FakeNodeForForEachLoop::FakeNodeForForEachLoop(const FakeNodeForForEachLoop& other):ElementaryNode(other),_loop(0),
264                                                                                     _normalFinish(false)
265 {
266 }
267
268 Node *FakeNodeForForEachLoop::simpleClone(ComposedNode *father, bool editionOnly) const
269 {
270   return new FakeNodeForForEachLoop(*this);
271 }
272
273 void FakeNodeForForEachLoop::exForwardFailed()
274 {
275   _loop->exForwardFailed();
276 }
277
278 void FakeNodeForForEachLoop::exForwardFinished()
279
280   _loop->exForwardFinished();
281 }
282
283 void FakeNodeForForEachLoop::execute()
284 {
285   if(!_normalFinish)
286     throw Exception("");//only to trigger ABORT on Executor
287   else
288     _loop->pushAllSequenceValues();
289 }
290
291 void FakeNodeForForEachLoop::aborted()
292 {
293   _loop->setState(YACS::ERROR);
294 }
295
296 void FakeNodeForForEachLoop::finished()
297 {
298   _loop->setState(YACS::DONE);
299 }
300
301 ForEachLoopPassedData::ForEachLoopPassedData(const std::vector<unsigned int>& passedIds, const std::vector<SequenceAny *>& passedOutputs, const std::vector<std::string>& nameOfOutputs):_passedIds(passedIds),_passedOutputs(passedOutputs),_nameOfOutputs(nameOfOutputs)
302 {
303   std::size_t sz(_passedIds.size()),sz1(passedOutputs.size()),sz2(nameOfOutputs.size());
304   if(sz1!=sz2)
305     throw YACS::Exception("ForEachLoopPassedData::ForEachLoopPassedData : nameOfOutputs and passedOutputs must have the same size !");
306   for(std::vector<SequenceAny *>::iterator it=_passedOutputs.begin();it!=_passedOutputs.end();it++)
307     {
308       const SequenceAny *elt(*it);
309       if(elt)
310         if(sz!=(std::size_t)elt->size())
311           throw YACS::Exception("ForEachLoopPassedData::ForEachLoopPassedData : incoherent input of passed data !");
312     }
313   for(std::vector<SequenceAny *>::iterator it=_passedOutputs.begin();it!=_passedOutputs.end();it++)
314     {
315       SequenceAny *elt(*it);
316       if(elt)
317         elt->incrRef();
318     }
319 }
320
321 ForEachLoopPassedData::~ForEachLoopPassedData()
322 {
323   for(std::vector<SequenceAny *>::iterator it=_passedOutputs.begin();it!=_passedOutputs.end();it++)
324     {
325       SequenceAny *elt(*it);
326       if(elt)
327         elt->decrRef();
328     }
329 }
330
331 void ForEachLoopPassedData::init()
332 {
333   _flagsIds.clear();
334 }
335
336 void ForEachLoopPassedData::checkCompatibilyWithNb(int nbOfElts) const
337 {
338   if(nbOfElts<0)
339     throw YACS::Exception("ForEachLoopPassedData::checkCompatibilyWithNb : nb of elts is expected to be > 0 !");
340   std::size_t sizeExp(_passedIds.size()),nbOfElts2(nbOfElts);
341   if(nbOfElts2<sizeExp)
342     throw YACS::Exception("ForEachLoopPassedData::checkCompatibilyWithNb : Invalid nb of elemts in input seq regarding passed data set !");
343   for(std::vector<unsigned int>::const_iterator it=_passedIds.begin();it!=_passedIds.end();it++)
344     {
345       if((*it)>=nbOfElts2)
346         throw YACS::Exception("ForEachLoopPassedData::checkCompatibilyWithNb : Invalid nb of elemts in input seq regarding passed data set 2 !");
347     }
348   _flagsIds.resize(nbOfElts);
349   std::fill(_flagsIds.begin(),_flagsIds.end(),false);
350   for(std::vector<unsigned int>::const_iterator it=_passedIds.begin();it!=_passedIds.end();it++)
351     {
352       if(*it<nbOfElts)
353         {
354           if(!_flagsIds[*it])
355             _flagsIds[*it]=true;
356           else
357             {
358               std::ostringstream oss; oss << "ForEachLoopPassedData::checkCompatibilyWithNb : id " << *it << " in list of ids appears more than once !";
359               throw YACS::Exception(oss.str());
360             }
361         }
362       else
363         {
364           std::ostringstream oss; oss << "ForEachLoopPassedData::checkCompatibilyWithNb : Presence of id " << *it << " in list of ids ! Must be in [0," <<  nbOfElts << ") !";
365           throw YACS::Exception(oss.str());
366         }
367     }
368 }
369
370 void ForEachLoopPassedData::checkLevel2(const std::vector<AnyInputPort *>& ports) const
371 {
372   std::size_t sz(_nameOfOutputs.size());
373   if(sz!=ports.size())
374     throw YACS::Exception("ForEachLoopPassedData::checkLevel2 : mismatch of size of vectors !");
375   for(std::size_t i=0;i<sz;i++)
376     {
377       AnyInputPort *elt(ports[i]);
378       if(!elt)
379         throw YACS::Exception("ForEachLoopPassedData::checkLevel2 : presence of null instance !");
380       if(_nameOfOutputs[i]!=elt->getName())
381         {
382           std::ostringstream oss; oss << "ForEachLoopPassedData::checkLevel2 : At pos #" << i << " the name is not OK !";
383           throw YACS::Exception(oss.str());
384         }
385     }
386 }
387
388 /*!
389  * performs local to abs id. Input \a localId refers to an id in all jobs to perform. Returned id refers to pos in whole output sequences.
390  */
391 int ForEachLoopPassedData::toAbsId(int localId) const
392 {
393   if(localId<0)
394     throw YACS::Exception("ForEachLoopPassedData::toAbsId : local pos must be >= 0 !");
395   int ret(0),curLocId(0);
396   for(std::vector<bool>::const_iterator it=_flagsIds.begin();it!=_flagsIds.end();it++,ret++)
397     {
398       if(!*it)
399         {
400           if(localId==curLocId)
401             return ret;
402           curLocId++;
403         }
404     }
405   throw YACS::Exception("ForEachLoopPassedData::toAbsId : not referenced Id !");
406 }
407
408 /*!
409  * Equivalent to toAbsId except that only ON are considered here.
410  */
411 int ForEachLoopPassedData::toAbsIdNot(int localId) const
412 {
413   if(localId<0)
414     throw YACS::Exception("ForEachLoopPassedData::toAbsIdNot : local pos must be >= 0 !");
415   int ret(0),curLocId(0);
416   for(std::vector<bool>::const_iterator it=_flagsIds.begin();it!=_flagsIds.end();it++,ret++)
417     {
418       if(*it)//<- diff is here !
419         {
420           if(localId==curLocId)
421             return ret;
422           curLocId++;
423         }
424     }
425   throw YACS::Exception("ForEachLoopPassedData::toAbsIdNot : not referenced Id !");
426 }
427
428 int ForEachLoopPassedData::getNumberOfElementsToDo() const
429 {
430   std::size_t nbAllElts(_flagsIds.size());
431   std::size_t ret(nbAllElts-_passedIds.size());
432   return ret;
433 }
434
435 void ForEachLoopPassedData::assignAlreadyDone(const std::vector<SequenceAny *>& execVals) const
436 {
437   std::size_t sz(execVals.size());
438   if(_passedOutputs.size()!=sz)
439     throw YACS::Exception("ForEachLoopPassedData::assignedAlreadyDone : mismatch of size of vectors !");
440   for(std::size_t i=0;i<sz;i++)
441     {
442       SequenceAny *elt(_passedOutputs[i]);
443       SequenceAny *eltDestination(execVals[i]);
444       if(!elt)
445         throw YACS::Exception("ForEachLoopPassedData::assignedAlreadyDone : presence of null elt !");
446       unsigned int szOfElt(elt->size());
447       for(unsigned int j=0;j<szOfElt;j++)
448         {
449           AnyPtr elt1((*elt)[j]);
450           int jAbs(toAbsIdNot(j));
451           eltDestination->setEltAtRank(jAbs,elt1);
452         }
453     }
454 }
455
456 ForEachLoop::ForEachLoop(const std::string& name, TypeCode *typeOfDataSplitted):DynParaLoop(name,typeOfDataSplitted),
457                                                                                 _splitterNode(NAME_OF_SPLITTERNODE,typeOfDataSplitted,this),
458                                                                                 _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0),_passedData(0)
459 {
460 }
461
462 ForEachLoop::ForEachLoop(const ForEachLoop& other, ComposedNode *father, bool editionOnly):DynParaLoop(other,father,editionOnly),
463                                                                                            _splitterNode(other._splitterNode,this),
464                                                                                            _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0),_passedData(0)
465 {
466   int i=0;
467   if(!editionOnly)
468     for(vector<AnySplitOutputPort *>::const_iterator iter2=other._outGoingPorts.begin();iter2!=other._outGoingPorts.end();iter2++,i++)
469       {
470         AnySplitOutputPort *temp=new AnySplitOutputPort(*(*iter2),this);
471         InterceptorInputPort *interc=new InterceptorInputPort(*other._intecptrsForOutGoingPorts[i],this);
472         temp->addRepr(getOutPort(other.getOutPortName((*iter2)->getRepr())),interc);
473         interc->setRepr(temp);
474         _outGoingPorts.push_back(temp);
475         _intecptrsForOutGoingPorts.push_back(interc);
476       }
477 }
478
479 Node *ForEachLoop::simpleClone(ComposedNode *father, bool editionOnly) const
480 {
481   return new ForEachLoop(*this,father,editionOnly);
482 }
483
484 ForEachLoop::~ForEachLoop()
485 {
486   cleanDynGraph();
487   for(vector<AnySplitOutputPort *>::iterator iter=_outGoingPorts.begin();iter!=_outGoingPorts.end();iter++)
488     delete *iter;
489   for(vector<InterceptorInputPort *>::iterator iter2=_intecptrsForOutGoingPorts.begin();iter2!=_intecptrsForOutGoingPorts.end();iter2++)
490     delete *iter2;
491   delete _passedData;
492 }
493
494 void ForEachLoop::init(bool start)
495 {
496   DynParaLoop::init(start);
497   _splitterNode.init(start);
498   _execCurrentId=0;
499   cleanDynGraph();
500   _currentIndex = 0;
501   exUpdateProgress();
502   if(_passedData)
503     _passedData->init();
504 }
505
506 void ForEachLoop::exUpdateState()
507 {
508   DEBTRACE("ForEachLoop::exUpdateState");
509   if(_state == YACS::DISABLED)
510     return;
511   if(_state == YACS::DONE)
512     return;
513   if(_inGate.exIsReady())
514     {
515       //internal graph update
516       int i;
517       int nbOfBr(_nbOfBranches.getIntValue()),nbOfElts(_splitterNode.getNumberOfElements()),nbOfEltsDone(0);
518       if(_passedData)
519         {
520           _passedData->checkCompatibilyWithNb(nbOfElts);
521           nbOfEltsDone=_passedData->getNumberOfEltsAlreadyDone();
522         }
523       int nbOfEltsToDo(nbOfElts-nbOfEltsDone);
524
525       DEBTRACE("nbOfElts=" << nbOfElts);
526       DEBTRACE("nbOfBr=" << nbOfBr);
527
528       if(nbOfEltsToDo==0)
529         {
530           prepareSequenceValues(0);
531           delete _nodeForSpecialCases;
532           _nodeForSpecialCases=new FakeNodeForForEachLoop(this,true);
533           setState(YACS::ACTIVATED);
534           return ;
535         }
536       if(nbOfBr<=0)
537         {
538           delete _nodeForSpecialCases;
539           _nodeForSpecialCases=new FakeNodeForForEachLoop(this,getAllOutPortsLeavingCurrentScope().empty());
540           setState(YACS::ACTIVATED);
541           return ;
542         }
543       if(nbOfBr>nbOfEltsToDo)
544         nbOfBr=nbOfEltsToDo;
545       _execNodes.resize(nbOfBr);
546       _execIds.resize(nbOfBr);
547       _execOutGoingPorts.resize(nbOfBr);
548       prepareSequenceValues(nbOfElts);
549       if(_initNode)
550         _execInitNodes.resize(nbOfBr);
551       _initializingCounter = 0;
552       if (_finalizeNode)
553         _execFinalizeNodes.resize(nbOfBr);
554
555       vector<Node *> origNodes;
556       origNodes.push_back(_initNode);
557       origNodes.push_back(_node);
558       origNodes.push_back(_finalizeNode);
559
560       //Conversion exceptions can be thrown by createOutputOutOfScopeInterceptors 
561       //so catch them to control errors
562       try
563         {
564           for(i=0;i<nbOfBr;i++)
565             {
566               DEBTRACE( "-------------- 2" );
567               vector<Node *> clonedNodes = cloneAndPlaceNodesCoherently(origNodes);
568               if(_initNode)
569                 _execInitNodes[i] = clonedNodes[0];
570               _execNodes[i] = clonedNodes[1];
571               if(_finalizeNode)
572                 _execFinalizeNodes[i] = clonedNodes[2];
573               DEBTRACE( "-------------- 4" );
574               prepareInputsFromOutOfScope(i);
575               DEBTRACE( "-------------- 5" );
576               createOutputOutOfScopeInterceptors(i);
577               DEBTRACE( "-------------- 6" );
578             }
579           for(i=0;i<nbOfBr;i++)
580             {
581               DEBTRACE( "-------------- 1 " << i << " " << _execCurrentId);
582               _execIds[i]=_execCurrentId;
583               int posInAbs(_execCurrentId);
584               if(_passedData)
585                 posInAbs=_passedData->toAbsId(_execCurrentId);
586               _splitterNode.putSplittedValueOnRankTo(posInAbs,i,true);
587               _execCurrentId++;
588               DEBTRACE( "-------------- 7" );
589             }
590           if(_passedData)
591             {
592               _passedData->checkLevel2(_execOutGoingPorts[0]);
593               _passedData->assignAlreadyDone(_execVals);
594             }
595         }
596       catch(YACS::Exception& ex)
597         {
598           //ForEachLoop must be put in error and the exception rethrown to notify the caller
599           DEBTRACE( "ForEachLoop::exUpdateState: " << ex.what() );
600           setState(YACS::ERROR);
601           exForwardFailed();
602           throw;
603         }
604
605       setState(YACS::ACTIVATED); // move the calling of setState method there for adding observers for clone nodes in GUI part
606
607       //let's go
608       for(i=0;i<nbOfBr;i++)
609         if(_initNode)
610           {
611             _execInitNodes[i]->exUpdateState();
612             _initializingCounter++;
613           }
614         else
615           {
616             _nbOfEltConsumed++;
617             _execNodes[i]->exUpdateState();
618           }
619
620       forwardExecStateToOriginalBody(_execNodes[nbOfBr-1]);
621     }
622 }
623
624 void ForEachLoop::exUpdateProgress()
625 {
626   // emit notification to all observers registered with the dispatcher on any change of the node's state
627   sendEvent("progress");
628 }
629
630 void ForEachLoop::getReadyTasks(std::vector<Task *>& tasks)
631 {
632   if(!_node)
633     return;
634   if(_state==YACS::TOACTIVATE) setState(YACS::ACTIVATED);
635   if(_state==YACS::TOACTIVATE || _state==YACS::ACTIVATED)
636     {
637       if(_nodeForSpecialCases)
638         {
639           _nodeForSpecialCases->getReadyTasks(tasks);
640           return ;
641         }
642       vector<Node *>::iterator iter;
643       for (iter=_execNodes.begin() ; iter!=_execNodes.end() ; iter++)
644         (*iter)->getReadyTasks(tasks);
645       for (iter=_execInitNodes.begin() ; iter!=_execInitNodes.end() ; iter++)
646         (*iter)->getReadyTasks(tasks);
647       for (iter=_execFinalizeNodes.begin() ; iter!=_execFinalizeNodes.end() ; iter++)
648         (*iter)->getReadyTasks(tasks);
649     }
650 }
651
652 int ForEachLoop::getNumberOfInputPorts() const
653 {
654   return DynParaLoop::getNumberOfInputPorts()+1;
655 }
656
657 void ForEachLoop::checkNoCyclePassingThrough(Node *node) throw(YACS::Exception)
658 {
659   //TO DO
660 }
661
662 void ForEachLoop::selectRunnableTasks(std::vector<Task *>& tasks)
663 {
664 }
665
666 std::list<InputPort *> ForEachLoop::getSetOfInputPort() const
667 {
668   list<InputPort *> ret=DynParaLoop::getSetOfInputPort();
669   ret.push_back((InputPort *)&_splitterNode._dataPortToDispatch);
670   return ret;
671 }
672
673 std::list<InputPort *> ForEachLoop::getLocalInputPorts() const
674 {
675   list<InputPort *> ret=DynParaLoop::getLocalInputPorts();
676   ret.push_back((InputPort *)&_splitterNode._dataPortToDispatch);
677   return ret;
678 }
679
680 InputPort *ForEachLoop::getInputPort(const std::string& name) const throw(YACS::Exception)
681 {
682   if(name==SplitterNode::NAME_OF_SEQUENCE_INPUT)
683     return (InputPort *)&_splitterNode._dataPortToDispatch;
684   else
685     return DynParaLoop::getInputPort(name);
686 }
687
688 OutputPort *ForEachLoop::getOutputPort(const std::string& name) const throw(YACS::Exception)
689 {
690   for(vector<AnySplitOutputPort *>::const_iterator iter=_outGoingPorts.begin();iter!=_outGoingPorts.end();iter++)
691     {
692       if(name==(*iter)->getName())
693         return (OutputPort *)(*iter);
694     }
695   return DynParaLoop::getOutputPort(name);
696 }
697
698 OutPort *ForEachLoop::getOutPort(const std::string& name) const throw(YACS::Exception)
699 {
700   for(vector<AnySplitOutputPort *>::const_iterator iter=_outGoingPorts.begin();iter!=_outGoingPorts.end();iter++)
701     {
702       if(name==(*iter)->getName())
703         return (OutPort *)(*iter);
704     }
705   return DynParaLoop::getOutPort(name);
706 }
707
708 Node *ForEachLoop::getChildByShortName(const std::string& name) const throw(YACS::Exception)
709 {
710   if(name==NAME_OF_SPLITTERNODE)
711     return (Node *)&_splitterNode;
712   else
713     return DynParaLoop::getChildByShortName(name);
714 }
715
716 //! Method used to notify the node that a child node has finished
717 /*!
718  * Update the current state and return the change state
719  *
720  *  \param node : the child node that has finished
721  *  \return the state change
722  */
723 YACS::Event ForEachLoop::updateStateOnFinishedEventFrom(Node *node)
724 {
725   DEBTRACE("updateStateOnFinishedEventFrom " << node->getName() << " " << node->getState());
726   unsigned int id;
727   switch(getIdentityOfNotifyerNode(node,id))
728     {
729     case INIT_NODE:
730       return updateStateForInitNodeOnFinishedEventFrom(node,id);
731     case WORK_NODE:
732       return updateStateForWorkNodeOnFinishedEventFrom(node,id,true);
733     case FINALIZE_NODE:
734       return updateStateForFinalizeNodeOnFinishedEventFrom(node,id);
735     default:
736       YASSERT(false);
737     }
738   return YACS::NOEVENT;
739 }
740
741 YACS::Event ForEachLoop::updateStateForInitNodeOnFinishedEventFrom(Node *node, unsigned int id)
742 {
743   _execNodes[id]->exUpdateState();
744   _nbOfEltConsumed++;
745   _initializingCounter--;
746   _currentIndex++;
747   if (_initializingCounter == 0)
748     _initNode->setState(DONE);
749   return YACS::NOEVENT;
750 }
751
752 /*!
753  * \param [in] isNormalFinish - if true
754  */
755 YACS::Event ForEachLoop::updateStateForWorkNodeOnFinishedEventFrom(Node *node, unsigned int id, bool isNormalFinish)
756 {
757   _currentIndex++;
758   exUpdateProgress();
759   if(isNormalFinish)
760     {
761       int globalId(_execIds[id]);
762       if(_passedData)
763         globalId=_passedData->toAbsId(globalId);
764       sendEvent2("progress_ok",&globalId);
765       storeOutValsInSeqForOutOfScopeUse(globalId,id);
766     }
767   else
768     {
769       int globalId(_execIds[id]);
770       if(_passedData)
771         globalId=_passedData->toAbsId(globalId);
772       sendEvent2("progress_ko",&globalId);
773     }
774   //
775   if(_execCurrentId==getFinishedId())
776     {//No more elements of _dataPortToDispatch to treat
777       _execIds[id]=NOT_RUNNING_BRANCH_ID;
778       //analyzing if some samples are still on treatment on other branches.
779       bool isFinished(true);
780       for(int i=0;i<_execIds.size() && isFinished;i++)
781         isFinished=(_execIds[i]==NOT_RUNNING_BRANCH_ID);
782       if(isFinished)
783         {
784           try
785           {
786               if(_failedCounter!=0)
787                 {// case of keepgoing mode + a failed
788                   std::ostringstream oss; oss << "Keep Going mode activated and some errors (" << _failedCounter << ")reported !";
789                   DEBTRACE("ForEachLoop::updateStateOnFinishedEventFrom : "<< oss.str());
790                   setState(YACS::FAILED);
791                   return YACS::ABORT;
792                 }
793               pushAllSequenceValues();
794
795               if (_node)
796                 {
797                   _node->setState(YACS::DONE);
798
799                   ComposedNode* compNode = dynamic_cast<ComposedNode*>(_node);
800                   if (compNode)
801                     {
802                       std::list<Node *> aChldn = compNode->getAllRecursiveConstituents();
803                       std::list<Node *>::iterator iter=aChldn.begin();
804                       for(;iter!=aChldn.end();iter++)
805                         (*iter)->setState(YACS::DONE);
806                     }
807                 }
808
809               if (_finalizeNode == NULL)
810                 {
811                   // No finalize node, we just finish the loop at the end of exec nodes execution
812                   setState(YACS::DONE);
813                   return YACS::FINISH;
814                 }
815               else
816                 {
817                   // Run the finalize nodes, the loop will be done only when they all finish
818                   _unfinishedCounter = 0;  // This counter indicates how many branches are not finished
819                   for (int i=0 ; i<_execIds.size() ; i++)
820                     {
821                       YASSERT(_execIds[i] == NOT_RUNNING_BRANCH_ID);
822                       DEBTRACE("Launching finalize node for branch " << i);
823                       _execFinalizeNodes[i]->exUpdateState();
824                       _unfinishedCounter++;
825                     }
826                   return YACS::NOEVENT;
827                 }
828           }
829           catch(YACS::Exception& ex)
830           {
831               DEBTRACE("ForEachLoop::updateStateOnFinishedEventFrom: "<<ex.what());
832               //no way to push results : put following nodes in FAILED state
833               //TODO could be more fine grain : put only concerned nodes in FAILED state
834               exForwardFailed();
835               setState(YACS::ERROR);
836               return YACS::ABORT;
837           }
838         }
839     }
840   else if(_state == YACS::ACTIVATED)
841     {//more elements to do and loop still activated
842       _execIds[id]=_execCurrentId;
843       node->init(false);
844       int posInAbs(_execCurrentId);
845       if(_passedData)
846         posInAbs=_passedData->toAbsId(_execCurrentId);
847       _splitterNode.putSplittedValueOnRankTo(posInAbs,id,false);
848       _execCurrentId++;
849       node->exUpdateState();
850       forwardExecStateToOriginalBody(node);
851       _nbOfEltConsumed++;
852     }
853   else
854     {//elements to process and loop no more activated
855       DEBTRACE("foreach loop state " << _state);
856     }
857   return YACS::NOEVENT;
858 }
859
860 YACS::Event ForEachLoop::updateStateForFinalizeNodeOnFinishedEventFrom(Node *node, unsigned int id)
861 {
862   DEBTRACE("Finalize node finished on branch " << id);
863   _unfinishedCounter--;
864   _currentIndex++;
865   exUpdateProgress();
866   DEBTRACE(_unfinishedCounter << " finalize nodes still running");
867   if (_unfinishedCounter == 0)
868     {
869       _finalizeNode->setState(YACS::DONE);
870       setState(YACS::DONE);
871       return YACS::FINISH;
872     }
873   else
874     return YACS::NOEVENT;
875 }
876
877 YACS::Event ForEachLoop::updateStateOnFailedEventFrom(Node *node, const Executor *execInst)
878 {
879   unsigned int id;
880   DynParaLoop::TypeOfNode ton(getIdentityOfNotifyerNode(node,id));
881   if(ton!=WORK_NODE || !execInst->getKeepGoingProperty())
882     return DynParaLoop::updateStateOnFailedEventFrom(node,execInst);
883   else
884     {
885       _failedCounter++;
886       return updateStateForWorkNodeOnFinishedEventFrom(node,id,false);
887     }
888 }
889
890 void ForEachLoop::InterceptorizeNameOfPort(std::string& portName)
891 {
892   std::replace_if(portName.begin(), portName.end(), std::bind1st(std::equal_to<char>(), '.'), '_');
893   portName += INTERCEPTOR_STR;
894 }
895
896 void ForEachLoop::buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView)
897 {
898   DynParaLoop::buildDelegateOf(port,finalTarget,pointsOfView);
899   string typeOfPortInstance=(port.first)->getNameOfTypeOfCurrentInstance();
900   if(typeOfPortInstance==OutputPort::NAME)
901     {
902       vector<AnySplitOutputPort *>::iterator iter=_outGoingPorts.begin();
903       int i=0;
904       for(;iter!=_outGoingPorts.end();iter++,i++)
905         if((*iter)->getRepr()==port.first || *iter==port.first)
906           break;
907       if(iter!=_outGoingPorts.end())
908         {
909           if(*iter!=port.first)
910             {
911               (*iter)->incrRef();
912               (*iter)->addRepr(port.first,_intecptrsForOutGoingPorts[i]);
913             }
914           port.first=*iter;
915         }
916       else
917         {
918           TypeCode *tcTrad((YACS::ENGINE::TypeCode*)finalTarget->edGetType()->subContentType(getFEDeltaBetween(port.first,finalTarget)));
919           TypeCodeSeq *newTc=(TypeCodeSeq *)TypeCode::sequenceTc("","",tcTrad);
920           // The out going ports belong to the ForEachLoop, whereas
921           // the delegated port belongs to a node child of the ForEachLoop.
922           // The name of the delegated port contains dots (bloc.node.outport),
923           // whereas the name of the out going port shouldn't do.
924           std::string outputPortName(getPortName(port.first));
925           InterceptorizeNameOfPort(outputPortName);
926           AnySplitOutputPort *newPort(new AnySplitOutputPort(outputPortName,this,newTc));
927           InterceptorInputPort *intercptor(new InterceptorInputPort(outputPortName + "_in",this,tcTrad));
928           intercptor->setRepr(newPort);
929           newTc->decrRef();
930           newPort->addRepr(port.first,intercptor);
931           _outGoingPorts.push_back(newPort);
932           _intecptrsForOutGoingPorts.push_back(intercptor);
933           port.first=newPort;
934         }
935     }
936   else
937     throw Exception("ForEachLoop::buildDelegateOf : not implemented for DS because not specified");
938 }
939
940 void ForEachLoop::getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(YACS::Exception)
941 {
942   string typeOfPortInstance=(port.first)->getNameOfTypeOfCurrentInstance();
943   if(typeOfPortInstance==OutputPort::NAME)
944     {
945       vector<AnySplitOutputPort *>::iterator iter=_outGoingPorts.begin();
946       for(;iter!=_outGoingPorts.end();iter++)
947         if((*iter)->getRepr()==port.first)
948           break;
949       if(iter==_outGoingPorts.end())
950         {
951           string what("ForEachLoop::getDelegateOf : Port with name "); what+=port.first->getName(); what+=" not exported by ForEachLoop "; what+=_name; 
952           throw Exception(what);
953         }
954       else
955         port.first=(*iter);
956     }
957   else
958     throw Exception("ForEachLoop::getDelegateOf : not implemented because not specified");
959 }
960
961 void ForEachLoop::releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(YACS::Exception)
962 {
963   string typeOfPortInstance=portDwn->getNameOfTypeOfCurrentInstance();
964   if(typeOfPortInstance==OutputPort::NAME)
965     {
966       vector<AnySplitOutputPort *>::iterator iter=_outGoingPorts.begin();
967       vector<InterceptorInputPort *>::iterator iter2=_intecptrsForOutGoingPorts.begin();
968       for(;iter!=_outGoingPorts.end();iter++,iter2++)
969         if((*iter)->getRepr()==portDwn)
970           break;
971       //ASSERT(portUp==*iter.second)
972       if((*iter)->decrRef())
973         {
974           AnySplitOutputPort *p=*iter;
975           _outGoingPorts.erase(iter);
976           delete p;
977           InterceptorInputPort *ip=*iter2;
978           _intecptrsForOutGoingPorts.erase(iter2);
979           delete ip;
980         }
981     }
982 }
983
984 OutPort *ForEachLoop::getDynOutPortByAbsName(int branchNb, const std::string& name)
985 {
986   string portName, nodeName;
987   splitNamesBySep(name,Node::SEP_CHAR_IN_PORT,nodeName,portName,false);
988   Node *staticChild = getChildByName(nodeName);
989   return _execNodes[branchNb]->getOutPort(portName);//It's impossible(garanteed by YACS::ENGINE::ForEachLoop::buildDelegateOf)
990   //that a link starting from _initNode goes out of scope of 'this'.
991 }
992
993 void ForEachLoop::cleanDynGraph()
994 {
995   DynParaLoop::cleanDynGraph();
996   for(vector< SequenceAny *>::iterator iter3=_execVals.begin();iter3!=_execVals.end();iter3++)
997     (*iter3)->decrRef();
998   _execVals.clear();
999   for(vector< vector<AnyInputPort *> >::iterator iter4=_execOutGoingPorts.begin();iter4!=_execOutGoingPorts.end();iter4++)
1000     for(vector<AnyInputPort *>::iterator iter5=(*iter4).begin();iter5!=(*iter4).end();iter5++)
1001       delete *iter5;
1002   _execOutGoingPorts.clear();
1003 }
1004
1005 void ForEachLoop::storeOutValsInSeqForOutOfScopeUse(int rank, int branchNb)
1006 {
1007   vector<AnyInputPort *>::iterator iter;
1008   int i=0;
1009   for(iter=_execOutGoingPorts[branchNb].begin();iter!=_execOutGoingPorts[branchNb].end();iter++,i++)
1010     {
1011       Any *val=(Any *)(*iter)->getValue();
1012       _execVals[i]->setEltAtRank(rank,val);
1013     }
1014 }
1015
1016 int ForEachLoop::getFinishedId()
1017 {
1018   if(!_passedData)
1019     return _splitterNode.getNumberOfElements();
1020   else
1021     return _passedData->getNumberOfElementsToDo();
1022 }
1023
1024 void ForEachLoop::prepareSequenceValues(int sizeOfSamples)
1025 {
1026   _execVals.resize(_outGoingPorts.size());
1027   vector<AnySplitOutputPort *>::iterator iter=_outGoingPorts.begin();
1028   for(int i=0;iter!=_outGoingPorts.end();iter++,i++)
1029     _execVals[i]=SequenceAny::New((*iter)->edGetType()->contentType(),sizeOfSamples);
1030 }
1031
1032 void ForEachLoop::pushAllSequenceValues()
1033 {
1034   vector<AnySplitOutputPort *>::iterator iter=_outGoingPorts.begin();
1035   int i=0;
1036   for(;iter!=_outGoingPorts.end();iter++,i++)
1037     (*iter)->put((const void *)_execVals[i]);
1038 }
1039
1040 void ForEachLoop::createOutputOutOfScopeInterceptors(int branchNb)
1041 {
1042   vector<AnySplitOutputPort *>::iterator iter=_outGoingPorts.begin();
1043   int i=0;
1044   for(;iter!=_outGoingPorts.end();iter++,i++)
1045     {
1046       DEBTRACE( (*iter)->getName() << " " << (*iter)->edGetType()->kind() );
1047       //AnyInputPort *interceptor=new AnyInputPort((*iter)->getName(),this,(*iter)->edGetType());
1048       OutPort *portOut=getDynOutPortByAbsName(branchNb,getOutPortName(((*iter)->getRepr())));
1049       DEBTRACE( portOut->getName() );
1050       TypeCode *tc((TypeCode *)(*iter)->edGetType()->contentType());
1051       AnyInputPort *interceptor=new AnyInputPort((*iter)->getName(),this,tc);
1052       portOut->addInPort(interceptor);
1053       _execOutGoingPorts[branchNb].push_back(interceptor);
1054     }
1055 }
1056
1057 void ForEachLoop::checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
1058                                        InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(YACS::Exception)
1059 {
1060   DynParaLoop::checkLinkPossibility(start, pointsOfViewStart, end, pointsOfViewEnd);
1061   if(end->getNode() == &_splitterNode)
1062     throw Exception("Illegal link within a foreach loop: \
1063 the 'SmplsCollection' port cannot be linked within the scope of the loop.");
1064   if(end == &_nbOfBranches)
1065     throw Exception("Illegal link within a foreach loop: \
1066 the 'nbBranches' port cannot be linked within the scope of the loop.");
1067 }
1068
1069 std::list<OutputPort *> ForEachLoop::getLocalOutputPorts() const
1070 {
1071   list<OutputPort *> ret;
1072   ret.push_back(getOutputPort(NAME_OF_SPLITTED_SEQ_OUT)); 
1073   return ret;
1074 }
1075
1076 void ForEachLoop::accept(Visitor *visitor)
1077 {
1078   visitor->visitForEachLoop(this);
1079 }
1080
1081 //! Dump the node state to a stream
1082 /*!
1083  * \param os : the output stream
1084  */
1085 void ForEachLoop::writeDot(std::ostream &os) const
1086 {
1087   os << "  subgraph cluster_" << getId() << "  {\n" ;
1088   //only one node in a loop
1089   if(_node)
1090     {
1091       _node->writeDot(os);
1092       os << getId() << " -> " << _node->getId() << ";\n";
1093     }
1094   os << "}\n" ;
1095   os << getId() << "[fillcolor=\"" ;
1096   YACS::StatesForNode state=getEffectiveState();
1097   os << getColorState(state);
1098   os << "\" label=\"" << "Loop:" ;
1099   os << getName() <<"\"];\n";
1100 }
1101
1102 //! Reset the state of the node and its children depending on the parameter level
1103 void ForEachLoop::resetState(int level)
1104 {
1105   if(level==0)return;
1106   DynParaLoop::resetState(level);
1107   _execCurrentId=0;
1108   //Note: cleanDynGraph is not a virtual method (must be called from ForEachLoop object) 
1109   cleanDynGraph();
1110 }
1111
1112 std::string ForEachLoop::getProgress() const
1113 {
1114   int nbElems(getNbOfElementsToBeProcessed());
1115   std::stringstream aProgress;
1116   if (nbElems > 0)
1117     aProgress << _currentIndex << "/" << nbElems;
1118   else
1119     aProgress << "0";
1120   return aProgress.str();
1121 }
1122
1123 //! Get the progress weight for all elementary nodes
1124 /*!
1125  * Only elementary nodes have weight. For each node in the loop, the weight done is multiplied
1126  * by the number of elements done and the weight total by the number total of elements
1127  */
1128 list<ProgressWeight> ForEachLoop::getProgressWeight() const
1129 {
1130   list<ProgressWeight> ret;
1131   list<Node *> setOfNode=edGetDirectDescendants();
1132   int elemDone=getCurrentIndex();
1133   int elemTotal=getNbOfElementsToBeProcessed();
1134   for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
1135     {
1136       list<ProgressWeight> myCurrentSet=(*iter)->getProgressWeight();
1137       for(list<ProgressWeight>::iterator iter=myCurrentSet.begin();iter!=myCurrentSet.end();iter++)
1138         {
1139           (*iter).weightDone=((*iter).weightTotal) * elemDone;
1140           (*iter).weightTotal*=elemTotal;
1141         }
1142       ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
1143     }
1144   return ret;
1145 }
1146
1147 int ForEachLoop::getNbOfElementsToBeProcessed() const
1148 {
1149   int nbBranches = _nbOfBranches.getIntValue();
1150   return _splitterNode.getNumberOfElements()
1151          + (_initNode ? nbBranches:0)
1152          + (_finalizeNode ? nbBranches:0) ;
1153 }
1154
1155 /*!
1156  * This method allows to retrieve the state of \a this during execution or after. This method works even if this is \b NOT complete, or during execution or after a failure in \a this.
1157  * The typical usage of this method is to retrieve the results of items that passed successfully to avoid to lose all of them if only one fails.
1158  * This method has one input \a execut and 3 outputs.
1159  *
1160  * \param [in] execut - The single input is for threadsafety reasons because this method can be called safely during the execution of \a this.
1161  * \param [out] outputs - For each output ports in \a this linked with nodes sharing the same father than \a this the passed results are stored.
1162  *                        All of the items in \a outputs have the same size.
1163  * \param [out] nameOfOutputs - The array with same size than \a outputs, that tells for each item in outputs the output port it refers to.
1164  * \return the list of ids among \c this->edGetSeqOfSamplesPort() that run successfully. The length of this returned array will be the length of all
1165  *         SequenceAny objects contained in \a outputs.
1166  *
1167  * \sa edGetSeqOfSamplesPort
1168  */
1169 std::vector<unsigned int> ForEachLoop::getPassedResults(Executor *execut, std::vector<SequenceAny *>& outputs, std::vector<std::string>& nameOfOutputs) const
1170 {
1171   YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&(execut->getTheMutexForSchedulerUpdate()));
1172   if(_execVals.empty())
1173     return std::vector<unsigned int>();
1174   if(_execOutGoingPorts.empty())
1175     return std::vector<unsigned int>();
1176   std::size_t sz(_execVals.size()); outputs.resize(sz); nameOfOutputs.resize(sz);
1177   const std::vector<AnyInputPort *>& ports(_execOutGoingPorts[0]);
1178   for(std::size_t i=0;i<sz;i++)
1179     {
1180       outputs[i]=_execVals[i]->removeUnsetItemsFromThis();
1181       nameOfOutputs[i]=ports[i]->getName();
1182     }
1183   return _execVals[0]->getSetItems();
1184 }
1185
1186 /*!
1187  * This method is typically useful for post-mortem relaunch to avoid to recompute already passed cases. This method takes in input exactly the parameters retrieved by
1188  * getPassedResults method.
1189  */
1190 void ForEachLoop::assignPassedResults(const std::vector<unsigned int>& passedIds, const std::vector<SequenceAny *>& passedOutputs, const std::vector<std::string>& nameOfOutputs)
1191 {
1192   delete _passedData;
1193   _failedCounter=0;
1194   _passedData=new ForEachLoopPassedData(passedIds,passedOutputs,nameOfOutputs);
1195 }
1196
1197 int ForEachLoop::getFEDeltaBetween(OutPort *start, InPort *end)
1198 {
1199   Node *ns(start->getNode()),*ne(end->getNode());
1200   ComposedNode *co(getLowestCommonAncestor(ns,ne));
1201   int ret(0);
1202   Node *work(ns);
1203   while(work!=co)
1204     {
1205       ForEachLoop *isFE(dynamic_cast<ForEachLoop *>(work));
1206       if(isFE)
1207         ret++;
1208       work=work->getFather();
1209     }
1210   work=ne;
1211   int delta(0);
1212   while(work!=co)
1213     {
1214       ForEachLoop *isFE(dynamic_cast<ForEachLoop *>(work));
1215       if(isFE)
1216         delta++;
1217       work=work->getFather();
1218     }
1219   if(dynamic_cast<AnySplitOutputPort *>(start))
1220     ret--;
1221   return ret-delta;
1222 }