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

Add a retarget_snrefs() utility function #374

Merged
merged 4 commits into from
Jan 16, 2025

Conversation

andlaus
Copy link
Member

@andlaus andlaus commented Dec 13, 2024

The problem is that accessing objects specified via short name reference always requires a context that is specific to the path via these objects are accessed; IOW, strictly speaking, resolving SNREFs cannot be done ahead of time (without copying everything for each possible context). Since odxtools is build on the assumption that all references can be resolved when a database is loaded (i.e., ahead of time) and copying everything for each possible context would be quickly running into RAM limitations, we provide retarget_snrefs(), a utility function that re-resolves the SNREFs reachable by a specified diagnostic layer using that diagnostic layer. While this is not a "100% solution" because sometimes contexts of SNREFs are more fine-grained than the diagnostic layer that contains them, it should be a workable solution for about 95% of people who run into this issue.

Usage:

import odxtools
from odxtools.utils import retarget_snrefs

db = odxtools.load_file("MyEcu.pdx")

retarget_snrefs(db, db.ecu_variants.Variant2)

After this, all objects specified via SNREFs reachable by the diagnostic layer "Variant2" will be resolved using the point of view of Variant2. Be aware that only a single variant can be "active" for a given database, i.e., in the example above, accessing a resolved object via a diagnostic layer other than "Variant2" will still yield the same result as for Variant2...

Andreas Lauser <andreas.lauser@mercedes-benz.com>, on behalf of MBition GmbH.
Provider Information

The problem is that accessing object specified via short name
reference always requires a context that is specific to the path via
the object is accessed to; IOW, strictly speaking, resolving SNREFs
cannot be done ahead of time (without copying everything for each
possible context). Since odxtools is build on the assumption that all
references can be resolved when a database is loaded and copying
everything for each possible context would be quickly running into RAM
limitations, we provide `retarget_snrefs()`, a utility function that
re-resolves the SNREFs reachable by a specified diagnostic layer using
that diagnostic layer. While this is not a "100% solution" because
sometimes contexts of SNREFs are more fine-grained than the diagnostic
layer that contains them, it should be a workable solution for about
95% of people who run into this issue.

Usage:

```python
import odxtools
from odxtools.utils import retarget_snrefs

db = odxtools.load_file("MyEcu.pdx")

retarget_snrefs(db, db.ecu_variants.Variant2)
```

After this, all objects specified via SNREFs reachable by the
diagnostic layer "Variant2" will be resolved using the point of view
of Variant2. Be aware that only a single variant can be "active" for a
given database, i.e., in the example above, accessing a resolved
object via a diagnostic layer other than "Variant2" will still yield
the same result as for Variant2...

Signed-off-by: Andreas Lauser <andreas.lauser@mercedes-benz.com>
Signed-off-by: Gerrit Ecke <gerrit.ecke@mercedes-benz.com>
@andlaus andlaus requested a review from kayoub5 December 13, 2024 11:17
@andlaus
Copy link
Member Author

andlaus commented Dec 13, 2024

note: while this does not "solve" #368 and #370, it should help to reduce the pain considerably...

@andlaus
Copy link
Member Author

andlaus commented Dec 13, 2024

@mafei1982: does retargeting the SNREFs to the ECU of interest fix the problem for you?

thanks to [at]kayoub5 for the nudge!

Signed-off-by: Andreas Lauser <andreas.lauser@mercedes-benz.com>
While it does not make much sense to do so (the idea is if the
`SnRefContext` is created internally in the toplevel call to the
function, the `.database` and `.diaglayer` attributes are assigned
automatically), doing it separately makes the code slightly easier to
understand.

thanks to [at]kayoub5 for the catch!

Signed-off-by: Andreas Lauser <andreas.lauser@mercedes-benz.com>
@andlaus
Copy link
Member Author

andlaus commented Jan 16, 2025

@kayoub5: do you see any issues which prevents merging this one?

(Actually I don't really see the point of the long names in addition
to descriptions, but that's a different matter...)

Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
@kayoub5
Copy link
Collaborator

kayoub5 commented Jan 16, 2025

@kayoub5: do you see any issues which prevents merging this one?

I don't see code issues, but the concept itself feels.... wrong

@andlaus
Copy link
Member Author

andlaus commented Jan 16, 2025

I don't see code issues, but the concept itself feels.... wrong

If you mean the concept of short name refs, I agree ;). Anyway, since it is okay with you and this functionality comes with zero side effects for people who don't have "Schrödinger's cat in a box"-type ECUs, I'll merge this...

@andlaus andlaus merged commit 30fb09b into mercedes-benz:main Jan 16, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants