-
Notifications
You must be signed in to change notification settings - Fork 5
Tweaks #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweaks #28
Changes from all commits
dcf004d
43b1fa0
767078d
02f70f0
231ce53
bb90e6c
b7ec136
d88476b
3e2e696
f695688
6f1bafe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
|
|
||
|
|
||
| class Element(object): | ||
|
|
||
| def __init__(self, name, length, element_type): | ||
| """An element of the ring. | ||
|
|
||
|
|
@@ -25,6 +26,7 @@ def __init__(self, name, length, element_type): | |
| self.families = set() | ||
| self._uc = dict() | ||
| self._devices = dict() | ||
| self._model = None | ||
|
|
||
| def __str__(self): | ||
| """Auxiliary function to print out an element. | ||
|
|
@@ -36,6 +38,9 @@ def __str__(self): | |
| """ | ||
| return 'Element: {0}, length: {1}, families: {2}'.format(self._name, self._length, self.families) | ||
|
|
||
| def set_model(self, model): | ||
| self._model = model | ||
|
|
||
| def get_fields(self): | ||
| """Get the fields defined on an element. | ||
|
|
||
|
|
@@ -86,7 +91,7 @@ def add_to_family(self, family): | |
| """ | ||
| self.families.add(family) | ||
|
|
||
| def get_pv_value(self, field, handle, unit=pytac.ENG, sim=False): | ||
| def get_value(self, field, handle, unit=pytac.ENG, sim=False): | ||
| """Get the value of a pv. | ||
|
|
||
| Returns the value of a pv on the element. This value is uniquely | ||
|
|
@@ -117,12 +122,12 @@ def get_pv_value(self, field, handle, unit=pytac.ENG, sim=False): | |
| else: | ||
| raise PvException("No device associated with field {0}".format(field)) | ||
| else: | ||
| value = self._physics.get_value(field, handle, unit) | ||
| value = self._model.get_value(field) | ||
| if unit == pytac.ENG: | ||
| value = self._uc[field].eng_to_phys(value) | ||
| value = self._uc[field].phys_to_eng(value) | ||
| return value | ||
|
|
||
| def put_pv_value(self, field, value, unit=pytac.ENG, sim=False): | ||
| def set_value(self, field, value, unit=pytac.ENG, sim=False): | ||
| """Set the pv value on a uniquely identified device. | ||
|
|
||
| This value can be set on the machine or the simulation. | ||
|
|
@@ -150,7 +155,7 @@ def put_pv_value(self, field, value, unit=pytac.ENG, sim=False): | |
| else: | ||
| if unit == pytac.ENG: | ||
| value = self._uc[field].eng_to_phys(value) | ||
| self._physics.put_value(field, value) | ||
| self._model.set_value(field, value) | ||
|
|
||
| def get_pv_name(self, field, handle='*'): | ||
| """ Get a pv name on a device. | ||
|
|
@@ -172,7 +177,7 @@ def get_pv_name(self, field, handle='*'): | |
| try: | ||
| return self._devices[field].get_pv_name(handle) | ||
| except KeyError: | ||
| raise PvException('Element has no device for field {}'.format(field)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this exception be renamed to something more generic, CsException perhaps?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. |
||
| raise PvException('{} has no device for field {}'.format(self, field)) | ||
|
|
||
| def get_cs(self, field): | ||
| return self._devices[field].get_cs() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,8 +63,12 @@ def test_load_quad_family(lattice): | |
| def test_load_correctors(lattice): | ||
| hcm = lattice.get_elements('HSTR') | ||
| vcm = lattice.get_elements('VSTR') | ||
| assert len(hcm) == 173 | ||
| assert len(vcm) == 173 | ||
| # these are the same elements with both devices on each | ||
| assert hcm == vcm | ||
| for element in hcm: | ||
| # each one has both a0 (VSTR) and b0 (HSTR) as fields | ||
| assert set(('a0', 'b0')).issubset(element.get_fields()) | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in some transfer lines or the injectors there are steerers in a single plane.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This module is designed to check specifically the loading of the VMX lattice, as opposed to something more generic. It's pretty useful for testing that everything is as it should be for Diamond, but it's generally OK because I think bundling the data for a machine is useful for anyone else using this. We could make this a bit clearer in the module name and comments. |
||
| @pytest.mark.parametrize('field', ('x', 'y')) | ||
| def test_bpm_unitconv(lattice, field): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,6 +139,8 @@ function insertpvs(index, pvs) | |
| field = 'b1'; | ||
| elseif strcmp(type, 'SEXT') | ||
| field = 'b2'; | ||
| elseif strcmp(type, 'VSTR') | ||
| field = 'a0'; | ||
| else | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be more robust to check the type here as well?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. This was a shortcut because everything left was either a bending magnet or a horizontal steerer. |
||
| field = 'b0'; | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should pv be removed from the comment as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.