OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
PyOpal::PyElementNS::PyElement< C > Class Template Reference

#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_< PyCmake_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 ()
 
OpalElementgetOpalElement ()
 
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< AttributeDefattributes
 
static std::string classDocstring
 
static bool converterRegistered = false
 
static bool hasGetFieldValue
 

Detailed Description

template<class C>
class PyOpal::PyElementNS::PyElement< C >

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.

Member Typedef Documentation

◆ PyC

template<class C >
typedef PyElement<C> PyOpal::PyElementNS::PyElement< C >::PyC

Definition at line 121 of file PyElement.h.

Constructor & Destructor Documentation

◆ PyElement() [1/4]

template<class C >
PyOpal::PyElementNS::PyElement< C >::PyElement
inline

Default constructor

Definition at line 271 of file PyElement.h.

◆ PyElement() [2/4]

template<class C >
PyOpal::PyElementNS::PyElement< C >::PyElement ( std::shared_ptr< C >  element)
inline

Constructor taking the element as argument

Definition at line 125 of file PyElement.h.

◆ PyElement() [3/4]

template<class C >
PyOpal::PyElementNS::PyElement< C >::PyElement ( const PyElement< C > &  rhs)

Copying is disabled

Definition at line 346 of file PyElement.h.

◆ ~PyElement()

template<class C >
PyOpal::PyElementNS::PyElement< C >::~PyElement ( )
inline

Default destructor

Definition at line 129 of file PyElement.h.

◆ PyElement() [4/4]

Member Function Documentation

◆ addAttributes()

template<class C >
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.

Here is the call graph for this function:

◆ dummyGet()

template<class C >
template<class ValueType >
ValueType PyOpal::PyElementNS::PyElement< C >::dummyGet ( ) const
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().

Here is the call graph for this function:

◆ dummySet()

template<class C >
template<class ValueType >
void PyOpal::PyElementNS::PyElement< C >::dummySet ( ValueType  test)
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().

Here is the call graph for this function:

◆ getAttribute()

template<class C >
PyObject * PyOpal::PyElementNS::PyElement< C >::getAttribute ( AttributeType  type,
std::string  opalName 
) const

Get the value of an attribute

  • type: the type expected for python
  • opalName: the name of the Opal Attribute Returns a PyObject holding data; INCREF is called on the object i.e. it is a new object, not borrowed.

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.

Here is the call graph for this function:

◆ getDocString()

template<class C >
std::string PyOpal::PyElementNS::PyElement< C >::getDocString ( AttributeDef def)
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.

Here is the call graph for this function:

◆ getElement()

template<class C >
C * PyOpal::PyElementNS::PyElement< C >::getElement ( )
inline

Definition at line 189 of file PyElement.h.

References PyOpal::PyElementNS::PyElement< C >::element_m.

◆ getFieldValue()

template<class C >
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

  • x: position in local coordinate system of the OpalElement
  • y: position in local coordinate system of the OpalElement
  • z: position in local coordinate system of the OpalElement
  • t: time Returns a tuple like (out_of_bounds, Bx, By, Bz, Ex, Ey, Ez).

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.

Here is the call graph for this function:

◆ getOpalElement()

template<class C >
OpalElement * PyOpal::PyElementNS::PyElement< C >::getOpalElement

Returns the OpalElement from the PyElement

Definition at line 400 of file PyElement.h.

◆ getPyOpalElement()

template<class C >
boost::python::object PyOpal::PyElementNS::PyElement< C >::getPyOpalElement

Definition at line 410 of file PyElement.h.

◆ make_class()

template<class C >
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.

◆ setAttribute()

template<class C >
void PyOpal::PyElementNS::PyElement< C >::setAttribute ( AttributeType  type,
std::string  opalName,
PyObject *  value 
)

Set the value of an attribute

  • type: the type expected for python
  • opalName: the name of the Opal Attribute
  • value: Python object holding the value to be stored. value refcnt is not changed - caller is responsible for managing the refcnt. It is an error if the Attribute does not exist (throws OpalException)

Definition at line 325 of file PyElement.h.

References PyOpal::PyElementNS::DOUBLE, PyOpal::PyElementNS::INT, and Attributes::setReal().

Here is the call graph for this function:

Member Data Documentation

◆ attributes

template<class C >
std::vector<AttributeDef> PyOpal::PyElementNS::PyElement< C >::attributes
staticprotected

Definition at line 192 of file PyElement.h.

◆ classDocstring

template<class C >
std::string PyOpal::PyElementNS::PyElement< C >::classDocstring
staticprotected

class data (attributes)

Definition at line 193 of file PyElement.h.

◆ converterRegistered

template<class C >
bool PyOpal::PyElementNS::PyElement< C >::converterRegistered = false
staticprotected

class docstring

Definition at line 194 of file PyElement.h.

◆ element_m

template<class C >
std::shared_ptr<C> PyOpal::PyElementNS::PyElement< C >::element_m
protected

field value

Definition at line 196 of file PyElement.h.

Referenced by PyOpal::PyElementNS::PyElement< C >::getElement().

◆ hasGetFieldValue

template<class C >
bool PyOpal::PyElementNS::PyElement< C >::hasGetFieldValue
staticprotected

set to true if the converter has been registered

Definition at line 195 of file PyElement.h.


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