Feature #18769

Uniform art::Assns iterator interface

Added by Gianluca Petrillo about 2 years ago. Updated about 1 year ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:
1.00 h
Spent time:
SSI Package:


While attempting some generic programming with art::Assns, I have faced a few inconsistencies in the iterator interface:

  1. the iterator is called assn_iterator in simple art::Assns, const_iterator in the ones with metadata
  2. there is no type data_t type in art::Assns with no metadata; while it is an understandable choice, having set it to void would have been easier to deal with
  3. the art::AssnsNode class does not exposes which types it contains (e.g. first_type, second_type)
  4. the art::AssnsNode class does not support tuple interface (std::tuple_element and std::get())

While I could work around each of these, I think it would be better to have them "right" in the original code. Please consider fixing any of these details.


#1 Updated by Kyle Knoepfel about 2 years ago

  • Description updated (diff)
  • Status changed from New to Accepted

We are willing to provide features 1, 3 and 4. We argue that since an art::Assns<A,B> type has no data attributed to the association, the correct metaprogramming approach is for the template to not have a data_t type alias.

#2 Updated by Kyle Knoepfel almost 2 years ago

  • Target version set to Vega

#3 Updated by Kyle Knoepfel over 1 year ago

  • Estimated time set to 1.00 h

#4 Updated by Kyle Knoepfel over 1 year ago

Implemented with commit canvas:943399f. In order to not unnecessarily pollute the std namespace, we have introduced the art::get<> and art::tuple_element(_t) functions/classes. To use these facilities in a seamless way with the STL, the get and tuple_element names should be introduced via using declarations or directives:

using namespace art;

auto const& assns = *e.getValidHandle<Assns<A, B, D>>(tag);

for (auto const& assn : assns) {
  auto const& a1 = get<Ptr<A>>(assn);
  auto const& b1 = get<Ptr<B>>(assn);
  auto const& d1 = get<D>(assn);

  static_assert(std::is_same_v<decltype(a1), tuple_element_t<0, decltype(assn)>>);

  // Explicit type included for clarity, but 'auto' could be used instead
  Ptr<A> const& a2 = get<0>(assn);
  Ptr<B> const& b2 = get<1>(assn);
  D const& d2 = get<2>(assn);

  assert(a1 == a2);
  assert(b1 == b2);
  assert(d1 == d2);

#5 Updated by Kyle Knoepfel over 1 year ago

  • Category set to Infrastructure
  • Status changed from Accepted to Resolved
  • Assignee set to Kyle Knoepfel
  • % Done changed from 0 to 100
  • Experiment LArSoft added
  • Experiment deleted (-)
  • SSI Package art added

#6 Updated by Kyle Knoepfel over 1 year ago

  • Target version changed from Vega to 3.01.00

#7 Updated by Kyle Knoepfel over 1 year ago

  • Target version changed from 3.01.00 to 3.02.00

#8 Updated by Kyle Knoepfel about 1 year ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF