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