From e44dc7f83a4ea74e190902d079c33246e882d9a0 Mon Sep 17 00:00:00 2001 From: Sherjeel Shabih Date: Tue, 8 Oct 2024 10:28:37 +0200 Subject: [PATCH] Adds a logic to match NX class at the same level when no base_section found --- src/pynxtools/nomad/schema.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pynxtools/nomad/schema.py b/src/pynxtools/nomad/schema.py index 5fbbb6ac8..e149131c4 100644 --- a/src/pynxtools/nomad/schema.py +++ b/src/pynxtools/nomad/schema.py @@ -553,7 +553,9 @@ def __create_group(xml_node: ET.Element, root_section: Section): nx_name = xml_attrs.get("name", nx_type) group_section = Section(validate=VALIDATE, nx_kind="group", name=nx_name) - __attach_base_section(group_section, root_section, __to_section(nx_type)) + __attach_base_section( + group_section, root_section, __to_section(nx_type), nx_type + ) __add_common_properties(group, group_section) nx_name = xml_attrs.get( @@ -577,7 +579,9 @@ def __create_group(xml_node: ET.Element, root_section: Section): __create_field(field, root_section) -def __attach_base_section(section: Section, container: Section, default: Section): +def __attach_base_section( + section: Section, container: Section, default: Section, section_nx_type: str = "" +): """ Potentially adds a base section to the given section, if the given container has a base-section with a suitable base. @@ -586,7 +590,11 @@ def __attach_base_section(section: Section, container: Section, default: Section if base_section: assert base_section.nx_kind == section.nx_kind, "Base section has wrong kind" else: - base_section = default + for base_sec_def in container.all_inner_section_definitions.values(): + if base_sec_def.more["nx_type"][2:] == section_nx_type[2:]: + base_section = base_sec_def + if not base_section: + base_section = default section.base_sections = [base_section]