Skip to content

Commit

Permalink
not using inner sections
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbrock committed Jan 17, 2025
1 parent 36a121e commit c1bc7d5
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/pynxtools/nomad/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,9 @@ def __create_group(xml_node: ET.Element, root_section: Section):
nx_type = __rename_nx_for_nomad(xml_attrs["type"])

nx_name = xml_attrs.get("name", nx_type.upper())
section_name = __rename_nx_for_nomad(nx_name, is_group=True)
section_name = (
root_section.name + "__" + __rename_nx_for_nomad(nx_name, is_group=True)
)
group_section = Section(validate=VALIDATE, nx_kind="group", name=section_name)

__attach_base_section(group_section, root_section, __to_section(nx_type))
Expand All @@ -651,8 +653,7 @@ def __create_group(xml_node: ET.Element, root_section: Section):
variable=__if_template(nx_name),
)

root_section.inner_section_definitions.append(group_section)

__section_definitions[section_name] = group_section
root_section.sub_sections.append(group_subsection)

__create_group(group, group_section)
Expand Down Expand Up @@ -707,8 +708,13 @@ def __attach_base_section(section: Section, container: Section, default: Section
a base-section with a suitable base.
"""
try:
newdefinitions = {}
for def_name, act_def in container.all_sub_sections.items():
newdefinitions[def_name] = act_def.sub_section
base_section = nexus_resolve_variadic_name(
container.all_inner_section_definitions, section.name, filter=default
newdefinitions,
section.name.split("__")[-1],
filter=default,
)
except ValueError:
base_section = None
Expand Down Expand Up @@ -855,7 +861,7 @@ def __add_section_from_nxdl(xml_node: ET.Element) -> Optional[Section]:
return None


def __create_package_from_nxdl_directories(nexus_section: Section) -> Package:
def __create_package_from_nxdl_directories() -> Package:
"""
Creates a metainfo package from the given nexus directory. Will generate the
respective metainfo definitions from all the nxdl files in that directory.
Expand All @@ -875,16 +881,28 @@ def __create_package_from_nxdl_directories(nexus_section: Section) -> Package:
sections.append(section)
sections.sort(key=lambda x: x.name)

nexus_sections = {}
for section_name in ["_Applications", "_BaseSections"]: # , '_InnerSections']:
nexus_sections[section_name] = Section(validate=VALIDATE, name=section_name)
package.section_definitions.append(nexus_sections[section_name])
for section in sections:
package.section_definitions.append(section)
if section.nx_category == "application" or (
section.nx_category == "base" and section.nx_name == "NXroot"
):
nexus_section.sub_sections.append(
if section.nx_category == "application":
nexus_sections["_Applications"].sub_sections.append(
SubSection(section_def=section, name=section.name)
)
elif section.nx_category == "base" and section.nx_name == "NXroot":
nexus_sections["_Applications"].sub_sections.append(
SubSection(section_def=section, name=section.name)
)
elif section.nx_category == "base":
nexus_sections["_BaseSections"].sub_sections.append(
SubSection(section_def=section, name=section.name)
)
for section_name in __section_definitions:
if "__" in section_name:
package.section_definitions.append(__section_definitions[section_name])

package.section_definitions.append(nexus_section)
return package


Expand Down Expand Up @@ -916,14 +934,6 @@ def init_nexus_metainfo():
if nexus_metainfo_package is not None:
return

# We take the application definitions and create a common parent section that allows
# to include nexus in an EntryArchive.
# To be able to register it into data section, it is expected that this section inherits from Schema.
nexus_section = Section(
validate=VALIDATE, name=__GROUPING_NAME, label=__GROUPING_NAME
)
nexus_section.base_sections = [Schema.m_def]

# try:
# load_nexus_schema('')
# except Exception:
Expand All @@ -932,7 +942,7 @@ def init_nexus_metainfo():
# save_nexus_schema('')
# except Exception:
# pass
nexus_metainfo_package = __create_package_from_nxdl_directories(nexus_section)
nexus_metainfo_package = __create_package_from_nxdl_directories()
nexus_metainfo_package.section_definitions.append(NexusMeasurement.m_def)

# We need to initialize the metainfo definitions. This is usually done automatically,
Expand Down

0 comments on commit c1bc7d5

Please sign in to comment.