1 // Copyright (C) 2012-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #ifndef __YACSEVALYFXPATTERN_HXX__
22 #define __YACSEVALYFXPATTERN_HXX__
24 #include "YACSEvalPort.hxx"
46 class YACSEvalObserver;
47 class YACSEvalListOfResources;
48 class ResourcesManager_cpp;
49 class YACSEvalYFXRunOnlyPatternInternalObserver;
51 class YACSEvalYFXPattern
54 virtual ~YACSEvalYFXPattern();
55 std::vector< YACSEvalInputPort *> getFreeInputPorts() const;
56 std::vector< YACSEvalOutputPort *> getFreeOutputPorts() const;
57 static YACSEvalYFXPattern *FindPatternFrom(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
58 void setParallelizeStatus(bool newVal) { _parallelizeStatus=newVal; }
59 bool getParallelizeStatus() const { return _parallelizeStatus; }
60 bool isAlreadyComputedResources() const;
61 void checkNonAlreadyComputedResources() const;
62 void checkAlreadyComputedResources() const;
63 void checkLocked() const;
64 void checkNonLocked() const;
65 static void CheckNodeIsOK(YACS::ENGINE::ComposedNode *node);
66 void registerObserver(YACSEvalObserver *observer);
67 YACSEvalObserver *getObserver() const { return _observer; }
68 YACSEvalYFX *getBoss() const { return _boss; }
69 virtual void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputs) = 0;
70 virtual void resetOutputsOfInterest() = 0;
71 virtual void generateGraph() = 0;
72 virtual void resetGeneratedGraph() = 0;
73 virtual void assignRandomVarsInputs() = 0;
74 virtual int assignNbOfBranches() = 0;
75 virtual bool isLocked() const = 0;
76 virtual YACSEvalListOfResources *giveResources() = 0;
77 virtual YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const = 0;
78 virtual std::string getErrorDetailsInCaseOfFailure() const = 0;
79 virtual std::string getStatusOfRunStr() const = 0;
80 virtual std::vector<YACSEvalSeqAny *> getResults() const = 0;
81 virtual std::vector<YACSEvalSeqAny *> getResultsInCaseOfFailure(std::vector<unsigned int>& passedIds) const = 0;
82 virtual bool go(bool stopASAP) const = 0;
84 static const char DFT_PROC_NAME[];
86 YACSEvalYFXPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
87 YACS::ENGINE::TypeCode *createSeqTypeCodeFrom(YACS::ENGINE::Proc *scheme, const std::string& zeType);
88 void setResources(YACSEvalListOfResources *res);
89 void resetResources();
90 YACSEvalListOfResources *getResourcesInternal() const { return _res; }
91 ResourcesManager_cpp *getCatalogInAppli() const { return _rm; }
92 static YACSEvalSeqAny *BuildValueInPort(YACS::ENGINE::InputPyPort *port);
93 static YACSEvalSeqAny *BuildValueFromEngineFrmt(YACS::ENGINE::SequenceAny *data);
99 bool _parallelizeStatus;
100 YACS::ENGINE::Proc *_scheme;
101 ResourcesManager_cpp *_rm;
102 YACSEvalListOfResources *_res;
103 mutable YACSEvalObserver *_observer;
105 std::vector< YACSEvalInputPort > _inputs;
106 std::vector< YACSEvalOutputPort > _outputs;
108 static const char ST_OK[]; // execution goes to the end without any trouble -> results can be exploited without any problem with getResults and getResultsInCaseOfFailure.
109 static const char ST_FAILED[]; // execution has reached some failed evaluation (normal errors due to incapacity of one node to evaluate) -> results can be exploited without any problem with getResultsInCaseOfFailure
110 static const char ST_ERROR[]; // execution has encountered hard errors (SIGSEGV in a server, internal error in YACS) -> results can be exploited with getResultsInCaseOfFailure but you can't make hypothesis for other ids not in passedIds.
111 static const std::size_t MAX_LGTH_OF_INP_DUMP;
114 class YACSEvalYFXRunOnlyPattern : public YACSEvalYFXPattern
117 YACSEvalYFXRunOnlyPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode);
118 ~YACSEvalYFXRunOnlyPattern();
119 void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputsOfInterest);
120 void resetOutputsOfInterest();
121 void generateGraph();
122 void resetGeneratedGraph();
123 int assignNbOfBranches();
124 void assignRandomVarsInputs();
125 bool isLocked() const;
126 YACSEvalListOfResources *giveResources();
127 YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const;
128 std::string getErrorDetailsInCaseOfFailure() const;
129 std::string getStatusOfRunStr() const;
130 std::vector<YACSEvalSeqAny *> getResults() const;
131 std::vector<YACSEvalSeqAny *> getResultsInCaseOfFailure(std::vector<unsigned int>& passedIds) const;
132 bool go(bool stopASAP) const;
134 YACS::ENGINE::ForEachLoop *getUndergroundForEach() const { return _FEInGeneratedGraph; }
135 static bool IsMatching(YACS::ENGINE::Proc *scheme, YACS::ENGINE::ComposedNode *& runNode);
137 static const char FIRST_FE_SUBNODE_NAME[];
138 static const char GATHER_NODE_NAME[];
140 void emitStart() const;
141 void buildInputPorts();
142 void buildOutputPorts();
143 YACS::ENGINE::ForEachLoop *findTopForEach() const;
145 YACS::ENGINE::ComposedNode *_runNode;
146 std::vector<YACSEvalOutputPort *> _outputsOfInterest;
147 YACS::ENGINE::Proc *_generatedGraph;
148 YACS::ENGINE::ForEachLoop *_FEInGeneratedGraph;
149 YACSEvalYFXRunOnlyPatternInternalObserver *_obs;