From 985ec9863ee36c54336a55906e325464c05e9641 Mon Sep 17 00:00:00 2001 From: Lauffenburger Thomas Date: Fri, 12 May 2017 16:34:00 +0200 Subject: [PATCH] add the new attribut weight in xml Signed-off-by: Ovidiu Mircescu --- src/engine/VisitorSaveSchema.cxx | 2 + src/yacsloader/loopParsers.hxx | 18 +++++++ src/yacsloader_swig/Test/testSaveLoadRun.py | 53 +++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/src/engine/VisitorSaveSchema.cxx b/src/engine/VisitorSaveSchema.cxx index ef6890f4f..4e33796b9 100644 --- a/src/engine/VisitorSaveSchema.cxx +++ b/src/engine/VisitorSaveSchema.cxx @@ -134,6 +134,7 @@ void VisitorSaveSchema::visitForEachLoop(ForEachLoop *node) _out << " state=\"disabled\""; if (!nbranch->isEmpty()) _out << " nbranch=\"" << nbranch->getIntValue() << "\""; + _out << " weight=\"" << node->getWeight() << "\""; if (node->edGetSamplePort()) _out << " type=\"" << node->edGetSamplePort()->edGetType()->name() << "\""; _out << ">" << endl; @@ -159,6 +160,7 @@ void VisitorSaveSchema::visitOptimizerLoop(OptimizerLoop *node) _out << " state=\"disabled\""; if (!nbranch->isEmpty()) _out << " nbranch=\"" << nbranch->getIntValue() << "\""; + _out << " weight=\"" << node->getWeight() << "\""; _out << " lib=\"" << node->getAlgLib() << "\""; _out << " entry=\"" << node->getSymbol() << "\""; _out << ">" << endl; diff --git a/src/yacsloader/loopParsers.hxx b/src/yacsloader/loopParsers.hxx index 570925302..db84e6ff1 100644 --- a/src/yacsloader/loopParsers.hxx +++ b/src/yacsloader/loopParsers.hxx @@ -506,6 +506,7 @@ struct foreachlooptypeParser:dynparalooptypeParser if(std::string(attr[i]) == "name")name(attr[i+1]); if(std::string(attr[i]) == "state")this->state(attr[i+1]); if(std::string(attr[i]) == "nbranch")nbranch(atoi(attr[i+1])); + if(std::string(attr[i]) == "weight")weight(atof(attr[i+1])); if(std::string(attr[i]) == "type")datatype(attr[i+1]); } postAttr(); @@ -513,6 +514,7 @@ struct foreachlooptypeParser:dynparalooptypeParser virtual void pre () { _nbranch=0; + _weight=1; this->looptypeParser::pre(); } virtual void name (const std::string& name) @@ -526,6 +528,11 @@ struct foreachlooptypeParser:dynparalooptypeParser DEBTRACE("foreach_nbranch: " << n ) _nbranch=n; } + virtual void weight (const double& x) + { + DEBTRACE("foreach_weight: " << x ) + _weight=x; + } virtual void datatype (const std::string& type) { DEBTRACE("foreach_datatype: "<< type) @@ -552,6 +559,7 @@ struct foreachlooptypeParser:dynparalooptypeParser this->_cnode=theRuntime->createForEachLoop(_name,currentProc->typeMap[_datatype]); //set number of branches if(_nbranch > 0)this->_cnode->edGetNbOfBranchesPort()->edInit(_nbranch); + this->_cnode->setWeight(_weight); this->_cnodes.push_back(this->_cnode); currentProc->names.push_back(_fullname + '.'); } @@ -565,6 +573,7 @@ struct foreachlooptypeParser:dynparalooptypeParser return b; } int _nbranch; + double _weight; std::string _fullname; std::string _name; std::string _datatype; @@ -595,6 +604,7 @@ struct optimizerlooptypeParser:dynparalooptypeParser if(std::string(attr[i]) == "name")name(attr[i+1]); if(std::string(attr[i]) == "state")this->state(attr[i+1]); if(std::string(attr[i]) == "nbranch")nbranch(atoi(attr[i+1])); + if(std::string(attr[i]) == "weight")weight(atof(attr[i+1])); if(std::string(attr[i]) == "lib")lib(attr[i+1]); if(std::string(attr[i]) == "entry")entry(attr[i+1]); if(std::string(attr[i]) == "kind")kind(attr[i+1]); @@ -604,6 +614,7 @@ struct optimizerlooptypeParser:dynparalooptypeParser virtual void pre () { _nbranch=0; + _weight=1; this->looptypeParser::pre(); } virtual void name (const std::string& name) @@ -625,6 +636,11 @@ struct optimizerlooptypeParser:dynparalooptypeParser DEBTRACE("optimizer_nbranch: " << n ) _nbranch=n; } + virtual void weight (const double& x) + { + DEBTRACE("foreach_weight: " << x ) + _weight=x; + } virtual void kind (const std::string& name) { _kind=name; @@ -634,6 +650,7 @@ struct optimizerlooptypeParser:dynparalooptypeParser this->_cnode=theRuntime->createOptimizerLoop(_name,_lib,_entry,true,_kind, currentProc); //set number of branches if(_nbranch > 0)this->_cnode->edGetNbOfBranchesPort()->edInit(_nbranch); + this->_cnode->setWeight(_weight); this->_cnodes.push_back(this->_cnode); currentProc->names.push_back(_fullname + '.'); } @@ -648,6 +665,7 @@ struct optimizerlooptypeParser:dynparalooptypeParser } int _nbranch; + double _weight; std::string _fullname; std::string _name; std::string _entry; diff --git a/src/yacsloader_swig/Test/testSaveLoadRun.py b/src/yacsloader_swig/Test/testSaveLoadRun.py index a4bc88c3a..6a35686d2 100755 --- a/src/yacsloader_swig/Test/testSaveLoadRun.py +++ b/src/yacsloader_swig/Test/testSaveLoadRun.py @@ -1578,6 +1578,59 @@ o4=i3 self.assertEqual(q.getState(),pilot.DONE) self.assertEqual(q.getChildByName("n2").getOutputPort("o4").getPyObj(),[0L,2L,10L,15L,20L,25L]) pass + + def test23(self): + """ test focused on weight attribut after a dump and reload from a xml file + """ + fname="test23.xml" + xmlStateFileName="saveState23.xml" + from datetime import datetime + p=self.r.createProc("prTest23") + cont=p.createContainer("gg","Salome") + cont.setProperty("name","localhost") + cont.setProperty("hostname","localhost") + cont.setProperty("type","multi") + td=p.createType("double","double") + ti=p.createType("int","int") + tsi=p.createSequenceTc("seqint","seqint",ti) + tsd=p.createSequenceTc("seqdbl","seqdbl",td) + n0=self.r.createScriptNode("","n0") + o0=n0.edAddOutputPort("o0",tsi) + n0.setScript("o0=[ elt for elt in range(6) ]") + p.edAddChild(n0) + n1=self.r.createForEachLoop("n1",ti) + n1.setWeight(3) + n10=self.r.createScriptNode("","n10") + n10.setExecutionMode("remote") + n10.setContainer(cont) + n1.edAddChild(n10) + n10.setScript(""" +import time +time.sleep(2) +o2=2*i1 +""") + i1=n10.edAddInputPort("i1",ti) + o2=n10.edAddOutputPort("o2",ti) + p.edAddChild(n1) + p.edAddLink(o0,n1.edGetSeqOfSamplesPort()) + p.edAddLink(n1.edGetSamplePort(),i1) + p.edAddCFLink(n0,n1) + n1.edGetNbOfBranchesPort().edInitPy(2) + n2=self.r.createScriptNode("","n2") + n2.setScript("o4=i3") + i3=n2.edAddInputPort("i3",tsi) + o4=n2.edAddOutputPort("o4",tsi) + n2.setScript("o4=i3") + p.edAddChild(n2) + p.edAddCFLink(n1,n2) + p.edAddLink(o2,i3) + p.saveSchema(fname) + # + l=loader.YACSLoader() + p=l.load(fname) + self.assertEqual(p.getChildByName("n1").getWeight(),3.0) + pass + pass if __name__ == '__main__': -- 2.39.2