3.10.1.3. opengate.base

3.10.1.3.1. Classes

MetaSingletonFatal

GateSingletonFatal

MetaUserInfo

GateObject

This is the base class used for all objects that handle user input in GATE.

DynamicGateObject

This is the base class used for all objects that handle user input in GATE.

GateUserInputSwitchDict

NOT USED YET!

3.10.1.3.2. Functions

process_cls(cls)

The factory function is meant to process classes inheriting from GateObject.

wrap_init_method(cls)

This is a factory function to process classes which inherit from GateObject.

check_property_name(name)

check_property(property_name, value, defaultvalue)

digest_user_info_defaults(cls)

add_properties_to_class(cls, user_info_defaults)

Add user_info defaults as properties to class if not yet present.

_make_property(property_name, default_value[, ...])

Return a property that stores the user_info item in a

make_docstring_for_user_info(name, default_value, options)

make_docstring(cls, user_info_defaults)

restore_userinfo_properties(cls, attributes)

recursive_userinfo_to_dict(obj)

Walk recursively across entries of user_info and convert to appropriate structure.

find_paths_in_gate_object_dictionary(go_dict[, ...])

recursively_search_object(obj[, condition])

find_all_gate_objects(dct)

find_all_paths(dct)

_get_user_info_options(user_info_name, object_type, ...)

Utility function to retrieve the options associated with a user info given the class name,

create_gate_object_from_dict(dct)

Function to (re-)create an object derived from GateObject based on a dictionary.

3.10.1.3.3. Module Contents

class opengate.base.MetaSingletonFatal[source]

Bases: type

_instances[source]
__call__(*args, **kwargs)[source]
class opengate.base.GateSingletonFatal[source]
class opengate.base.MetaUserInfo[source]

Bases: type

_created_classes[source]
__call__(*args, **kwargs)[source]
opengate.base.process_cls(cls)[source]

The factory function is meant to process classes inheriting from GateObject. It digests the user info parametrisation from all classes in the inheritance tree and enhances the __init__ method, so it calls the __finalize_init__ method at the very end of the __init__ call, which is required to check for invalid attribute setting.

opengate.base.wrap_init_method(cls)[source]

This is a factory function to process classes which inherit from GateObject. It is called from the main factory function process_cls(). This function wraps and reattaches the __init__ method of this class, if it implements one. The wrapped __init__ first calls the “original” __init__ and subsequently the method __finalize_init__, which has a base implementation in GateObject, in case the __init__ is the furthest down in the inheritance chain. The method __finalize_init__ is needed to allow GateObject.__setattr__ to check for invalid attribute setting.

opengate.base.check_property_name(name)[source]
opengate.base.check_property(property_name, value, defaultvalue)[source]
opengate.base.digest_user_info_defaults(cls)[source]
opengate.base.add_properties_to_class(cls, user_info_defaults)[source]

Add user_info defaults as properties to class if not yet present.

opengate.base._make_property(property_name, default_value, options=None, container_dict=None)[source]

Return a property that stores the user_info item in a dictionary which is an attribute of the object (self).

opengate.base.make_docstring_for_user_info(name, default_value, options)[source]
opengate.base.make_docstring(cls, user_info_defaults)[source]
opengate.base.restore_userinfo_properties(cls, attributes)[source]
class opengate.base.GateObject(*args, simulation=None, **kwargs)[source]

This is the base class used for all objects that handle user input in GATE.

The class is assumed to be processed by process_cls(), either explicitly or via the metaclass MetaUserInfo, before any instances of the class are created. Some class attributes, e.g. inherited_user_info_defaults, are created as part of this processing.

name: str[source]
inherited_user_info_defaults: dict[source]
user_info_defaults[source]
classmethod has_been_processed()[source]
_simulation[source]
number_of_warnings = 0[source]
_temporary_warning_cache = [][source]
user_info[source]
property simulation[source]
__str__()[source]
__getstate__()[source]

Method needed for pickling. May be overridden in inheriting classes.

__setstate__(d)[source]

Method needed for pickling. May be overridden in inheriting classes.

__reduce__()[source]

This method is called when the object is pickled. Usually, pickle works well without this custom __reduce__ method, but objects handling user_infos need a custom __reduce__ to make sure the properties linked to the user_infos are properly created

The return arguments are: 1) A callable used to create the instance when unpickling 2) A tuple of arguments to be passed to the callable in 1 3) The dictionary of the object’s properties to be passed to the __setstate__ method (if defined)

__setattr__(key, value)[source]
__enter__()[source]
__exit__(exception_type, exception_value, traceback)[source]
__finalize_init__()[source]

This method should be called once all attributes have been defined, usually at the end of the __init__ method. It defines the set of known_attribues that will be used to detect errors when the user tries to use a new attribute or misspells an attribute, e.g. box.mohter instead of box.mother.

__add_to_simulation__()[source]

Hook method which can be called by managers. Specific classes can use this to implement actions to be taken when an object is being added to the simulation, e.g. adding a certain actor implies switching on certain physics options.

property type_name[source]
close()[source]

Dummy implementation for inherited classes which do not implement this method.

release_g4_references()[source]

Dummy implementation for inherited classes which do not implement this method.

copy_user_info(other_obj)[source]
to_dictionary()[source]
from_dictionary(d)[source]
warn_user(message)[source]
class opengate.base.DynamicGateObject(*args, simulation=None, **kwargs)[source]

Bases: GateObject

This is the base class used for all objects that handle user input in GATE.

The class is assumed to be processed by process_cls(), either explicitly or via the metaclass MetaUserInfo, before any instances of the class are created. Some class attributes, e.g. inherited_user_info_defaults, are created as part of this processing.

dynamic_params: List | None[source]
user_info_defaults[source]
property is_dynamic[source]
property dynamic_user_info[source]
process_dynamic_parametrisation(params)[source]
_add_dynamic_parametrisation_to_userinfo(params, name)[source]

This base class implementation only acts as a setter. Classes inheriting from this class should implement an add_dynamic_parametrisation() method which actually does something with the parameters and then call super().add_dynamic_parametrisation(). Inheriting classes should avoid calling this method directly.

add_dynamic_parametrisation(name=None, **params)[source]
create_changers()[source]
class opengate.base.GateUserInputSwitchDict(default_switches, *args, **kwargs)[source]

Bases: box.Box

NOT USED YET!

Specialized version of a Box (dict) to represent a dictionary with boolean switches.

The switches handled by the object need to be defined when the object is created via a dictionary passed as argument ‘default_switches’. No switches can be added later, nor can switches be removed. Switch values are automatically converted to Bool if possible.

_switches[source]
__setitem__(key, value)[source]
abstract __delitem__(key)[source]

The ‘del’ operator applied on items is blocked so no entries can be removed.

__setattr__(key, value)[source]

Make sure to by-pass the __setattr__ method from the Box class for the key ‘_switches’ because Box would otherwise turn this into an entry in self, but we want it to be a pure attribute.

opengate.base.recursive_userinfo_to_dict(obj)[source]

Walk recursively across entries of user_info and convert to appropriate structure. Dictionary-like structures are mapped to dictionary and walked across recursively. List-like structures are mapped to lists and walked across recursively. GateObject-like objects are converted through their to_dictionary() method. All other input (presumably common data types including numpy structures) is left untouched.

opengate.base.find_paths_in_gate_object_dictionary(go_dict, only_input_files=False)[source]
opengate.base.recursively_search_object(obj, condition=lambda x: ...)[source]
opengate.base.find_all_gate_objects(dct)[source]
opengate.base.find_all_paths(dct)[source]
opengate.base._get_user_info_options(user_info_name, object_type, class_module)[source]

Utility function to retrieve the options associated with a user info given the class name, the module in which the class is defined, and the name of the user info.

opengate.base.create_gate_object_from_dict(dct)[source]

Function to (re-)create an object derived from GateObject based on a dictionary.

Used as part of the deserialization chain, when reading simulations stored as JSON file.