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

Return type from a complex call with an index after it is Any. Should probably not be. #164

Open
gordonwatts opened this issue Feb 4, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@gordonwatts
Copy link
Member

This code:

from typing import Iterable
from func_adl_servicex_xaodr22 import FuncADLQueryPHYSLITE
from func_adl_servicex_xaodr22.type_support import cpp_type
from func_adl_servicex_xaodr22.vector_elementlink_datavector_xaod_muon_v1___ import (
    vector_ElementLink_DataVector_xAOD_Muon_v1___,
)
from func_adl_servicex_xaodr22.elementlink_datavector_xaod_muon_v1__ import (
    ElementLink_DataVector_xAOD_Muon_v1__,
)

# Define the type for std::vector<ElementLink<xAOD::MuonContainer>>
# cpp_vfloat = cpp_type[Iterable[float]]("float", float, "std::vector<float>")
cpp_muon_links = cpp_type[vector_ElementLink_DataVector_xAOD_Muon_v1___](
    "ElementLink<DataVector<xAOD::Muon_v1>>",
    ElementLink_DataVector_xAOD_Muon_v1__,
    "vector<ElementLink<DataVector<xAOD::Muon_v1>>>",
)


query = (
    FuncADLQueryPHYSLITE()
    .Select(lambda e: e.Vertices("BPHY4Quads"))
    .Select(
        lambda vtxs: {
            "x": vtxs.Select(lambda v: v.x()),
            "QUAD_Muon0": vtxs.Select(
                lambda v: v.auxdataConst[cpp_muon_links]("MuonLinks")[0].pt()
            ),
        }
    )
)

Has the v.auxdataConst[cpp_muon_links]("MuonLinks") returning a type of Any rather than the cpp_muon_links.

@gordonwatts gordonwatts added the bug Something isn't working label Feb 4, 2025
@gordonwatts gordonwatts self-assigned this Feb 4, 2025
@gordonwatts
Copy link
Member Author

Looks like it boils down to this guy failing to identify this as an iterable, which it certianly should be:

def _is_iterable_direct(t: Type) -> bool:
    "Is this type iterable?"
    return getattr(t, "_name", None) == "Iterable" or getattr(t, "__name__", None) == "Iterable"

Or - being able to follow it up the list to find out if there is an inherited object that might be an iterable.

This is for type ElementLink_DataVector_xAOD_Muon_v1__ - so, is that directly an iterable, or do you have to deref it first? Hahaha. I wonder if I got caught by that. No - wait - this is not iterable. This is a pointer to the type. Something else is going on here.

@gordonwatts
Copy link
Member Author

Ok - maybe the problem is that the call is:

"Call(func=Attribute(value=Name(id='v', ctx=Load()), attr='auxdataConst_vector_ElementLink_DataVector_xAOD_Muon_v1___', ctx=Load()), args=[Constant(value='MuonLinks')], keywords=[])"

But when we did type resolution it came back as:

"<class 'func_adl_servicex_xaodr22.elementlink_datavector_xaod_muon_v1__.ElementLink_DataVector_xAOD_Muon_v1__'>"

Note that the outter vector got lost.

@gordonwatts
Copy link
Member Author

Ok - further investigation - that Any is probably ok - because after that code deals with a parameterized call. That said, when I define the cpp_muon_links like this:

# Define the type for std::vector<ElementLink<xAOD::MuonContainer>>
cpp_muon_links = cpp_type[Iterable[ElementLink_DataVector_xAOD_Muon_v1__]](
    "ElementLink<DataVector<xAOD::Muon_v1>>",
    Iterable[ElementLink_DataVector_xAOD_Muon_v1__],
    "std::vector<ElementLink<DataVector<xAOD::Muon_v1>>>",
)

it seems to work right, but if you look at the definition for cpp_vfloat you see something different:

cpp_vfloat = cpp_type[Iterable[float]]("float", float, "std::vector<float>")
cpp_vint = cpp_type[Iterable[int]]("int", int, "std::vector<int>")

So - something is wrong. Also - see other things that look wrong in those definitions of cpp_vint, etc. In particular, what is T used for (the type parameter)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant