Salome HOME
[EDF29576] : 2 options remaining
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 23 Feb 2024 08:22:30 +0000 (09:22 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 23 Feb 2024 08:22:30 +0000 (09:22 +0100)
src/engine/Node.cxx
src/engine/Node.hxx
src/yacsloader/driver.py
src/yacsloader_swig/loader.i

index 18309aa9a9ad41b7b7dc5eb4518e87e45a9c4adb..b2e41304dbad4c9e6beef515195c04789f794d3e 100644 (file)
@@ -27,6 +27,7 @@
 #include "InputDataStreamPort.hxx"
 #include "OutputDataStreamPort.hxx"
 #include <iostream>
+#include <fstream>
 
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
@@ -616,6 +617,12 @@ void Node::writeDot(std::ostream &os) const
   os << getQualifiedName() <<"\"];\n";
 }
 
+void Node::writeDotInFile(const std::string& fileName) const
+{
+  std::ofstream f(fileName);
+  this->writeDot(f);
+}
+
 //! same as Node::getName() in most cases, but differs for children of switch
 /*!
  *  used by writeDot to distinguish children of switch, by adding a prefix to the name.
index 9955cb13e6285481cc73512bda1968abc8d26f6f..1e045a94bb3a829ea20507805d3be5696397a2c8 100644 (file)
@@ -129,6 +129,7 @@ namespace YACS
       bool exIsControlReady() const;
       std::list<Node *> getOutNodes() const;
       virtual void writeDot(std::ostream &os) const;
+      void writeDotInFile(const std::string& fileName) const;
       virtual void exUpdateState();
       virtual void exFailedState();
       virtual void exDisabledState();
index 0f2b1f2388cfed04f2423f811da56f4a54e3d9e5..9a9b7b410de5ccb7838e7fb1adb2da57c0786bff 100644 (file)
@@ -19,7 +19,7 @@
 #
 
 # python3 /home/H87074/salome/990_CEA/SALOME-master-native-DB11-SRC/SOURCES/yacs/src/yacsloader/driver.py -v -kt micro_schema.xml
-# python3 /home/H87074/salome/990_CEA/SALOME-master-native-DB11-SRC/SOURCES/yacs/src/yacsloader/driver.py --stop-on-error --dump-on-error="popo.xml" -v -kt -ip "PyScript0.p1=7" --dump-final="tutu.xml" micro_schema2.xml
+# python3 /home/H87074/salome/990_CEA/SALOME-master-native-DB11-SRC/SOURCES/yacs/src/yacsloader/driver.py -d 3 --stop-on-error --dump-on-error="popo.xml" -v -kt -ip "PyScript0.p1=7" --dump-final="tutu.xml" micro_schema2.xml
 
 import loader
 import SALOMERuntime
@@ -30,19 +30,12 @@ import logging
 struct arguments
 {
   int display = 0;
-  std::string finalDump;
   int dump = 0;
-  std::string loadState;
-  int reset = 0;
 };
 
     {"display",         'd', "level", 0,                   "Display dot files: 0=never to 3=very often (default 0)"},
-    {"dump-final",      'f', "file",  OPTION_ARG_OPTIONAL, "dump final state"},
     {"dump",            'g', "nbsec", OPTION_ARG_OPTIONAL, "dump state"},
-    {"load-state",      'l', "file",  0,                   "Load State from a previous partial execution"},
     {"save-xml-schema", 'x', "file",  OPTION_ARG_OPTIONAL, "dump xml schema"},
-    {"reset",           'r', "level", 0,                   "Reset the schema before execution: 0=nothing, 1=reset error nodes to ready state (default 0)"},
-
 """
 
 my_runtime_yacs = None
@@ -82,7 +75,7 @@ def loadGraph( xmlFileName ):
     p=l.load( xmlFileName )
     return p
 
-def patchGraph( proc, squeezeMemory, initPorts):
+def patchGraph( proc, squeezeMemory, initPorts, loadStateXmlFile, reset, display):
     """
     Args:
     -----
@@ -90,7 +83,9 @@ def patchGraph( proc, squeezeMemory, initPorts):
     proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated
     squeezeMemory ( bool ) : squeezememory to be activated
     initPorts (list<string>) : list of bloc.node.port=value.
-
+    loadStateXmlFile (string) : file if any of state to be loaded inside proc
+    reset (int) : 
+    display (int) :
     """
     def parse_init_port(input):
       """
@@ -110,11 +105,21 @@ def patchGraph( proc, squeezeMemory, initPorts):
       for node in allNodes:
         if isinstance(proc,SALOMERuntime.PythonNode):
           node.setSqueezeStatus( True )
-      for initPort in initPorts:
-         node,port,value = parse_init_port(initPort)
-         init_state = proc.setInPortValue(node, port, value)
-         if init_state != value:
-            raise RuntimeError(f"Error on initialization of {initPort}")
+    #
+    for initPort in initPorts:
+        node,port,value = parse_init_port(initPort)
+        init_state = proc.setInPortValue(node, port, value)
+        if init_state != value:
+          raise RuntimeError(f"Error on initialization of {initPort}")
+    #
+    if loadStateXmlFile:
+      loader.loadState( proc, loadStateXmlFile )
+      if reset > 0:
+        proc.resetState(reset)
+        proc.exUpdateState()
+    #
+    if display > 0:
+       proc.writeDotInFile("toto")
          
 @SALOMEInitializationNeeded
 def prepareExecution(proc, isStop, dumpErrorFile):
@@ -132,7 +137,7 @@ def prepareExecution(proc, isStop, dumpErrorFile):
   return ex
 
 @SALOMEInitializationNeeded
-def executeGraph( executor, proc, finalDump ):
+def executeGraph( executor, proc, finalDump, display ):
     """
     Args:
     -----
@@ -140,13 +145,18 @@ def executeGraph( executor, proc, finalDump ):
     executor (pilot.ExecutorSwig) : Executor in charge of evaluation.
     proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated
     finalDump ( string ) : filename containing final result of graph, if any.
-
+    display (int) :
     """
     import pilot
-    executor.RunW(proc,0)
+    executor.RunW(proc,display)
     if proc.getEffectiveState() != pilot.DONE:
       raise RuntimeError( proc.getErrorReport() )
+    #
+    if display > 0:
+       proc.writeDotInFile("titi")
+    #
     if finalDump:
+      logging.info(f"Final dump requested : {finalDump}")
       SALOMERuntime.schemaSaveStateUnsafe( proc, finalDump )
 
 @SALOMEInitializationNeeded
@@ -168,15 +178,19 @@ if __name__ == "__main__":
     import argparse
     parser = argparse.ArgumentParser()
     parser.add_argument('xmlfilename',help = "XML file containing YACS schema to be executed")
+    parser.add_argument("-d", "--display", dest = "display", type=int, default=[0], nargs=1, help="Display dot files: 0=never to 3=very often")
     parser.add_argument("-v", "--verbose", dest = "verbose",help="Produce verbose output", action='store_true')
     parser.add_argument("--stop-on-error",dest="stop",help="Stop on first error", action='store_true')
-    parser.add_argument("--dump-on-error",dest="dumpErrorFile",help="Stop on first error and dump state")
+    parser.add_argument("-e","--dump-on-error",dest="dumpErrorFile", type=str, const='dumpErrorState.xml', default="", nargs='?', help="Stop on first error and dump state")
     parser.add_argument("-kt", "--kerneltrace", dest = "kerneltrace",help="Produce verbose of SALOME/KERNEL", action='store_true')
-    parser.add_argument("--dump-final", dest ="finalDump", type=str, default="", help="dump final state")
+    parser.add_argument("-f","--dump-final", dest ="finalDump", type=str, const='finalDumpState.xml', default="", nargs='?', help="dump final state")
+    parser.add_argument("--load-state", dest="loadState", type=str, default="", help="Load State from a previous partial execution")
     parser.add_argument("--shutdown", dest = 'shutdown', type=int , default=1, help="Shutdown the schema: 0=no shutdown to 3=full shutdown")
+    parser.add_argument("--reset", dest = "reset", type=int , default = 0, help="Reset the schema before execution: 0=nothing, 1=reset error nodes to ready state")
     parser.add_argument("-z","--donotsqueeze", dest = "donotsqueeze", help = "Desactivate squeeze memory optimization.", action='store_true')
     parser.add_argument("-ip","--init-port", dest = 'init_port', type=str, help="Initialisation value of a port, specified as bloc.node.port=value.")
     args = parser.parse_args()
+    args.display = args.display[0]
     #
     if args.verbose:
       setVerbose( args.kerneltrace )
@@ -184,7 +198,7 @@ if __name__ == "__main__":
       positionVerbosityOfLoggerRegardingState()
     #
     proc = loadGraph( args.xmlfilename )
-    patchGraph( proc, not args.donotsqueeze, args.init_port.split(","))
+    patchGraph( proc, not args.donotsqueeze, args.init_port.split(","), args.loadState, args.reset, args.display)
     executor = prepareExecution( proc, args.stop, args.dumpErrorFile)
-    executeGraph( executor, proc, args.finalDump)
+    executeGraph( executor, proc, args.finalDump, args.display)
     destroyElementsGeneratedByExecutionOfGraph( proc, args.shutdown )
index 3466b4c4f4267f6b721f66835456ffdd35d13587..e9b3f03131d923a901f4b80403656a8f6b64ae16 100644 (file)
 %import "xmlParserBase.hxx"
 %include "LoadState.hxx"
 
+namespace YACS
+{
+  namespace ENGINE
+  {
+    void loadState(YACS::ENGINE::Proc *p,const std::string& xmlStateFile);
+  }
+}