TWiki> CMSPublic Web>WorkBookAssociationMap (revision 2)EditAttachPDF

AssociationMap

Introduction

In many case it is convenient to associate quantities to objects existing in a collections. This is true for different reasons, some of what could be:

  • we can add extra information to an object without modifying its structure
  • reprocessing only the associated quantities without need to reprocess the main object
  • give the possibility to drop the extra information when writing to disk and save disk space

We provide a generic association map implementation that uses EDM persistent references (edm::Ref<..>) in the template:

  • AssociationMap<T>

where T is one of different possible helper classes described below.

Different Types of AssociationMap

Different types of AssociationMap are supported and can be used specifying different types of template argument type to AssociationMap<T>. The supported types are:

  • edm::OneToValue <CKey, Val, index>: associates an object of type Val to an object in a collection of type CKey. The associated object is contained by value in the map. The reference to the object in the collection of type CKey is stored as an index of type index, which, by default, is the type unsigned int. Shorter indices can be used for collections with small number of objects in order to save some disk space.
  • edm::OneToOne <CKey, CVal, index>: associates an object in a collection of type CVal to an objects in a collection of type CKey. The association is stored by reference in the map. As before, the reference to the object in the collection of type CKey is stored as an index of type index.
  • edm::OneToMany <CKey, CVal, index>: associates many objects in a collection of type CVal to an objects in a collection of type CKey.
  • edm::OneToManyWithQuality <CKey, CVal, Q, index>: associates many objects in a collection of type CVal to an objects in a collection of type CKey. The association is stored by reference in the map in conjunction with an object of type Q that is intended to measure the quality of the match. The class Q should support the operator " < ".

Data Storage in an AssociationMap

With the exeption of data stored by value in AssociationMap<OneToValue> type, references to objects are stored as indices that are by default of type unsigned int, but can be of different types, to save disk space, if thy refer to collections with a small number of objects. A reference to the collection as a whole (edm::RefProd<...>), which contains the product identifier of the collection (again an unsigned integer index) is stored only once in the AssociationMap. So, the total size of a map containing N association is determined by:

  • one product identifier for the main collection of type CKey
  • one product identifier for the associated collection of type CVal (not stored for OneToValue map)
  • N indices for the associated objects in the collection of type CKey
  • either:
    • N objects of type Val, for OneToValue map
    • N indices for the associated objects from the collection of type CVal for OneToOne map
    • N vectors of indices for the type OneToMany map
    • N vectors of indices plus quality Q pair for the type OneToManyWithQuality map

AssociationMap Interface

The AssociationMap interface is designed in a way similar to std::map, from the Standard C++ Library.

Whenever the associated object is accessed by reference, a persistent edm::Ref<..> is used in place of a C++ reference.

An example of how to fill and retrieve objects from an AssociationMap is the following, that associates multiple references to tracks to jets:

  typedef 
    edm::AssociationMap<
      edm::OneToMany<CaloJetCollection, TrackCollection> 
    > JetTracksMap;

  JetTracksMap map;

  CaloJetRef rj = ...; 
  TrackRef rt = ...;
  map->insert( rj, rt );
  const TrackRefVector & tracks = map[ rj ];

  JetTracksMap::const_iterator i = map.find( rj );
  assert( i != map.end() );
  const CaloJetRef & jet1 = i->key;
  const TrackRefVector & tracks1 = i->val;

Generating AssociationMap Dictionaries

In order to create a dictionary to insert AssociationMap objects in the event, the following guidelines should be followed:

  • references to products (collections) are stored using the template type edm::helpers::KeyVal<CKey, CVal> for all maps except for OneToValue, which needs one one reference, and uses the template edm::helpers::Key&CKey>. Those template specializations should be added to the dictionary
  • the internally stored map type should be added added to the dictionary if not already defined in DataFormats/Common library. In particular:
    • AssociationMap<OneToValue<CKey, Val, index> > requires std::map<index, Val> that is already defined in DataFormats/Common for some trivial cases of the type Val
    • AssociationMap<OneToOne<CKey, CVal, index> > requires std::map<index, index> that in most of the cases is already defined in DataFormats/Common library
    • AssociationMap<OneToMany<CKey, CVal, index> > requires std::map<index, std::vector<index> > that in most of the cases is         already defined in =DataFormats/Common library
    • AssociationMap<OneToManyWithQuality<CKey, CVal, Q, index> > requires =std::map<index, std::vector< std::pair< index, Q > > >
  • the type =edm::AssociationMap<...> should be added
  • the wrapper edm::Wrapper<edm::AssociationMap<...> > should be added declaring the field transientMap_ as transient data member

The table below summarises the internally stored map type for the different association map types.

map type required internal map availability of dictionary in DataFormats/Common
OneToValue<CKey, Val, index> std::map<index, Val> defined for Val identical to index and of type undigned long, unsigned int, unsigned short
OneToOne<CKey, CVal, index> std::map<index, index> defined for index of type undigned long, unsigned int, unsigned short
OneToMany<CKey, CVal, index> =std::map<index, std::vector<index> > defined for index of type undigned long, unsigned int, unsigned short
OneToManyWithQuality<CKey, CVal, Q, index> std::map<index, std::vector< std::pair< index, Q > > > not available

An example of dictionary generation is the following that associates many tracks to a jet, inspired from DataFormats/BTauReco:

<lcgdict>
  <class name="edm::helpers::KeyVal<edm::RefProd<std::vector<reco::CaloJetCollection> >, edm::RefProd<std::vector<reco::TrackCollection> > >" />
  <class name="edm::AssociationMap<edm::OneToMany<std::vector<reco::CaloJet>, std::vector<reco::Track>, unsigned int > >">
    <field name="transientMap_" transient="true" />
  </class>
  <!-- the dictionary for std::map<unsigned int, std::vector<unsigned int> > is not needed
         because it is defined in DataFormats/Common library -->
</lcgdict>


Luca Lista - 11 Oct 2006

Edit | Attach | Watch | Print version | History: r21 | r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r2 - 2006-10-11 - LucaLista


ESSENTIALS

ADVANCED TOPICS


 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback