Project

General

Profile

Feature #18788

functions like util::for_each_associated_group and util::associated_groups not relying on the presence of at least one associated object per element

Added by Giuseppe Cerati over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Category:
Library
Target version:
-
Start date:
01/24/2018
Due date:
% Done:

100%

Estimated time:
2.00 h
Spent time:
Experiment:
LArSoft
Co-Assignees:
Duration:

Description

see: http://nusoft.fnal.gov/larsoft/doxsvn/html/namespaceutil.html#a19cc23cf942017f81281aeee4c7ba4c1
for_each_associated_group requires that e.g. for associations of each track to its hits, each track must have at least one associated hit.
this is not necessarily true for other kind of associations, especially those involving PFParticles


Related issues

Blocked by LArSoft - Milestone #18796: Adopt art 2.10Closed01/25/2018

Associated revisions

Revision af92b912 (diff)
Added by Gianluca Petrillo over 2 years ago

Added `util::associated_groups_with_left()` utility function.

With the customary unit tests.
This solves feature request from issue #18788.

History

#1 Updated by Gianluca Petrillo over 2 years ago

  • Category set to Library
  • Status changed from New to Feedback
  • Experiment LArSoft added
  • Experiment deleted (-)

An additional function art::for_each_group_with_left() is offered by art v02_10_01, which calls the function in argument for each key which has at least one associated object (in the example, for every track that has associated hits), just like lar::for_each_associated_group(), but reports also which is the associated key object (in the example, which track the hits refer to).

Is this fulfilling the request? if not, we may need a more precise example of intended use.

Note that this is not available yet in LArSoft.

#2 Updated by Giuseppe Cerati over 2 years ago

Is this available also for an "associated_groups"-like function?

#3 Updated by Gianluca Petrillo over 2 years ago

#4 Updated by Gianluca Petrillo over 2 years ago

  • Status changed from Feedback to New

No, just like associated_groups() is not available in art.
If that is part of this request, additional code will have to be developed.

#5 Updated by Giuseppe Cerati over 2 years ago

I think 'associated_groups' is very useful since it directly returns the groups and there may be use cases for which one does not want to do loop over all keys.
So I consider it part of the request (but probably not super high priority).

#6 Updated by Gianluca Petrillo over 2 years ago

lar::associated_groups() gets away with it easily, because it has to return only a range1 of single objects, let's call it Range<art::Ptr<recob::Hit>>.
In the case of the request, two objects need to be returned. I would propose as return type a range of std::pair<art::Ptr<recob::Track>, Range<art::Ptr<recob::Hit>>>.
The user will have to access first and second, until we have C++17 enabled. At that point, structured binding can be used:

for (auto const& [track, hits]: lar::associated_groups_with_key(...)) { ... }

1 This "range" is an opaque objects behaving as a collection.

#7 Updated by Lynn Garren over 2 years ago

  • Status changed from New to Assigned
  • Assignee set to Gianluca Petrillo

Giuseppe approves of this proposal.

#8 Updated by Gianluca Petrillo over 2 years ago

  • Status changed from Assigned to Work in progress
  • Estimated time set to 2.00 h

#9 Updated by Gianluca Petrillo over 2 years ago

  • % Done changed from 0 to 100

A function uti::associated_groups_with_left() has been added to lardata/Utilities/ForEachAssociatedGroup.h, with its unit test.
The function is named after the related art::for_each_group_with_left(). Unit test is provided as usual, and the documentation is in Doxygen format.
An example of usage from the unit test parsing an association of integers and strings:

auto const& int_to_str_assns = *e.getValidHandle<art::Assns<int, std::string>>(fInputLabel);

for (auto const& group: util::associated_groups_with_left(int_to_str_assns))
   {
      auto const& key = std::get<0>(group);  // group.first also ok
      auto const& strs = std::get<1>(group); // group.second also ok

      std::cout << "#" << (*key) << " (" << key << ")" << std::endl;
      for(art::Ptr<std::string> const& s: strs) {
         std::cout << " - " << s << " \"" << *s << "\"" << std::endl;
      }
   } // for associated groups

#10 Updated by Gianluca Petrillo over 2 years ago

  • Status changed from Work in progress to Resolved

The new feature is merged in develop branch of lardata repository.

#11 Updated by Gianluca Petrillo over 2 years ago

  • Status changed from Resolved to Closed


Also available in: Atom PDF