CMS 3D CMS Logo

AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector > Class Template Reference

#include <PhysicsTools/UtilAlgos/interface/AssociationVectorSelector.h>

Inheritance diagram for AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 AssociationVectorSelector (const edm::ParameterSet &)

Private Types

typedef edm::AssociationVector
< KeyRefProd, CVal > 
association_t
typedef association_t::CKey collection_t

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &)

Private Attributes

edm::InputTag association_
KeySelector selectKey_
ValSelector selectVal_


Detailed Description

template<typename KeyRefProd, typename CVal, typename KeySelector = AnySelector, typename ValSelector = AnySelector>
class AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >

Definition at line 17 of file AssociationVectorSelector.h.


Member Typedef Documentation

template<typename KeyRefProd, typename CVal, typename KeySelector = AnySelector, typename ValSelector = AnySelector>
typedef edm::AssociationVector<KeyRefProd, CVal> AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::association_t [private]

Definition at line 21 of file AssociationVectorSelector.h.

template<typename KeyRefProd, typename CVal, typename KeySelector = AnySelector, typename ValSelector = AnySelector>
typedef association_t::CKey AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::collection_t [private]

Definition at line 22 of file AssociationVectorSelector.h.


Constructor & Destructor Documentation

template<typename KeyRefProd, typename CVal, typename KeySelector, typename ValSelector>
AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::AssociationVectorSelector ( const edm::ParameterSet cfg  )  [inline]

Definition at line 36 of file AssociationVectorSelector.h.

00036                                                                                                                            :
00037   association_(cfg.template getParameter<edm::InputTag>("association")),
00038   selectKey_(reco::modules::make<KeySelector>(cfg)),
00039   selectVal_(reco::modules::make<ValSelector>(cfg)) {
00040   std::string alias(cfg.template getParameter<std::string>("@module_label"));
00041   produces<collection_t>().setBranchAlias(alias);
00042   produces<association_t>().setBranchAlias(alias + "Association");
00043 }


Member Function Documentation

template<typename KeyRefProd, typename CVal, typename KeySelector, typename ValSelector>
void AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::produce ( edm::Event evt,
const edm::EventSetup  
) [inline, private, virtual]

Implements edm::EDProducer.

Definition at line 46 of file AssociationVectorSelector.h.

References AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::association_, clone(), edm::Event::getByLabel(), edm::Event::getRefBeforePut(), i, VarParsing::obj, edm::Event::put(), AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::selectKey_, AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::selectVal_, size, and std.

00046                                                                                                                        {
00047   using namespace edm;
00048   using namespace std;
00049   Handle<association_t> association;
00050   evt.getByLabel(association_, association);
00051   auto_ptr<collection_t> selected(new collection_t);  
00052   vector<typename CVal::value_type> selectedValues;
00053   size_t size = association->size();
00054   selected->reserve(size);
00055   selectedValues.reserve(size);
00056   for(typename association_t::const_iterator i = association->begin();
00057       i != association->end(); ++i) {
00058     const typename association_t::key_type & obj = * i->first;
00059     if(selectKey_(obj)&&selectVal_(i->second)) {
00060       typedef typename edm::clonehelper::CloneTrait<collection_t>::type clone_t;
00061       selected->push_back(clone_t::clone(obj));
00062       selectedValues.push_back(i->second);
00063     }
00064   }
00065   // new association must be created after the
00066   // selected collection is full because it uses the size
00067   KeyRefProd ref = evt.getRefBeforePut<collection_t>();
00068   auto_ptr<association_t> selectedAssociation(new association_t(ref, selected.get()));
00069   size = selected->size();
00070   OrphanHandle<collection_t> oh = evt.put(selected);
00071   for(size_t i = 0; i != size; ++i)
00072     selectedAssociation->setValue(i, selectedValues[i]);
00073   evt.put(selectedAssociation);
00074 }


Member Data Documentation

template<typename KeyRefProd, typename CVal, typename KeySelector = AnySelector, typename ValSelector = AnySelector>
edm::InputTag AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::association_ [private]

Definition at line 24 of file AssociationVectorSelector.h.

Referenced by AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::produce().

template<typename KeyRefProd, typename CVal, typename KeySelector = AnySelector, typename ValSelector = AnySelector>
KeySelector AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::selectKey_ [private]

Definition at line 25 of file AssociationVectorSelector.h.

Referenced by AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::produce().

template<typename KeyRefProd, typename CVal, typename KeySelector = AnySelector, typename ValSelector = AnySelector>
ValSelector AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::selectVal_ [private]

Definition at line 26 of file AssociationVectorSelector.h.

Referenced by AssociationVectorSelector< KeyRefProd, CVal, KeySelector, ValSelector >::produce().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:14:50 2009 for CMSSW by  doxygen 1.5.4