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

#include <PyOpalObject.h>

Inheritance diagram for PyOpal::PyOpalObjectNS::PyOpalObject< C >:
Inheritance graph
[legend]

Public Types

typedef PyOpalObject< C > PyC
 
typedef PyOpalObject< C > PyC
 

Public Member Functions

 PyOpalObject ()
 
 PyOpalObject (std::shared_ptr< C > object)
 
 PyOpalObject (const PyOpalObject< C > &rhs)
 
 ~PyOpalObject ()
 
boost::python::class_< PyCmake_class (const char *className)
 
template<class PYCLASS >
void addAttributes (PYCLASS &pyclass)
 
template<class PYCLASS >
void addExecute (PYCLASS &pyclass)
 
template<class PYCLASS >
void addRegister (PYCLASS &pyclass)
 
template<class PYCLASS >
void addGetOpalElement (PYCLASS &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)
 
std::shared_ptr< C > getOpalShared ()
 
 PyOpalObject ()
 
 PyOpalObject (std::shared_ptr< C > object)
 
 PyOpalObject (const PyOpalObject< C > &rhs)
 
 ~PyOpalObject ()
 
boost::python::class_< PyCmake_class (const char *className)
 
template<class PYCLASS >
void addAttributes (PYCLASS &pyclass)
 
template<class PYCLASS >
void addExecute (PYCLASS &pyclass)
 
template<class PYCLASS >
void addRegister (PYCLASS &pyclass)
 
template<class PYCLASS >
void addGetOpalName (PYCLASS &pyclass)
 
template<class PYCLASS >
void addSetOpalName (PYCLASS &pyclass)
 
template<class PYCLASS >
void addGetOpalElement (PYCLASS &pyclass)
 
template<class PYCLASS >
void addGetFieldValue (PYCLASS &pyclass, double distanceUnits, double timeUnits, double bfieldUnits, double efieldUnits)
 
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)
 
std::shared_ptr< C > getOpalShared ()
 
std::shared_ptr< C > getOpalShared () const
 
 PyOpalObject ()
 
 PyOpalObject ()
 

Protected Member Functions

std::string getDocString (AttributeDef &def)
 
std::string getDocString (AttributeDef &def)
 

Static Protected Member Functions

static void execute (PyOpalObject< C > &pyobject)
 
static void registerObject (PyOpalObject< C > &pyobject)
 
static boost::python::object getPyOpalElement (PyOpalObject< C > &pyobject)
 
static boost::python::object getFieldValue (PyOpalObjectNS::PyOpalObject< C > &pyobject, double x, double y, double z, double t)
 
static std::string getOpalName (const PyOpalObject< C > &pyobject)
 
static void setOpalName (PyOpalObject< C > &pyobject, std::string name)
 
static void execute (PyOpalObject< C > &pyobject)
 
static void registerObject (PyOpalObject< C > &pyobject)
 
static boost::python::object getPyOpalElement (PyOpalObject< C > &pyobject)
 

Protected Attributes

std::shared_ptr< C > object_m
 

Static Protected Attributes

static std::vector< AttributeDefattributes
 
static std::string classDocstring
 
static bool converterRegistered
 
static double distanceUnits_m = 1
 
static double timeUnits_m = 1
 
static double bfieldUnits_m = 1
 
static double efieldUnits_m = 1
 
static const std::string getFieldValueDocString
 

Detailed Description

template<class C>
class PyOpal::PyOpalObjectNS::PyOpalObject< C >

PyOpalObject<C> is the basic wrapper class for Opal Objects

PyOpalObject<C> is a wrapper for an Opal Object 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.

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 PyOpalObjectGetProperty to hold the Attribute name and then dummyGet just tells PyElementGetProperty the address of the PyOpalObject. 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 PyOpalObject python::boost calls PyElementGetProperty.postcall PyElementGetProperty.postcall calls PyOpalObject->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 PyOpalObject.h.

Member Typedef Documentation

◆ PyC [1/2]

template<class C >
typedef PyOpalObject<C> PyOpal::PyOpalObjectNS::PyOpalObject< C >::PyC

Definition at line 120 of file PyOpalObject.h.

◆ PyC [2/2]

template<class C >
typedef PyOpalObject<C> PyOpal::PyOpalObjectNS::PyOpalObject< C >::PyC

Definition at line 121 of file PyOpalObject.h.

Constructor & Destructor Documentation

◆ PyOpalObject() [1/8]

template<class C >
PyOpal::PyOpalObjectNS::PyOpalObject< C >::PyOpalObject
inline

Default constructor

Definition at line 333 of file PyOpalObject.h.

◆ PyOpalObject() [2/8]

template<class C >
PyOpal::PyOpalObjectNS::PyOpalObject< C >::PyOpalObject ( std::shared_ptr< C >  object)
inline

Constructor taking the element as argument

Definition at line 124 of file PyOpalObject.h.

◆ PyOpalObject() [3/8]

template<class C >
PyOpal::PyOpalObjectNS::PyOpalObject< C >::PyOpalObject ( const PyOpalObject< C > &  rhs)

Copying is disabled

Definition at line 421 of file PyOpalObject.h.

◆ ~PyOpalObject() [1/2]

template<class C >
PyOpal::PyOpalObjectNS::PyOpalObject< C >::~PyOpalObject ( )
inline

Default destructor

Definition at line 128 of file PyOpalObject.h.

◆ PyOpalObject() [4/8]

template<class C >
PyOpal::PyOpalObjectNS::PyOpalObject< C >::PyOpalObject ( )
inline

Default constructor

◆ PyOpalObject() [5/8]

template<class C >
PyOpal::PyOpalObjectNS::PyOpalObject< C >::PyOpalObject ( std::shared_ptr< C >  object)
inline

Constructor taking the element as argument

Definition at line 125 of file PyOpalObject.h.

◆ PyOpalObject() [6/8]

template<class C >
PyOpal::PyOpalObjectNS::PyOpalObject< C >::PyOpalObject ( const PyOpalObject< C > &  rhs)

Copying is disabled

◆ ~PyOpalObject() [2/2]

template<class C >
PyOpal::PyOpalObjectNS::PyOpalObject< C >::~PyOpalObject ( )
inline

Default destructor

Definition at line 129 of file PyOpalObject.h.

◆ PyOpalObject() [7/8]

◆ PyOpalObject() [8/8]

Member Function Documentation

◆ addAttributes() [1/2]

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addAttributes ( PYCLASS &  pyclass)

◆ addAttributes() [2/2]

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addAttributes ( PYCLASS &  pyclass)

Add attributes to the python class.

◆ addExecute() [1/2]

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addExecute ( PYCLASS &  pyclass)

Add an "execute" method to the python class (e.g. if it is an ACTION)

Definition at line 450 of file PyOpalObject.h.

Referenced by PyOpal::PyDistributionNS::BOOST_PYTHON_MODULE(), and PyOpal::PyTrackRunNS::BOOST_PYTHON_MODULE().

◆ addExecute() [2/2]

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addExecute ( PYCLASS &  pyclass)

Add an "execute" method to the python class (e.g. if it is an ACTION)

◆ addGetFieldValue()

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addGetFieldValue ( PYCLASS &  pyclass,
double  distanceUnits,
double  timeUnits,
double  bfieldUnits,
double  efieldUnits 
)

Add a "get_field_value" method to the python class (for elements that expose a field)

  • PYCLASS: instance of the class to which the field is added
  • distanceUnits: set the distance units so that UI is in OPAL units
  • timeUnits: set the time units so that UI is in OPAL units
  • bfieldUnits: set the bfield units so that UI is in OPAL units
  • efieldUnits: set the efield units so that UI is in OPAL units

It is encouraged to expose the field map for field-type objects, for user to check that the field is as expected.

Note that conversion factors for units in distance, time, bfield and efield should be provided - the OPAL unit system should be exposed to user (see OPAL docs for current recommendation). Opal will call element->apply(R*distanceUnits, P, t*timeUnits, Efield, Bfield) and return Efield*efieldUnits, BField*bfield units.

Definition at line 643 of file PyOpalObject.h.

◆ addGetOpalElement() [1/2]

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addGetOpalElement ( PYCLASS &  pyclass)

◆ addGetOpalElement() [2/2]

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addGetOpalElement ( PYCLASS &  pyclass)

Add a "get_opal_element" method to the python class (to overload as a PyOpalElement)

This is required for OpalElement objects, in order that they can be used in a OPAL line object (for setting up beamlines having multiple elements). In general, if C is an OpalElement, developer should call addGetOpalElement in the module setup function.

◆ addGetOpalName()

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addGetOpalName ( PYCLASS &  pyclass)

Add a get_opal_name method to the python class (to get the opal internal string that uniquely identifies the object)

Definition at line 625 of file PyOpalObject.h.

◆ addRegister() [1/2]

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addRegister ( PYCLASS &  pyclass)

Add a "register" method to the python class (to register against opal global data header)

Definition at line 456 of file PyOpalObject.h.

Referenced by PyOpal::PyBeamNS::BOOST_PYTHON_MODULE().

◆ addRegister() [2/2]

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addRegister ( PYCLASS &  pyclass)

Add a "register" method to the python class (to register against opal global data object)

◆ addSetOpalName()

template<class C >
template<class PYCLASS >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::addSetOpalName ( PYCLASS &  pyclass)

Add a set_opal_name method to the python class (to set the opal internal string that uniquely identifies the object)

Definition at line 631 of file PyOpalObject.h.

◆ dummyGet() [1/2]

template<class C >
template<class ValueType >
ValueType PyOpal::PyOpalObjectNS::PyOpalObject< C >::dummyGet ( ) const
inline

dummyGet sets the object ptr for PyOpalObjectGetProperty but doesn't actually do the get(...)

Definition at line 162 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::PyOpalObjectGetProperty< C >::setObject().

Here is the call graph for this function:

◆ dummyGet() [2/2]

template<class C >
template<class ValueType >
ValueType PyOpal::PyOpalObjectNS::PyOpalObject< C >::dummyGet ( ) const
inline

dummyGet sets the object ptr for PyOpalObjectGetProperty but doesn't actually do the get(...)

Definition at line 205 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::PyOpalObjectGetProperty< C >::setObject().

Here is the call graph for this function:

◆ dummySet() [1/2]

template<class C >
template<class ValueType >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::dummySet ( ValueType  test)
inline

dummySet sets the element ptr for PyOpalObjectSetProperty but doesn't actually do the set(...)

Definition at line 168 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::PyOpalObjectSetProperty< C >::setObject().

Here is the call graph for this function:

◆ dummySet() [2/2]

template<class C >
template<class ValueType >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::dummySet ( ValueType  test)
inline

dummySet sets the element ptr for PyOpalObjectSetProperty but doesn't actually do the set(...)

◆ execute() [1/2]

template<class C >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::execute ( PyOpalObject< C > &  pyobject)
staticprotected

Definition at line 296 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared().

Here is the call graph for this function:

◆ execute() [2/2]

template<class C >
static void PyOpal::PyOpalObjectNS::PyOpalObject< C >::execute ( PyOpalObject< C > &  pyobject)
staticprotected

◆ getAttribute() [1/2]

template<class C >
PyObject * PyOpal::PyOpalObjectNS::PyOpalObject< 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 336 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::attributeName, PyOpal::PyOpalObjectNS::BOOL, PyOpal::PyOpalObjectNS::DOUBLE, PyOpal::PyOpalObjectNS::FLOATLIST, Attributes::getBool(), Attributes::getReal(), Attributes::getRealArray(), Attributes::getString(), PyOpal::PyOpalObjectNS::INT, and PyOpal::PyOpalObjectNS::STRING.

Here is the call graph for this function:

◆ getAttribute() [2/2]

template<class C >
PyObject * PyOpal::PyOpalObjectNS::PyOpalObject< 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)

◆ getDocString() [1/2]

template<class C >
std::string PyOpal::PyOpalObjectNS::PyOpalObject< C >::getDocString ( AttributeDef def)
protected

◆ getDocString() [2/2]

template<class C >
std::string PyOpal::PyOpalObjectNS::PyOpalObject< C >::getDocString ( AttributeDef def)
protected

pointer to the element Generates a docstring from the attribute

◆ getFieldValue()

template<class C >
boost::python::object PyOpal::PyOpalObjectNS::PyOpalObject< C >::getFieldValue ( PyOpalObjectNS::PyOpalObject< C > &  pyobject,
double  x,
double  y,
double  z,
double  t 
)
staticprotected

Definition at line 271 of file PyOpalObject.h.

References Component::apply(), PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared(), and Attrib::Distribution::R.

Here is the call graph for this function:

◆ getOpalName()

template<class C >
std::string PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalName ( const PyOpalObject< C > &  pyobject)
staticprotected

Definition at line 377 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared().

Here is the call graph for this function:

◆ getOpalShared() [1/3]

template<class C >
std::shared_ptr< C > PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared ( )
inline

◆ getOpalShared() [2/3]

template<class C >
std::shared_ptr< C > PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared ( )
inline

Returns the Opal Object from the PyOpalObject

Definition at line 233 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::PyOpalObject< C >::object_m.

◆ getOpalShared() [3/3]

template<class C >
std::shared_ptr< C > PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared ( ) const
inline

Returns the Opal Object from the PyOpalObject (const version)

Definition at line 236 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::PyOpalObject< C >::object_m.

◆ getPyOpalElement() [1/2]

template<class C >
boost::python::object PyOpal::PyOpalObjectNS::PyOpalObject< C >::getPyOpalElement ( PyOpalObjectNS::PyOpalObject< C > &  pyobject)
staticprotected

Definition at line 315 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared().

Here is the call graph for this function:

◆ getPyOpalElement() [2/2]

template<class C >
static boost::python::object PyOpal::PyOpalObjectNS::PyOpalObject< C >::getPyOpalElement ( PyOpalObject< C > &  pyobject)
staticprotected

◆ make_class() [1/2]

template<class C >
boost::python::class_< PyOpalObject< C > > PyOpal::PyOpalObjectNS::PyOpalObject< C >::make_class ( const char *  className)
inline

This is the basic method to make a class. It should normally be called when the module is declared, BOOST_PYTHON_MODULE.

Note that while in principle this could be static, in the end we need an instance of C so that we can access the docString from the attribute.

Definition at line 439 of file PyOpalObject.h.

Referenced by PyOpal::PyBeamNS::BOOST_PYTHON_MODULE(), PyOpal::PyDistributionNS::BOOST_PYTHON_MODULE(), PyOpal::PyOpalLocalCartesianOffset::BOOST_PYTHON_MODULE(), PyOpal::PyOpalElement::BOOST_PYTHON_MODULE(), PyOpal::PyRingDefinition::BOOST_PYTHON_MODULE(), PyOpal::PyTrackRunNS::BOOST_PYTHON_MODULE(), PyOpal::PyTrackCmdNS::BOOST_PYTHON_MODULE(), and PyOpal::PyVerticalFFAMagnet::BOOST_PYTHON_MODULE().

◆ make_class() [2/2]

template<class C >
boost::python::class_< PyC > PyOpal::PyOpalObjectNS::PyOpalObject< C >::make_class ( const char *  className)
inline

This is the basic method to make a class. It should normally be called when the module is declared, BOOST_PYTHON_MODULE.

Note that while in principle this could be static, in the end we need an instance of C so that we can access the docString from the attribute.

◆ registerObject() [1/2]

template<class C >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::registerObject ( PyOpalObjectNS::PyOpalObject< C > &  pyobject)
staticprotected

Definition at line 302 of file PyOpalObject.h.

References OpalData::define(), OpalData::getInstance(), and PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared().

Here is the call graph for this function:

◆ registerObject() [2/2]

template<class C >
static void PyOpal::PyOpalObjectNS::PyOpalObject< C >::registerObject ( PyOpalObject< C > &  pyobject)
staticprotected

◆ setAttribute() [1/2]

template<class C >
void PyOpal::PyOpalObjectNS::PyOpalObject< 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 384 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::attributeName, PyOpal::PyOpalObjectNS::BOOL, PyOpal::PyOpalObjectNS::DOUBLE, PyOpal::PyOpalObjectNS::FLOATLIST, PyOpal::PyOpalObjectNS::INT, Attributes::setBool(), Attributes::setReal(), Attributes::setRealArray(), Attributes::setString(), and PyOpal::PyOpalObjectNS::STRING.

Here is the call graph for this function:

◆ setAttribute() [2/2]

template<class C >
void PyOpal::PyOpalObjectNS::PyOpalObject< 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)

◆ setOpalName()

template<class C >
void PyOpal::PyOpalObjectNS::PyOpalObject< C >::setOpalName ( PyOpalObject< C > &  pyobject,
std::string  name 
)
staticprotected

Definition at line 383 of file PyOpalObject.h.

References PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared(), and name.

Here is the call graph for this function:

Member Data Documentation

◆ attributes

template<class C >
static std::vector< AttributeDef > PyOpal::PyOpalObjectNS::PyOpalObject< C >::attributes
staticprotected

Definition at line 193 of file PyOpalObject.h.

◆ bfieldUnits_m

template<class C >
double PyOpal::PyOpalObjectNS::PyOpalObject< C >::bfieldUnits_m = 1
staticprotected

Definition at line 258 of file PyOpalObject.h.

◆ classDocstring

template<class C >
static std::string PyOpal::PyOpalObjectNS::PyOpalObject< C >::classDocstring
staticprotected

class data (attributes)

Definition at line 194 of file PyOpalObject.h.

◆ converterRegistered

template<class C >
static bool PyOpal::PyOpalObjectNS::PyOpalObject< C >::converterRegistered
staticprotected

class docstring

Definition at line 195 of file PyOpalObject.h.

◆ distanceUnits_m

template<class C >
double PyOpal::PyOpalObjectNS::PyOpalObject< C >::distanceUnits_m = 1
staticprotected

Definition at line 256 of file PyOpalObject.h.

◆ efieldUnits_m

template<class C >
double PyOpal::PyOpalObjectNS::PyOpalObject< C >::efieldUnits_m = 1
staticprotected

Definition at line 259 of file PyOpalObject.h.

◆ getFieldValueDocString

template<class C >
const std::string PyOpal::PyOpalObjectNS::PyOpalObject< C >::getFieldValueDocString
staticprotected

Definition at line 260 of file PyOpalObject.h.

◆ object_m

template<class C >
std::shared_ptr< C > PyOpal::PyOpalObjectNS::PyOpalObject< C >::object_m
protected

set to true if the converter has been registered

Definition at line 196 of file PyOpalObject.h.

Referenced by PyOpal::PyOpalObjectNS::PyOpalObject< C >::getOpalShared().

◆ timeUnits_m

template<class C >
double PyOpal::PyOpalObjectNS::PyOpalObject< C >::timeUnits_m = 1
staticprotected

Definition at line 257 of file PyOpalObject.h.


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