Skip to content
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

Add support for choice element #23

Open
domna opened this issue Feb 19, 2024 · 4 comments
Open

Add support for choice element #23

domna opened this issue Feb 19, 2024 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@domna
Copy link
Collaborator

domna commented Feb 19, 2024

In NXDL one can use a choice element to select out of two elements. We should also support this in this conversion tool.

Here is a link to the manual: https://manual.nexusformat.org/defs_intro.html#choice

@lukaspie
Copy link
Collaborator

I just tried it, it is actually already supported. You can write

choice:
  pass_energy(NX_FLOAT):
    unit: NX_ENERGY
  drift_energy(NX_FLOAT):
    unit: NX_ENERGY

which is translated through nyaml as

<field name="choice">
      <field name="pass_energy" type="NX_FLOAT" units="NX_ENERGY"/>
      <field name="drift_energy" type="NX_FLOAT" units="NX_ENERGY"/>
</field>

The backwards conversion does also work.

So this is just a documentation issue.

@lukaspie lukaspie added the documentation Improvements or additions to documentation label Feb 19, 2024
@domna
Copy link
Collaborator Author

domna commented Feb 19, 2024

Yes, but it is picking up a different syntax. It should be a tag choice, i.e.,

<choice ...>
...
</choie>

@lukaspie
Copy link
Collaborator

Ah right. Anyway, according to the manual, choice is only for groups, so it should not actually work for choosing between different fields of a base class, right? And it should also have a fixed name like pixel_shape in the example in the manual, so just choosing between two different names is also not supported.

@domna
Copy link
Collaborator Author

domna commented Feb 19, 2024

Ah right. Anyway, according to the manual, choice is only for groups, so it should not actually work for choosing between different fields of a base class, right? And it should also have a fixed name like pixel_shape in the example in the manual, so just choosing between two different names is also not supported.

Yes, I actually remembered this incorrectly. I updated my original comment on the drift_energy. However, I think it's also helpful to have the choice element for fields, so I opened an issue for it: nexusformat/definitions#1357

Anyways, I think we should still add the support in nyaml and pynxtools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants