Salome HOME
Work in progress save and load state.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Mon, 18 Apr 2016 09:26:31 +0000 (11:26 +0200)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Mon, 18 Apr 2016 09:26:31 +0000 (11:26 +0200)
21 files changed:
src/engine/Bloc.cxx
src/engine/Bloc.hxx
src/engine/ComposedNode.cxx
src/engine/ComposedNode.hxx
src/engine/DynParaLoop.cxx
src/engine/DynParaLoop.hxx
src/engine/Executor.cxx
src/engine/ForEachLoop.cxx
src/engine/ForEachLoop.hxx
src/engine/OptimizerLoop.cxx
src/engine/OptimizerLoop.hxx
src/engine/Scheduler.hxx
src/engine/VisitorSaveState.cxx
src/runtime/CMakeLists.txt
src/runtime/VisitorSalomeSaveState.cxx [new file with mode: 0644]
src/runtime/VisitorSalomeSaveState.hxx [new file with mode: 0644]
src/runtime_swig/CMakeLists.txt
src/runtime_swig/SALOMERuntime.i
src/yacsloader/LoadState.cxx
src/yacsloader/LoadState.hxx
src/yacsloader/driver.cxx

index c91c7617295b77577717288021043a6942ba4824..4df68b4a638f93fc92af8af2947ac14782172ff4 100644 (file)
@@ -403,7 +403,7 @@ YACS::Event Bloc::updateStateOnFinishedEventFrom(Node *node)
  * \param node : node that has emitted the event
  * \return the event to notify to bloc's father
  */
-YACS::Event Bloc::updateStateOnFailedEventFrom(Node *node, const Executor *execInst)
+YACS::Event Bloc::updateStateOnFailedEventFrom(Node *node)
 {
   node->exForwardFailed();
   if(areAllSubNodesFinished())
index 2e81f089097c3a204371dc76479c99b568cbc528..190b360541da60ad350b41ea2fdcb4d717fd3468 100644 (file)
@@ -69,7 +69,7 @@ namespace YACS
       void checkNoCyclePassingThrough(Node *node) throw(Exception);
       std::vector< std::pair<OutGate *, InGate *> > getSetOfInternalCFLinks() const;
       YACS::Event updateStateOnFinishedEventFrom(Node *node);
-      YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
+      YACS::Event updateStateOnFailedEventFrom(Node *node);
       void initComputation() const;
       void performCFComputationsOnlyOneLevel(LinkInfo& info) const;
       void performCFComputations(LinkInfo& info) const;
index 09134bdb0f2d0717cef4876ede700147b9ee0cd9..71576cd2bd823ae5dddfee5159f4b3faa827de2b 100644 (file)
@@ -241,8 +241,7 @@ std::vector<Task *> ComposedNode::getNextTasks(bool& isMore)
  * Calls ComposedNode::updateStateFrom to update state from task to root node
  */
 void ComposedNode::notifyFrom(const Task *sender, //* I : task emitting event
-                              YACS::Event event,   //* I : event emitted
-                              const Executor *execInst
+                              YACS::Event event   //* I : event emitted
                               )
 {
   DEBTRACE("ComposedNode::notifyFrom " << event);
@@ -252,12 +251,12 @@ void ComposedNode::notifyFrom(const Task *sender, //* I : task emitting event
   ComposedNode *curLevelNode=taskTyped->_father;
   if(!curLevelNode)//Specific case of loop when 0 turn is specified without any enclosing bloc.
     return ;
-  curEvent=curLevelNode->updateStateFrom(lminus1LevelNode,curEvent,execInst);
+  curEvent=curLevelNode->updateStateFrom(lminus1LevelNode,curEvent);
   while(curEvent!=YACS::NOEVENT && curLevelNode!=this)
     {
       lminus1LevelNode=curLevelNode;
       curLevelNode=curLevelNode->_father;
-      curEvent=curLevelNode->updateStateFrom(lminus1LevelNode,curEvent,execInst);
+      curEvent=curLevelNode->updateStateFrom(lminus1LevelNode,curEvent);
     }
 }
 
@@ -1376,8 +1375,7 @@ OutputDataStreamPort *ComposedNode::getOutputDataStreamPort(const std::string& n
  * Called by ComposedNode::notifyFrom
  */
 YACS::Event ComposedNode::updateStateFrom(Node *node,        //* I : node emitting event
-                                          YACS::Event event,  //* I : event emitted
-                                          const Executor *execInst
+                                          YACS::Event event  //* I : event emitted
                                           )
 {
   DEBTRACE("updateStateFrom: " << node->getName() << " " << event);
@@ -1392,7 +1390,7 @@ YACS::Event ComposedNode::updateStateFrom(Node *node,        //* I : node emitti
           return updateStateOnFinishedEventFrom(node);
           break;
         case YACS::ABORT:
-          return updateStateOnFailedEventFrom(node,execInst);
+          return updateStateOnFailedEventFrom(node);
           break;
         default:
           return YACS::NOEVENT;//TODO unexpected type of event
@@ -1434,7 +1432,7 @@ YACS::Event ComposedNode::updateStateOnStartEventFrom(Node *node)
 }
 
 //! Method used to notify the node that a child node has failed
-YACS::Event ComposedNode::updateStateOnFailedEventFrom(Node *node, const Executor *execInst)
+YACS::Event ComposedNode::updateStateOnFailedEventFrom(Node *node)
 {
    setState(YACS::FAILED);
    return YACS::ABORT;
index b3d8e2e6c9007ed4b728d4b4f3468d293cade571..a4a06626e4c7905dbcd6cb871ad0f74434964fb8 100644 (file)
@@ -64,7 +64,7 @@ namespace YACS
       DeploymentTree checkDeploymentTree(bool deep) const throw(Exception);
       std::vector<Task *> getNextTasks(bool& isMore);
       virtual bool isPlacementPredictableB4Run() const = 0;
-      void notifyFrom(const Task *sender, YACS::Event event, const Executor *execInst);
+      void notifyFrom(const Task *sender, YACS::Event event);
       bool edAddLink(OutPort *start, InPort *end) throw(Exception);
       virtual bool edAddDFLink(OutPort *start, InPort *end) throw(Exception);
       //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
@@ -136,10 +136,10 @@ namespace YACS
       static bool splitNamesBySep(const std::string& globalName, const char separator[],
                                   std::string& firstPart, std::string& lastPart, bool priority) throw(Exception);
       virtual Node *getChildByShortName(const std::string& name) const throw(Exception) = 0;
-      YACS::Event updateStateFrom(Node *node, YACS::Event event, const Executor *execInst);//update the state of this. Precondition : node->_father == this
+      YACS::Event updateStateFrom(Node *node, YACS::Event event);//update the state of this. Precondition : node->_father == this
       virtual YACS::Event updateStateOnStartEventFrom(Node *node);//transition 3 doc P.R
       virtual YACS::Event updateStateOnFinishedEventFrom(Node *node) = 0;//transition 9 doc P.R.
-      virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);//transition 9 doc P.R.
+      virtual YACS::Event updateStateOnFailedEventFrom(Node *node);//transition 9 doc P.R.
       virtual void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
                                         InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
       virtual void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
index db101aebadadf8de673135da8abc0b6eee390f4a..97ed761fe498647a8a1368c1d0ddbd1c1e9e882e 100644 (file)
@@ -696,7 +696,7 @@ void DynParaLoop::forwardExecStateToOriginalBody(Node *execNode)
  *  \param node : the child node that has failed
  *  \return the state change
  */
-YACS::Event DynParaLoop::updateStateOnFailedEventFrom(Node *node, const Executor *execInst)
+YACS::Event DynParaLoop::updateStateOnFailedEventFrom(Node *node)
 {
   DEBTRACE("DynParaLoop::updateStateOnFailedEventFrom " << node->getName());
   setState(YACS::FAILED);
index 86c9e839909064888e4136b7fbe6a5aabee9231b..513b0153aa9140a3702166b9db5855366bb92307 100644 (file)
@@ -124,7 +124,7 @@ namespace YACS
       TypeOfNode getIdentityOfNotifyerNode(const Node *node, unsigned& id);
       InputPort *getDynInputPortByAbsName(int branchNb, const std::string& name, bool initNodeAdmitted);
       virtual void forwardExecStateToOriginalBody(Node *execNode);
-      virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
+      virtual YACS::Event updateStateOnFailedEventFrom(Node *node);
       std::vector<Node *> cloneAndPlaceNodesCoherently(const std::vector<Node *> & origNodes);
       Node * checkConsistencyAndSetNode(Node* &nodeToReplace, Node* DISOWNnode);
       Node * removeNode(Node* &nodeToRemove);
index 1130df735062aadeef730193f6a9b1033b36314d..213b0bacff75dc73b75fe06d003576b0b516bdf1 100644 (file)
@@ -651,6 +651,7 @@ bool Executor::saveState(const std::string& xmlFile)
   DEBTRACE("Executor::saveState() in " << xmlFile);
   bool result = false;
   try {
+    YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&_mutexForSchedulerUpdate);
     YACS::ENGINE::VisitorSaveState vst(_root);
     vst.openFileDump(xmlFile.c_str());
     _root->accept(&vst);
@@ -828,7 +829,7 @@ void Executor::loadTask(Task *task, const Executor *execInst)
   traceExec(task, "state:TOLOAD", ComputePlacement(task));
   {//Critical section
     YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&_mutexForSchedulerUpdate);
-    _mainSched->notifyFrom(task,YACS::START,execInst);
+    _mainSched->notifyFrom(task,YACS::START);
   }//End of critical section
   try
     {
@@ -843,7 +844,7 @@ void Executor::loadTask(Task *task, const Executor *execInst)
       {//Critical section
         YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&_mutexForSchedulerUpdate);
         task->aborted();
-        _mainSched->notifyFrom(task,YACS::ABORT,execInst);
+        _mainSched->notifyFrom(task,YACS::ABORT);
         traceExec(task, "state:"+Node::getStateName(task->getState()), ComputePlacement(task));
       }//End of critical section
     }
@@ -853,7 +854,7 @@ void Executor::loadTask(Task *task, const Executor *execInst)
       {//Critical section
         YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&_mutexForSchedulerUpdate);
         task->aborted();
-        _mainSched->notifyFrom(task,YACS::ABORT,execInst);
+        _mainSched->notifyFrom(task,YACS::ABORT);
         traceExec(task, "state:"+Node::getStateName(task->getState()), ComputePlacement(task));
       }//End of critical section
     }
@@ -926,7 +927,7 @@ void Executor::launchTasks(const std::vector<Task *>& tasks)
           {//Critical section
             YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&_mutexForSchedulerUpdate);
             (*iter)->aborted();
-            _mainSched->notifyFrom(*iter,YACS::ABORT,this);
+            _mainSched->notifyFrom(*iter,YACS::ABORT);
           }//End of critical section
         }
       catch(...) 
@@ -945,7 +946,7 @@ void Executor::launchTasks(const std::vector<Task *>& tasks)
           {//Critical section
             YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&_mutexForSchedulerUpdate);
             (*iter)->aborted();
-            _mainSched->notifyFrom(*iter,YACS::ABORT,this);
+            _mainSched->notifyFrom(*iter,YACS::ABORT);
           }//End of critical section
         }
       if((*iter)->getState() == YACS::ERROR)
@@ -971,7 +972,7 @@ void Executor::launchTasks(const std::vector<Task *>& tasks)
               {//Critical section
                 YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&_mutexForSchedulerUpdate);
                 t->aborted();
-                _mainSched->notifyFrom(t,YACS::ABORT,this);
+                _mainSched->notifyFrom(t,YACS::ABORT);
               }//End of critical section
               traceExec(t, "state:"+Node::getStateName(t->getState()),ComputePlacement(*iter));
             }
@@ -1224,7 +1225,7 @@ void *Executor::functionForTaskExecution(void *arg)
             task->aborted();
           }
         execInst->traceExec(task, "state:"+Node::getStateName(task->getState()),placement);
-        sched->notifyFrom(task,ev,execInst);
+        sched->notifyFrom(task,ev);
       }
     catch(Exception& ex)
       {
index 303cc1492ceb5aa9f55f25dadd52d5196de7de3f..4c767b5b7385fcd61667c0806a2f74421a449a46 100644 (file)
@@ -318,6 +318,14 @@ ForEachLoopPassedData::ForEachLoopPassedData(const std::vector<unsigned int>& pa
     }
 }
 
+ForEachLoopPassedData::ForEachLoopPassedData(const ForEachLoopPassedData& copy)
+: _passedIds(copy._passedIds),
+  _passedOutputs(copy._passedOutputs),
+  _nameOfOutputs(copy._nameOfOutputs),
+  _flagsIds(copy._flagsIds)
+{
+}
+
 ForEachLoopPassedData::~ForEachLoopPassedData()
 {
   for(std::vector<SequenceAny *>::iterator it=_passedOutputs.begin();it!=_passedOutputs.end();it++)
@@ -866,12 +874,14 @@ YACS::Event ForEachLoop::updateStateForFinalizeNodeOnFinishedEventFrom(Node *nod
     return YACS::NOEVENT;
 }
 
-YACS::Event ForEachLoop::updateStateOnFailedEventFrom(Node *node, const Executor *execInst)
+YACS::Event ForEachLoop::updateStateOnFailedEventFrom(Node *node)
 {
   unsigned int id;
   DynParaLoop::TypeOfNode ton(getIdentityOfNotifyerNode(node,id));
-  if(ton!=WORK_NODE || !execInst->getKeepGoingProperty())
-    return DynParaLoop::updateStateOnFailedEventFrom(node,execInst);
+  // TODO: deal with keepgoing
+  // if(ton!=WORK_NODE || !execInst->getKeepGoingProperty())
+  if(ton!=WORK_NODE )
+    return DynParaLoop::updateStateOnFailedEventFrom(node);
   else
     {
       _failedCounter++;
@@ -1163,7 +1173,9 @@ std::vector<unsigned int> ForEachLoop::getPassedResults(Executor *execut, std::v
     return std::vector<unsigned int>();
   if(_execOutGoingPorts.empty())
     return std::vector<unsigned int>();
-  std::size_t sz(_execVals.size()); outputs.resize(sz); nameOfOutputs.resize(sz);
+  std::size_t sz(_execVals.size());
+  outputs.resize(sz);
+  nameOfOutputs.resize(sz);
   const std::vector<AnyInputPort *>& ports(_execOutGoingPorts[0]);
   for(std::size_t i=0;i<sz;i++)
     {
@@ -1184,3 +1196,31 @@ void ForEachLoop::assignPassedResults(const std::vector<unsigned int>& passedIds
   _passedData=new ForEachLoopPassedData(passedIds,passedOutputs,nameOfOutputs);
 }
 
+/*!
+ * This method is used to obtain the values already processed by the ForEachLoop.
+ * A new ForEachLoopPassedData object is returned. You have to delete it.
+ */
+ForEachLoopPassedData* ForEachLoop::getProcessedData()const
+{
+  std::vector<SequenceAny *> outputs;
+  std::vector<std::string> nameOfOutputs;
+  if(_execVals.empty() || _execOutGoingPorts.empty())
+    return new ForEachLoopPassedData(std::vector<unsigned int>(), outputs, nameOfOutputs);
+  std::size_t sz(_execVals.size());
+  outputs.resize(sz);
+  nameOfOutputs.resize(sz);
+  const std::vector<AnyInputPort *>& ports(_execOutGoingPorts[0]);
+  for(std::size_t i=0;i<sz;i++)
+    {
+      outputs[i]=_execVals[i]->removeUnsetItemsFromThis();
+      nameOfOutputs[i]=ports[i]->getName();
+    }
+  return new ForEachLoopPassedData(_execVals[0]->getSetItems(), outputs, nameOfOutputs);
+}
+
+void ForEachLoop::setProcessedData(ForEachLoopPassedData* processedData)
+{
+  if(_passedData)
+    delete _passedData;
+  _passedData = processedData;
+}
index efb9888fb4e6bb2df5b175198a7a2f7e4151d039..875b900fa8a2e2a59818f749f5e820da65eab98b 100644 (file)
@@ -127,6 +127,7 @@ namespace YACS
     {
     public:
       ForEachLoopPassedData(const std::vector<unsigned int>& passedIds, const std::vector<SequenceAny *>& passedOutputs, const std::vector<std::string>& nameOfOutputs);
+      ForEachLoopPassedData(const ForEachLoopPassedData& copy);
       ~ForEachLoopPassedData();
       void init();
       void checkCompatibilyWithNb(int nbOfElts) const;
@@ -136,6 +137,10 @@ namespace YACS
       int toAbsIdNot(int localId) const;
       int getNumberOfElementsToDo() const;
       void assignAlreadyDone(const std::vector<SequenceAny *>& execVals) const;
+      const std::vector<unsigned int>& getIds()const {return _passedIds;}
+      const std::vector<SequenceAny *>& getOutputs()const {return _passedOutputs;}
+      const std::vector<std::string>& getOutputNames()const {return _nameOfOutputs;}
+      //const std::vector<bool>& getFlags()const {return _flagsIds;}
     private:
       std::vector<unsigned int> _passedIds;
       std::vector<SequenceAny *> _passedOutputs;
@@ -196,6 +201,8 @@ namespace YACS
       int getCurrentIndex() const { return _currentIndex; }
       int getNbOfElementsToBeProcessed() const;
 #ifndef SWIG
+      ForEachLoopPassedData* getProcessedData()const;
+      void setProcessedData(ForEachLoopPassedData* processedData);
       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);
 #endif
@@ -207,7 +214,7 @@ namespace YACS
       YACS::Event updateStateForInitNodeOnFinishedEventFrom(Node *node, unsigned int id);
       YACS::Event updateStateForWorkNodeOnFinishedEventFrom(Node *node, unsigned int id, bool isNormalFinish);
       YACS::Event updateStateForFinalizeNodeOnFinishedEventFrom(Node *node, unsigned int id);
-      YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
+      YACS::Event updateStateOnFailedEventFrom(Node *node);
       void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
       void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
       void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
index 83d9dce364aa473b7a7287ff06fd64d6f82512ab..ddb2ac508c3eaadf5e0db410fa8380fb1348e2c9 100644 (file)
@@ -456,7 +456,7 @@ YACS::Event OptimizerLoop::finalize()
  *  \param node : the child node that has failed
  *  \return the state change
  */
-YACS::Event OptimizerLoop::updateStateOnFailedEventFrom(Node *node, const Executor *execInst)
+YACS::Event OptimizerLoop::updateStateOnFailedEventFrom(Node *node)
 {
   DEBTRACE("OptimizerLoop::updateStateOnFailedEventFrom " << node->getName());
   _alg->setError(string("Error during the execution of YACS node ") + node->getName() +
@@ -464,7 +464,7 @@ YACS::Event OptimizerLoop::updateStateOnFailedEventFrom(Node *node, const Execut
   _alg->finishProxy();
   _myPool.destroyAll();
   DEBTRACE("OptimizerLoop::updateStateOnFailedEventFrom: returned from error notification.");
-  return DynParaLoop::updateStateOnFailedEventFrom(node,execInst);
+  return DynParaLoop::updateStateOnFailedEventFrom(node);
 }
 
 void OptimizerLoop::checkNoCyclePassingThrough(Node *node) throw(YACS::Exception)
index b489ee576c5d89baff364b0bd27961dc7f6b5850..2a098438a855d47aa4adfec2c2d1030c535610f2 100644 (file)
@@ -107,7 +107,7 @@ namespace YACS
       YACS::Event finalize();
 
     protected:
-      virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
+      virtual YACS::Event updateStateOnFailedEventFrom(Node *node);
       void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
       void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
       void checkControlDependancy(OutPort *start, InPort *end, bool cross,
index 1b39f885002cd90b34891a1e1e5bc83df41179a8..a326f67b6dc5ff855763f026ee75cc6d274f0082 100644 (file)
@@ -31,7 +31,6 @@ namespace YACS
   namespace ENGINE
   {
     class Task;
-    class Executor;
     
     class Scheduler
     {
@@ -43,7 +42,7 @@ namespace YACS
       virtual std::string getTaskName(Task *task) const = 0;
       virtual std::vector<Task *> getNextTasks(bool& isMore) = 0;
       virtual void selectRunnableTasks(std::vector<Task *>& tasks) = 0;
-      virtual void notifyFrom(const Task *sender, YACS::Event event, const Executor *execInst) = 0;
+      virtual void notifyFrom(const Task *sender, YACS::Event event) = 0;
       //Placement methods
       virtual DeploymentTree getDeploymentTree() const = 0;
       virtual bool isPlacementPredictableB4Run() const = 0;
index 8c27bbca63052543fbe0b81f8fcbf2bce1ce702f..47178e2db9b71ef4563efb7200fc8fd06856aea7 100644 (file)
@@ -325,4 +325,4 @@ void VisitorSaveState::visitStudyInNode(DataNode *node)
 void VisitorSaveState::visitStudyOutNode(DataNode *node)
 {
   visitElementaryNode(node);
-}
+}
\ No newline at end of file
index de103b4e662c22249c49c8aeff733ff7165031ca..a61b05b3f39298e9298d44f2fc975ad157723a8a 100644 (file)
@@ -144,6 +144,7 @@ SET(YACSRuntimeSALOME_HEADERS
   SalomeOptimizerLoop.hxx
   DistributedPythonNode.hxx
   PyOptimizerAlg.hxx
+  VisitorSalomeSaveState.hxx
   )
 
 # --- sources ---
@@ -210,6 +211,7 @@ SET(YACSRuntimeSALOME_SOURCES
   PyStdout.cxx                   
   SalomeOptimizerLoop.cxx        
   PyOptimizerAlg.cxx             
+  VisitorSalomeSaveState.cxx
   )
 
 # --- rules ---
diff --git a/src/runtime/VisitorSalomeSaveState.cxx b/src/runtime/VisitorSalomeSaveState.cxx
new file mode 100644 (file)
index 0000000..0c95368
--- /dev/null
@@ -0,0 +1,115 @@
+// Copyright (C) 2006-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
+//
+
+#include "VisitorSalomeSaveState.hxx"
+#include "TypeConversions.hxx"
+#include "ForEachLoop.hxx"
+#include "Proc.hxx"
+#include "Executor.hxx"
+#include "AutoLocker.hxx"
+
+#include "YacsTrace.hxx"
+
+using namespace YACS::ENGINE;
+
+VisitorSalomeSaveState::VisitorSalomeSaveState(ComposedNode *root)
+:VisitorSaveState(root)
+{
+}
+
+VisitorSalomeSaveState::~VisitorSalomeSaveState()
+{
+}
+
+void VisitorSalomeSaveState::visitForEachLoop(ForEachLoop *node)
+{
+  node->ComposedNode::accept(this);
+  if (!_out) throw Exception("No file open for dump state");
+  std::string name = _root->getName();
+  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
+  DEBTRACE("VisitorSaveState::visitForEachLoop ------ " << name);
+  _out << "  <node type='forEachLoop'>" << std::endl;
+  _out << "    <name>" << name << "</name>" << std::endl;
+  _out << "    <state>" << _nodeStateName[node->getState()] << "</state>" << std::endl;
+//  VisitorSaveState::visitForEachLoop(node);
+  StatesForNode state = node->getState();
+  if(YACS::LOADED == state or
+    YACS::ACTIVATED == state or
+    YACS::SUSPENDED == state or
+    YACS::EXECFAILED == state or
+    YACS::PAUSE == state or
+    YACS::TORECONNECT == state or
+    YACS::INTERNALERR == state or
+    YACS::FAILED == state or
+    YACS::ERROR == state)
+  {
+    ForEachLoopPassedData* processedData = node->getProcessedData();
+    if(processedData)
+    {
+      const std::vector<unsigned int>& processedIndexes = processedData->getIds();
+      std::vector<SequenceAny *>::const_iterator it_outputs;
+      std::vector<std::string>::const_iterator it_names;
+      
+      for(it_outputs = processedData->getOutputs().begin(), it_names = processedData->getOutputNames().begin();
+          it_names != processedData->getOutputNames().end();
+          it_outputs++, it_names++)
+      {
+        _out << "    <loopOutputPort>" << std::endl;
+        _out << "      <name>" << (*it_names) << "</name>" << std::endl;
+        for(unsigned int i = 0; i < (*it_outputs)->size(); i++)
+        {
+          AnyPtr value = (*(*it_outputs))[i];
+          _out << "      <sample><index>" << processedIndexes[i]<< "</index>";
+          if(value)
+            _out << convertNeutralXml(value->getType(), value);
+          else
+            _out << "<value>None</value>";
+          _out << "      </sample>" << std::endl;
+        }
+        _out << "    </loopOutputPort>" << std::endl;
+      }
+      
+      delete processedData;
+      processedData = NULL;
+    }
+  }
+  _out << "  </node>" << std::endl;
+}
+
+
+SchemaSaveState::SchemaSaveState(Proc* proc, Executor* exec)
+: _p(proc),
+  _exec(exec)
+{
+  YASSERT(_p);
+  YASSERT(_exec);
+}
+
+SchemaSaveState::~SchemaSaveState()
+{
+}
+
+void SchemaSaveState::save(std::string xmlSchemaFile)
+{
+  YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&(_exec->getTheMutexForSchedulerUpdate()));
+  VisitorSalomeSaveState vss(_p);
+  vss.openFileDump(xmlSchemaFile);
+  _p->accept(&vss);
+  vss.closeFileDump();
+}
diff --git a/src/runtime/VisitorSalomeSaveState.hxx b/src/runtime/VisitorSalomeSaveState.hxx
new file mode 100644 (file)
index 0000000..a979f39
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (C) 2006-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
+//
+
+#ifndef VISITORSALOMESAVESTATE_HXX
+#define VISITORSALOMESAVESTATE_HXX
+
+#include "VisitorSaveState.hxx"
+#include "YACSRuntimeSALOMEExport.hxx"
+
+namespace YACS
+{
+  namespace ENGINE
+  {
+    class Executor;
+    class YACSRUNTIMESALOME_EXPORT VisitorSalomeSaveState : public VisitorSaveState
+    {
+      public:
+      VisitorSalomeSaveState(ComposedNode *root);
+      virtual ~VisitorSalomeSaveState();
+      virtual void visitForEachLoop(ForEachLoop *node);
+    };
+
+    class YACSLIBENGINE_EXPORT SchemaSaveState
+    {
+    public:
+      SchemaSaveState(Proc* proc, Executor* exec);
+      virtual ~SchemaSaveState();
+      virtual void save(std::string xmlSchemaFile);
+    private:
+      Proc* _p;
+      Executor* _exec;
+    };
+  }
+}
+#endif // VISITORSALOMESAVESTATE_HXX
index 4ee93c0768f07124e717d149ceeedfeb03326a59..879620de2846edaec5eeae3aa7709034c1d35790 100644 (file)
@@ -92,6 +92,7 @@ SET(SWIGINCLUDES
   ${PROJECT_SOURCE_DIR}/src/runtime/CORBAPorts.hxx
   ${PROJECT_SOURCE_DIR}/src/runtime/TypeConversions.hxx
   ${PROJECT_SOURCE_DIR}/src/runtime/SalomeOptimizerLoop.hxx
+  ${PROJECT_SOURCE_DIR}/src/runtime/VisitorSalomeSaveState.hxx
   )
 SWIG_ADD_MODULE(SALOMERuntime python SALOMERuntime.i)
 ADD_DEPENDENCIES(_SALOMERuntime 
index d7f7c8700f6e21ac6a76ab6267bd6e361077c3ad..258904c9deb26de83b9ed1ba3749ee77fee68af6 100644 (file)
 #include "TypeConversions.hxx"
 #include "TypeCode.hxx"
 #include "VisitorSaveSalomeSchema.hxx"
+#include "VisitorSalomeSaveState.hxx"
 #include "SalomeOptimizerLoop.hxx"
 #include "DistributedPythonNode.hxx"
 #include "PyOptimizerAlg.hxx"
 #include "PyStdout.hxx"
+#include "ExecutorSwig.hxx"
 #include <sstream>
 %}
 
 %include "SalomeOptimizerLoop.hxx"
 %include "DistributedPythonNode.hxx"
 
+namespace YACS
+{
+  namespace ENGINE
+  {
+    class SchemaSaveState
+    {
+    public:
+      SchemaSaveState(Proc* proc, Executor* exec);
+      virtual void save(std::string xmlSchemaFile);
+    };
+  }
+}
+
+
 %extend YACS::ENGINE::OutputPresetPort
 {
   void setDataPy(PyObject *ob)
index be6cb45917695e7d13e9f589fb048359b1893206..f4222f10c2ebb695f27787a140342c84b13a8d67 100644 (file)
@@ -27,6 +27,8 @@
 #include "Runtime.hxx"
 #include "InputPort.hxx"
 #include "ElementaryNode.hxx"
+#include "ForEachLoop.hxx"
+#include "Any.hxx"
 
 #include <iostream>
 #include <string>
@@ -249,6 +251,7 @@ void nodeParser::onStart (const XML_Char* elem, const xmlChar** p)
   else if (element == "nbdone")    parser = new attrParser();
   else if (element == "condition") parser = new attrParser();
   else if (element == "outputPort") parser = new outputParser();
+  else if (element == "loopOutputPort") parser = new loopPortParser();
   else
     { 
       _what = "expected name, state or inputPort, got <" + element + ">";
@@ -659,7 +662,148 @@ void simpleTypeParser::charData(std::string data)
   _data = _data + data;
 }
 
+// ----------------------------------------------------------------------------
+
+void loopPortParser::init(const xmlChar** p, xmlParserBase* father)
+{
+  DEBTRACE("loopPortParser::init()");
+  _state = XMLINPORT;
+  _father = father;
+  _stackState.push(_state);
+  if (p) getAttributes(p);
+}
+
+void loopPortParser::onStart(const XML_Char* elem, const xmlChar** p)
+{
+  DEBTRACE("loopPortParser::onStart" << elem);
+  string element(elem);
+  stateParser *parser = 0;
+  if (element == "name")      parser = new attrParser();
+  else if (element == "sample") parser = new sampleParser();
+  else
+    { 
+      _what = "expected name or sample, got <" + element + ">";
+      _state = XMLFATALERROR;
+      stopParse(_what);
+    }
+  if (parser)
+    {
+      _stackParser.push(parser);
+      XML_SetUserData(_xmlParser, parser);
+      parser->init(p, this);
+    }
+}
+
+void loopPortParser::onEnd(const XML_Char* name)
+{
+  string portName = _mapAttrib["name"];
+  string nodeName = _father->getAttribute("name");
+  string nodeType = _father->getAttribute("type");
+  Node *node = _p->getChildByName(nodeName);
+  if (nodeType != "forEachLoop")
+  {
+    _what = "loopOutputPort attribute is not valid for node <" + nodeName + ">";
+    _state = XMLFATALERROR;
+    stopParse(_what);
+  }
+}
+
+void loopPortParser::charData(std::string data)
+{
+}
+
+// ----------------------------------------------------------------------------
+
+void sampleParser::init(const xmlChar** p, xmlParserBase* father)
+{
+  DEBTRACE("sampleParser::init()");
+  _state = XMLINPORT;
+  _father = father;
+  _stackState.push(_state);
+  if (p) getAttributes(p);
+}
 
+void sampleParser::onStart(const XML_Char* elem, const xmlChar** p)
+{
+  DEBTRACE("sampleParser::onStart" << elem);
+  string element(elem);
+  stateParser *parser = 0;
+  if (element == "index")      parser = new attrParser();
+  else if (element == "value") parser = new valueParser();
+  else
+    { 
+      _what = "expected index or value, got <" + element + ">";
+      _state = XMLFATALERROR;
+      stopParse(_what);
+    }
+  if (parser)
+    {
+      _stackParser.push(parser);
+      XML_SetUserData(_xmlParser, parser);
+      parser->init(p, this);
+    }
+}
+
+void sampleParser::onEnd(const XML_Char* name)
+{
+  if (_mapAttrib.find("index") == _mapAttrib.end())
+    {
+      _what = "no attribute index in sample ";
+      _state = XMLFATALERROR;
+      stopParse(_what);
+    }
+  int index =  atoi(_mapAttrib["index"].c_str());
+  Any * value;
+  value = xmlToAny();
+}
+
+void sampleParser::charData(std::string data)
+{
+}
+
+Any* sampleParser::xmlToAny() throw(ConversionException)
+{
+  xmlDocPtr doc;
+  xmlNodePtr cur;
+  YACS::ENGINE::Any *ob=NULL;
+  {
+    doc = xmlParseMemory(_data.c_str(), _data.length());
+    if (doc == NULL )
+      {
+        stringstream msg;
+        msg << "Problem in conversion: XML Document not parsed successfully ";
+        msg << " (" << __FILE__ << ":" << __LINE__ << ")";
+        throw ConversionException(msg.str());
+      }
+    cur = xmlDocGetRootElement(doc);
+    if (cur == NULL)
+      {
+        xmlFreeDoc(doc);
+        stringstream msg;
+        msg << "Problem in conversion: empty XML Document";
+        msg << " (" << __FILE__ << ":" << __LINE__ << ")";
+        throw ConversionException(msg.str());
+      }
+    while (cur != NULL)
+      {
+        if ((!xmlStrcmp(cur->name, (const xmlChar *)"value")))
+          {
+            ob=convertXmlNeutral(edGetType(),doc,cur);
+            break;
+          }
+        cur = cur->next;
+      }
+    xmlFreeDoc(doc);
+    if(ob==NULL)
+      {
+        stringstream msg;
+        msg << "Problem in conversion: incorrect XML value";
+        msg << " (" << __FILE__ << ":" << __LINE__ << ")";
+        throw ConversionException(msg.str());
+      }
+  }
+  return ob;
+}
 
 // ----------------------------------------------------------------------------
 
index ea318eb6c4e7a6f4b2d669d1c6bef9608638bdd1..16e423442671c03723ee199c6ee5ab8cd6c00d12 100644 (file)
 
 #include "YACSloaderExport.hxx"
 #include "xmlParserBase.hxx"
+#include "InputPort.hxx"
 
 #include "define.hxx"
 #include "Exception.hxx"
+#include <vector>
 
 namespace YACS
 {
@@ -32,6 +34,8 @@ namespace YACS
   {
     class Proc;
     class Runtime;
+    class SequenceAny;
+    class Any;
 
     //! Load state from a file into a Proc
     /*!
@@ -172,6 +176,29 @@ namespace YACS
       virtual void charData(std::string data);
     };
 
+    class YACSLOADER_EXPORT loopPortParser: public stateParser
+    {
+    public:
+      virtual void init(const xmlChar** p, xmlParserBase* father=0);
+      virtual void onStart (const XML_Char* elem, const xmlChar** p);
+      virtual void onEnd   (const XML_Char* name);
+      virtual void charData(std::string data);
+      std::vector<unsigned int> _ids;
+      std::vector<SequenceAny *> _outputValues;
+      std::vector<std::string> _outputNames;
+    };
+
+    class YACSLOADER_EXPORT sampleParser: public stateParser
+    {
+    public:
+      virtual void init(const xmlChar** p, xmlParserBase* father=0);
+      virtual void onStart (const XML_Char* elem, const xmlChar** p);
+      virtual void onEnd   (const XML_Char* name);
+      virtual void charData(std::string data);
+    protected:
+      Any* xmlToAny()throw(ConversionException);
+    };
+
   }
 }
 #endif
index ffdc95e790e0c40d2ba8bdd3e73d667167eb68ad..f71028e60bffbad176e36c2b5e4b259733c012b8 100644 (file)
@@ -24,7 +24,7 @@
 #include "Exception.hxx"
 #include "Executor.hxx"
 #include "parsers.hxx"
-#include "VisitorSaveState.hxx"
+#include "VisitorSalomeSaveState.hxx"
 #include "VisitorSaveSalomeSchema.hxx"
 #include "LoadState.hxx"
 #include "Dispatcher.hxx"
@@ -216,7 +216,7 @@ void Handler(int theSigId)
       bool isFinalDump = (strlen(myArgs.finalDump) != 0);
       if (isFinalDump)
         {
-          YACS::ENGINE::VisitorSaveState vst(p);
+          YACS::ENGINE::VisitorSalomeSaveState vst(p);
           vst.openFileDump(myArgs.finalDump);
           p->accept(&vst);
           vst.closeFileDump();
@@ -252,7 +252,7 @@ void * dumpState(void *arg)
 #endif
     string cmd = "touch " + st->lockFile;
     system(cmd.c_str());
-    YACS::ENGINE::VisitorSaveState vst(p);
+    YACS::ENGINE::VisitorSalomeSaveState vst(p);
     vst.openFileDump(st->dumpFile);
     p->accept(&vst);
     vst.closeFileDump();
@@ -544,7 +544,7 @@ int main (int argc, char* argv[])
       bool isFinalDump = (strlen(myArgs.finalDump) != 0);
       if (isFinalDump)
         {
-          YACS::ENGINE::VisitorSaveState vst(p);
+          YACS::ENGINE::VisitorSalomeSaveState vst(p);
           vst.openFileDump(myArgs.finalDump);
           p->accept(&vst);
           vst.closeFileDump();