Salome HOME
Fix the python API of the savestate feature. SHAPER_2.7.0 V8_3_0b1
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 21 Mar 2017 16:19:24 +0000 (17:19 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 21 Mar 2017 16:19:24 +0000 (17:19 +0100)
Proc::savestate is now deprecated.
You have to use VisitorSalomeSaveState (c++) or SALOMERuntime.schemaSaveState (python).

src/engine/Proc.hxx
src/runtime/VisitorSalomeSaveState.cxx
src/runtime/VisitorSalomeSaveState.hxx
src/runtime_swig/SALOMERuntime.i
src/yacsloader_swig/Test/testSaveLoadRun.py

index f2a7ea96c34b0ed8b1db6baf53466a82dc2d33cd..95cc82d5700c1c0350482f8cbefdc6ab7543d46c 100644 (file)
@@ -98,6 +98,8 @@ namespace YACS
       virtual void setEdition(bool edition);
       virtual void modified();
       virtual void saveSchema(const std::string& xmlSchemaFile);
+      //! deprecated. See VisitorSalomeSaveState and schemaSaveState in order
+      //! to deal with the execution state of ForEachLoop.
       virtual void saveState(const std::string& xmlStateFile);
     protected:
       void removeContainers();
index 589f76db1f0f76ebe58007ede60dcf71fda751ad..b0957cf9363b98110f6b10a018f122096e03eeba 100644 (file)
@@ -111,24 +111,13 @@ void VisitorSalomeSaveState::visitForEachLoop(ForEachLoop *node)
   _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)
+void YACS::ENGINE::schemaSaveState(Proc* proc,
+                                  Executor* exec,
+                                  const std::string& xmlSchemaFile)
 {
-  YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&(_exec->getTheMutexForSchedulerUpdate()));
-  VisitorSalomeSaveState vss(_p);
+  YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&(exec->getTheMutexForSchedulerUpdate()));
+  VisitorSalomeSaveState vss(proc);
   vss.openFileDump(xmlSchemaFile);
-  _p->accept(&vss);
+  proc->accept(&vss);
   vss.closeFileDump();
 }
index a979f39a7629ddf8f4ecd888548b77a3fd14a84f..ceb4afd1d3de526540b75df4dd25b37dead3915e 100644 (file)
@@ -36,16 +36,9 @@ namespace YACS
       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;
-    };
+    YACSLIBENGINE_EXPORT void schemaSaveState(Proc* proc,
+                                              Executor* exec,
+                                              const std::string& xmlSchemaFile);
   }
 }
 #endif // VISITORSALOMESAVESTATE_HXX
index c28691cd327c3a360bb853b61da13bd0aa8f5512..59ce1a3d04e25f57c71f55607ce95014e601d849 100644 (file)
@@ -140,12 +140,9 @@ namespace YACS
 {
   namespace ENGINE
   {
-    class SchemaSaveState
-    {
-    public:
-      SchemaSaveState(Proc* proc, Executor* exec);
-      virtual void save(std::string xmlSchemaFile);
-    };
+    void schemaSaveState(Proc* proc,
+                         Executor* exec,
+                         const std::string& xmlSchemaFile);
   }
 }
 
index 95c07735cf7fbab5662a8ce6182f22419f06edfe..a4bc88c3aa7aa17269a49f8201f04e33b8586d27 100755 (executable)
@@ -1516,7 +1516,7 @@ o2=2*i1
     myRun.start()
     import time
     time.sleep(5)
-    p.saveState(xmlStateFileName)
+    SALOMERuntime.schemaSaveState(p, ex, xmlStateFileName)
     a,b,c=n1.getPassedResults(ex)
     myRun.join()
     t0=datetime.now()-startt
@@ -1547,6 +1547,39 @@ o2=5*i1
     pass
   pass
 
+  def test22(self):
+    """Restart from a saved state in a foreach loop without using assignPassedResults.
+       This test uses the files test21.xml and saveState21.xml produced by test21.
+    """
+    fname="test21.xml"
+    xmlStateFileName="saveState21.xml"
+
+    ex=pilot.ExecutorSwig()
+    l=loader.YACSLoader()
+    q=l.load(fname)
+    q.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(6) ]")
+    q.getChildByName("n1").getChildByName("n10").setScript("""
+import time
+time.sleep(0.1)
+print "execution n10:", i1
+o2=5*i1
+""")
+    q.getChildByName("n2").setScript("""
+print "execution n2:", i3
+o4=i3
+""")
+    loader.loadState(q, xmlStateFileName)
+    q.resetState(1)
+    q.exUpdateState()
+    #
+    ex.RunW(q,0,False)
+    #
+    self.assertEqual(q.getChildByName("n1").getState(),pilot.DONE)
+    self.assertEqual(q.getState(),pilot.DONE)
+    self.assertEqual(q.getChildByName("n2").getOutputPort("o4").getPyObj(),[0L,2L,10L,15L,20L,25L])
+    pass
+  pass
+
 if __name__ == '__main__':
   import os,sys
   U = os.getenv('USER')