CMS 3D CMS Logo

AssociationVectorSelector.h
Go to the documentation of this file.
1 #ifndef CommonTools_UtilAlgos_AssociationVectorSelector_h
2 #define CommonTools_UtilAlgos_AssociationVectorSelector_h
3 /* \class AssociationVectorSelector
4  *
5  * \author Luca Lista, INFN
6  *
7  * \version $Id: AssociationVectorSelector.h,v 1.2 2010/02/20 20:55:16 wmtan Exp $
8  */
9 
14 
15 template <typename KeyRefProd, typename CVal, typename KeySelector = AnySelector, typename ValSelector = AnySelector>
17 public:
19 
20 private:
23  void produce(edm::Event&, const edm::EventSetup&) override;
25  KeySelector selectKey_;
26  ValSelector selectVal_;
27 };
28 
34 
35 template <typename KeyRefProd, typename CVal, typename KeySelector, typename ValSelector>
37  const edm::ParameterSet& cfg)
38  : associationToken_(consumes<association_t>(cfg.template getParameter<edm::InputTag>("association"))),
39  selectKey_(reco::modules::make<KeySelector>(cfg, consumesCollector())),
40  selectVal_(reco::modules::make<ValSelector>(cfg, consumesCollector())) {
41  std::string alias(cfg.template getParameter<std::string>("@module_label"));
42  produces<collection_t>().setBranchAlias(alias);
43  produces<association_t>().setBranchAlias(alias + "Association");
44 }
45 
46 template <typename KeyRefProd, typename CVal, typename KeySelector, typename ValSelector>
48  const edm::EventSetup&) {
49  using namespace edm;
50  using namespace std;
52  evt.getByToken(associationToken_, association);
53  unique_ptr<collection_t> selected(new collection_t);
54  vector<typename CVal::value_type> selectedValues;
55  size_t size = association->size();
56  selected->reserve(size);
57  selectedValues.reserve(size);
58  for (typename association_t::const_iterator i = association->begin(); i != association->end(); ++i) {
59  const typename association_t::key_type& obj = *i->first;
60  if (selectKey_(obj) && selectVal_(i->second)) {
61  typedef typename edm::clonehelper::CloneTrait<collection_t>::type clone_t;
62  selected->push_back(clone_t::clone(obj));
63  selectedValues.push_back(i->second);
64  }
65  }
66  // new association must be created after the
67  // selected collection is full because it uses the size
68  KeyRefProd ref = evt.getRefBeforePut<collection_t>();
69  unique_ptr<association_t> selectedAssociation(new association_t(ref, selected.get()));
70  size = selected->size();
71  OrphanHandle<collection_t> oh = evt.put(std::move(selected));
72  for (size_t i = 0; i != size; ++i)
73  selectedAssociation->setValue(i, selectedValues[i]);
74  evt.put(std::move(selectedAssociation));
75 }
76 
77 #endif
edm::Event::getRefBeforePut
RefProd< PROD > getRefBeforePut()
Definition: Event.h:158
Handle.h
mps_fire.i
i
Definition: mps_fire.py:428
AssociationVectorSelector::associationToken_
edm::EDGetTokenT< association_t > associationToken_
Definition: AssociationVectorSelector.h:24
AssociationVectorSelector::selectKey_
KeySelector selectKey_
Definition: AssociationVectorSelector.h:25
EDProducer.h
AssociationVectorSelector::AssociationVectorSelector
AssociationVectorSelector(const edm::ParameterSet &)
Definition: AssociationVectorSelector.h:36
AssociationVectorSelector::collection_t
association_t::CKey collection_t
Definition: AssociationVectorSelector.h:22
modules
Definition: MuonCleanerBySegments.cc:35
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm::AssociationVector::CKey
KeyRefProd::product_type CKey
Definition: AssociationVector.h:74
edm
HLT enums.
Definition: AlignableModifier.h:19
AnySelector.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
CloneTrait.h
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::clonehelper::CloneTrait
Definition: CloneTrait.h:12
AssociationVectorSelector
Definition: AssociationVectorSelector.h:16
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:535
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::AssociationVector
Definition: AssociationVector.h:67
edm::AssociationVector::key_type
KeyRef::value_type key_type
Definition: AssociationVector.h:76
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
AssociationVectorSelector::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: AssociationVectorSelector.h:47
AssociationVectorSelector::association_t
edm::AssociationVector< KeyRefProd, CVal > association_t
Definition: AssociationVectorSelector.h:21
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::AssociationVector::const_iterator
transient_vector_type::const_iterator const_iterator
Definition: AssociationVector.h:106
edm::EventSetup
Definition: EventSetup.h:58
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition: ParameterAdapter.h:21
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
AssociationVectorSelector::selectVal_
ValSelector selectVal_
Definition: AssociationVectorSelector.h:26
edm::OrphanHandle
Definition: EDProductfwd.h:39
hgcal::association
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
Definition: LayerClusterAssociatorByEnergyScoreImpl.h:44
SiStripOfflineCRack_cfg.alias
alias
Definition: SiStripOfflineCRack_cfg.py:128
edm::EDProducer
Definition: EDProducer.h:35
ParameterAdapter.h
AssociationVector.h
ParameterSet.h
edm::Event
Definition: Event.h:73
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443