1 // Copyright (C) 2012-2021 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"
47 class YACSEvalSession;
48 class YACSEvalObserver;
49 class YACSEvalExecParams;
50 class YACSEvalListOfResources;
51 class ResourcesManager_cpp;
52 class YACSEvalYFXRunOnlyPatternInternalObserver;
54 class YACSEvalYFXPattern
57 virtual ~YACSEvalYFXPattern();
58 std::vector< YACSEvalInputPort *> getFreeInputPorts() const;
59 std::vector< YACSEvalOutputPort *> getFreeOutputPorts() const;
60 static YACSEvalYFXPattern *FindPatternFrom(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
61 void setParallelizeStatus(bool newVal) { _parallelizeStatus=newVal; }
62 bool getParallelizeStatus() const { return _parallelizeStatus; }
63 bool isAlreadyComputedResources() const;
64 void checkNonAlreadyComputedResources() const;
65 void checkAlreadyComputedResources() const;
66 void checkLocked() const;
67 void checkNonLocked() const;
68 static void CheckNodeIsOK(YACS::ENGINE::ComposedNode *node);
69 void registerObserver(YACSEvalObserver *observer);
70 YACSEvalObserver *getObserver() const { return _observer; }
71 YACSEvalYFX *getBoss() const { return _boss; }
72 YACSEvalListOfResources *getResourcesInternal() const { return _res; }
73 virtual void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputs) = 0;
74 virtual void resetOutputsOfInterest() = 0;
75 virtual void generateGraph() = 0;
76 virtual void resetGeneratedGraph() = 0;
77 virtual void assignRandomVarsInputs() = 0;
78 virtual int assignNbOfBranches() = 0;
79 virtual bool isLocked() const = 0;
80 virtual YACSEvalListOfResources *giveResources() = 0;
81 virtual YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const = 0;
82 virtual std::string getErrorDetailsInCaseOfFailure() const = 0;
83 virtual std::string getStatusOfRunStr() const = 0;
84 virtual std::vector<YACSEvalSeqAny *> getResults() const = 0;
85 virtual std::vector<YACSEvalSeqAny *> getResultsInCaseOfFailure(std::vector<unsigned int>& passedIds) const = 0;
86 virtual bool go(const YACSEvalExecParams& params, YACSEvalSession *session) const = 0;
88 const std::vector< YACSEvalInputPort >& getInputs() const { return _inputs; }
89 static YACS::ENGINE::TypeCode *CreateSeqTypeCodeFrom(YACS::ENGINE::Proc *scheme, const std::string& zeType);
90 static YACSEvalSeqAny *BuildValueInPort(YACS::ENGINE::InputPyPort *port);
92 YACSEvalYFXPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
93 void setResources(YACSEvalListOfResources *res);
94 void resetResources();
95 ResourcesManager_cpp *getCatalogInAppli() const { return _rm; }
96 static YACSEvalSeqAny *BuildValueFromEngineFrmt(YACS::ENGINE::SequenceAny *data);
102 bool _parallelizeStatus;
103 YACS::ENGINE::Proc *_scheme;
104 ResourcesManager_cpp *_rm;
105 YACSEvalListOfResources *_res;
106 mutable YACSEvalObserver *_observer;
108 std::vector< YACSEvalInputPort > _inputs;
109 std::vector< YACSEvalOutputPort > _outputs;
111 static const char ST_OK[]; // execution goes to the end without any trouble -> results can be exploited without any problem with getResults and getResultsInCaseOfFailure.
112 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
113 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.
114 static const std::size_t MAX_LGTH_OF_INP_DUMP;
117 class YACSEvalYFXGraphGen;
119 class YACSEvalYFXRunOnlyPattern : public YACSEvalYFXPattern
122 YACSEvalYFXRunOnlyPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode);
123 ~YACSEvalYFXRunOnlyPattern();
124 void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputsOfInterest);
125 void resetOutputsOfInterest();
126 void generateGraph();
127 void resetGeneratedGraph();
128 int assignNbOfBranches();
129 void assignRandomVarsInputs();
130 bool isLocked() const;
131 YACSEvalListOfResources *giveResources();
132 YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const;
133 std::string getErrorDetailsInCaseOfFailure() const;
134 std::string getStatusOfRunStr() const;
135 std::vector<YACSEvalSeqAny *> getResults() const;
136 std::vector<YACSEvalSeqAny *> getResultsInCaseOfFailure(std::vector<unsigned int>& passedIds) const;
137 bool go(const YACSEvalExecParams& params, YACSEvalSession *session) const;
139 YACS::ENGINE::ForEachLoop *getUndergroundForEach() const;
140 static bool IsMatching(YACS::ENGINE::Proc *scheme, YACS::ENGINE::ComposedNode *& runNode);
142 void emitStart() const;
143 void buildInputPorts();
144 void buildOutputPorts();
145 YACSEvalYFXGraphGen *getGenerator() const;
147 const std::vector<YACSEvalOutputPort *>& getOutputsOfInterest() const { return _outputsOfInterest; }
148 YACS::ENGINE::ComposedNode *getRunNode() const { return _runNode; }
151 YACS::ENGINE::ComposedNode *_runNode;
152 std::vector<YACSEvalOutputPort *> _outputsOfInterest;
153 YACSEvalYFXGraphGen *_gen;
154 YACSEvalYFXRunOnlyPatternInternalObserver *_obs;
157 class YACSEvalYFXGraphGen
163 virtual ~CustomPatcher() { }
164 virtual void addOutputVar(const std::string& name) = 0;
165 virtual void assignOutput(YACS::ENGINE::InlineNode *node) = 0;
168 YACSEvalYFXGraphGen(YACSEvalYFXRunOnlyPattern *boss);
169 YACSEvalYFXRunOnlyPattern *getBoss() const { return _boss; }
171 virtual ~YACSEvalYFXGraphGen();
172 virtual void generateGraph() = 0;
173 virtual bool go(const YACSEvalExecParams& params, YACSEvalSession *session) const = 0;
174 virtual std::vector<YACSEvalSeqAny *> getResults() const = 0;
175 virtual std::string getErrors()const = 0;
176 bool isLocked() const;
177 int assignNbOfBranches();
178 void resetGeneratedGraph();
179 YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const { return _generatedGraph; }
180 YACS::ENGINE::ForEachLoop *getUndergroundForEach() const { return _FEInGeneratedGraph; }
182 void generateGraphCommon(CustomPatcher& patcher);
184 YACSEvalYFXRunOnlyPattern *_boss;
186 YACS::ENGINE::Proc *_generatedGraph;
187 YACS::ENGINE::ForEachLoop *_FEInGeneratedGraph;
189 static const char DFT_PROC_NAME[];
190 static const char FIRST_FE_SUBNODE_NAME[];
191 static const char GATHER_NODE_NAME[];
192 static const char HIDDEN_INDEX_VAR[];
195 class YACSEvalYFXGraphGenInteractive : public YACSEvalYFXGraphGen
198 YACSEvalYFXGraphGenInteractive(YACSEvalYFXRunOnlyPattern *boss):YACSEvalYFXGraphGen(boss) { }
199 void generateGraph();
200 bool go(const YACSEvalExecParams& params, YACSEvalSession *session) const;
201 std::vector<YACSEvalSeqAny *> getResults() const;
202 virtual std::string getErrors()const;
205 class YACSEvalYFXGraphGenCluster : public YACSEvalYFXGraphGen
208 YACSEvalYFXGraphGenCluster(YACSEvalYFXRunOnlyPattern *boss):YACSEvalYFXGraphGen(boss),_jobid(0) { }
209 void generateGraph();
210 bool go(const YACSEvalExecParams& params, YACSEvalSession *session) const;
211 std::vector<YACSEvalSeqAny *> getResults() const;
212 virtual std::string getErrors()const;
214 std::string _locSchemaFile;
215 std::string _jobName;
217 mutable std::string _errors;
218 mutable std::vector< std::vector<double> > _res;