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 #include "YACSEvalYFX.hxx"
22 #include "YACSEvalYFXPattern.hxx"
23 #include "YACSEvalAutoPtr.hxx"
24 #include "YACSEvalResource.hxx"
25 #include "YACSEvalSession.hxx"
26 #include "YACSEvalPort.hxx"
27 #include "RuntimeSALOME.hxx"
28 #include "Executor.hxx"
30 #include "Exception.hxx"
31 #include "parsers.hxx"
40 YACSEvalYFX *YACSEvalYFX::BuildFromFile(const std::string& xmlOfScheme)
42 YACS::ENGINE::RuntimeSALOME::setRuntime();
44 YACS::ENGINE::Proc *scheme(l.load(xmlOfScheme.c_str()));
45 return new YACSEvalYFX(scheme,true);
48 YACSEvalYFX *YACSEvalYFX::BuildFromScheme(YACS::ENGINE::Proc *scheme)
50 return new YACSEvalYFX(scheme,false);
53 std::vector< YACSEvalInputPort * > YACSEvalYFX::getFreeInputPorts() const
55 return _pattern->getFreeInputPorts();
58 std::vector< YACSEvalOutputPort * > YACSEvalYFX::getFreeOutputPorts() const
60 return _pattern->getFreeOutputPorts();
63 void YACSEvalYFX::lockPortsForEvaluation(const std::vector< YACSEvalInputPort * >& inputsOfInterest, const std::vector< YACSEvalOutputPort * >& outputsOfInterest)
65 checkPortsForEvaluation(inputsOfInterest,outputsOfInterest);
66 _pattern->setOutPortsOfInterestForEvaluation(outputsOfInterest);
69 void YACSEvalYFX::unlockAll()
71 std::vector< YACSEvalInputPort * > allInputs(getFreeInputPorts());
72 for(std::vector< YACSEvalInputPort * >::const_iterator it=allInputs.begin();it!=allInputs.end();it++)
74 _pattern->resetOutputsOfInterest();
75 _pattern->resetGeneratedGraph();
78 bool YACSEvalYFX::isLocked() const
80 return _pattern->isLocked();
84 * Caller is not responsible from returned pointer
86 YACSEvalListOfResources *YACSEvalYFX::giveResources()
88 return _pattern->giveResources();
91 bool YACSEvalYFX::run(YACSEvalSession *session, int& nbOfBranches)
93 _pattern->generateGraph();
96 throw YACS::Exception("YACSEvalYFX::run : input session in null !");
99 YACSEvalListOfResources *rss(giveResources());
100 rss->checkOKForRun();
101 _pattern->assignRandomVarsInputs();
103 nbOfBranches=_pattern->assignNbOfBranches();
104 return _pattern->go(_params,session);
107 void YACSEvalYFX::registerObserver(YACSEvalObserver *observer)
110 throw YACS::Exception("YACSEvalYFX::registerObserver : no pattern !");
111 _pattern->registerObserver(observer);
114 YACSEvalObserver *YACSEvalYFX::getObserver()
117 throw YACS::Exception("YACSEvalYFX::getObserver : no pattern !");
118 return _pattern->getObserver();
121 std::string YACSEvalYFX::getErrorDetailsInCaseOfFailure() const
123 return _pattern->getErrorDetailsInCaseOfFailure();
126 std::string YACSEvalYFX::getStatusOfRunStr() const
128 return _pattern->getStatusOfRunStr();
131 std::vector<YACSEvalSeqAny *> YACSEvalYFX::getResults() const
133 return _pattern->getResults();
136 std::vector<YACSEvalSeqAny *> YACSEvalYFX::getResultsInCaseOfFailure(std::vector<unsigned int>& passedIds) const
138 return _pattern->getResultsInCaseOfFailure(passedIds);
141 YACS::ENGINE::Proc *YACSEvalYFX::getUndergroundGeneratedGraph() const
143 return _pattern->getUndergroundGeneratedGraph();
146 void YACSEvalYFX::setParallelizeStatus(bool newVal)
148 _pattern->setParallelizeStatus(newVal);
151 bool YACSEvalYFX::getParallelizeStatus() const
153 return _pattern->getParallelizeStatus();
156 YACSEvalYFX::YACSEvalYFX(YACS::ENGINE::Proc *scheme, bool ownScheme):_pattern(0)
158 _pattern=YACSEvalYFXPattern::FindPatternFrom(this,scheme,ownScheme);
161 void YACSEvalYFX::checkPortsForEvaluation(const std::vector< YACSEvalInputPort * >& inputs, const std::vector< YACSEvalOutputPort * >& outputs) const
163 std::set<YACSEvalInputPort * > inputs2(inputs.begin(),inputs.end());
164 std::vector< YACSEvalInputPort * > allInputs(getFreeInputPorts());
165 std::vector< YACSEvalOutputPort * > allOutputs(getFreeOutputPorts());
166 for(std::vector< YACSEvalInputPort * >::const_iterator it=allInputs.begin();it!=allInputs.end();it++)
168 if(inputs2.find(*it)==inputs2.end())
170 if(!(*it)->isOKForLock())
172 std::ostringstream oss; oss << "YACSEvalYFX::checkPortsForEvaluation : input port with name \"" << (*it)->getName() << "\" is not set properly !";
173 throw YACS::Exception(oss.str());
177 for(std::vector< YACSEvalOutputPort * >::const_iterator it=outputs.begin();it!=outputs.end();it++)
178 if(std::find(allOutputs.begin(),allOutputs.end(),*it)==allOutputs.end())
179 throw YACS::Exception("YACSEvalYFX::lockPortsForEvaluation : one of output is not part of this !");
180 std::set< YACSEvalOutputPort * > soutputs(outputs.begin(),outputs.end());
181 if(soutputs.size()!=outputs.size())
182 throw YACS::Exception("YACSEvalYFX::lockPortsForEvaluation : each elt in outputs must appear once !");
183 for(std::vector< YACSEvalInputPort * >::const_iterator it=allInputs.begin();it!=allInputs.end();it++)
185 (*it)->declareRandomnessStatus(inputs2.find(*it)!=inputs2.end());
190 YACSEvalYFX::~YACSEvalYFX()