Skip to content

Retrival methods of ElementArray (and subclasses) #196

@gubaidulinvadim

Description

@gubaidulinvadim
  1. It seems that all Simulator/ControlSystem methods get_all_XXX, which I think are based on the ElementHolder class, returns a list and not arrays.
    A small example based on SOLEIL II example notebook:
control_mode = sr.design

bpms = control_mode.get_all_bpms() 
type(bpms) # returns list

bpms = control_mode.get_bpms("BPM")
type(bpms) # returns pyaml.arrays.bpm_array.BPMArray

From what I see, this is the case for all these methods, which prevent using the nice feature of the arrays.

  1. The methods of the ElementHolder class have no docstrings, but they are the ones exposed to the user here.
control_mode.get_bpms?
Signature: control_mode.get_bpms(name: str) -> pyaml.arrays.bpm_array.BPMArray
Docstring: <no docstring>
File:      ~/Python_dev/pyaml/pyaml/pyaml/common/element_holder.py
Type:      method
  1. More of a comment/question: maybe this is me not knowing how to use pyAML but I was thinking that string-matching was implemented at the array level, is it? I was expecting the following code to work:
bpms = control_mode.get_element("BPM*")
---------------------------------------------------------------------------
PyAMLException                            Traceback (most recent call last)
Cell In[74], line 1
----> 1 bpms = control_mode.get_element("BPM*")

File [~/Python_dev/pyaml/pyaml/pyaml/common/element_holder.py:109](http://localhost:8889/home/gamelina/Python_dev/pyaml/pyaml/pyaml/common/element_holder.py#line=108), in ElementHolder.get_element(self, name)
    108 def get_element(self, name: str) -> Element:
--> 109     return self.__get("Element", name, self.__ALL)

File [~/Python_dev/pyaml/pyaml/pyaml/common/element_holder.py:95](http://localhost:8889/home/gamelina/Python_dev/pyaml/pyaml/pyaml/common/element_holder.py#line=94), in ElementHolder.__get(self, what, name, array)
     93 def __get(self, what, name, array) -> Element:
     94     if name not in array:
---> 95         raise PyAMLException(f"{what} {name} not defined")
     96     return array[name]

PyAMLException: Element BPM* not defined

Originally posted by @GamelinAl in #195 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions