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

Allow for open enumerations #1521

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion base_classes/NXobject.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
For example, all IGSNs (see below) are DOIs and all DOIs are Handles; however, an IGSN should have type IGSN (and not DOI or Hdl).
Similarly, an ARK, Purl, ORCID and ROR identifiers should have their corresponding types and should not use the more generic URL identifier.
</doc>
<enumeration>
<enumeration open="true">
<item value="ARK">
<doc>
Archival Resource Key.
Expand Down
2 changes: 1 addition & 1 deletion base_classes/NXsensor.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</group>
<field name="measurement">
<doc>name for measured signal</doc>
<enumeration>
<enumeration open="true">
<item value="temperature" />
<item value="pH" />
<item value="magnetic_field" />
Expand Down
5 changes: 2 additions & 3 deletions base_classes/NXsource.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</field>
<field name="type">
<doc>type of radiation source (pick one from the enumerated list and spell exactly)</doc>
<enumeration>
<enumeration open="true">
<item value="Spallation Neutron Source" />
<item value="Pulsed Reactor Neutron Source" />
<item value="Reactor Neutron Source" />
Expand Down Expand Up @@ -165,10 +165,9 @@
</group>
<field name="mode">
<doc>source operating mode</doc>
<enumeration>
<enumeration open="true">
<item value="Single Bunch"><doc>for storage rings</doc></item>
<item value="Multi Bunch"><doc>for storage rings</doc></item>
<!-- other sources could add to this -->
</enumeration>
</field>
<field name="top_up" type="NX_BOOLEAN">
Expand Down
12 changes: 9 additions & 3 deletions dev_tools/docs/nxdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,16 @@ def _print_enumeration(self, indent, ns, parent):
if len(node_list) == 0:
return ""

if len(node_list) == 1:
self._print(f"{indent}Obligatory value:", end="")
if parent.attrib.get("open", "false") == "true":
self._print(
f"{indent}Any of these values or a custom value (if you use a custom value, also set @custom=True):",
end="",
)
else:
self._print(f"{indent}Any of these values:", end="")
if len(node_list) == 1:
self._print(f"{indent}Obligatory value:", end="")
else:
self._print(f"{indent}Any of these values:", end="")

docs = OrderedDict()
for item in node_list:
Expand Down
24 changes: 23 additions & 1 deletion nxdl.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ https://stackoverflow.com/a/48980995/1046449 -->

(This data type is used internally in the NXDL schema
to define elements and attributes to be used by users in NXDL specifications.)

::

<field name="mode">
Expand All @@ -1244,6 +1244,20 @@ https://stackoverflow.com/a/48980995/1046449 -->
</enumeration>
</field>

Enumerations can be closed or open. A closed enumeration is one where the list of
values are the only ones allowed for a specification. An open enumeration is one
where the list of values is incomplete and additional values other than those listed
are allowed. Open enumerations should be used sparingly as the designer of the enumeration
should try to find all possible values for a given field/attribute.

In case an open enumeration is used and the data provider wants to declare that the provided
value deliberately not from the given list of values, the data provider should,

* for fields, set the attribute ``@custom=True``.
* for attributes, set an additional attribute ``@my_attribute_custom=True``, where
``my_attribute`` is the name of the attribute with the open enumeration.

Such attributes can be used deliberately to suppress warnings in NeXus validators.
</xs:documentation>
</xs:annotation>
<xs:sequence>
Expand Down Expand Up @@ -1279,6 +1293,14 @@ https://stackoverflow.com/a/48980995/1046449 -->
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="open" use="optional" type="nx:NX_BOOLEAN" default="false" >
<xs:annotation>
<xs:documentation>
Is this an open enumeration?
An open enumeration allows additional values not listed.
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>

<xs:complexType name="dimensionsType">
Expand Down
Loading