Go to the documentation of this file.00001 #ifndef CommonTools_UtilAlgos_AssociationVector2ValueMap_h
00002 #define CommonTools_UtilAlgos_AssociationVector2ValueMap_h
00003
00004
00005
00006
00007
00008
00009
00010 #include "DataFormats/Common/interface/AssociationVector.h"
00011 #include "DataFormats/Common/interface/ValueMap.h"
00012 #include "FWCore/Framework/interface/EDProducer.h"
00013 #include "FWCore/Utilities/interface/InputTag.h"
00014
00015 template<typename KeyRefProd, typename CVal>
00016 class AssociationVector2ValueMap : public edm::EDProducer {
00017 public:
00018 AssociationVector2ValueMap(const edm::ParameterSet&);
00019 private:
00020 typedef edm::AssociationVector<KeyRefProd, CVal> av_t;
00021 typedef typename CVal::value_type value_t;
00022 typedef edm::ValueMap<value_t> vm_t;
00023 typedef typename av_t::CKey collection_t;
00024 void produce(edm::Event&, const edm::EventSetup&);
00025 edm::InputTag av_;
00026 };
00027
00028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "DataFormats/Common/interface/Handle.h"
00031 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
00032 #include "DataFormats/Common/interface/CloneTrait.h"
00033
00034 template<typename KeyRefProd, typename CVal>
00035 AssociationVector2ValueMap<KeyRefProd, CVal>::AssociationVector2ValueMap(const edm::ParameterSet& cfg) :
00036 av_(cfg.template getParameter<edm::InputTag>("src")) {
00037 produces<vm_t>();
00038 }
00039
00040 template<typename KeyRefProd, typename CVal>
00041 void AssociationVector2ValueMap<KeyRefProd, CVal>::produce(edm::Event& evt, const edm::EventSetup&) {
00042 using namespace edm;
00043 using namespace std;
00044 Handle<av_t> av;
00045 evt.getByLabel(av_, av);
00046
00047 auto_ptr<vm_t> vm(new vm_t);
00048 typename vm_t::Filler filler(*vm);
00049 filler.fill();
00050 size_t size = av->size();
00051 vector<value_t> values;
00052 values.reserve(size);
00053 for(typename av_t::const_iterator i = av->begin(); i != av->end(); ++i) {
00054 values.push_back(i->second);
00055 }
00056 filler.insert(av->keyProduct(), values.begin(), values.end());
00057 evt.put(vm);
00058 }
00059
00060 #endif