1 // Copyright (C) 2012-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #include "YACSEvalYFXPattern.hxx"
22 #include "YACSEvalResource.hxx"
23 #include "YACSEvalSeqAny.hxx"
24 #include "YACSEvalObserver.hxx"
25 #include "YACSEvalAutoPtr.hxx"
27 #include "ElementaryNode.hxx"
28 #include "RuntimeSALOME.hxx"
29 #include "Dispatcher.hxx"
30 #include "Executor.hxx"
31 #include "InputPort.hxx"
32 #include "LinkInfo.hxx"
33 #include "TypeCode.hxx"
36 #include "PythonPorts.hxx"
37 #include "ForEachLoop.hxx"
38 #include "PythonNode.hxx"
39 #include "InlineNode.hxx"
40 #include "ServiceNode.hxx"
42 #include "ResourcesManager.hxx"
50 const char YACSEvalYFXPattern::DFT_PROC_NAME[]="YFX";
52 const char YACSEvalYFXPattern::ST_OK[]="ALL_OK";
54 const char YACSEvalYFXPattern::ST_FAILED[]="SOME_SAMPLES_FAILED_AND_ALL_OF_THEM_FAILED_DETERMINISTICALLY";
56 const char YACSEvalYFXPattern::ST_ERROR[]="SOME_SAMPLES_FAILED_BUT_IMPOSSIBLE_TO_CONCLUDE_ON_THEM";
58 const std::size_t YACSEvalYFXPattern::MAX_LGTH_OF_INP_DUMP=10000;
60 const char YACSEvalYFXRunOnlyPattern::FIRST_FE_SUBNODE_NAME[]="Bloc";
62 const char YACSEvalYFXRunOnlyPattern::GATHER_NODE_NAME[]="__gather__";
64 std::vector< YACSEvalInputPort *> YACSEvalYFXPattern::getFreeInputPorts() const
66 std::size_t sz(_inputs.size());
67 std::vector< YACSEvalInputPort *> ret;
68 std::vector< YACSEvalInputPort >::const_iterator it(_inputs.begin());
69 for(std::size_t i=0;i<sz;i++,it++)
70 ret.push_back(const_cast<YACSEvalInputPort *>(&(*it)));
74 std::vector< YACSEvalOutputPort *> YACSEvalYFXPattern::getFreeOutputPorts() const
76 std::size_t sz(_outputs.size());
77 std::vector< YACSEvalOutputPort *> ret;
78 std::vector< YACSEvalOutputPort >::const_iterator it(_outputs.begin());
79 for(std::size_t i=0;i<sz;i++,it++)
80 ret.push_back(const_cast<YACSEvalOutputPort *>(&(*it)));
84 YACSEvalYFXPattern *YACSEvalYFXPattern::FindPatternFrom(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme)
87 throw YACS::Exception("YACSEvalYFXPattern::FindPatternFrom : input scheme must be not null !");
89 YACS::ENGINE::ComposedNode *zeRunNode(0);
90 bool isMatchingRunOnlyPattern(YACSEvalYFXRunOnlyPattern::IsMatching(scheme,zeRunNode));
91 if(isMatchingRunOnlyPattern)
92 return new YACSEvalYFXRunOnlyPattern(boss,scheme,ownScheme,zeRunNode);
94 throw YACS::Exception("YACSEvalYFXPattern::FindPatternFrom : no pattern found for the input scheme !");
97 bool YACSEvalYFXPattern::isAlreadyComputedResources() const
102 void YACSEvalYFXPattern::checkNonAlreadyComputedResources() const
104 if(isAlreadyComputedResources())
105 throw YACS::Exception("checkNonAlreadyComputedResources : instance of computed resources already computed !");
108 void YACSEvalYFXPattern::checkAlreadyComputedResources() const
110 if(!isAlreadyComputedResources())
111 throw YACS::Exception("checkAlreadyComputedResources : instance of computed resources not already computed !");
114 void YACSEvalYFXPattern::checkLocked() const
117 throw YACS::Exception("YACSEvalYFXPattern::checkLocked : Pattern is not locked !");
120 void YACSEvalYFXPattern::checkNonLocked() const
123 throw YACS::Exception("YACSEvalYFXPattern::checkNonLocked : Pattern is locked !");
126 void YACSEvalYFXPattern::CheckNodeIsOK(YACS::ENGINE::ComposedNode *node)
128 /*YACS::ENGINE::LinkInfo info(YACS::ENGINE::LinkInfo::WARN_ONLY_DONT_STOP);
131 node->checkConsistency(info);
133 catch(YACS::Exception& e)
136 if(info.getNumberOfErrLinks(YACS::ENGINE::E_ALL)!=0)
137 throw YACS::Exception("YACSEvalYFXPattern::CheckNodeIsOK : found node is not OK !");
138 std::list<YACS::ENGINE::ElementaryNode *> allNodes(node->getRecursiveConstituents());
139 for(std::list<YACS::ENGINE::ElementaryNode *>::const_iterator it=allNodes.begin();it!=allNodes.end();it++)
141 YACS::ENGINE::ServiceNode *node0(dynamic_cast<YACS::ENGINE::ServiceNode *>(*it));
142 YACS::ENGINE::InlineNode *node1(dynamic_cast<YACS::ENGINE::InlineNode *>(*it));
145 YACS::ENGINE::Container *cont(node0->getContainer());
146 YACS::ENGINE::ComponentInstance *comp(node0->getComponent());
149 std::ostringstream oss; oss << "YACSEvalYFXPattern::CheckNodeIsOK : ServiceNode called \"" << node0->getName() << "\" is not correctly defined !";
150 throw YACS::Exception(oss.str());
155 YACS::ENGINE::Container *cont(node1->getContainer());
156 if(!cont && node1->getExecutionMode()==YACS::ENGINE::InlineNode::REMOTE_STR)
158 std::ostringstream oss; oss << "YACSEvalYFXPattern::CheckNodeIsOK : InlineNode called \"" << node1->getName() << "\" is not correctly defined !";
159 throw YACS::Exception(oss.str());
165 void YACSEvalYFXPattern::registerObserver(YACSEvalObserver *observer)
167 if(_observer==observer)
170 _observer->decrRef();
173 _observer->incrRef();
176 YACSEvalYFXPattern::YACSEvalYFXPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme):_boss(boss),_scheme(scheme),_ownScheme(ownScheme),_parallelizeStatus(true),_rm(new ResourcesManager_cpp),_res(0),_observer(0)
180 YACS::ENGINE::TypeCode *YACSEvalYFXPattern::createSeqTypeCodeFrom(YACS::ENGINE::Proc *scheme, const std::string& zeType)
182 std::ostringstream oss; oss << "list[" << zeType << "]";
183 YACS::ENGINE::TypeCode *tc(scheme->getTypeCode(zeType));
184 return scheme->createSequenceTc(oss.str(),oss.str(),tc);
187 void YACSEvalYFXPattern::setResources(YACSEvalListOfResources *res)
189 checkNonAlreadyComputedResources();
195 void YACSEvalYFXPattern::resetResources()
201 YACSEvalSeqAny *YACSEvalYFXPattern::BuildValueInPort(YACS::ENGINE::InputPyPort *port)
204 throw YACS::Exception("YACSEvalYFXPattern::GetValueInPort : null input port !");
205 PyObject *obj(port->getPyObj());
206 YACS::ENGINE::TypeCode *tc(port->edGetType());
207 YACS::ENGINE::TypeCodeSeq *tcc(dynamic_cast<YACS::ENGINE::TypeCodeSeq *>(tc));
210 std::ostringstream oss; oss << "YACSEvalYFXPattern::GetValueInPort : internal error for tc of input \"" << port->getName() << "\"";
211 throw YACS::Exception(oss.str());
213 const YACS::ENGINE::TypeCode *tcct(tcc->contentType());
214 if(!PyList_Check(obj))
215 throw YACS::Exception("YACSEvalYFXPattern::GetValueInPort : internal error 2 !");
216 std::size_t sz(PyList_Size(obj));
217 if(tcct->kind()==YACS::ENGINE::Double)
219 std::vector<double> eltCpp(sz);
220 for(std::size_t i=0;i<sz;i++)
222 PyObject *elt(PyList_GetItem(obj,i));
223 eltCpp[i]=PyFloat_AsDouble(elt);
225 YACS::AutoCppPtr<YACSEvalSeqAnyDouble> elt(new YACSEvalSeqAnyDouble(eltCpp));
226 return elt.dettach();
228 else if(tcct->kind()==YACS::ENGINE::Int)
230 std::vector<int> eltCpp(sz);
231 for(std::size_t i=0;i<sz;i++)
233 PyObject *elt(PyList_GetItem(obj,i));
234 eltCpp[i]=PyInt_AsLong(elt);
236 YACS::AutoCppPtr<YACSEvalSeqAnyInt> elt(new YACSEvalSeqAnyInt(eltCpp));
237 return elt.dettach();
240 throw YACS::Exception("YACSEvalYFXPattern::GetValueInPort : not implemented yet for other than Double and Int !");
243 YACSEvalSeqAny *YACSEvalYFXPattern::BuildValueFromEngineFrmt(YACS::ENGINE::SequenceAny *data)
245 unsigned int sz(data->size());
246 std::vector<double> eltCpp(sz);
247 for(unsigned int ii=0;ii<sz;ii++)
249 YACS::ENGINE::AnyPtr elt((*data)[ii]);
250 YACS::ENGINE::Any *eltPtr((YACS::ENGINE::Any *)elt);
251 YACS::ENGINE::AtomAny *eltPtr2(dynamic_cast<YACS::ENGINE::AtomAny *>(eltPtr));
254 std::ostringstream oss; oss << "YACSEvalYFXPattern::BuildValueFromEngineFrmt : error at pos #" << ii << " ! It is not an AtomAny !";
255 throw YACS::Exception(oss.str());
257 eltCpp[ii]=eltPtr2->getDoubleValue();
259 return new YACSEvalSeqAnyDouble(eltCpp);
262 void YACSEvalYFXPattern::cleanScheme()
269 YACSEvalYFXPattern::~YACSEvalYFXPattern()
272 _observer->decrRef();
277 /////////////////////
279 class YACSEvalYFXRunOnlyPatternInternalObserver : public YACS::ENGINE::Observer
282 YACSEvalYFXRunOnlyPatternInternalObserver(YACSEvalYFXRunOnlyPattern *boss):_boss(boss) { if(!_boss) throw YACS::Exception("YACSEvalYFXRunOnlyPatternInternalObserver constructor : null boss not supported :)"); }
283 void notifyObserver(YACS::ENGINE::Node *object, const std::string& event);
285 YACSEvalYFXRunOnlyPattern *_boss;
288 void YACSEvalYFXRunOnlyPatternInternalObserver::notifyObserver(YACS::ENGINE::Node *object, const std::string& event)
290 YACS::ENGINE::ForEachLoop *object2(dynamic_cast<YACS::ENGINE::ForEachLoop *>(object));
293 YACSEvalObserver *obs(_boss->getObserver());
296 if(event=="progress")
297 obs->notifyNewNumberOfPassedItems(_boss->getBoss(),object2->getCurrentIndex());
300 /////////////////////
302 YACSEvalYFXRunOnlyPattern::YACSEvalYFXRunOnlyPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode):YACSEvalYFXPattern(boss,scheme,ownScheme),_runNode(runNode),_generatedGraph(0),_FEInGeneratedGraph(0),_obs(new YACSEvalYFXRunOnlyPatternInternalObserver(this))
305 throw YACS::Exception("YACSEvalYFXRunOnlyPattern : internal run node must be not null !");
310 YACSEvalYFXRunOnlyPattern::~YACSEvalYFXRunOnlyPattern()
315 void YACSEvalYFXRunOnlyPattern::setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputsOfInterest)
318 _outputsOfInterest=outputsOfInterest;
321 void YACSEvalYFXRunOnlyPattern::resetOutputsOfInterest()
324 _outputsOfInterest.clear();
327 void YACSEvalYFXRunOnlyPattern::generateGraph()
329 static const char LISTPYOBJ_STR[]="list[pyobj]";
330 if(_outputsOfInterest.empty())
332 YACS::ENGINE::RuntimeSALOME::setRuntime();
333 YACS::ENGINE::RuntimeSALOME *r(YACS::ENGINE::getSALOMERuntime());
334 _generatedGraph=r->createProc(DFT_PROC_NAME);
335 YACS::ENGINE::TypeCode *pyobjTC(_generatedGraph->createInterfaceTc("python:obj:1.0","pyobj",std::list<YACS::ENGINE::TypeCodeObjref *>()));
336 std::ostringstream oss; oss << "Loop_" << _runNode->getName();
337 _generatedGraph->createType(YACSEvalAnyDouble::TYPE_REPR,"double");
338 _generatedGraph->createType(YACSEvalAnyInt::TYPE_REPR,"int");
340 YACS::ENGINE::InlineNode *n0(r->createScriptNode(YACS::ENGINE::PythonNode::KIND,"__initializer__"));
341 _generatedGraph->edAddChild(n0);
342 YACS::ENGINE::TypeCode *listPyobjTC(_generatedGraph->createSequenceTc(LISTPYOBJ_STR,LISTPYOBJ_STR,pyobjTC));
343 YACS::ENGINE::OutputPort *sender(n0->edAddOutputPort("sender",listPyobjTC));
344 std::ostringstream var0;
345 for(std::vector< YACSEvalInputPort >::const_iterator it=_inputs.begin();it!=_inputs.end();it++)
347 if((*it).isRandomVar())
349 var0 << (*it).getName() << ",";
350 YACS::ENGINE::TypeCode *tc(createSeqTypeCodeFrom(_generatedGraph,(*it).getTypeOfData()));
351 YACS::ENGINE::InputPort *inp(n0->edAddInputPort((*it).getName(),tc));
352 YACS::ENGINE::InputPyPort *inpc(dynamic_cast<YACS::ENGINE::InputPyPort *>(inp));
354 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::generateGraph : internal error 1 !");
355 (*it).setUndergroundPortToBeSet(inpc);
358 std::ostringstream n0Script; n0Script << "sender=zip(" << var0.str() << ")\n";
359 n0->setScript(n0Script.str());
361 YACS::ENGINE::ForEachLoop *n1(r->createForEachLoop(oss.str(),pyobjTC));
362 _FEInGeneratedGraph=n1;
363 _generatedGraph->edAddChild(n1);
364 _generatedGraph->edAddCFLink(n0,n1);
365 _generatedGraph->edAddDFLink(sender,n1->edGetSeqOfSamplesPort());
366 YACS::ENGINE::InlineNode *n2(r->createScriptNode(YACS::ENGINE::PythonNode::KIND,GATHER_NODE_NAME));
367 _generatedGraph->edAddChild(n2);
368 _generatedGraph->edAddCFLink(n1,n2);
370 YACS::ENGINE::Bloc *n10(r->createBloc(FIRST_FE_SUBNODE_NAME));
372 YACS::ENGINE::InlineNode *n100(r->createScriptNode(YACS::ENGINE::PythonNode::KIND,"__dispatch__"));
373 YACS::ENGINE::Node *n101(_runNode->cloneWithoutCompAndContDeepCpy(0,true));
374 n10->edAddChild(n100);
375 n10->edAddChild(n101);
376 YACS::ENGINE::InputPort *dispatchIn(n100->edAddInputPort("i0",pyobjTC));
377 n10->edAddCFLink(n100,n101);
378 n1->edAddDFLink(n1->edGetSamplePort(),dispatchIn);
379 std::ostringstream var1;
380 for(std::vector< YACSEvalInputPort >::const_iterator it=_inputs.begin();it!=_inputs.end();it++)
382 if((*it).isRandomVar())
384 var1 << (*it).getName() << ",";
385 YACS::ENGINE::OutputPort *myOut(n100->edAddOutputPort((*it).getName(),_generatedGraph->getTypeCode((*it).getTypeOfData())));
386 std::string tmpPortName(_runNode->getInPortName((*it).getUndergroundPtr()));
387 YACS::ENGINE::InputPort *myIn(n101->getInputPort(tmpPortName));
388 n10->edAddDFLink(myOut,myIn);
391 std::ostringstream n100Script; n100Script << var1.str() << "=i0\n";
392 n100->setScript(n100Script.str());
393 for(std::vector< YACSEvalOutputPort * >::const_iterator it=_outputsOfInterest.begin();it!=_outputsOfInterest.end();it++)
395 YACS::ENGINE::TypeCode *tc(createSeqTypeCodeFrom(_generatedGraph,(*it)->getTypeOfData()));
396 YACS::ENGINE::InputPort *myIn(n2->edAddInputPort((*it)->getName(),tc));
397 std::string tmpPortName(_runNode->getOutPortName((*it)->getUndergroundPtr()));
398 YACS::ENGINE::OutputPort *myOut(n101->getOutputPort(tmpPortName));
399 _generatedGraph->edAddDFLink(myOut,myIn);
401 _generatedGraph->updateContainersAndComponents();
404 void YACSEvalYFXRunOnlyPattern::resetGeneratedGraph()
406 delete _generatedGraph;
411 int YACSEvalYFXRunOnlyPattern::assignNbOfBranches()
413 checkAlreadyComputedResources();
415 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::assignNbOfBranches : the generated graph has not been created !");
416 std::list<YACS::ENGINE::Node *> nodes(_generatedGraph->getChildren());
417 YACS::ENGINE::ForEachLoop *zeMainNode(0);
418 for(std::list<YACS::ENGINE::Node *>::const_iterator it=nodes.begin();it!=nodes.end();it++)
420 YACS::ENGINE::ForEachLoop *isZeMainNode(dynamic_cast<YACS::ENGINE::ForEachLoop *>(*it));
424 zeMainNode=isZeMainNode;
426 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::assignNbOfBranches : internal error 1 !");
430 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::assignNbOfBranches : internal error 2 !");
431 unsigned int nbProcsDeclared(getResourcesInternal()->getNumberOfProcsDeclared());
432 nbProcsDeclared=std::max(nbProcsDeclared,4u);
434 if(getParallelizeStatus())
436 nbOfBranch=(nbProcsDeclared/getResourcesInternal()->getMaxLevelOfParallelism());
437 nbOfBranch=std::max(nbOfBranch,1);
439 YACS::ENGINE::InputPort *zeInputToSet(zeMainNode->edGetNbOfBranchesPort());
440 YACS::ENGINE::AnyInputPort *zeInputToSetC(dynamic_cast<YACS::ENGINE::AnyInputPort *>(zeInputToSet));
442 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::assignNbOfBranches : internal error 3 !");
443 YACS::ENGINE::Any *a(YACS::ENGINE::AtomAny::New(nbOfBranch));
444 zeInputToSetC->put(a);
445 zeInputToSetC->exSaveInit();
450 void YACSEvalYFXRunOnlyPattern::assignRandomVarsInputs()
452 std::size_t sz(std::numeric_limits<std::size_t>::max());
453 for(std::vector< YACSEvalInputPort >::const_iterator it=_inputs.begin();it!=_inputs.end();it++)
454 if((*it).isRandomVar())
456 std::size_t locSize((*it).initializeUndergroundWithSeq());
457 if(sz==std::numeric_limits<std::size_t>::max())
461 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::assignRandomVarsInputs : length of sequences in random vars must be the same !");
465 bool YACSEvalYFXRunOnlyPattern::isLocked() const
467 return _generatedGraph!=0;
470 YACSEvalListOfResources *YACSEvalYFXRunOnlyPattern::giveResources()
473 if(!isAlreadyComputedResources())
475 YACS::ENGINE::DeploymentTree dt(_runNode->getDeploymentTree());
476 _runNode->removeRecursivelyRedundantCL();
477 YACSEvalListOfResources *res(new YACSEvalListOfResources(_runNode->getMaxLevelOfParallelism(),getCatalogInAppli(),dt));
480 return getResourcesInternal();
483 YACS::ENGINE::Proc *YACSEvalYFXRunOnlyPattern::getUndergroundGeneratedGraph() const
485 return _generatedGraph;
488 std::string YACSEvalYFXRunOnlyPattern::getErrorDetailsInCaseOfFailure() const
490 std::string st(getStatusOfRunStr());//test if a run has occurred.
492 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::getErrorDetailsInCaseOfFailure : The execution of scheme has been carried out to the end without any problem !");
493 // All the problem can only comes from foreach -> scan it
494 YACS::ENGINE::ForEachLoop *fe(findTopForEach());
495 YACS::ENGINE::NodeStateNameMap nsm;
496 unsigned nbB(fe->getNumberOfBranchesCreatedDyn());
497 std::ostringstream oss;
498 for(unsigned j=0;j<nbB;j++)
500 YACS::ENGINE::Node *nn(fe->getChildByNameExec(FIRST_FE_SUBNODE_NAME,j));
501 YACS::ENGINE::Bloc *nnc(dynamic_cast<YACS::ENGINE::Bloc *>(nn));
503 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::getErrorDetailsInCaseOfFailure : internal error 1 ! The direct son of main foreach is expected to be a Bloc !");
504 if(nnc->getState()==YACS::DONE)
506 std::list< YACS::ENGINE::ElementaryNode *> fec(nnc->getRecursiveConstituents());
507 for(std::list< YACS::ENGINE::ElementaryNode *>::reverse_iterator it1=fec.rbegin();it1!=fec.rend();it1++)
509 YACS::StatesForNode st0((*it1)->getState());
512 oss << "NODE = " << nnc->getChildName(*it1) << std::endl;
513 oss << "STATUS = " << nsm[st0] << std::endl;
514 oss << "BRANCH ID = " << j << std::endl;
515 std::list<YACS::ENGINE::InputPort *> inps((*it1)->getSetOfInputPort());
516 for(std::list<YACS::ENGINE::InputPort *>::const_iterator it2=inps.begin();it2!=inps.end();it2++)
518 std::string d((*it2)->getHumanRepr());
520 d=d.substr(0,MAX_LGTH_OF_INP_DUMP);
521 oss << "INPUT \"" << (*it2)->getName() << "\" = " << d << std::endl;
523 oss << "DETAILS = " << std::endl;
524 oss << (*it1)->getErrorDetails();
531 std::string YACSEvalYFXRunOnlyPattern::getStatusOfRunStr() const
533 YACS::StatesForNode st(_generatedGraph->getState());
539 case YACS::TOACTIVATE:
540 case YACS::ACTIVATED:
541 case YACS::SUSPENDED:
544 case YACS::DESACTIVATED:
546 std::ostringstream oss; oss << "YACSEvalYFXRunOnlyPattern::getStatusOfRunStr : Unexpected state \"" << YACS::ENGINE::Node::getStateName(st) << "\" ! Did you invoke run ?";
547 throw YACS::Exception(oss.str());
549 case YACS::LOADFAILED:
550 case YACS::EXECFAILED:
552 case YACS::INTERNALERR:
553 return std::string(ST_ERROR);
555 return std::string(ST_FAILED);
557 return std::string(ST_OK);
560 std::ostringstream oss; oss << "YACSEvalYFXRunOnlyPattern::getStatusOfRunStr : unrecognized and managed state \"" << YACS::ENGINE::Node::getStateName(st) << "\" !";
561 throw YACS::Exception(oss.str());
566 std::vector<YACSEvalSeqAny *> YACSEvalYFXRunOnlyPattern::getResults() const
568 if(_generatedGraph->getState()!=YACS::DONE)
569 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::getResults : the execution did not finished correctly ! getResults should not be called !");
570 std::vector<YACSEvalSeqAny *> ret(_outputsOfInterest.size());
571 YACS::ENGINE::Node *node(_generatedGraph->getChildByName(GATHER_NODE_NAME));
572 YACS::ENGINE::PythonNode *nodeC(dynamic_cast<YACS::ENGINE::PythonNode *>(node));
574 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::getResults : internal error !");
576 for(std::vector< YACSEvalOutputPort * >::const_iterator it=_outputsOfInterest.begin();it!=_outputsOfInterest.end();it++,ii++)
578 YACS::ENGINE::InPort *input(nodeC->getInPort((*it)->getName()));
579 YACS::ENGINE::InputPyPort *inputC(dynamic_cast<YACS::ENGINE::InputPyPort *>(input));
582 std::ostringstream oss; oss << "YACSEvalYFXRunOnlyPattern::getResults : internal error for input \"" << (*it)->getName() << "\"";
583 throw YACS::Exception(oss.str());
585 ret[ii]=BuildValueInPort(inputC);
591 * This method works if run succeeded (true return) and also if graph has failed. Graph failed means soft error of evaluation due to error in evaluation (example 1/0 or a normal throw from one node)
592 * If a more serious error occured (SIGSEGV of a server or internal error in YACS engine, cluster error, loose of connection...) this method will throw an exception to warn the caller that the results may be
594 std::vector<YACSEvalSeqAny *> YACSEvalYFXRunOnlyPattern::getResultsInCaseOfFailure(std::vector<unsigned int>& passedIds) const
596 YACS::StatesForNode st(_generatedGraph->getState());
600 std::vector<YACSEvalSeqAny *> ret(getResults());
604 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::getResultsInCaseOfFailure : internal error ! The returned vector has a null pointer at pos #0 !");
605 std::size_t sz(ret[0]->size());
606 passedIds.resize(sz);
607 for(std::size_t i=0;i<sz;i++)
612 getStatusOfRunStr();// To check that the status is recognized.
613 std::list<YACS::ENGINE::Node *> lns(_generatedGraph->edGetDirectDescendants());
614 YACS::ENGINE::ForEachLoop *fe(findTopForEach());
616 YACS::ENGINE::Executor exe;
617 std::vector<YACS::ENGINE::SequenceAny *> outputs;
618 std::vector<std::string> nameOfOutputs;
619 passedIds=fe->getPassedResults(&exe,outputs,nameOfOutputs);//<- the key invokation is here.
620 std::size_t sz(passedIds.size()),ii(0);
621 std::vector<YACSEvalSeqAny *> ret(_outputsOfInterest.size());
622 for(std::vector<YACSEvalOutputPort *>::const_iterator it1=_outputsOfInterest.begin();it1!=_outputsOfInterest.end();it1++,ii++)
624 YACS::ENGINE::OutputPort *p((*it1)->getUndergroundPtr());
625 std::string st(_runNode->getOutPortName(p));
626 std::ostringstream oss; oss << FIRST_FE_SUBNODE_NAME << '.' << _runNode->getName() << '.' << st;
628 YACS::ENGINE::ForEachLoop::InterceptorizeNameOfPort(st);
629 std::vector<std::string>::iterator it2(std::find(nameOfOutputs.begin(),nameOfOutputs.end(),st));
630 if(it2==nameOfOutputs.end())
632 std::ostringstream oss; oss << "YACSEvalYFXRunOnlyPattern::getResultsInCaseOfFailure : internal error 3 ! Unable to locate interceptor with name " << st << " ! Possibilities are : ";
633 std::copy(nameOfOutputs.begin(),nameOfOutputs.end(),std::ostream_iterator<std::string>(oss," "));
635 throw YACS::Exception(oss.str());
637 std::size_t pos(std::distance(nameOfOutputs.begin(),it2));
638 ret[ii]=BuildValueFromEngineFrmt(outputs[pos]);
643 void YACSEvalYFXRunOnlyPattern::emitStart() const
645 YACSEvalObserver *obs(getObserver());
648 obs->notifyNumberOfSamplesToEval(getBoss(),_FEInGeneratedGraph->getNbOfElementsToBeProcessed());
651 bool YACSEvalYFXRunOnlyPattern::IsMatching(YACS::ENGINE::Proc *scheme, YACS::ENGINE::ComposedNode *& runNode)
653 std::list<YACS::ENGINE::Node *> nodes(scheme->getChildren());
656 bool areAllElementary(true);
657 for(std::list<YACS::ENGINE::Node *>::const_iterator it=nodes.begin();it!=nodes.end() && areAllElementary;it++)
658 if(!dynamic_cast<YACS::ENGINE::ElementaryNode *>(*it))
659 areAllElementary=false;
663 CheckNodeIsOK(scheme);
669 YACS::ENGINE::ComposedNode *candidate(dynamic_cast<YACS::ENGINE::ComposedNode *>(nodes.front()));
672 CheckNodeIsOK(candidate);
676 void YACSEvalYFXRunOnlyPattern::buildInputPorts()
679 std::list< YACS::ENGINE::InputPort *> allInputPorts(_runNode->getSetOfInputPort());
680 std::vector<std::string> allNames;
681 for(std::list< YACS::ENGINE::InputPort *>::const_iterator it=allInputPorts.begin();it!=allInputPorts.end();it++)
683 YACS::ENGINE::InputPort *elt(*it);
685 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::buildInputPorts : presence of null input !");
686 std::set<YACS::ENGINE::OutPort *> bls(elt->edSetOutPort());
689 if(YACSEvalPort::IsInputPortPublishable(elt))
691 std::string inpName(elt->getName());
693 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::buildInputPorts : an input has empty name ! Should not !");
694 _inputs.push_back(YACSEvalInputPort(elt));
695 if(std::find(allNames.begin(),allNames.end(),inpName)!=allNames.end())
697 std::ostringstream oss; oss << "YACSEvalYFXRunOnlyPattern::buildInputPorts : input name \"" << inpName << "\" appears more than once !";
698 throw YACS::Exception(oss.str());
700 allNames.push_back(inpName);
706 void YACSEvalYFXRunOnlyPattern::buildOutputPorts()
709 std::list< YACS::ENGINE::OutputPort *> allOutputPorts(_runNode->getSetOfOutputPort());
710 std::vector<std::string> allNames;
711 for(std::list< YACS::ENGINE::OutputPort *>::const_iterator it=allOutputPorts.begin();it!=allOutputPorts.end();it++)
713 YACS::ENGINE::OutputPort *elt(*it);
714 if(YACSEvalPort::IsOutputPortPublishable(elt))
717 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::buildOutputPorts : presence of null output !");
718 std::string outpName(elt->getName());
720 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::buildOutputPorts : an output has empty name ! Should not !");
721 if(std::find(allNames.begin(),allNames.end(),outpName)!=allNames.end())
723 std::ostringstream oss; oss << "YACSEvalYFXRunOnlyPattern::buildOutputPorts : output name \"" << outpName << "\" appears more than once !";
724 throw YACS::Exception(oss.str());
726 _outputs.push_back(YACSEvalOutputPort(*it));
731 YACS::ENGINE::ForEachLoop *YACSEvalYFXRunOnlyPattern::findTopForEach() const
733 std::list<YACS::ENGINE::Node *> lns(_generatedGraph->edGetDirectDescendants());
734 YACS::ENGINE::ForEachLoop *fe(0);
735 for(std::list<YACS::ENGINE::Node *>::const_iterator it=lns.begin();it!=lns.end();it++)
737 fe=dynamic_cast<YACS::ENGINE::ForEachLoop *>(*it);
742 throw YACS::Exception("YACSEvalYFXRunOnlyPattern::findTopForEach : internal error 2 ! ForEach is not accessible !");