Salome HOME
Merge branch 'omu/py2yacsgui'
[modules/yacs.git] / src / engine / DynParaLoop.hxx
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 #ifndef __DYNPARALOOP_HXX__
21 #define __DYNPARALOOP_HXX__
22
23 #include "YACSlibEngineExport.hxx"
24 #include "ComposedNode.hxx"
25 #include "AnyInputPort.hxx"
26 #include "AnyOutputPort.hxx"
27 #include "OutputPort.hxx"
28
29 namespace YACS
30 {
31   namespace ENGINE
32   { 
33     /*!
34      * \brief Base class for dynamically (fully or semifully) built graphs.
35      * \ingroup Nodes
36      */
37     class YACSLIBENGINE_EXPORT DynParaLoop : public ComposedNode
38     {
39     protected:
40       typedef enum
41         {
42           INIT_NODE = 5,
43           WORK_NODE = 6,
44           FINALIZE_NODE = 7
45       } TypeOfNode;
46     protected:
47       Node *_node;
48       Node *_initNode;
49       Node *_finalizeNode;
50       unsigned _nbOfEltConsumed;
51       std::vector<int> _execIds;
52       AnyInputPort _nbOfBranches;
53       AnyOutputPort _splittedPort;
54       std::vector<Node *> _execNodes;
55       std::vector<Node *> _execInitNodes;
56       std::vector<Node *> _execFinalizeNodes;
57       int _initializingCounter;
58       int _unfinishedCounter;
59       int _failedCounter;
60       double _weight;
61     protected:
62       static const char NAME_OF_SPLITTED_SEQ_OUT[];
63       static const char OLD_NAME_OF_SPLITTED_SEQ_OUT[];
64       static const char NAME_OF_NUMBER_OF_BRANCHES[];
65     protected:
66       DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted);
67       virtual ~DynParaLoop();
68       DynParaLoop(const DynParaLoop& other, ComposedNode *father, bool editionOnly);
69     public:
70       Node *edRemoveNode();
71       Node *edRemoveInitNode();
72       Node *edRemoveFinalizeNode();
73       //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
74       Node *edSetNode(Node *DISOWNnode);
75       Node *edSetInitNode(Node *DISOWNnode);
76       Node *edSetFinalizeNode(Node *DISOWNnode);
77       virtual bool edAddDFLink(OutPort *start, InPort *end) throw(Exception);
78       void init(bool start=true);
79       InputPort *edGetNbOfBranchesPort() { return &_nbOfBranches; }
80       int getNumberOfInputPorts() const;
81       int getNumberOfOutputPorts() const;
82       unsigned getNumberOfEltsConsumed() const { return _nbOfEltConsumed; }
83       int getBranchIDOfNode(Node *node) const;
84       std::list<OutputPort *> getSetOfOutputPort() const;
85       std::list<OutputPort *> getLocalOutputPorts() const;
86       OutputPort *edGetSamplePort() { return &_splittedPort; }
87       OutPort *getOutPort(const std::string& name) const throw(Exception);
88       InputPort *getInputPort(const std::string& name) const throw(Exception);
89       OutputPort *getOutputPort(const std::string& name) const throw(Exception);
90       //! For the moment false is returned : impovement about it coming soon.
91       bool isPlacementPredictableB4Run() const;
92       void edRemoveChild(Node *node) throw(Exception);
93       virtual bool edAddChild(Node *DISOWNnode) throw(Exception);
94       std::list<Node *> edGetDirectDescendants() const;
95       std::list<InputPort *> getSetOfInputPort() const;
96       std::list<InputPort *> getLocalInputPorts() const;
97       unsigned getNumberOfBranchesCreatedDyn() const throw(Exception);
98       Node *getChildByShortName(const std::string& name) const throw(Exception);
99       Node *getChildByNameExec(const std::string& name, unsigned id) const throw(Exception);
100       std::vector<Node *> getNodes() const { return _execNodes; } // need to use in GUI part for adding observers for clone nodes
101       double getWeight() const { return _weight; }
102       void setWeight(double newVal);
103       double getWeightRegardingDPL() const { return getWeight(); }
104       bool isMultiplicitySpecified(unsigned& value) const;
105       void forceMultiplicity(unsigned value);
106       virtual void checkBasicConsistency() const throw(Exception);
107       virtual std::string getErrorReport();
108       void accept(Visitor *visitor);
109       Node * getInitNode();
110       Node * getExecNode();
111       Node * getFinalizeNode();
112       int getMaxLevelOfParallelism() const;
113       void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap);
114     protected:
115       void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
116       void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
117       void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
118       void checkControlDependancy(OutPort *start, InPort *end, bool cross,
119                                   std::map < ComposedNode *,  std::list < OutPort * >, SortHierarc >& fw,
120                                   std::vector<OutPort *>& fwCross,
121                                   std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
122                                   LinkInfo& info) const;
123       virtual void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
124                                        InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
125     protected:
126       void cleanDynGraph();
127       void prepareInputsFromOutOfScope(int branchNb);
128       void putValueOnBranch(Any *val, unsigned branchId, bool first);
129       TypeOfNode getIdentityOfNotifyerNode(const Node *node, unsigned& id);
130       InputPort *getDynInputPortByAbsName(int branchNb, const std::string& name, bool initNodeAdmitted);
131       virtual void forwardExecStateToOriginalBody(Node *execNode);
132       virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
133       std::vector<Node *> cloneAndPlaceNodesCoherently(const std::vector<Node *> & origNodes);
134       Node * checkConsistencyAndSetNode(Node* &nodeToReplace, Node* DISOWNnode);
135       Node * removeNode(Node* &nodeToRemove);
136       virtual void shutdown(int level);
137     };
138   }
139 }
140
141 #endif