Salome HOME
Save foreach state - work in progress.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Mon, 27 Feb 2017 09:56:37 +0000 (10:56 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Mon, 27 Feb 2017 09:56:37 +0000 (10:56 +0100)
20 files changed:
1  2 
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/runtime/CMakeLists.txt
src/runtime_swig/CMakeLists.txt
src/runtime_swig/SALOMERuntime.i
src/yacsloader/CMakeLists.txt
src/yacsloader/LoadState.cxx
src/yacsloader/LoadState.hxx
src/yacsloader/driver.cxx
src/yacsloader_swig/loader.i

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 54535a140d33a0fc73d74d506e73d1821ecdb437,4c767b5b7385fcd61667c0806a2f74421a449a46..4ed7f7ac5e030a41ee3b8bad5c2f31245272e6ac
@@@ -29,7 -29,7 +29,7 @@@
  #include <sstream>
  #include <algorithm>    // std::replace_if
  
--//#define _DEVDEBUG_
++#define _DEVDEBUG_
  #include "YacsTrace.hxx"
  
  using namespace YACS::ENGINE;
@@@ -1194,20 -1196,31 +1206,69 @@@ void ForEachLoop::assignPassedResults(c
    _passedData=new ForEachLoopPassedData(passedIds,passedOutputs,nameOfOutputs);
  }
  
 +int ForEachLoop::getFEDeltaBetween(OutPort *start, InPort *end)
 +{
 +  Node *ns(start->getNode()),*ne(end->getNode());
 +  ComposedNode *co(getLowestCommonAncestor(ns,ne));
 +  int ret(0);
 +  Node *work(ns);
 +  while(work!=co)
 +    {
 +      ForEachLoop *isFE(dynamic_cast<ForEachLoop *>(work));
 +      if(isFE)
 +        ret++;
 +      work=work->getFather();
 +    }
 +  if(dynamic_cast<AnySplitOutputPort *>(start))
 +    ret--;
 +  return ret;
 +}
++
+ /*!
+  * 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;
+ }
++
++/*!
++ * \param portName : "interceptorized" name of port.
++ */
++const YACS::ENGINE::TypeCode* ForEachLoop::getOutputPortType(const std::string& portName)const
++{
++  const YACS::ENGINE::TypeCode* ret=NULL;
++  vector<AnySplitOutputPort *>::const_iterator it;
++  for(it=_outGoingPorts.begin();it!=_outGoingPorts.end() && ret==NULL;it++)
++  {
++    std::string originalPortName(getPortName(*it));
++    //InterceptorizeNameOfPort(originalPortName);
++    DEBTRACE("ForEachLoop::getOutputPortType compare " << portName << " == " << originalPortName);
++    if(originalPortName == portName)
++    {
++      ret = (*it)->edGetType()->contentType();
++    }
++  }
++  return ret;
++}
index 7c1968d38eca47298b28895e43f192aed1679dc7,875b900fa8a2e2a59818f749f5e820da65eab98b..0f3690fb06d157d0981f70e48b6f47cc48d55a2b
@@@ -195,11 -200,12 +200,14 @@@ namespace YAC
        std::list<ProgressWeight> getProgressWeight() const;
        int getCurrentIndex() const { return _currentIndex; }
        int getNbOfElementsToBeProcessed() const;
 +      static int getFEDeltaBetween(OutPort *start, InPort *end);
  #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
++     const TypeCode* getOutputPortType(const std::string& portName)const;
      protected:
        Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
        void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
Simple merge
Simple merge
Simple merge
Simple merge
index 1f3e47394eb58687c45896a7a8d68b2adb1a5c23,879620de2846edaec5eeae3aa7709034c1d35790..abfcdca0a2d3e5ed40df2a14b4c07696bf774ce0
@@@ -92,12 -92,15 +92,13 @@@ SET(SWIGINCLUDE
    ${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
    )
 +SET(SWIG_MODULE_SALOMERuntime_EXTRA_DEPS 
 +    ${PROJECT_SOURCE_DIR}/src/engine_swig/pilot.i 
 +    ${PROJECT_SOURCE_DIR}/src/engine_swig/engtypemaps.i  
 +    ${SWIGINCLUDES})
  SWIG_ADD_MODULE(SALOMERuntime python SALOMERuntime.i)
 -ADD_DEPENDENCIES(_SALOMERuntime 
 -                 SALOMERuntime.i 
 -                 ${PROJECT_SOURCE_DIR}/src/engine_swig/pilot.i 
 -                 ${PROJECT_SOURCE_DIR}/src/engine_swig/engtypemaps.i 
 -                 docruntime.i 
 -                 ${SWIGINCLUDES})
  
  SWIG_LINK_LIBRARIES(SALOMERuntime ${_link_LIBRARIES})
  IF(WIN32)
Simple merge
index 20052f3721d0c1a7544e13ca1baa66ca60fe6019,ddfc6b004d979049a61cbd3a06e9e7f31273041b..71a9807f818689ea6286e6f49d71ebd45c1ca2e7
@@@ -73,6 -73,6 +73,7 @@@ SET(YACSloader_LIBRARIE
    ${OMNIORB_LIBRARIES}
    ${LIBXML2_LIBRARIES}
    YACSlibEngine
++  YACSRuntimeSALOME
    )
  SET(_link_LIBRARIES
    YACSloader
index faaa1a5fdd5ea162fa6bc29f97458f028418758f,f4222f10c2ebb695f27787a140342c84b13a8d67..2de532554eb27f0990fb9931aa81660f621c132f
@@@ -27,6 -27,8 +27,9 @@@
  #include "Runtime.hxx"
  #include "InputPort.hxx"
  #include "ElementaryNode.hxx"
+ #include "ForEachLoop.hxx"
+ #include "Any.hxx"
++#include "TypeConversions.hxx"
  
  #include <iostream>
  #include <string>
@@@ -34,7 -36,7 +37,7 @@@
  #include <cstdarg>
  #include <cassert>
  
--//#define _DEVDEBUG_
++#define _DEVDEBUG_
  #include "YacsTrace.hxx"
  
  using namespace YACS::ENGINE;
@@@ -231,6 -232,6 +234,7 @@@ public
  void nodeParser::init(const xmlChar** p, xmlParserBase* father)
  {
    DEBTRACE("nodeParser::init()");
++  _loopSamples.clear();
    _state = XMLINNODE;
    _father = father;
    _stackState.push(_state);
@@@ -250,6 -251,7 +254,12 @@@ void nodeParser::onStart (const XML_Cha
    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 if (element == "loopOutputPort")
++  {
++    loopPortParser* sparser = new loopPortParser();
++    _loopSamples.push_back(sparser);
++    parser = sparser;
++  }
    else
      { 
        _what = "expected name, state or inputPort, got <" + element + ">";
@@@ -362,10 -364,10 +372,118 @@@ void nodeParser::onEnd   (const XML_Cha
          }
        mySwitch->edGetConditionPort()->edInit(condition);
      }
++  else if (nodeType == "forEachLoop")
++  {
++    ForEachLoop* feNode = dynamic_cast<ForEachLoop*>(node);
++    if(!feNode)
++    {
++      _what = "node is not a ForEachLoop: " + _mapAttrib["name"];
++      _state = XMLFATALERROR;
++      stopParse(_what);
++    }
++    else
++    {
++      std::vector<unsigned int> passedIds;
++      std::vector<SequenceAny *> passedOutputs;
++      std::vector<std::string> nameOfOutputs;
++      bool firstPort = true;
++      std::list<loopPortParser*>::const_iterator itPort;
++      for(itPort=_loopSamples.begin(); itPort!=_loopSamples.end(); itPort++)
++      {
++        const std::string& portName =(*itPort)->getPortName();
++        nameOfOutputs.push_back(portName);
++        const YACS::ENGINE::TypeCode* tc = feNode->getOutputPortType(portName);
++        if(!tc)
++        {
++          _what = "Impossible to find the type of the port " + portName;
++          _state = XMLFATALERROR;
++          stopParse(_what);
++          return;
++        }
++        unsigned int nbSamples = (*itPort)->getNbSamples();
++        SequenceAny* seqValues = SequenceAny::New(tc, nbSamples);
++        passedOutputs.push_back(seqValues);
++        for(unsigned int i = 0; i < nbSamples; i++)
++        {
++          unsigned int sampleId = (*itPort)->getSampleId(i);
++          const std::string& sampleData = (*itPort)->getSampleData(i);
++          Any* value = xmlToAny(sampleData, tc);
++          if(firstPort)
++          {
++            passedIds.push_back(sampleId);
++            seqValues->setEltAtRank(i, value);
++          }
++          else
++          {
++            unsigned int pos = 0;
++            while(pos < passedIds.size() && sampleId != passedIds[pos])
++              pos++;
++            if(pos < passedIds.size())
++              seqValues->setEltAtRank(pos, value);
++            else
++            {
++              _what = "Inconsistent sample id in foreach node " + _mapAttrib["name"];
++              _state = XMLFATALERROR;
++              stopParse(_what);
++              itPort=_loopSamples.end();
++              return;
++            }
++          }
++        }
++        firstPort = false;
++      }
++      feNode->assignPassedResults(passedIds, passedOutputs, nameOfOutputs);
++    }
++  }
  
    stateParser::onEnd(name);
  }
  
++Any* nodeParser::xmlToAny(const std::string& data, const YACS::ENGINE::TypeCode* tc)const
++{
++  xmlDocPtr doc;
++  xmlNodePtr cur;
++  //YACS::ENGINE::Any *ob=YACS::ENGINE::AtomAny::New(0);
++  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(tc,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;
++}
++
  // ----------------------------------------------------------------------------
  
  void attrParser::init(const xmlChar** p, xmlParserBase* father)
@@@ -660,7 -662,148 +778,130 @@@ void simpleTypeParser::charData(std::st
    _data = _data + data;
  }
  
 -  _state = XMLINPORT;
+ // ----------------------------------------------------------------------------
+ void loopPortParser::init(const xmlChar** p, xmlParserBase* father)
+ {
+   DEBTRACE("loopPortParser::init()");
 -  else if (element == "sample") parser = new sampleParser();
++  //_state = XMLINPORT;
+   _father = father;
+   _stackState.push(_state);
++  _ids.clear();
++  _sampleData.clear();
+   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();
 -  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);
 -  }
++  else if (element == "sample") parser = new sampleParser(this);
+   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)
+ {
++  stateParser::onEnd(name);
+ }
+ void loopPortParser::charData(std::string data)
+ {
+ }
  
 -  _state = XMLINPORT;
++void loopPortParser::addSample(int index, const std::string data)
++{
++  _ids.push_back(index);
++  _sampleData.push_back(data);
++}
++
++unsigned int loopPortParser::getNbSamples()const
++{
++  return _ids.size();
++}
++
++unsigned int loopPortParser::getSampleId(unsigned int i)const
++{
++  return _ids[i];
++}
++
++const std::string& loopPortParser::getSampleData(unsigned int i)const
++{
++  return _sampleData[i];
++}
++
++const std::string& loopPortParser::getPortName()const
++{
++  return _mapAttrib.at("name");
++}
++
+ // ----------------------------------------------------------------------------
++sampleParser::sampleParser(loopPortParser* father)
++: stateParser(),
++  _sampleFather(father)
++{
++}
++
+ void sampleParser::init(const xmlChar** p, xmlParserBase* father)
+ {
+   DEBTRACE("sampleParser::init()");
 -  Any * value;
 -  value = xmlToAny();
++  //_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* 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;
++  _sampleFather->addSample(index, _data);
++  stateParser::onEnd(name);
+ }
+ void sampleParser::charData(std::string data)
+ {
++  _data = _data + data;
+ }
  
  // ----------------------------------------------------------------------------
  
index 3935d569ee57d9504a8e3157f2de9ed5e20ebb7e,16e423442671c03723ee199c6ee5ab8cd6c00d12..6102e0b3f72407f3fc770a1919f019da7cf17c81
@@@ -25,6 -26,7 +26,8 @@@
  
  #include "define.hxx"
  #include "Exception.hxx"
+ #include <vector>
++#include <list>
  
  namespace YACS
  {
@@@ -32,6 -34,8 +35,9 @@@
    {
      class Proc;
      class Runtime;
+     class SequenceAny;
+     class Any;
++    class TypeCode;
  
      //! Load state from a file into a Proc
      /*!
      };
  
  
++    class loopPortParser;
      class YACSLOADER_EXPORT nodeParser: 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);
++      Any* xmlToAny(const std::string& data, const TypeCode* tc)const;
        std::string _nodeName;
        std::string _nodeState;
++    private:
++      std::list<loopPortParser*> _loopSamples;
      };
  
      class YACSLOADER_EXPORT attrParser: public stateParser
        virtual void charData(std::string data);
      };
  
 -      std::vector<SequenceAny *> _outputValues;
 -      std::vector<std::string> _outputNames;
+     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);
++      void addSample(int index, const std::string data);
++      unsigned int getNbSamples()const;
++      unsigned int getSampleId(unsigned int i)const;
++      const std::string& getSampleData(unsigned int i)const;
++      const std::string& getPortName()const;
++    private:
+       std::vector<unsigned int> _ids;
 -    protected:
 -      Any* xmlToAny()throw(ConversionException);
++      std::vector<std::string> _sampleData;
+     };
+     class YACSLOADER_EXPORT sampleParser: public stateParser
+     {
+     public:
++      sampleParser(loopPortParser* father);
+       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);
++    private:
++      loopPortParser* _sampleFather;
+     };
    }
  }
  #endif
Simple merge
index 4f41b4ad19388381cc3ff7b327dd5e7698d786a5,821157f5da35a507f39e979f5decfd6d2542927d..13dd1bcd9c0bfa5e061813d14d01fd3ad41e9055
@@@ -67,5 -67,5 +67,5 @@@
  %include "YACSloaderExport.hxx"
  %include "parsers.hxx"
  %import "xmlParserBase.hxx"
--%include "LoadState.hxx"
++//%include "LoadState.hxx"