OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
|
#include <PyElement.h>
Public Types | |
typedef PyElement< C > | PyC |
Public Member Functions | |
PyElement () | |
PyElement (std::shared_ptr< C > element) | |
PyElement (const PyElement< C > &rhs) | |
~PyElement () | |
boost::python::class_< PyC > | make_class (const char *className) |
void | addAttributes (boost::python::class_< PyC > &pyclass) |
template<class ValueType > | |
ValueType | dummyGet () const |
template<class ValueType > | |
void | dummySet (ValueType test) |
PyObject * | getAttribute (AttributeType type, std::string opalName) const |
void | setAttribute (AttributeType type, std::string opalName, PyObject *value) |
boost::python::object | getFieldValue (double x, double y, double z, double t) const |
boost::python::object | getPyOpalElement () |
OpalElement * | getOpalElement () |
C * | getElement () |
PyElement () | |
Protected Member Functions | |
std::string | getDocString (AttributeDef &def) |
Protected Attributes | |
std::shared_ptr< C > | element_m |
Static Protected Attributes | |
static std::vector< AttributeDef > | attributes |
static std::string | classDocstring |
static bool | converterRegistered = false |
static bool | hasGetFieldValue |
PyElement<C> is the basic wrapper class for OpalElements
PyElement<C> is a wrapper for an OpalElement C. Opal Attributes are implemented in python as properties (public member data). Some default method calls can be enabled in the concrete implementation by setting flags. Docstring can be enabled by setting classDocString.
element_m: pointer to the base element attributes: vector of attributes. The order of the vector is the order that attributes will appear in the docstring classDocString: overall docstring. docstrings on each property and method are added automatically by the framework. hasGetFieldValue: set to true to add a get_field_value method to the class; this is useful for OpalElements that expose a field object.
property access is set up in make_class using add_property from boost::python. Normally, the "get" method can't take any data; this would mean that we can't pass an Attribute name for the OpalElement lookup. In order to get around this limitation, we have a "dummy" getter dummyGet. Then there is a "real" getter, which is hidden in the call policy for the property (a sort of pre- and post- decorator). We use PyElementGetProperty to hold the Attribute name and then dummyGet just tells PyElementGetProperty the address of the PyElement. PyElementGetProperty does a postcall action to overwrite the return value with the "real" return value, based on the stored Attribute name.
Setters work in exactly the same way, except now we have dummySet and PyElementSetProperty to handle the interface.
The routine then looks like: python::boost calls dummyGet; dummyGet tells PyElementGetProperty pointer to PyElement python::boost calls PyElementGetProperty.postcall PyElementGetProperty.postcall calls PyElement->getAttribute; where getAttribute takes the name of the Attribute as a string. It's a bit of a faff.
Definition at line 119 of file PyElement.h.
typedef PyElement<C> PyOpal::PyElementNS::PyElement< C >::PyC |
Definition at line 121 of file PyElement.h.
|
inline |
Default constructor
Definition at line 271 of file PyElement.h.
|
inline |
Constructor taking the element as argument
Definition at line 125 of file PyElement.h.
PyOpal::PyElementNS::PyElement< C >::PyElement | ( | const PyElement< C > & | rhs | ) |
Copying is disabled
Definition at line 346 of file PyElement.h.
|
inline |
Default destructor
Definition at line 129 of file PyElement.h.
PyOpal::PyElementNS::PyElement< OpalElement >::PyElement | ( | ) |
void PyOpal::PyElementNS::PyElement< C >::addAttributes | ( | boost::python::class_< PyC > & | pyclass | ) |
Add attributes to the python class.
Definition at line 372 of file PyElement.h.
References PyOpal::PyElementNS::DOUBLE, PyOpal::PyOpalObjectNS::getFieldValue(), and PyOpal::PyElementNS::INT.
|
inline |
dummyGet sets the element ptr for PyElementGetProperty but doesn't actually do the get(...)
Definition at line 145 of file PyElement.h.
References PyOpal::PyElementNS::PyElementGetProperty< C >::setElement().
|
inline |
dummySet sets the element ptr for PyElementSetProperty but doesn't actually do the set(...)
Definition at line 151 of file PyElement.h.
References PyOpal::PyElementNS::PyElementSetProperty< C >::setElement().
PyObject * PyOpal::PyElementNS::PyElement< C >::getAttribute | ( | AttributeType | type, |
std::string | opalName | ||
) | const |
Get the value of an attribute
It is an error if the Attribute does not exist (throws OpalException)
Definition at line 296 of file PyElement.h.
References PyOpal::PyElementNS::DOUBLE, Attributes::getReal(), and PyOpal::PyElementNS::INT.
|
protected |
pointer to the element Generates a docstring from the attribute
Definition at line 350 of file PyElement.h.
References PyOpal::PyElementNS::attributeName, PyOpal::PyElementNS::AttributeDef::docString_m, Attribute::getHelp(), PyOpal::PyElementNS::AttributeDef::opalName_m, PyOpal::PyElementNS::AttributeDef::pyName_m, and PyOpal::PyElementNS::AttributeDef::type_m.
|
inline |
Definition at line 189 of file PyElement.h.
References PyOpal::PyElementNS::PyElement< C >::element_m.
boost::python::object PyOpal::PyElementNS::PyElement< C >::getFieldValue | ( | double | x, |
double | y, | ||
double | z, | ||
double | t | ||
) | const |
Get the field at a point in position and time, for the OpalElement
Only added to the python class if hasGetFieldValue is true.
Definition at line 277 of file PyElement.h.
References Component::apply(), and Attrib::Distribution::R.
OpalElement * PyOpal::PyElementNS::PyElement< C >::getOpalElement |
Returns the OpalElement from the PyElement
Definition at line 400 of file PyElement.h.
boost::python::object PyOpal::PyElementNS::PyElement< C >::getPyOpalElement |
Definition at line 410 of file PyElement.h.
boost::python::class_< PyElement< C > > PyOpal::PyElementNS::PyElement< C >::make_class | ( | const char * | className | ) |
This is the basic method to make a class. It should normally be called when the module is declared, BOOST_PYTHON_MODULE.
Definition at line 364 of file PyElement.h.
void PyOpal::PyElementNS::PyElement< C >::setAttribute | ( | AttributeType | type, |
std::string | opalName, | ||
PyObject * | value | ||
) |
Set the value of an attribute
Definition at line 325 of file PyElement.h.
References PyOpal::PyElementNS::DOUBLE, PyOpal::PyElementNS::INT, and Attributes::setReal().
|
staticprotected |
Definition at line 192 of file PyElement.h.
|
staticprotected |
class data (attributes)
Definition at line 193 of file PyElement.h.
|
staticprotected |
class docstring
Definition at line 194 of file PyElement.h.
|
protected |
field value
Definition at line 196 of file PyElement.h.
Referenced by PyOpal::PyElementNS::PyElement< C >::getElement().
|
staticprotected |
set to true if the converter has been registered
Definition at line 195 of file PyElement.h.