Feature #18638

Add to proxy the support for associations with meta data

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

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


Estimated time:
40.00 h
Spent time:


We need to add to proxy the support for associations with meta data!
This is critical for the usability of proxies in the long term.

Associated revisions

Revision 536a1961 (diff)
Added by Gianluca Petrillo almost 3 years ago

Added interface for association metadata in proxy classes

This solves issue #18638:
- withAssociatedMeta() and withAssociatedMetaAs() allow caller to
specify the metadata
- withZeroOrOneMeta() and withZeroOrOneMetaAs() allow caller to
specify the metadata
- a new iterator allows access to the full association information
(left, right, metadata)

The unit test is now using an association with metadata.


#1 Updated by Lynn Garren almost 3 years ago

  • Status changed from New to Assigned
  • Estimated time set to 40.00 h

The interface needs to be designed.

#2 Updated by Gianluca Petrillo almost 3 years ago

In the proposed design and implementation, the access to metadata is currently offered only via iterators (i.e. there is no way to get a collection of only metadata).
To implement this, a change has been made to the iterator values, which used to be just art::Ptr<R> and now is a complex object. While this object behaves mostly as art::Ptr<R>, it's not hard to devise code that stresses the difference. Therefore this is a mildly breaking change. New functions proxy::withAssociatedMeta() and proxy::withZeroOrOneMeta() (and corresponding xxxMetaAs()) issue the request of merging an association with a specified metadata type.
An example of usage of the new interface is in the unit test at lardata:source:lardata/test/RecoBaseProxy/ method ProxyBaseTest::proxyUsageExample(), which now reads:

  auto tracks = proxy::getCollection<std::vector<recob::Track>>(
    event, tracksTag,
    proxy::withAssociatedMeta<recob::Hit, recob::TrackHitMeta>()

  if (tracks.empty()) {
    mf::LogVerbatim("ProxyBaseTest") << "No tracks in '" << tracksTag.encode()
      << "'";

  mf::LogVerbatim("ProxyBaseTest") << "Collection '" << tracksTag.encode()
    << "' contains " << tracks.size() << " tracks.";

  auto onCollection
    = [](recob::Hit const& hit){ return hit.SignalType() == geo::kCollection; };

  for (auto trackInfo: tracks) {

    recob::Track const& track = *trackInfo; // access to the track
    double const startTheta = track.Theta();

    double const length = trackInfo->Length(); // access to track members

    // access to associated data (returns random-access collection-like object)
    decltype(auto) hits = trackInfo.get<recob::Hit>();

    lar::util::StatCollector<float> dQds;
    double charge = 0.0;
    for (auto const& hitInfo: hits) {
      // hitInfo is equivalent to a art::Ptr<recob::Hit>
      double const hitCharge = hitInfo->Integral();
      charge += hitCharge;

      if (onCollection(*hitInfo)) { // 
        double const ds =; // access recob::TrackHitMeta
        if (ds > 0.0) dQds.add(hitCharge / ds);
      } // if on collection

    } // for hits

    mf::LogVerbatim log("ProxyBaseTest");
      << "[#" << trackInfo.index() << "] track ID=" << track.ID()
      << " (" << length << " cm, starting with theta=" << startTheta
      << " rad) deposited charge=" << charge
      << " with " << hits.size() << " hits";
    if (dQds.N() > 0) {
      log << " (<dQ/ds> = " 
        << dQds.Average() << " +/- " << dQds.RMS() << " Q/cm from " 
        << dQds.N() << " hits in collection planes)";

  } // for tracks

The interface is fully exercised in another method of the test module, ProxyBaseTest::testTracks().
More details on the interface are documented in Doxygen for classes proxy::details::AssnsNode and proxy::details::assns_node_iterator.

#3 Updated by Gianluca Petrillo almost 3 years ago

  • Category set to Data products
  • Status changed from Assigned to Resolved
  • % Done changed from 0 to 100

The basic infrastructure is implemented in branch feature/gp_Issue18638 of lardata.
The branch is updated to develop branch as of today (v06_64_00).

#4 Updated by Gianluca Petrillo over 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF