std::string ForEachLoop::getProgress() const
{
- int nbElems = _splitterNode.getNumberOfElements();
+ int nbElems(getNbOfElementsToBeProcessed());
std::stringstream aProgress;
if (nbElems > 0)
aProgress << _currentIndex << "/" << nbElems;
return aProgress.str();
}
+int ForEachLoop::getNbOfElementsToBeProcessed() const
+{
+ return _splitterNode.getNumberOfElements();
+}
+
/*!
* This method allows to retrieve the state of \a this during execution or after. This method works even if this is \b NOT complete, or during execution or after a failure in \a this.
* The typical usage of this method is to retrieve the results of items that passed successfully to avoid to lose all of them if only one fails.
virtual std::string typeName() {return "YACS__ENGINE__ForEachLoop";}
virtual void resetState(int level);
std::string getProgress() const;
+ int getCurrentIndex() const { return _currentIndex; }
+ int getNbOfElementsToBeProcessed() const;
#ifndef SWIG
std::vector<unsigned int> getPassedResults(Executor *execut, std::vector<SequenceAny *>& outputs, std::vector<std::string>& nameOfOutputs) const;
void assignPassedResults(const std::vector<unsigned int>& passedIds, const std::vector<SequenceAny *>& passedOutputs, const std::vector<std::string>& nameOfOutputs);
${LIBXML2_LIBRARIES}
)
-# no more than 4 files should be installed
SET(YACSEvalYFX_HEADERS
YACSEvalYFXExport.hxx
YACSEvalYFX.hxx
YACSEvalSeqAny.hxx
YACSEvalResource.hxx
YACSEvalSession.hxx
+ YACSEvalObserver.hxx
+ YACSEvalExecParams.hxx
)
SET(YACSevalYFX_SOURCES
YACSEvalSeqAny.cxx
YACSEvalResource.cxx
YACSEvalSession.cxx
+ YACSEvalObserver.cxx
)
ADD_LIBRARY(YACSevalYFX ${YACSevalYFX_SOURCES})
--- /dev/null
+// Copyright (C) 2012-2015 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __YACSEVALEXECPARAMS_HXX__
+#define __YACSEVALEXECPARAMS_HXX__
+
+#include "YACSEvalYFXExport.hxx"
+
+class YACSEvalExecParams
+{
+public:
+ YACSEVALYFX_EXPORT YACSEvalExecParams():_stopASAPAfterError(true) { }
+ YACSEVALYFX_EXPORT bool getStopASAPAfterErrorStatus() const { return _stopASAPAfterError; }
+ YACSEVALYFX_EXPORT void setStopASAPAfterErrorStatus(bool newStatus) { _stopASAPAfterError=newStatus; }
+private:
+ bool _stopASAPAfterError;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2012-2015 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#include "YACSEvalObserver.hxx"
+
+void YACSEvalObserver::incrRef() const
+{
+ _cnt++;
+}
+
+bool YACSEvalObserver::decrRef() const
+{
+ bool ret(--_cnt==0);
+ if(ret)
+ delete this;
+ return ret;
+}
--- /dev/null
+// Copyright (C) 2012-2015 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __YACSEVALOBSERVER_HXX__
+#define __YACSEVALOBSERVER_HXX__
+
+#include "YACSEvalYFXExport.hxx"
+
+#include <string>
+
+class YACSEvalYFX;
+
+class YACSEvalObserver
+{
+public:
+ YACSEVALYFX_EXPORT YACSEvalObserver():_cnt(1) { }
+ YACSEVALYFX_EXPORT YACSEvalObserver(const YACSEvalObserver& other):_cnt(1) { }// counter must be equal to 1 even in case of copy
+ YACSEVALYFX_EXPORT void incrRef() const;
+ YACSEVALYFX_EXPORT bool decrRef() const;
+ YACSEVALYFX_EXPORT int getCnt() const { return _cnt; }
+ YACSEVALYFX_EXPORT virtual void notifyNumberOfSamplesToEval(YACSEvalYFX *sender, int nbOfSamples) = 0;
+ YACSEVALYFX_EXPORT virtual void notifyNewNumberOfPassedItems(YACSEvalYFX *sender, int sampleId) = 0;
+ //YACSEVALYFX_EXPORT virtual void warningHappen(const std::string& warnDetails) = 0;
+ //YACSEVALYFX_EXPORT virtual void errorHappen(const std::string& errorDetails) = 0;
+private:
+ virtual ~YACSEvalObserver() { }
+private:
+ mutable int _cnt;
+};
+
+#endif
PyThreadState *_save;
};
-
YACSEvalYFX *YACSEvalYFX::BuildFromFile(const std::string& xmlOfScheme)
{
YACS::ENGINE::RuntimeSALOME::setRuntime();
nbOfBranches=_pattern->assignNbOfBranches();
mySession->launch();
YACS::ENGINE::Executor exe;
+ exe.setKeepGoingProperty(!_params.getStopASAPAfterErrorStatus());
//
+ _pattern->emitStart();
{
MyAutoThreadSaver locker;
exe.RunW(getUndergroundGeneratedGraph());
return getUndergroundGeneratedGraph()->getState()==YACS::DONE;
}
+void YACSEvalYFX::registerObserver(YACSEvalObserver *observer)
+{
+ if(!_pattern)
+ throw YACS::Exception("YACSEvalYFX::registerObserver : no pattern !");
+ _pattern->registerObserver(observer);
+}
+
+YACSEvalObserver *YACSEvalYFX::getObserver()
+{
+ if(!_pattern)
+ throw YACS::Exception("YACSEvalYFX::getObserver : no pattern !");
+ return _pattern->getObserver();
+}
+
std::vector<YACSEvalSeqAny *> YACSEvalYFX::getResults() const
{
return _pattern->getResults();
YACSEvalYFX::YACSEvalYFX(YACS::ENGINE::Proc *scheme, bool ownScheme):_pattern(0)
{
- _pattern=YACSEvalYFXPattern::FindPatternFrom(scheme,ownScheme);
+ _pattern=YACSEvalYFXPattern::FindPatternFrom(this,scheme,ownScheme);
}
void YACSEvalYFX::checkPortsForEvaluation(const std::vector< YACSEvalInputPort * >& inputs, const std::vector< YACSEvalOutputPort * >& outputs) const
#define __YACSEVALYFX_HXX__
#include "YACSEvalYFXExport.hxx"
+#include "YACSEvalExecParams.hxx"
#include <string>
#include <vector>
}
}
+class YACSEvalObserver;
class YACSEvalSeqAny;
class YACSEvalSession;
class YACSEvalYFXPattern;
public:
YACSEVALYFX_EXPORT static YACSEvalYFX *BuildFromFile(const std::string& xmlOfScheme);
YACSEVALYFX_EXPORT static YACSEvalYFX *BuildFromScheme(YACS::ENGINE::Proc *scheme);
+ YACSEVALYFX_EXPORT YACSEvalExecParams *getParams() const { return &_params; }
YACSEVALYFX_EXPORT std::vector< YACSEvalInputPort * > getFreeInputPorts() const;
YACSEVALYFX_EXPORT std::vector< YACSEvalOutputPort * > getFreeOutputPorts() const;
YACSEVALYFX_EXPORT void lockPortsForEvaluation(const std::vector< YACSEvalInputPort * >& inputsOfInterest, const std::vector< YACSEvalOutputPort * >& outputsOfInterest);
YACSEVALYFX_EXPORT bool isLocked() const;
YACSEVALYFX_EXPORT YACSEvalListOfResources *giveResources();
YACSEVALYFX_EXPORT bool run(YACSEvalSession *session, int& nbOfBranches);
+ YACSEVALYFX_EXPORT void registerObserver(YACSEvalObserver *observer);
+ YACSEVALYFX_EXPORT YACSEvalObserver *getObserver();
YACSEVALYFX_EXPORT std::vector<YACSEvalSeqAny *> getResults() const;
//
YACSEVALYFX_EXPORT YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const;
void checkPortsForEvaluation(const std::vector< YACSEvalInputPort * >& inputs, const std::vector< YACSEvalOutputPort * >& outputs) const;
private:
YACSEvalYFXPattern *_pattern;
+ mutable YACSEvalExecParams _params;
};
#endif
#include "YACSEvalYFXPattern.hxx"
#include "YACSEvalResource.hxx"
#include "YACSEvalSeqAny.hxx"
+#include "YACSEvalObserver.hxx"
#include "YACSEvalAutoPtr.hxx"
#include "ElementaryNode.hxx"
#include "RuntimeSALOME.hxx"
+#include "Dispatcher.hxx"
#include "InputPort.hxx"
#include "LinkInfo.hxx"
#include "TypeCode.hxx"
return ret;
}
-YACSEvalYFXPattern *YACSEvalYFXPattern::FindPatternFrom(YACS::ENGINE::Proc *scheme, bool ownScheme)
+YACSEvalYFXPattern *YACSEvalYFXPattern::FindPatternFrom(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme)
{
if(!scheme)
throw YACS::Exception("YACSEvalYFXPattern::FindPatternFrom : input scheme must be not null !");
YACS::ENGINE::ComposedNode *zeRunNode(0);
bool isMatchingRunOnlyPattern(YACSEvalYFXRunOnlyPattern::IsMatching(scheme,zeRunNode));
if(isMatchingRunOnlyPattern)
- return new YACSEvalYFXRunOnlyPattern(scheme,ownScheme,zeRunNode);
+ return new YACSEvalYFXRunOnlyPattern(boss,scheme,ownScheme,zeRunNode);
}
throw YACS::Exception("YACSEvalYFXPattern::FindPatternFrom : no pattern found for the input scheme !");
}
}*/
}
-YACSEvalYFXPattern::YACSEvalYFXPattern(YACS::ENGINE::Proc *scheme, bool ownScheme):_scheme(scheme),_ownScheme(ownScheme),_rm(new ResourcesManager_cpp),_res(0)
+void YACSEvalYFXPattern::registerObserver(YACSEvalObserver *observer)
+{
+ if(_observer==observer)
+ return ;
+ if(_observer)
+ _observer->decrRef();
+ _observer=observer;
+ if(_observer)
+ _observer->incrRef();
+}
+
+YACSEvalYFXPattern::YACSEvalYFXPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme):_boss(boss),_scheme(scheme),_ownScheme(ownScheme),_rm(new ResourcesManager_cpp),_res(0),_observer(0)
{
}
YACSEvalYFXPattern::~YACSEvalYFXPattern()
{
+ if(_observer)
+ _observer->decrRef();
delete _rm;
delete _res;
}
-YACSEvalYFXRunOnlyPattern::YACSEvalYFXRunOnlyPattern(YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode):YACSEvalYFXPattern(scheme,ownScheme),_runNode(runNode),_generatedGraph(0)
+/////////////////////
+
+class YACSEvalYFXRunOnlyPatternInternalObserver : public YACS::ENGINE::Observer
+{
+public:
+ YACSEvalYFXRunOnlyPatternInternalObserver(YACSEvalYFXRunOnlyPattern *boss):_boss(boss) { if(!_boss) throw YACS::Exception("YACSEvalYFXRunOnlyPatternInternalObserver constructor : null boss not supported :)"); }
+ void notifyObserver(YACS::ENGINE::Node *object, const std::string& event);
+private:
+ YACSEvalYFXRunOnlyPattern *_boss;
+};
+
+void YACSEvalYFXRunOnlyPatternInternalObserver::notifyObserver(YACS::ENGINE::Node *object, const std::string& event)
+{
+ YACS::ENGINE::ForEachLoop *object2(dynamic_cast<YACS::ENGINE::ForEachLoop *>(object));
+ if(!object2)
+ return ;
+ YACSEvalObserver *obs(_boss->getObserver());
+ if(!obs)
+ return ;
+ if(event=="progress")
+ obs->notifyNewNumberOfPassedItems(_boss->getBoss(),object2->getCurrentIndex());
+}
+
+/////////////////////
+
+YACSEvalYFXRunOnlyPattern::YACSEvalYFXRunOnlyPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode):YACSEvalYFXPattern(boss,scheme,ownScheme),_runNode(runNode),_generatedGraph(0),_FEInGeneratedGraph(0),_obs(new YACSEvalYFXRunOnlyPatternInternalObserver(this))
{
if(!_runNode)
throw YACS::Exception("YACSEvalYFXRunOnlyPattern : internal run node must be not null !");
buildOutputPorts();
}
+YACSEvalYFXRunOnlyPattern::~YACSEvalYFXRunOnlyPattern()
+{
+ delete _obs;
+}
+
void YACSEvalYFXRunOnlyPattern::setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputsOfInterest)
{
checkNonLocked();
n0->setScript(n0Script.str());
//
YACS::ENGINE::ForEachLoop *n1(r->createForEachLoop(oss.str(),pyobjTC));
+ _FEInGeneratedGraph=n1;
_generatedGraph->edAddChild(n1);
_generatedGraph->edAddCFLink(n0,n1);
_generatedGraph->edAddDFLink(sender,n1->edGetSeqOfSamplesPort());
return ret;
}
+void YACSEvalYFXRunOnlyPattern::emitStart() const
+{
+ YACSEvalObserver *obs(getObserver());
+ if(!obs)
+ return ;
+ obs->notifyNumberOfSamplesToEval(getBoss(),_FEInGeneratedGraph->getNbOfElementsToBeProcessed());
+}
+
bool YACSEvalYFXRunOnlyPattern::IsMatching(YACS::ENGINE::Proc *scheme, YACS::ENGINE::ComposedNode *& runNode)
{
std::list<YACS::ENGINE::Node *> nodes(scheme->getChildren());
{
class Proc;
class TypeCode;
+ class ForEachLoop;
class ComposedNode;
class InputPyPort;
}
}
+class YACSEvalYFX;
+class YACSEvalObserver;
class YACSEvalListOfResources;
class ResourcesManager_cpp;
+class YACSEvalYFXRunOnlyPatternInternalObserver;
class YACSEvalYFXPattern
{
virtual ~YACSEvalYFXPattern();
std::vector< YACSEvalInputPort *> getFreeInputPorts() const;
std::vector< YACSEvalOutputPort *> getFreeOutputPorts() const;
- static YACSEvalYFXPattern *FindPatternFrom(YACS::ENGINE::Proc *scheme, bool ownScheme);
+ static YACSEvalYFXPattern *FindPatternFrom(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
bool isAlreadyComputedResources() const;
void checkNonAlreadyComputedResources() const;
void checkAlreadyComputedResources() const;
void checkLocked() const;
void checkNonLocked() const;
static void CheckNodeIsOK(YACS::ENGINE::ComposedNode *node);
+ void registerObserver(YACSEvalObserver *observer);
+ YACSEvalObserver *getObserver() const { return _observer; }
+ YACSEvalYFX *getBoss() const { return _boss; }
virtual void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputs) = 0;
virtual void resetOutputsOfInterest() = 0;
virtual void generateGraph() = 0;
virtual YACSEvalListOfResources *giveResources() = 0;
virtual YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const = 0;
virtual std::vector<YACSEvalSeqAny *> getResults() const = 0;
+ virtual void emitStart() const = 0;
public:
static const char DFT_PROC_NAME[];
protected:
- YACSEvalYFXPattern(YACS::ENGINE::Proc *scheme, bool ownScheme);
+ YACSEvalYFXPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
YACS::ENGINE::TypeCode *createSeqTypeCodeFrom(YACS::ENGINE::Proc *scheme, const std::string& zeType);
void setResources(YACSEvalListOfResources *res);
void resetResources();
private:
void cleanScheme();
private:
+ YACSEvalYFX *_boss;
bool _ownScheme;
YACS::ENGINE::Proc *_scheme;
ResourcesManager_cpp *_rm;
YACSEvalListOfResources *_res;
+ mutable YACSEvalObserver *_observer;
protected:
std::vector< YACSEvalInputPort > _inputs;
std::vector< YACSEvalOutputPort > _outputs;
class YACSEvalYFXRunOnlyPattern : public YACSEvalYFXPattern
{
public:
- YACSEvalYFXRunOnlyPattern(YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode);
+ YACSEvalYFXRunOnlyPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode);
+ ~YACSEvalYFXRunOnlyPattern();
void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputsOfInterest);
void resetOutputsOfInterest();
void generateGraph();
YACSEvalListOfResources *giveResources();
YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const;
std::vector<YACSEvalSeqAny *> getResults() const;
+ void emitStart() const;
+ //
+ YACS::ENGINE::ForEachLoop *getUndergroundForEach() const { return _FEInGeneratedGraph; }
static bool IsMatching(YACS::ENGINE::Proc *scheme, YACS::ENGINE::ComposedNode *& runNode);
public:
static const char GATHER_NODE_NAME[];
YACS::ENGINE::ComposedNode *_runNode;
std::vector<YACSEvalOutputPort *> _outputsOfInterest;
YACS::ENGINE::Proc *_generatedGraph;
+ YACS::ENGINE::ForEachLoop *_FEInGeneratedGraph;
+ YACSEvalYFXRunOnlyPatternInternalObserver *_obs;
};
#endif
std::string getCorbaConfigFileName() const;
};
+class YACSEvalExecParams
+{
+public:
+ bool getStopASAPAfterErrorStatus() const;
+ void setStopASAPAfterErrorStatus(bool newStatus);
+private:
+ YACSEvalExecParams();
+};
+
class YACSEvalYFX
{
public:
static YACSEvalYFX *BuildFromFile(const std::string& xmlOfScheme);
static YACSEvalYFX *BuildFromScheme(YACS::ENGINE::Proc *schema);
+ YACSEvalExecParams *getParams() const;
std::vector<YACSEvalInputPort *> getFreeInputPorts() const;
std::vector<YACSEvalOutputPort *> getFreeOutputPorts() const;
void unlockAll();
bool isLocked() const;
YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const;
YACSEvalListOfResources *giveResources();
+ //void registerObserver(YACSEvalObserver *observer);
%extend
{
void lockPortsForEvaluation(PyObject *inputsOfInterest, PyObject *outputsOfInterest)
<fromnode>node0</fromnode> <fromport>c</fromport>
<tonode>node1</tonode> <toport>d</toport>
</datalink>
- <parameter>
- <tonode>node0</tonode><toport>b</toport>
- <value><double>1.3</double></value>
- </parameter>
<parameter>
<tonode>node1</tonode><toport>e</toport>
<value><double>2.5</double></value>
</parameter>
+ <parameter>
+ <tonode>node0</tonode><toport>b</toport>
+ <value><double>1.3</double></value>
+ </parameter>
</proc>