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

fix: use podio::ObjectID::index in CalorimeterHitDigi #1600

Closed
wants to merge 2 commits into from

Conversation

wdconinc
Copy link
Contributor

Briefly, what does this PR introduce?

Instead of using our own counting index in the loop, we should use the podio::ObjectID index, which is semantically defined as the order in the collection. Reduces locals, but otherwise pedantic.

What kind of change does this PR introduce?

  • Bug fix (issue #__)
  • New feature (issue #__)
  • Documentation update
  • Other: pedanticism, is that even a word?

Please check if this PR fulfills the following:

  • Tests for the changes have been added
  • Documentation has been added / updated
  • Changes have been communicated to collaborators

Does this PR introduce breaking changes? What changes might users need to make to their code?

No.

Does this PR change default behavior?

No.

@wdconinc wdconinc requested review from a team and ruse-traveler and removed request for a team August 24, 2024 01:07
Copy link

merge_map[hid].push_back(ix);

ix++;
merge_map[hid].push_back(ahit.getObjectID().index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the input hit collection is ever becomes a subset collection, e.g. through filtering the hits or merging other collection of hits this will stop working correctly. What could be neater, and safer to cover for these instances, is having a map to a vector of the hits themselves rather than indices?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were actually discussing a similar situation in the context of the track-cluster merge/splitter:
#1406 (comment)

So for my own understanding: if an input collection is somehow a subset (particularly if it's from merging other collections), is there a way to access specific members of that subset safely other than just insertion index (e.g. (*input_collect)[index])?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the full objectID should be relatively safe. I am concerned it might stop being unique when we start moving between events/timeframes, particularly when collecting from several JEvents. My preferred alternative approach, which someone might tell me is bad practice, would be to have a map which uses the pointer to the hit itself as the key/value.

In this case e.g.
std::unordered_map<uint64_t, std::vector<edm4hep::SimCalorimeterHit*>> merge_map;

And in #1406
typedef std::map<edm4eic::ProtoCluster*, bool, CompareObjectID> MapToFlag;

I guess some downsides would be that the variable is linked to a type which using the ObjectID isn't. If there are other issues with this approach hopefully someone else can pitch in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podio separates the user layer from the POD layer. Multiple user layer objects can refer to the same underlying POD data, in particular when they are a mutable and immutable user layer object. Storing a pointer to the user layer is therefore maybe not recommended.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! Thanks for the clarifications @simonge and @wdconinc!

@wdconinc wdconinc marked this pull request as draft August 28, 2024 13:56
@wdconinc
Copy link
Contributor Author

Closing since pedantic and good arguments against this change brought forward in #1600 (comment).

@wdconinc wdconinc closed this Aug 29, 2024
@wdconinc wdconinc deleted the podio-ObjectID-index branch August 29, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants