Version: 8.3.0
YACS::ENGINE::PyFuncNode Class Reference

#include <PythonNode.hxx>

Inheritance diagram for YACS::ENGINE::PyFuncNode:
Collaboration diagram for YACS::ENGINE::PyFuncNode:

Public Member Functions

 PyFuncNode (const PyFuncNode &other, ComposedNode *father)
 
 PyFuncNode (const std::string &name)
 
virtual ~PyFuncNode ()
 
virtual void init (bool start=true)
 
virtual void checkBasicConsistency () const throw (Exception)
 
virtual void execute ()
 
virtual void load ()
 
virtual void loadRemote ()
 
virtual void loadLocal ()
 
virtual void executeRemote ()
 
virtual void executeLocal ()
 
virtual void shutdown (int level)
 Stop all pending activities of the node. More...
 
std::string getContainerLog ()
 returns a string that contains the name of the container log file if it exists More...
 
PyFuncNodecloneNode (const std::string &name)
 Create a new node of same type with a given name. More...
 
virtual std::string typeName ()
 
- Public Member Functions inherited from YACS::ENGINE::InlineFuncNode
virtual void setFname (const std::string &fname)
 Set the function name to use in node execution. More...
 
virtual std::string getFname ()
 
void accept (Visitor *visitor)
 
virtual ~InlineFuncNode ()
 
- Public Member Functions inherited from YACS::ENGINE::InlineNode
virtual void setScript (const std::string &script)
 Set the script (as a string) to execute. More...
 
virtual std::string getScript ()
 
virtual ~InlineNode ()
 
virtual void setExecutionMode (const std::string &mode)
 
virtual std::string getExecutionMode ()
 
virtual void setContainer (Container *container)
 
virtual ContainergetContainer ()
 
void performDuplicationOfPlacement (const Node &other)
 performs a duplication of placement using clone method of containers and components. clone behaviour is driven by attachOnCloning attribute. More...
 
void performShallowDuplicationOfPlacement (const Node &other)
 performs a also duplication of placement but here containers and components are not copied at all whatever the value of attachedOnCloning. More...
 
bool isDeployable () const
 
int getMaxLevelOfParallelism () const
 
- Public Member Functions inherited from YACS::ENGINE::ElementaryNode
virtual ~ElementaryNode ()
 
void exUpdateState ()
 Update the node state. More...
 
ComponentInstancegetComponent ()
 
const ComponentInstancegetComponent () const
 
YACS::StatesForNode getState () const
 
void getReadyTasks (std::vector< Task * > &tasks)
 
void edRemovePort (Port *port) throw (Exception)
 
std::list< ElementaryNode * > getRecursiveConstituents () const
 
std::list< ProgressWeightgetProgressWeight () const
 Get the progress weight for all elementary nodes. More...
 
NodegetChildByName (const std::string &name) const throw (Exception)
 
ComposedNodegetDynClonerIfExists (const ComposedNode *levelToStop) const
 
int getNumberOfInputPorts () const
 
int getNumberOfOutputPorts () const
 
std::string getInPortName (const InPort *) const throw (Exception)
 
std::string getOutPortName (const OutPort *) const throw (Exception)
 
InputPortgetInputPort (const std::string &name) const throw (Exception)
 
OutputPortgetOutputPort (const std::string &name) const throw (Exception)
 
std::list< InputPort * > getSetOfInputPort () const
 
std::list< OutputPort * > getSetOfOutputPort () const
 
std::list< InputPort * > getLocalInputPorts () const
 
std::list< OutputPort * > getLocalOutputPorts () const
 
std::set< OutPort * > getAllOutPortsLeavingCurrentScope () const
 
std::set< InPort * > getAllInPortsComingFromOutsideOfCurrentScope () const
 
virtual std::vector< std::pair
< OutPort *, InPort * > > 
getSetOfLinksLeavingCurrentScope () const
 
virtual std::vector< std::pair
< InPort *, OutPort * > > 
getSetOfLinksComingInCurrentScope () const
 
std::list< InputDataStreamPort * > getSetOfInputDataStreamPort () const
 
std::list< OutputDataStreamPort * > getSetOfOutputDataStreamPort () const
 
InputDataStreamPortgetInputDataStreamPort (const std::string &name) const throw (Exception)
 
OutputDataStreamPortgetOutputDataStreamPort (const std::string &name) const throw (Exception)
 
virtual InputPortcreateInputPort (const std::string &inputPortName, TypeCode *type)
 
virtual OutputPortcreateOutputPort (const std::string &outputPortName, TypeCode *type)
 
virtual InputDataStreamPortcreateInputDataStreamPort (const std::string &inputPortDSName, TypeCode *type)
 
virtual OutputDataStreamPortcreateOutputDataStreamPort (const std::string &outputPortDSName, TypeCode *type)
 
virtual InputPortedAddInputPort (const std::string &inputPortName, TypeCode *type) throw (Exception)
 
virtual OutputPortedAddOutputPort (const std::string &outputPortName, TypeCode *type) throw (Exception)
 
virtual InputDataStreamPortedAddInputDataStreamPort (const std::string &inputPortDSName, TypeCode *type) throw (Exception)
 
virtual OutputDataStreamPortedAddOutputDataStreamPort (const std::string &outputPortDSName, TypeCode *type) throw (Exception)
 
virtual void edOrderInputPorts (const std::list< InputPort * > &ports)
 
virtual void edOrderOutputPorts (const std::list< OutputPort * > &ports)
 
virtual void edUpdateState ()
 update the status of the node More...
 
virtual void ensureLoading ()
 Put this node into TOLOAD state when possible. More...
 
void begin ()
 
bool isReady ()
 
void finished ()
 
void aborted ()
 
void loaded ()
 Notify this node that it is loaded. More...
 
void connected ()
 Notify this node that it is connected. More...
 
virtual std::string getErrorDetails ()
 Give a description of error when node status is ERROR. More...
 
virtual void initService ()
 
virtual void connectService ()
 
virtual void disconnectService ()
 
virtual void getCoupledTasks (std::set< Task * > &coupledSet)
 Calls getCoupledNodes for Task interface. More...
 
virtual void getCoupledNodes (std::set< Task * > &coupledSet)
 Put all nodes that are coupled to this node in coupledSet. More...
 
virtual void addDatastreamPortToInitMultiService (const std::string &port_name, int number)
 
template<class PORT >
void edRemovePortTypedFromSet (PORT *port, std::list< PORT * > &setOfPorts) throw (Exception)
 
template<class PORT >
bool isPortNameAlreadyExist (const std::string &portName, const std::list< PORT * > &setOfPorts)
 
- Public Member Functions inherited from YACS::ENGINE::Node
virtual ~Node ()
 
virtual void resetState (int level)
 Reset the node state depending on the parameter level. More...
 
Nodeclone (ComposedNode *father, bool editionOnly=true) const
 This method MUST NEVER BE VIRTUAL More...
 
NodecloneWithoutCompAndContDeepCpy (ComposedNode *father, bool editionOnly=true) const
 This method MUST NEVER BE VIRTUAL More...
 
void setState (YACS::StatesForNode theState)
 Sets the given state for node. More...
 
virtual YACS::StatesForNode getEffectiveState () const
 Return the node state in the context of its father. More...
 
virtual YACS::StatesForNode getEffectiveState (const Node *) const
 Return the effective state of a node in the context of this one (its father) More...
 
std::string getColorState (YACS::StatesForNode state) const
 Return the color associated to a state. More...
 
InGategetInGate ()
 
OutGategetOutGate ()
 
const std::string & getName () const
 
void setName (const std::string &name)
 Change the name of the node. More...
 
ComposedNodegetFather () const
 
const std::string getId () const
 
bool exIsControlReady () const
 
std::list< Node * > getOutNodes () const
 
virtual void writeDot (std::ostream &os) const
 Dump to the input stream a dot representation of the node. More...
 
virtual void exFailedState ()
 Notify this node that its execution has failed. More...
 
virtual void exDisabledState ()
 Notify this node that it has been disabled. More...
 
std::list< InPort * > getSetOfInPort () const
 
std::list< OutPort * > getSetOfOutPort () const
 
virtual std::set< InputPort * > edGetSetOfUnitializedInputPort () const
 Becomes deprecated soon. Replaced by ComposedNode::CheckConsistency. More...
 
virtual bool edAreAllInputPortInitialized () const
 Becomes deprecated soon. Replaced by ComposedNode::CheckConsistency. More...
 
InPortgetInPort (const std::string &name) const throw (Exception)
 
InPropertyPortgetInPropertyPort () const throw (Exception)
 
virtual OutPortgetOutPort (const std::string &name) const throw (Exception)
 
std::list< ComposedNode * > getAllAscendanceOf (ComposedNode *levelToStop=0) const
 
bool operator> (const Node &other) const
 
bool operator< (const Node &other) const
 
std::string getImplementation () const
 
virtual ComposedNodegetRootNode () const throw (Exception)
 
virtual void setProperty (const std::string &name, const std::string &value)
 
virtual std::string getProperty (const std::string &name)
 
std::map< std::string,
std::string > 
getProperties ()
 
std::map< std::string,
std::string > 
getPropertyMap ()
 
virtual void setProperties (std::map< std::string, std::string > properties)
 
virtual ProcgetProc ()
 
virtual const ProcgetProc () const
 
std::string getQualifiedName () const
 same as Node::getName() in most cases, but differs for children of switch More...
 
int getNumId ()
 return node instance identifiant, unique for each node instance More...
 
std::vector< std::pair
< std::string, int > > 
getDPLScopeInfo (ComposedNode *gfn)
 
virtual void applyDPLScope (ComposedNode *gfn)
 
virtual void sendEvent (const std::string &event)
 emit notification to all observers registered with the dispatcher More...
 
virtual void sendEvent2 (const std::string &event, void *something)
 emit notification to all observers registered with the dispatcher More...
 
virtual std::string getErrorDetails () const
 
virtual void setErrorDetails (const std::string &error)
 
virtual void modified ()
 Sets Node in modified state and its father if it exists. More...
 
virtual int isModified ()
 
virtual int isValid ()
 indicates if the node is valid (returns 1) or not (returns 0) More...
 
virtual std::string getErrorReport ()
 returns a string that contains an error report if the node is in error More...
 
virtual void cleanNodes ()
 Clean the node in case of not clean exit. More...
 
- Public Member Functions inherited from YACS::ENGINE::Task
virtual ~Task ()
 

Static Public Attributes

static const char SCRIPT_FOR_SERIALIZATION []
 
- Static Public Attributes inherited from YACS::ENGINE::PythonEntry
static const char SCRIPT_FOR_SIMPLE_SERIALIZATION []
 

Protected Member Functions

NodesimpleClone (ComposedNode *father, bool editionOnly) const
 
void createRemoteAdaptedPyInterpretor (Engines::Container_ptr objContainer)
 returns an object, you have to deal with (UnRegister) More...
 
Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny (Engines::Container_ptr objContainer) const
 returns (if any) an object, you have to deal with (UnRegister) More...
 
void assignRemotePyInterpretor (Engines::PyNodeBase_var remoteInterp)
 
Engines::PyNodeBase_var getRemoteInterpreterHandle ()
 
const char * getSerializationScript () const
 
- Protected Member Functions inherited from YACS::ENGINE::InlineFuncNode
 InlineFuncNode (const InlineFuncNode &other, ComposedNode *father)
 
 InlineFuncNode (const std::string &name)
 
- Protected Member Functions inherited from YACS::ENGINE::InlineNode
 InlineNode (const InlineNode &other, ComposedNode *father)
 
 InlineNode (const std::string &name)
 
- Protected Member Functions inherited from YACS::ENGINE::ElementaryNode
 ElementaryNode (const std::string &name)
 
 ElementaryNode (const ElementaryNode &other, ComposedNode *father)
 
void initCommonPartWithoutStateManagement (bool start)
 
virtual void createMultiDatastreamPorts ()
 
void edDisconnectAllLinksWithMe ()
 
bool areAllInputPortsValid () const
 
template<class PORT >
PORT * getPort (const std::string &name, const std::list< PORT * > &setOfPorts) const throw (Exception)
 
template<class PORT , class ENUMTYPE >
PORT * edAddPort (const std::string &portName, std::list< PORT * > &setOfPorts, ENUMTYPE type) throw (Exception)
 
template<class PORT , class ENUMTYPE >
bool edCheckAddPort (const std::string &portName, std::list< PORT * > &setOfPorts, ENUMTYPE type) throw (Exception)
 
- Protected Member Functions inherited from YACS::ENGINE::Node
 Node (const std::string &name)
 
 Node (const Node &other, ComposedNode *father)
 
virtual void exForwardFailed ()
 
virtual void exForwardFinished ()
 
- Protected Member Functions inherited from YACS::ENGINE::PythonEntry
 PythonEntry ()
 
 ~PythonEntry ()
 
void commonRemoteLoad (InlineNode *reqNode)
 
void commonRemoteLoadPart1 (InlineNode *reqNode)
 
Engines::Container_var commonRemoteLoadPart2 (InlineNode *reqNode, bool &isInitializeRequested)
 
void commonRemoteLoadPart3 (InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested)
 

Protected Attributes

PyObject * _pyfunc
 
Engines::PyNode_var _pynode
 
- Protected Attributes inherited from YACS::ENGINE::InlineFuncNode
std::string _fname
 
- Protected Attributes inherited from YACS::ENGINE::InlineNode
std::string _script
 
std::string _mode
 
Container_container
 
- Protected Attributes inherited from YACS::ENGINE::ElementaryNode
std::list< InputPort * > _setOfInputPort
 
std::list< OutputPort * > _setOfOutputPort
 
std::list< InputDataStreamPort * > _setOfInputDataStreamPort
 
std::list< OutputDataStreamPort * > _setOfOutputDataStreamPort
 
bool _createDatastreamPorts
 
bool _multi_port_node
 
- Protected Attributes inherited from YACS::ENGINE::Node
InGate _inGate
 
OutGate _outGate
 
InPropertyPort_inPropertyPort
 
std::string _name
 
ComposedNode_father
 
YACS::StatesForNode _state
 
int _modified
 
std::string _errorDetails
 
int _numId
 
std::string _implementation
 
std::map< std::string,
std::string > 
_propertyMap
 
- Protected Attributes inherited from YACS::ENGINE::PythonEntry
PyObject * _context
 
PyObject * _pyfuncSer
 
PyObject * _pyfuncUnser
 
PyObject * _pyfuncSimpleSer
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::ENGINE::Node
static std::string getStateName (YACS::StatesForNode state)
 Return the name of a state. More...
 
- Public Attributes inherited from YACS::ENGINE::Node
YACS::Colour _colour
 
- Static Protected Member Functions inherited from YACS::ENGINE::ElementaryNode
template<class PORT >
static void edRemovePortTypedFromSet (PORT *port, std::list< PORT * > &setOfPorts) throw (Exception)
 
template<class PORT >
static bool isPortNameAlreadyExist (const std::string &portName, const std::list< PORT * > &setOfPorts)
 
- Static Protected Member Functions inherited from YACS::ENGINE::PythonEntry
static std::string GetContainerLog (const std::string &mode, Container *container, const Task *askingTask)
 
- Static Protected Attributes inherited from YACS::ENGINE::Node
static const char SEP_CHAR_IN_PORT [] ="."
 
static int _total = 0
 

Detailed Description

Definition at line 98 of file PythonNode.hxx.

Constructor & Destructor Documentation

PyFuncNode::PyFuncNode ( const PyFuncNode other,
ComposedNode father 
)

Definition at line 771 of file PythonNode.cxx.

References YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::Node::_implementation, DEBTRACE, YACS::ENGINE::getSALOMERuntime(), and YACS::ENGINE::PythonNode::IMPL_NAME.

Referenced by cloneNode(), and simpleClone().

771  :InlineFuncNode(other,father),_pyfunc(0)
772 {
774  {
775  AutoGIL agil;
776  _context=PyDict_New();
777  DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
778  if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
779  {
780  stringstream msg;
781  msg << "Not possible to set builtins" << __FILE__ << ":" << __LINE__;
782  _errorDetails=msg.str();
783  throw Exception(msg.str());
784  }
785  }
786 }
PyFuncNode::PyFuncNode ( const std::string &  name)

Definition at line 788 of file PythonNode.cxx.

References YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::Node::_implementation, DEBTRACE, YACS::ENGINE::getSALOMERuntime(), and YACS::ENGINE::PythonNode::IMPL_NAME.

788  : InlineFuncNode(name),_pyfunc(0)
789 {
790 
792  DEBTRACE( "PyFuncNode::PyFuncNode " << name );
793  {
794  AutoGIL agil;
795  _context=PyDict_New();
796  DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
797  if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
798  {
799  stringstream msg;
800  msg << "Not possible to set builtins" << __FILE__ << ":" << __LINE__;
801  _errorDetails=msg.str();
802  throw Exception(msg.str());
803  }
804  }
805 }
PyFuncNode::~PyFuncNode ( )
virtual

Definition at line 807 of file PythonNode.cxx.

References _pynode.

808 {
809  if(!CORBA::is_nil(_pynode))
810  {
811  _pynode->UnRegister();
812  }
813 }

Member Function Documentation

void PyFuncNode::assignRemotePyInterpretor ( Engines::PyNodeBase_var  remoteInterp)
protectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 1211 of file PythonNode.cxx.

References _pynode.

1212 {
1213  if(!CORBA::is_nil(_pynode))
1214  {
1215  Engines::PyNode_var tmpp(Engines::PyNode::_narrow(remoteInterp));
1216  if(_pynode->_is_equivalent(tmpp))
1217  return ;
1218  }
1219  if(!CORBA::is_nil(_pynode))
1220  _pynode->UnRegister();
1221  _pynode=Engines::PyNode::_narrow(remoteInterp);
1222 }
void PyFuncNode::checkBasicConsistency ( ) const throw (Exception)
virtual

Reimplemented from YACS::ENGINE::InlineFuncNode.

Definition at line 829 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_script, YACS::ENGINE::InlineFuncNode::checkBasicConsistency(), DEBTRACE, YACS::ENGINE::Node::getName(), and YACS::ENGINE::newPyStdOut().

830 {
831  DEBTRACE("checkBasicConsistency");
833  {
834  AutoGIL agil;
835  PyObject* res;
836  res=Py_CompileString(_script.c_str(),getName().c_str(),Py_file_input);
837  if(res == NULL)
838  {
839  std::string error="";
840  PyObject* new_stderr = newPyStdOut(error);
841  PySys_SetObject((char*)"stderr", new_stderr);
842  PyErr_Print();
843  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
844  Py_DECREF(new_stderr);
845  throw Exception(error);
846  }
847  else
848  Py_XDECREF(res);
849  }
850 }
PyFuncNode * PyFuncNode::cloneNode ( const std::string &  name)
virtual

Create a new node of same type with a given name.

Reimplemented from YACS::ENGINE::InlineNode.

Definition at line 1230 of file PythonNode.cxx.

References YACS::ENGINE::InlineFuncNode::_fname, YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, YACS::ENGINE::ElementaryNode::edAddInputPort(), YACS::ENGINE::ElementaryNode::edAddOutputPort(), YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::DataPort::getName(), gui.Appli::n, p, PyFuncNode(), YACS::ENGINE::InlineFuncNode::setFname(), and YACS::ENGINE::InlineNode::setScript().

1231 {
1232  PyFuncNode* n=new PyFuncNode(name);
1233  n->setScript(_script);
1234  n->setFname(_fname);
1235  list<InputPort *>::iterator iter;
1236  for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
1237  {
1238  InputPyPort *p=(InputPyPort *)*iter;
1239  n->edAddInputPort(p->getName(),p->edGetType());
1240  }
1241  list<OutputPort *>::iterator iter2;
1242  for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
1243  {
1244  OutputPyPort *p=(OutputPyPort *)*iter2;
1245  n->edAddOutputPort(p->getName(),p->edGetType());
1246  }
1247  return n;
1248 }
void PyFuncNode::createRemoteAdaptedPyInterpretor ( Engines::Container_ptr  objContainer)
protectedvirtual

returns an object, you have to deal with (UnRegister)

Implements YACS::ENGINE::PythonEntry.

Definition at line 1194 of file PythonNode.cxx.

References _pynode, YACS::ENGINE::Node::getName(), and YACS::ENGINE::InlineNode::getScript().

1195 {
1196  if(!CORBA::is_nil(_pynode))
1197  _pynode->UnRegister();
1198  _pynode=objContainer->createPyNode(getName().c_str(),getScript().c_str());
1199 }
void PyFuncNode::execute ( )
virtual

Implements YACS::ENGINE::Task.

Definition at line 938 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_mode, executeLocal(), executeRemote(), and YACS::ENGINE::PythonNode::REMOTE_NAME.

939 {
941  executeRemote();
942  else
943  executeLocal();
944 }
void PyFuncNode::executeLocal ( )
virtual

Definition at line 1073 of file PythonNode.cxx.

References YACS::ENGINE::Node::_errorDetails, _pyfunc, YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::DataPort::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::ElementaryNode::getNumberOfInputPorts(), YACS::ENGINE::ElementaryNode::getNumberOfOutputPorts(), YACS::ENGINE::InputPyPort::getPyObj(), YACS::ENGINE::TypeCode::kind(), YACS::ENGINE::newPyStdOut(), p, YACS::ENGINE::OutputPyPort::put(), and YACS::Exception::what().

Referenced by execute().

1074 {
1075  DEBTRACE( "++++++++++++++ PyFuncNode::execute: " << getName() << " ++++++++++++++++++++" );
1076 
1077  int pos=0;
1078  PyObject* ob;
1079  if(!_pyfunc)throw Exception("PyFuncNode badly loaded");
1080  {
1081  AutoGIL agil;
1082  DEBTRACE( "---------------PyFuncNode::inputs---------------" );
1083  PyObject* args = PyTuple_New(getNumberOfInputPorts()) ;
1084  list<InputPort *>::iterator iter2;
1085  for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
1086  {
1087  InputPyPort *p=(InputPyPort *)*iter2;
1088  DEBTRACE( "port name: " << p->getName() );
1089  DEBTRACE( "port kind: " << p->edGetType()->kind() );
1090  ob=p->getPyObj();
1091 #ifdef _DEVDEBUG_
1092  PyObject_Print(ob,stderr,Py_PRINT_RAW);
1093  cerr << endl;
1094 #endif
1095  DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1096  Py_INCREF(ob);
1097  PyTuple_SetItem(args,pos,ob);
1098  DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1099  pos++;
1100  }
1101  DEBTRACE( "---------------End PyFuncNode::inputs---------------" );
1102 
1103  DEBTRACE( "----------------PyFuncNode::calculation---------------" );
1104 #ifdef _DEVDEBUG_
1105  PyObject_Print(_pyfunc,stderr,Py_PRINT_RAW);
1106  cerr << endl;
1107  PyObject_Print(args,stderr,Py_PRINT_RAW);
1108  cerr << endl;
1109 #endif
1110  DEBTRACE( "_pyfunc refcnt: " << _pyfunc->ob_refcnt );
1111  PyObject* result = PyObject_CallObject( _pyfunc , args ) ;
1112  DEBTRACE( "_pyfunc refcnt: " << _pyfunc->ob_refcnt );
1113  Py_DECREF(args);
1114  fflush(stdout);
1115  fflush(stderr);
1116  if(result == NULL)
1117  {
1118  _errorDetails="";
1119  PyObject* new_stderr = newPyStdOut(_errorDetails);
1120  PySys_SetObject((char*)"stderr", new_stderr);
1121  std::ostringstream stream;
1122  stream << "/tmp/PythonNode_";
1123  stream << getpid();
1124  ofstream errorfile(stream.str().c_str());
1125  if (errorfile.is_open())
1126  {
1127  errorfile << _script;
1128  errorfile.close();
1129  }
1130  PyErr_Print();
1131  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1132  Py_DECREF(new_stderr);
1133  throw Exception("Error during execution");
1134  }
1135  DEBTRACE( "----------------End PyFuncNode::calculation---------------" );
1136 
1137  DEBTRACE( "-----------------PyFuncNode::outputs-----------------" );
1138  int nres=1;
1139  if(result == Py_None)
1140  nres=0;
1141  else if(PyTuple_Check(result))
1142  nres=PyTuple_Size(result);
1143 
1144  if(getNumberOfOutputPorts() != nres)
1145  {
1146  std::string msg="Number of output arguments : Mismatch between definition and execution";
1147  Py_DECREF(result);
1148  _errorDetails=msg;
1149  throw Exception(msg);
1150  }
1151 
1152  pos=0;
1153 #ifdef _DEVDEBUG_
1154  PyObject_Print(result,stderr,Py_PRINT_RAW);
1155  cerr << endl;
1156 #endif
1157  list<OutputPort *>::iterator iter;
1158  try
1159  {
1160  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
1161  {
1162  OutputPyPort *p=(OutputPyPort *)*iter;
1163  DEBTRACE( "port name: " << p->getName() );
1164  DEBTRACE( "port kind: " << p->edGetType()->kind() );
1165  DEBTRACE( "port pos : " << pos );
1166  if(PyTuple_Check(result))ob=PyTuple_GetItem(result,pos) ;
1167  else ob=result;
1168  DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1169 #ifdef _DEVDEBUG_
1170  PyObject_Print(ob,stderr,Py_PRINT_RAW);
1171  cerr << endl;
1172 #endif
1173  p->put(ob);
1174  pos++;
1175  }
1176  }
1177  catch(ConversionException& ex)
1178  {
1179  Py_DECREF(result);
1180  _errorDetails=ex.what();
1181  throw;
1182  }
1183  DEBTRACE( "-----------------End PyFuncNode::outputs-----------------" );
1184  Py_DECREF(result);
1185  }
1186  DEBTRACE( "++++++++++++++ End PyFuncNode::execute: " << getName() << " ++++++++++++++++++++" );
1187 }
void PyFuncNode::executeRemote ( )
virtual

Definition at line 946 of file PythonNode.cxx.

References YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::PythonEntry::_pyfuncSer, YACS::ENGINE::PythonEntry::_pyfuncUnser, _pynode, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, YACS::ENGINE::PythonEntry::commonRemoteLoadPart2(), DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::InlineNode::getContainer(), YACS::ENGINE::InlineFuncNode::getFname(), YACS::ENGINE::DataPort::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::ElementaryNode::getNumberOfInputPorts(), YACS::ENGINE::ElementaryNode::getNumberOfOutputPorts(), YACS::ENGINE::InputPyPort::getPyObj(), YACS::ENGINE::InlineNode::getScript(), CORBAEngineTest::i, YACS::ENGINE::TypeCode::kind(), p, YACS::ENGINE::OutputPyPort::put(), and YACS::Exception::what().

Referenced by execute().

947 {
948  DEBTRACE( "++++++++++++++ PyFuncNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
949  if(!_pyfuncSer)
950  throw Exception("DistributedPythonNode badly loaded");
951  //
952  if(dynamic_cast<HomogeneousPoolContainer *>(getContainer()))
953  {
954  bool dummy;
955  commonRemoteLoadPart2(this,dummy);
956  _pynode->executeAnotherPieceOfCode(getScript().c_str());
957  }
958  //
959  Engines::pickledArgs_var serializationInputCorba(new Engines::pickledArgs);;
960  {
961  AutoGIL agil;
962  PyObject *ob(0);
963  //===========================================================================
964  // Get inputs in input ports, build a Python tuple and pickle it
965  //===========================================================================
966  PyObject *args(PyTuple_New(getNumberOfInputPorts()));
967  int pos(0);
968  for(std::list<InputPort *>::iterator iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++,pos++)
969  {
970  InputPyPort *p=(InputPyPort *)*iter2;
971  ob=p->getPyObj();
972  Py_INCREF(ob);
973  PyTuple_SetItem(args,pos,ob);
974  }
975 #ifdef _DEVDEBUG_
976  PyObject_Print(args,stderr,Py_PRINT_RAW);
977  std::cerr << endl;
978 #endif
979  PyObject *serializationInput=PyObject_CallObject(_pyfuncSer,args);
980  Py_DECREF(args);
981  //The pickled string may contain NULL characters so use PyString_AsStringAndSize
982  char *serializationInputC(0);
983  Py_ssize_t len;
984  if (PyString_AsStringAndSize(serializationInput, &serializationInputC, &len))
985  throw Exception("DistributedPythonNode problem in python pickle");
986 
987  serializationInputCorba->length(len);
988  for(int i=0; i < len ; i++)
989  serializationInputCorba[i]=serializationInputC[i];
990  Py_DECREF(serializationInput);
991  }
992 
993  //===========================================================================
994  // Execute in remote Python node
995  //===========================================================================
996  DEBTRACE( "-----------------starting remote python invocation-----------------" );
997  Engines::pickledArgs_var resultCorba;
998  try
999  {
1000  resultCorba=_pynode->execute(getFname().c_str(),serializationInputCorba);
1001  }
1002  catch( const SALOME::SALOME_Exception& ex )
1003  {
1004  std::string msg="Exception on remote python invocation";
1005  msg += '\n';
1006  msg += ex.details.text.in();
1007  _errorDetails=msg;
1008  throw Exception(msg);
1009  }
1010  DEBTRACE( "-----------------end of remote python invocation-----------------" );
1011  //===========================================================================
1012  // Get results, unpickle and put them in output ports
1013  //===========================================================================
1014  char *resultCorbaC=new char[resultCorba->length()+1];
1015  resultCorbaC[resultCorba->length()]='\0';
1016  for(int i=0;i<resultCorba->length();i++)
1017  resultCorbaC[i]=resultCorba[i];
1018 
1019  {
1020  AutoGIL agil;
1021 
1022  PyObject *resultPython(PyString_FromStringAndSize(resultCorbaC,resultCorba->length()));
1023  delete [] resultCorbaC;
1024  PyObject *args(PyTuple_New(1)),*ob(0);
1025  PyTuple_SetItem(args,0,resultPython);
1026  PyObject *finalResult=PyObject_CallObject(_pyfuncUnser,args);
1027  Py_DECREF(args);
1028 
1029  DEBTRACE( "-----------------PythonNode::outputs-----------------" );
1030  int nres=1;
1031  if(finalResult == Py_None)
1032  nres=0;
1033  else if(PyTuple_Check(finalResult))
1034  nres=PyTuple_Size(finalResult);
1035 
1036  if(getNumberOfOutputPorts() != nres)
1037  {
1038  std::string msg="Number of output arguments : Mismatch between definition and execution";
1039  Py_DECREF(finalResult);
1040  _errorDetails=msg;
1041  throw Exception(msg);
1042  }
1043 
1044  try
1045  {
1046  int pos(0);
1047  for(std::list<OutputPort *>::iterator iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++, pos++)
1048  {
1049  OutputPyPort *p=(OutputPyPort *)*iter;
1050  DEBTRACE( "port name: " << p->getName() );
1051  DEBTRACE( "port kind: " << p->edGetType()->kind() );
1052  DEBTRACE( "port pos : " << pos );
1053  if(PyTuple_Check(finalResult))
1054  ob=PyTuple_GetItem(finalResult,pos) ;
1055  else
1056  ob=finalResult;
1057  DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1058  p->put(ob);
1059  }
1060  Py_DECREF(finalResult);
1061  }
1062  catch(ConversionException& ex)
1063  {
1064  Py_DECREF(finalResult);
1065  _errorDetails=ex.what();
1066  throw;
1067  }
1068  }
1069 
1070  DEBTRACE( "++++++++++++++ ENDOF PyFuncNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
1071 }
std::string PyFuncNode::getContainerLog ( )
virtual

returns a string that contains the name of the container log file if it exists

Do nothing here. To subclass

Reimplemented from YACS::ENGINE::Node.

Definition at line 1250 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_container, YACS::ENGINE::InlineNode::_mode, and YACS::ENGINE::PythonEntry::GetContainerLog().

1251 {
1253 }
Engines::PyNodeBase_var PyFuncNode::getRemoteInterpreterHandle ( )
protectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 1224 of file PythonNode.cxx.

References _pynode.

1225 {
1226  return Engines::PyNodeBase::_narrow(_pynode);
1227 }
const char* YACS::ENGINE::PyFuncNode::getSerializationScript ( ) const
inlineprotectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 107 of file PythonNode.hxx.

107 { return SCRIPT_FOR_SERIALIZATION; }
void PyFuncNode::init ( bool  start = true)
virtual

initialisation of all input and output ports and gates, for execution

Reimplemented from YACS::ENGINE::ElementaryNode.

Definition at line 815 of file PythonNode.cxx.

References YACS::ENGINE::Node::_state, YACS::DISABLED, YACS::ENGINE::Node::exDisabledState(), YACS::ENGINE::ElementaryNode::initCommonPartWithoutStateManagement(), YACS::LOADED, YACS::READY, YACS::ENGINE::Node::setState(), and YACS::TORECONNECT.

816 {
818  if(_state == YACS::DISABLED)
819  {
820  exDisabledState(); // to refresh propagation of DISABLED state
821  return ;
822  }
823  if(start) //complete initialization
825  else if(_state > YACS::LOADED)// WARNING FuncNode has internal vars (CEA usecase) ! Partial initialization (inside a loop). Exclusivity of funcNode.
827 }
void PyFuncNode::load ( )
virtual

Reimplemented from YACS::ENGINE::ElementaryNode.

Definition at line 852 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_mode, DEBTRACE, loadLocal(), loadRemote(), and YACS::ENGINE::PythonNode::REMOTE_NAME.

853 {
854  DEBTRACE( "---------------PyfuncNode::load function---------------" );
856  loadRemote();
857  else
858  loadLocal();
859 }
void PyFuncNode::loadLocal ( )
virtual

Definition at line 866 of file PythonNode.cxx.

References YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::InlineFuncNode::_fname, _pyfunc, YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::_setOfOutputPort, DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::DataPort::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::TypeCode::kind(), YACS::ENGINE::newPyStdOut(), and p.

Referenced by load().

867 {
868  DEBTRACE( "---------------PyFuncNode::load function " << getName() << " ---------------" );
869  DEBTRACE( _script );
870 
871 #ifdef _DEVDEBUG_
872  list<OutputPort *>::iterator iter;
873  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
874  {
875  OutputPyPort *p=(OutputPyPort *)*iter;
876  DEBTRACE( "port name: " << p->getName() );
877  DEBTRACE( "port kind: " << p->edGetType()->kind() );
878  }
879 #endif
880 
881  {
882  AutoGIL agil;
883  DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
884 
885  std::ostringstream stream;
886  stream << "/tmp/PythonNode_";
887  stream << getpid();
888 
889  PyObject* code=Py_CompileString(_script.c_str(), stream.str().c_str(), Py_file_input);
890  if(code == NULL)
891  {
892  _errorDetails="";
893  PyObject* new_stderr = newPyStdOut(_errorDetails);
894  PySys_SetObject((char*)"stderr", new_stderr);
895  PyErr_Print();
896  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
897  Py_DECREF(new_stderr);
898  throw Exception("Error during execution");
899  }
900  PyObject *res = PyEval_EvalCode((PyCodeObject *)code, _context, _context);
901  Py_DECREF(code);
902  Py_XDECREF(res);
903 
904  DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
905  if(PyErr_Occurred ())
906  {
907  _errorDetails="";
908  PyObject* new_stderr = newPyStdOut(_errorDetails);
909  PySys_SetObject((char*)"stderr", new_stderr);
910  ofstream errorfile(stream.str().c_str());
911  if (errorfile.is_open())
912  {
913  errorfile << _script;
914  errorfile.close();
915  }
916  PyErr_Print();
917  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
918  Py_DECREF(new_stderr);
919  throw Exception("Error during execution");
920  return;
921  }
922  _pyfunc=PyDict_GetItemString(_context,_fname.c_str());
923  DEBTRACE( "_pyfunc refcnt: " << _pyfunc->ob_refcnt );
924  if(_pyfunc == NULL)
925  {
926  _errorDetails="";
927  PyObject* new_stderr = newPyStdOut(_errorDetails);
928  PySys_SetObject((char*)"stderr", new_stderr);
929  PyErr_Print();
930  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
931  Py_DECREF(new_stderr);
932  throw Exception("Error during execution");
933  }
934  DEBTRACE( "---------------End PyFuncNode::load function---------------" );
935  }
936 }
void PyFuncNode::loadRemote ( )
virtual

Definition at line 861 of file PythonNode.cxx.

References YACS::ENGINE::PythonEntry::commonRemoteLoad().

Referenced by load().

862 {
863  commonRemoteLoad(this);
864 }
Engines::PyNodeBase_var PyFuncNode::retrieveDftRemotePyInterpretorIfAny ( Engines::Container_ptr  objContainer) const
protectedvirtual

returns (if any) an object, you have to deal with (UnRegister)

Implements YACS::ENGINE::PythonEntry.

Definition at line 1201 of file PythonNode.cxx.

References YACS::ENGINE::Node::getName(), and PMMLBasicsTestLauncher::ret.

1202 {
1203  Engines::PyNode_var ret(objContainer->getDefaultPyNode(getName().c_str()));
1204  if(!CORBA::is_nil(ret))
1205  {
1206  ret->Register();
1207  }
1208  return Engines::PyNodeBase::_narrow(ret);
1209 }
void PyFuncNode::shutdown ( int  level)
virtual

Stop all pending activities of the node.

This method should be called when a Proc is finished and must be deleted from the YACS server

Reimplemented from YACS::ENGINE::Node.

Definition at line 1255 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_container, YACS::ENGINE::InlineNode::_mode, _pynode, DEBTRACE, and YACS::ENGINE::Container::shutdown().

1256 {
1257  DEBTRACE("PyFuncNode::shutdown " << level);
1258  if(_mode=="local")return;
1259  if(_container)
1260  {
1261  if(!CORBA::is_nil(_pynode)) _pynode->UnRegister();
1262  _pynode=Engines::PyNode::_nil();
1263  _container->shutdown(level);
1264  }
1265 }
Node * PyFuncNode::simpleClone ( ComposedNode father,
bool  editionOnly 
) const
protectedvirtual

Implements YACS::ENGINE::Node.

Definition at line 1189 of file PythonNode.cxx.

References PyFuncNode().

1190 {
1191  return new PyFuncNode(*this,father);
1192 }
virtual std::string YACS::ENGINE::PyFuncNode::typeName ( )
inlinevirtual

Reimplemented from YACS::ENGINE::InlineFuncNode.

Definition at line 123 of file PythonNode.hxx.

123 { return "YACS__ENGINE__PyFuncNode"; }

Member Data Documentation

PyObject* YACS::ENGINE::PyFuncNode::_pyfunc
protected

Definition at line 127 of file PythonNode.hxx.

Referenced by executeLocal(), and loadLocal().

Engines::PyNode_var YACS::ENGINE::PyFuncNode::_pynode
protected
const char PyFuncNode::SCRIPT_FOR_SERIALIZATION
static
Initial value:
="import cPickle\n"
"def pickleForDistPyth2009(*args,**kws):\n"
" return cPickle.dumps((args,kws),-1)\n"
"\n"
"def unPickleForDistPyth2009(st):\n"
" args=cPickle.loads(st)\n"
" return args\n"

Definition at line 125 of file PythonNode.hxx.


The documentation for this class was generated from the following files: