Skip to content

Commit

Permalink
Add the define_enum metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonwatts committed Mar 25, 2024
1 parent ab94eea commit f35057b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
17 changes: 13 additions & 4 deletions func_adl_xAOD/common/meta_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from copy import copy
from func_adl_xAOD.common.event_collections import EventCollectionSpecification
from func_adl_xAOD.common.cpp_ast import CPPCodeSpecification
from func_adl_xAOD.common.cpp_types import add_method_type_info, collection, terminal
from func_adl_xAOD.common.cpp_types import (
add_method_type_info,
collection,
terminal,
define_enum,
)
from func_adl_xAOD.common.cpp_types import CPPParsedTypeInfo, parse_type
from typing import Any, Dict, List, Union
from dataclasses import dataclass, field
Expand Down Expand Up @@ -134,9 +139,11 @@ def process_metadata(
md["code"],
md["result_name"] if "result_name" in md else "result",
md["return_type"],
bool(md["return_is_collection"])
if "return_is_collection" in md
else False,
(
bool(md["return_is_collection"])
if "return_is_collection" in md
else False
),
md["method_object"] if "method_object" in md else None,
md["instance_object"] if "instance_object" in md else None,
)
Expand Down Expand Up @@ -245,6 +252,8 @@ def process_metadata(
"cms_miniaod", md["name"], md["include_files"], container_type, []
)
cpp_funcs.append(spec)
elif md_type == "define_enum":
define_enum(md["namespace"], md["name"], md["values"])
elif md_type in extended_properties:
r = copy(extended_properties[md_type])
for k in (all_k for all_k in md.keys() if all_k != "metadata_type"):
Expand Down
24 changes: 24 additions & 0 deletions tests/common/test_meta_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from func_adl_xAOD.common import cpp_types
import func_adl_xAOD.common.statement as statement
from func_adl_xAOD.atlas.xaod.event_collections import (
atlas_xaod_event_collection_collection,
Expand Down Expand Up @@ -901,6 +902,29 @@ class TestMetadata:
assert len(specs) == 0


def test_md_define_enum():
"Add an enum"
metadata = [
{
"metadata_type": "define_enum",
"namespace": "xAOD.Jet",
"name": "Color",
"values": ["one", "two", "three"],
}
]

process_metadata(metadata)

ns = cpp_types.get_toplevel_ns("xAOD")
assert ns is not None
ns_jet = ns.get_ns("Jet")
assert ns_jet is not None

e_info = ns_jet.get_enum("Color")
assert e_info is not None
assert len(e_info.values) == 3


# Some integration tests!
# We need to setup a whole dummy dataset so we can test this in isolation of CMS and ATLAS
# code.
Expand Down

0 comments on commit f35057b

Please sign in to comment.