66 Port(other,newHelder),
74 for(set<InPort *>::iterator iter=ports.begin();iter!=ports.end();iter++)
75 (*iter)->getAllRepresentants(repr);
100 _repr(0),_intercptr(0),_cnt(1)
106 Port(other,newHelder),
107 _repr(0),_intercptr(0),_cnt(1)
164 if (valCsted)
return valCsted->
size();
178 stringstream xmldump;
180 xmldump <<
"<value><array><data>" << endl;
181 for (
int i = 0;
i < nbElem;
i++)
187 xmldump <<
"<value><double>" << setprecision(16) << val->
getDoubleValue() <<
"</double></value>" << endl;
190 xmldump <<
"<value><int>" << val->
getIntValue() <<
"</int></value>" << endl;
193 xmldump <<
"<value><boolean>" << val->
getBoolValue() <<
"</boolean></value>" << endl;
196 xmldump <<
"<value><string>" << val->
getStringValue() <<
"</string></value>" << endl;
202 xmldump <<
"<value><error> NO_SERIALISATION_AVAILABLE </error></value>" << endl;
206 xmldump <<
"</data></array></value>" << endl;
207 return xmldump.str();
212 _dataPortToDispatch(NAME_OF_SEQUENCE_INPUT,
219 _dataPortToDispatch(other._dataPortToDispatch,this)
262 _normalFinish(normalFinish)
306 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)
308 std::size_t sz(
_passedIds.size()),sz1(passedOutputs.size()),sz2(nameOfOutputs.size());
310 throw YACS::Exception(
"ForEachLoopPassedData::ForEachLoopPassedData : nameOfOutputs and passedOutputs must have the same size !");
315 if(sz!=(std::size_t)elt->
size())
316 throw YACS::Exception(
"ForEachLoopPassedData::ForEachLoopPassedData : incoherent input of passed data !");
327 : _passedIds(copy._passedIds),
328 _passedOutputs(copy._passedOutputs),
329 _nameOfOutputs(copy._nameOfOutputs),
330 _flagsIds(copy._flagsIds)
352 throw YACS::Exception(
"ForEachLoopPassedData::checkCompatibilyWithNb : nb of elts is expected to be > 0 !");
353 std::size_t sizeExp(
_passedIds.size()),nbOfElts2(nbOfElts);
354 if(nbOfElts2<sizeExp)
355 throw YACS::Exception(
"ForEachLoopPassedData::checkCompatibilyWithNb : Invalid nb of elemts in input seq regarding passed data set !");
359 throw YACS::Exception(
"ForEachLoopPassedData::checkCompatibilyWithNb : Invalid nb of elemts in input seq regarding passed data set 2 !");
371 std::ostringstream oss; oss <<
"ForEachLoopPassedData::checkCompatibilyWithNb : id " << *it <<
" in list of ids appears more than once !";
377 std::ostringstream oss; oss <<
"ForEachLoopPassedData::checkCompatibilyWithNb : Presence of id " << *it <<
" in list of ids ! Must be in [0," << nbOfElts <<
") !";
387 throw YACS::Exception(
"ForEachLoopPassedData::checkLevel2 : mismatch of size of vectors !");
388 for(std::size_t
i=0;
i<sz;
i++)
392 throw YACS::Exception(
"ForEachLoopPassedData::checkLevel2 : presence of null instance !");
395 std::ostringstream oss; oss <<
"ForEachLoopPassedData::checkLevel2 : At pos #" <<
i <<
" the name is not OK !";
407 throw YACS::Exception(
"ForEachLoopPassedData::toAbsId : local pos must be >= 0 !");
408 int ret(0),curLocId(0);
409 for(std::vector<bool>::const_iterator it=
_flagsIds.begin();it!=
_flagsIds.end();it++,ret++)
413 if(localId==curLocId)
418 throw YACS::Exception(
"ForEachLoopPassedData::toAbsId : not referenced Id !");
427 throw YACS::Exception(
"ForEachLoopPassedData::toAbsIdNot : local pos must be >= 0 !");
428 int ret(0),curLocId(0);
429 for(std::vector<bool>::const_iterator it=
_flagsIds.begin();it!=
_flagsIds.end();it++,ret++)
433 if(localId==curLocId)
438 throw YACS::Exception(
"ForEachLoopPassedData::toAbsIdNot : not referenced Id !");
450 std::size_t sz(execVals.size());
452 throw YACS::Exception(
"ForEachLoopPassedData::assignedAlreadyDone : mismatch of size of vectors !");
453 for(std::size_t
i=0;
i<sz;
i++)
458 throw YACS::Exception(
"ForEachLoopPassedData::assignedAlreadyDone : presence of null elt !");
459 unsigned int szOfElt(elt->
size());
460 for(
unsigned int j=0;j<szOfElt;j++)
470 DynParaLoop(name,typeOfDataSplitted,std::move(branchManager)),
471 _splitterNode(NAME_OF_SPLITTERNODE,typeOfDataSplitted,this),
472 _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0),_passedData(0)
477 _splitterNode(other._splitterNode,this),
478 _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0),_passedData(0)
517 DEBTRACE(
"ForEachLoopGen::exUpdateState");
533 int nbOfEltsToDo(nbOfElts-nbOfEltsDone);
554 if(nbOfBr>nbOfEltsToDo)
566 vector<Node *> origNodes;
568 origNodes.push_back(
_node);
575 for(
i=0;
i<nbOfBr;
i++)
590 for(
i=0;
i<nbOfBr;
i++)
608 for(
auto iter : portsToSetVals)
618 DEBTRACE(
"ForEachLoopGen::exUpdateState: " <<
ex.what() );
628 for(
i=0;
i<nbOfBr;
i++)
662 vector<Node *>::iterator iter;
664 (*iter)->getReadyTasks(tasks);
666 (*iter)->getReadyTasks(tasks);
668 (*iter)->getReadyTasks(tasks);
712 if(name==(*iter)->getName())
722 if(name==(*iter)->getName())
808 std::ostringstream oss; oss <<
"Keep Going mode activated and some errors (" <<
_failedCounter <<
")reported !";
809 DEBTRACE(
"ForEachLoopGen::updateStateOnFinishedEventFrom : "<< oss.str());
823 std::list<Node *>::iterator iter=aChldn.begin();
824 for(;iter!=aChldn.end();iter++)
842 DEBTRACE(
"Launching finalize node for branch " <<
i);
851 DEBTRACE(
"ForEachLoopGen::updateStateOnFinishedEventFrom: "<<
ex.what());
883 DEBTRACE(
"Finalize node finished on branch " <<
id);
914 std::replace_if(portName.begin(), portName.end(), std::bind(std::equal_to<char>(),
'.',std::placeholders::_1),
'_');
921 string typeOfPortInstance=(port.first)->getNameOfTypeOfCurrentInstance();
924 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
927 if((*iter)->getRepr()==port.first || *iter==port.first)
931 if(*iter!=port.first)
946 std::string outputPortName(
getPortName(port.first));
952 newPort->
addRepr(port.first,intercptor);
959 throw Exception(
"ForEachLoopGen::buildDelegateOf : not implemented for DS because not specified");
964 string typeOfPortInstance=(port.first)->getNameOfTypeOfCurrentInstance();
967 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
969 if((*iter)->getRepr()==port.first)
973 string what(
"ForEachLoopGen::getDelegateOf : Port with name "); what+=port.first->getName(); what+=
" not exported by ForEachLoop "; what+=
_name;
980 throw Exception(
"ForEachLoopGen::getDelegateOf : not implemented because not specified");
988 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
991 if((*iter)->getRepr()==portDwn)
994 if((*iter)->decrRef())
1008 string portName, nodeName;
1011 return _execNodes[branchNb]->getOutPort(portName);
1018 for(vector< SequenceAny *>::iterator iter3=
_execVals.begin();iter3!=
_execVals.end();iter3++)
1019 (*iter3)->decrRef();
1022 for(vector<AnyInputPort *>::iterator iter5=(*iter4).begin();iter5!=(*iter4).end();iter5++)
1029 vector<AnyInputPort *>::iterator iter;
1033 Any *val=(
Any *)(*iter)->getValue();
1049 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
1056 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
1064 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
1068 DEBTRACE( (*iter)->getName() <<
" " << (*iter)->edGetType()->kind() );
1080 InPort *end,
const std::list<ComposedNode *>& pointsOfViewEnd)
1084 throw Exception(
"Illegal link within a foreach loop: \
1085 the 'SmplsCollection' port cannot be linked within the scope of the loop.");
1087 throw Exception(
"Illegal link within a foreach loop: \
1088 the 'nbBranches' port cannot be linked within the scope of the loop.");
1093 list<OutputPort *> ret;
1104 os <<
" subgraph cluster_" <<
getId() <<
" {\n" ;
1112 os <<
getId() <<
"[fillcolor=\"" ;
1115 os <<
"\" label=\"" <<
"Loop:" ;
1131 std::stringstream aProgress;
1136 return aProgress.str();
1146 list<ProgressWeight> ret;
1150 for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
1152 list<ProgressWeight> myCurrentSet=(*iter)->getProgressWeight();
1153 for(list<ProgressWeight>::iterator iter=myCurrentSet.begin();iter!=myCurrentSet.end();iter++)
1155 (*iter).weightDone=((*iter).weightTotal) * elemDone;
1156 (*iter).weightTotal*=elemTotal;
1158 ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
1166 int nbBranches =
_nbOfBranches->getNumberOfBranches(nbOfElems);
1190 return std::vector<unsigned int>();
1192 return std::vector<unsigned int>();
1195 nameOfOutputs.resize(sz);
1197 for(std::size_t
i=0;
i<sz;
i++)
1199 outputs[
i]=
_execVals[
i]->removeUnsetItemsFromThis();
1200 nameOfOutputs[
i]=ports[
i]->getName();
1240 std::vector<SequenceAny *> outputs;
1241 std::vector<std::string> nameOfOutputs;
1246 nameOfOutputs.resize(sz);
1248 for(std::size_t
i=0;
i<sz;
i++)
1250 outputs[
i]=
_execVals[
i]->removeUnsetItemsFromThis();
1251 nameOfOutputs[
i]=ports[
i]->getName();
1269 vector<AnySplitOutputPort *>::const_iterator it;
1274 DEBTRACE(
"ForEachLoopGen::getOutputPortType compare " << portName <<
" == " << originalPortName);
1275 if(originalPortName == portName)
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
#define INFO_YACSTRACE(msg)
: Allow to manage memory of instances of T. The only constraint on T is to have method incrRef and De...
void getAllRepresented(std::set< OutPort * > &represented) const
bool addInPort(InPort *inPort)
void addRepr(OutPort *repr, InterceptorInputPort *intercptr)
int removeInPort(InPort *inPort, bool forward)
InterceptorInputPort * _intercptr
OutputPort * clone(Node *newHelder) const
AnySplitOutputPort(const std::string &name, Node *node, TypeCode *type)
: Interface for management of storage of data formated dynamically in its TypeCode....
virtual std::string getStringValue() const =0
virtual int getIntValue() const =0
virtual double getDoubleValue() const =0
virtual bool getBoolValue() const =0
Base class for all composed nodes.
Node * getChildByName(const std::string &name) const
std::string getName() const
virtual std::list< Node * > getAllRecursiveConstituents()
Idem getAllRecursiveNodes, but this node is NOT included.
std::set< OutPort * > getAllOutPortsLeavingCurrentScope() const
List all output ports of children nodes that are linked to out of scope input ports.
std::string getPortName(const PORT *port) const
static bool splitNamesBySep(const std::string &globalName, const char separator[], std::string &firstPart, std::string &lastPart, bool priority)
Splits name globalName in 2 parts using separator.
std::string getOutPortName(const OutPort *) const
virtual void resetState(int level)
Reset the state of the node and its children depending on the parameter level.
std::set< InPort * > getAllInPortsComingFromOutsideOfCurrentScope() const
List all input ports that are linked to out of scope ports.
static ComposedNode * getLowestCommonAncestor(Node *node1, Node *node2)
Retrieves the lowest common ancestor of 2 nodes.
std::string getNameOfTypeOfCurrentInstance() const
TypeCode * edGetType() const
std::string getName() const
Base class for dynamically (fully or semifully) built graphs.
Node * getChildByShortName(const std::string &name) const
InputPort * getInputPort(const std::string &name) const
Get an input port given its name.
int getNumberOfInputPorts() const
virtual void checkLinkPossibility(OutPort *start, const std::list< ComposedNode * > &pointsOfViewStart, InPort *end, const std::list< ComposedNode * > &pointsOfViewEnd)
std::unique_ptr< NbBranchesAbstract > _nbOfBranches
std::vector< Node * > _execNodes
static const char NAME_OF_SPLITTED_SEQ_OUT[]
std::vector< Node * > cloneAndPlaceNodesCoherently(const std::vector< Node * > &origNodes)
Clone nodes and make their placement consistent with the placement of the original ones.
void buildDelegateOf(InPort *&port, OutPort *initialStart, const std::list< ComposedNode * > &pointsOfView)
OutputPort * getOutputPort(const std::string &name) const
Get an output port given its name.
unsigned _nbOfEltConsumed
OutPort * getOutPort(const std::string &name) const
std::vector< int > _execIds
std::list< Node * > edGetDirectDescendants() const
virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst)
Method used to notify the node that a child node has failed.
std::list< InputPort * > getLocalInputPorts() const
redefined on derived class of ComposedNode. by default a ComposedNode has no port by itself
void init(bool start=true)
std::vector< Node * > _execFinalizeNodes
void prepareInputsFromOutOfScope(int branchNb)
virtual void cleanDynGraph()
virtual void forwardExecStateToOriginalBody(Node *execNode)
void putValueOnBranch(Any *val, unsigned branchId, bool first)
std::vector< Node * > _execInitNodes
std::list< InputPort * > getSetOfInputPort() const
TypeOfNode getIdentityOfNotifyerNode(const Node *node, unsigned &id)
Base class for all calculation nodes.
InputPort * getInputPort(const std::string &name) const
void init(bool start=true)
void getReadyTasks(std::vector< Task * > &tasks)
YACS::BASES::Mutex & getTheMutexForSchedulerUpdate()
bool getKeepGoingProperty() const
FakeNodeForForEachLoop(ForEachLoopGen *loop, bool normalFinish)
Node * simpleClone(ComposedNode *father, bool editionOnly) const
Node * simpleClone(ComposedNode *father, bool editionOnly=true) const
void accept(Visitor *visitor)
ForEachLoopDyn(const std::string &name, TypeCode *typeOfDataSplitted)
SplitterNode _splitterNode
InputPort * getInputPort(const std::string &name) const
Get an input port given its name.
friend class FakeNodeForForEachLoop
std::vector< SequenceAny * > _execVals
void cleanDynGraph() override
static const char INTERCEPTOR_STR[]
OutPort * getOutPort(const std::string &name) const
void exUpdateState()
Update the node state.
Node * getChildByShortName(const std::string &name) const
void init(bool start=true)
void assignPassedResults(const std::vector< unsigned int > &passedIds, const std::vector< SequenceAny * > &passedOutputs, const std::vector< std::string > &nameOfOutputs)
void storeOutValsInSeqForOutOfScopeUse(int rank, int branchNb)
void setProcessedData(ForEachLoopPassedData *processedData)
int getCurrentIndex() const
std::vector< AnySplitOutputPort * > _outGoingPorts
ForEachLoopGen(const std::string &name, TypeCode *typeOfDataSplitted, std::unique_ptr< NbBranchesAbstract > &&branchManager)
virtual void resetState(int level)
Reset the state of the node and its children depending on the parameter level.
YACS::Event updateStateForInitNodeOnFinishedEventFrom(Node *node, unsigned int id)
std::list< InputPort * > getSetOfInputPort() const
static const int NOT_RUNNING_BRANCH_ID
void checkLinkPossibility(OutPort *start, const std::list< ComposedNode * > &pointsOfViewStart, InPort *end, const std::list< ComposedNode * > &pointsOfViewEnd)
std::vector< InterceptorInputPort * > _intecptrsForOutGoingPorts
ports linked to node outside the current scope
void createOutputOutOfScopeInterceptors(int branchNb)
const TypeCode * getOutputPortType(const std::string &portName) const
void writeDot(std::ostream &os) const
Dump the node state to a stream.
void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list< ComposedNode * > &pointsOfView)
std::string getProgress() const
void buildDelegateOf(std::pair< OutPort *, OutPort * > &port, InPort *finalTarget, const std::list< ComposedNode * > &pointsOfView)
std::list< InputPort * > getLocalInputPorts() const
redefined on derived class of ComposedNode. by default a ComposedNode has no port by itself
ForEachLoopPassedData * getProcessedData() const
static int getFEDeltaBetween(OutPort *start, InPort *end)
void getDelegateOf(std::pair< OutPort *, OutPort * > &port, InPort *finalTarget, const std::list< ComposedNode * > &pointsOfView)
FakeNodeForForEachLoop * _nodeForSpecialCases
std::vector< unsigned int > getPassedResults(Executor *execut, std::vector< SequenceAny * > &outputs, std::vector< std::string > &nameOfOutputs) const
std::vector< std::vector< AnyInputPort * > > _execOutGoingPorts
int getNbOfElementsToBeProcessed() const
void selectRunnableTasks(std::vector< Task * > &tasks)
ForEachLoopPassedData * _passedData
int getNumberOfInputPorts() const
static void InterceptorizeNameOfPort(std::string &portName)
std::list< OutputPort * > getLocalOutputPorts() const
redefined on derived class of ComposedNode. by default a ComposedNode has no port by itself
void checkNoCyclePassingThrough(Node *node)
void getReadyTasks(std::vector< Task * > &tasks)
void prepareSequenceValues(int sizeOfSamples)
YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst)
Method used to notify the node that a child node has failed.
void pushAllSequenceValues()
YACS::Event updateStateOnFinishedEventFrom(Node *node)
Method used to notify the node that a child node has finished.
OutputPort * getOutputPort(const std::string &name) const
Get an output port given its name.
OutPort * getDynOutPortByAbsName(int branchNb, const std::string &name)
unsigned _execCurrentId
ports created for TypeCodes correctness
YACS::Event updateStateForWorkNodeOnFinishedEventFrom(Node *node, unsigned int id, bool isNormalFinish)
static const char NAME_OF_SPLITTERNODE[]
std::list< ProgressWeight > getProgressWeight() const
Get the progress weight for all elementary nodes.
YACS::Event updateStateForFinalizeNodeOnFinishedEventFrom(Node *node, unsigned int id)
std::vector< SequenceAny * > _passedOutputs
std::vector< std::string > _nameOfOutputs
int toAbsIdNot(int localId) const
void checkCompatibilyWithNb(int nbOfElts) const
ForEachLoopPassedData(const std::vector< unsigned int > &passedIds, const std::vector< SequenceAny * > &passedOutputs, const std::vector< std::string > &nameOfOutputs)
void checkLevel2(const std::vector< AnyInputPort * > &ports) const
std::vector< unsigned int > _passedIds
int toAbsId(int localId) const
std::vector< bool > _flagsIds
int getNumberOfElementsToDo() const
int getNumberOfEltsAlreadyDone() const
void assignAlreadyDone(const std::vector< SequenceAny * > &execVals) const
void accept(Visitor *visitor)
Node * simpleClone(ComposedNode *father, bool editionOnly=true) const
friend class InterceptorInputPort
bool canSafelySqueezeMemory() const
Base class for all nodes.
virtual void sendEvent2(const std::string &event, void *something)
emit notification to all observers registered with the dispatcher
virtual void exForwardFinished()
virtual void setErrorDetails(const std::string &error)
std::string getColorState(YACS::StatesForNode state) const
Return the color associated to a state.
virtual void exUpdateState()
Update the node state.
const std::string getId() const
virtual void init(bool start=true)
ComposedNode * getFather() const
virtual void writeDot(std::ostream &os) const
Dump to the input stream a dot representation of the node.
void setState(YACS::StatesForNode theState)
Sets the given state for node.
virtual YACS::StatesForNode getState() const
virtual void sendEvent(const std::string &event)
emit notification to all observers registered with the dispatcher
static const char SEP_CHAR_IN_PORT[]
const std::string & getName() const
virtual void exForwardFailed()
virtual YACS::StatesForNode getEffectiveState() const
Return the node state in the context of its father.
YACS::StatesForNode _state
virtual int removeInPort(InPort *inPort, bool forward)=0
virtual bool addInPort(InPort *inPort)=0
virtual void getAllRepresented(std::set< OutPort * > &represented) const
bool addInPort(InPort *inPort)
int removeInPort(InPort *inPort, bool forward)
std::set< InputPort * > _setOfInputPort
std::set< InPort * > edSetInPort() const
Base class for all ports.
void setEltAtRank(int i, const Any *elem)
unsigned int size() const
static SequenceAny * New(const std::vector< T > &vec)
void putSplittedValueOnRankTo(int rankInSeq, int branch, bool first)
InputPort * getInputPort(const std::string &name) const
SplitterNode(const std::string &name, TypeCode *typeOfData, ForEachLoopGen *father)
SeqAnyInputPort _dataPortToDispatch
void init(bool start=true)
unsigned getNumberOfElements() const
Node * simpleClone(ComposedNode *father, bool editionOnly) const
static const char NAME_OF_SEQUENCE_INPUT[]
Class for sequence objects.
Base class for all type objects.
virtual const TypeCode * contentType() const
static TypeCode * sequenceTc(const char *id, const char *name, TypeCode *content)
static factory of sequence type given an id, a name and a content type
const TypeCode * subContentType(int lev) const
virtual void visitForEachLoopDyn(ForEachLoopDyn *node)=0
virtual void visitForEachLoop(ForEachLoop *node)=0
YACSLIBENGINE_EXPORT std::string ToBase64(const std::string &bytes)