AssociationVector2ValueMap

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#ifndef CommonTools_UtilAlgos_AssociationVector2ValueMap_h
#define CommonTools_UtilAlgos_AssociationVector2ValueMap_h
/* \class AssociationVector2ValueMap
 *
 * \author Luca Lista, INFN
 *
 * \version $Id: AssociationVector2ValueMap.h,v 1.2 2010/02/20 20:55:15 wmtan Exp $
 */

#include "DataFormats/Common/interface/AssociationVector.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Utilities/interface/InputTag.h"

template <typename KeyRefProd, typename CVal>
class AssociationVector2ValueMap : public edm::global::EDProducer<> {
public:
  AssociationVector2ValueMap(const edm::ParameterSet&);

private:
  typedef edm::AssociationVector<KeyRefProd, CVal> av_t;
  typedef typename CVal::value_type value_t;
  typedef edm::ValueMap<value_t> vm_t;
  typedef typename av_t::CKey collection_t;
  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
  edm::EDGetTokenT<av_t> av_;
};

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"
#include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
#include "DataFormats/Common/interface/CloneTrait.h"

template <typename KeyRefProd, typename CVal>
AssociationVector2ValueMap<KeyRefProd, CVal>::AssociationVector2ValueMap(const edm::ParameterSet& cfg)
    : av_(consumes<av_t>(cfg.template getParameter<edm::InputTag>("src"))) {
  produces<vm_t>();
}

template <typename KeyRefProd, typename CVal>
void AssociationVector2ValueMap<KeyRefProd, CVal>::produce(edm::StreamID,
                                                           edm::Event& evt,
                                                           const edm::EventSetup&) const {
  using namespace edm;
  using namespace std;
  Handle<av_t> av;
  evt.getByToken(av_, av);

  unique_ptr<vm_t> vm(new vm_t);
  typename vm_t::Filler filler(*vm);
  filler.fill();
  size_t size = av->size();
  vector<value_t> values;
  values.reserve(size);
  for (typename av_t::const_iterator i = av->begin(); i != av->end(); ++i) {
    values.push_back(i->second);
  }
  filler.insert(av->keyProduct(), values.begin(), values.end());
  evt.put(std::move(vm));
}

#endif