CMS 3D CMS Logo

AssociativeIterator Class Reference


Detailed Description

Author:
Giovanni Petrucciani, SNS Pisa

Allows iteraton on a "new style" associative container (ValueMap, Association) as a collection of std::pair<key, value>.

The key is built on the fly using a helper (ItemGetter) that produces keys given ProductID and index At the moment such a helper is available only in full framework (EdmEventItemGetter<RefType>)

KeyRefType can be Ref<C>, RefToBase<T>, Ptr<T> AssociativeCollection can be ValueMap<V>, Association<C>

Example usage is as follows: Handle<ValueMap<double> > hDiscriminators; iEvent.getByLabel(..., hDiscriminators); AssociativeIterator<RefToBase<Jet>, ValueMap<double> > itBTags(*hDiscriminators, EdmEventItemGetter(iEvent)), endBTags = itBTags.end(); for ( ; itBTags != endBTags; ++itBTags ) { cout << " Jet PT = " << itBTags->first->pt() << ", disc = " << itBTags->second << endl; } or, for edm::Association Handle<Association<GenParticleCollection> > hMCMatch; iEvent.getByLabel(..., hMCMatch); AssociativeIterator<RefToBase<Candidate>, Association<GenParticleCollection> > itMC(*hMCMatch, EdmEventItemGetter(iEvent)), endMC = itMC.end(); for ( ; itMC != endMC; ++itMC ) { cout << " Particle with PT = " << itMC->first->pt() ; if (itMC->second.isNull()) { cout << " UNMATCHED." << endl; } else { cout << " matched. MC PT = " << itMC->second->pt() << endl; } }

Version:
Id:
AssociativeIterator.h,v 1.2 2009/11/04 15:30:19 wmtan Exp