CMS 3D CMS Logo

AnythingToValueMap.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_TagAndProbe_interface_AnythingToValueMap_h
2 #define PhysicsTools_TagAndProbe_interface_AnythingToValueMap_h
3 
8 
12 
13 namespace pat {
14  namespace helper {
15 
16  template <class Adaptor,
17  class Collection = typename Adaptor::Collection,
18  typename value_type = typename Adaptor::value_type>
20  public:
21  typedef typename edm::ValueMap<value_type> Map;
22  typedef typename Map::Filler MapFiller;
23  explicit AnythingToValueMap(const edm::ParameterSet& iConfig)
24  : failSilently_(iConfig.getUntrackedParameter<bool>("failSilently", false)),
25  src_(consumes<Collection>(iConfig.getParameter<edm::InputTag>("src"))),
26  adaptor_(iConfig, consumesCollector()) {
27  produces<Map>(adaptor_.label());
28  }
29  ~AnythingToValueMap() override {}
30 
31  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
32 
33  private:
36  Adaptor adaptor_;
37  };
38 
39  template <class Adaptor, class Collection, typename value_type>
41  const edm::EventSetup& iSetup) {
43  iEvent.getByToken(src_, handle);
44  if (handle.failedToGet() && failSilently_)
45  return;
46 
47  bool adaptorOk = adaptor_.init(iEvent);
48  if ((!adaptorOk) && failSilently_)
49  return;
50 
51  std::vector<value_type> ret;
52  ret.reserve(handle->size());
53 
54  adaptor_.run(*handle, ret);
55 
56  auto map = std::make_unique<Map>();
58  filler.insert(handle, ret.begin(), ret.end());
59  filler.fill();
60  iEvent.put(std::move(map), adaptor_.label());
61  }
62 
63  template <class Adaptor,
64  class Collection = typename Adaptor::Collection,
65  typename value_type = typename Adaptor::value_type>
67  public:
68  typedef typename edm::ValueMap<value_type> Map;
69  typedef typename Map::Filler MapFiller;
70  explicit ManyThingsToValueMaps(const edm::ParameterSet& iConfig)
71  : failSilently_(iConfig.getUntrackedParameter<bool>("failSilently", false)),
72  src_(consumes<Collection>(iConfig.getParameter<edm::InputTag>("collection"))),
73  inputs_(iConfig.getParameter<std::vector<edm::InputTag> >("associations")) {
74  for (std::vector<edm::InputTag>::const_iterator it = inputs_.begin(), ed = inputs_.end(); it != ed; ++it) {
75  adaptors_.push_back(Adaptor(*it, iConfig, consumesCollector()));
76  produces<Map>(adaptors_.back().label());
77  }
78  }
79  ~ManyThingsToValueMaps() override {}
80 
81  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
82 
83  private:
86  std::vector<edm::InputTag> inputs_;
87  std::vector<Adaptor> adaptors_;
88  };
89 
90  template <class Adaptor, class Collection, typename value_type>
92  const edm::EventSetup& iSetup) {
94  iEvent.getByToken(src_, handle);
95  if (handle.failedToGet() && failSilently_)
96  return;
97 
98  std::vector<value_type> ret;
99  ret.reserve(handle->size());
100 
101  for (typename std::vector<Adaptor>::iterator it = adaptors_.begin(), ed = adaptors_.end(); it != ed; ++it) {
102  ret.clear();
103  if (it->run(iEvent, *handle, ret)) {
104  auto map = std::make_unique<Map>();
105  MapFiller filler(*map);
106  filler.insert(handle, ret.begin(), ret.end());
107  filler.fill();
108  iEvent.put(std::move(map), it->label());
109  } else {
110  if (!failSilently_)
111  throw cms::Exception("ManyThingsToValueMaps") << "Error in adapter " << it->label() << "\n";
112  }
113  }
114  }
115 
116  } // namespace helper
117 } // namespace pat
118 
119 #endif
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
pat::helper::AnythingToValueMap::adaptor_
Adaptor adaptor_
Definition: AnythingToValueMap.h:36
electrons_cff.bool
bool
Definition: electrons_cff.py:393
funct::false
false
Definition: Factorize.h:29
pat::helper::ManyThingsToValueMaps::Map
edm::ValueMap< value_type > Map
Definition: AnythingToValueMap.h:68
EDProducer.h
pat::helper::AnythingToValueMap
Definition: AnythingToValueMap.h:19
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::EDGetTokenT< Collection >
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
pat::helper::ManyThingsToValueMaps
Definition: AnythingToValueMap.h:66
edm::EDConsumerBase::consumesCollector
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Definition: EDConsumerBase.cc:46
pat::helper::ManyThingsToValueMaps::inputs_
std::vector< edm::InputTag > inputs_
Definition: AnythingToValueMap.h:86
pat::helper::ManyThingsToValueMaps::MapFiller
Map::Filler MapFiller
Definition: AnythingToValueMap.h:69
pat::helper::AnythingToValueMap::~AnythingToValueMap
~AnythingToValueMap() override
Definition: AnythingToValueMap.h:29
edm::Handle
Definition: AssociativeIterator.h:50
pat::helper::ManyThingsToValueMaps::failSilently_
bool failSilently_
Definition: AnythingToValueMap.h:84
pat::helper::ManyThingsToValueMaps::src_
edm::EDGetTokenT< Collection > src_
Definition: AnythingToValueMap.h:85
RefToBase.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
pat::helper::AnythingToValueMap::MapFiller
Map::Filler MapFiller
Definition: AnythingToValueMap.h:22
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
helper
Definition: helper.py:1
pat::helper::AnythingToValueMap::AnythingToValueMap
AnythingToValueMap(const edm::ParameterSet &iConfig)
Definition: AnythingToValueMap.h:23
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::helper::AnythingToValueMap::src_
edm::EDGetTokenT< Collection > src_
Definition: AnythingToValueMap.h:35
pat::helper::AnythingToValueMap::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: AnythingToValueMap.h:40
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
pat::helper::AnythingToValueMap::failSilently_
bool failSilently_
Definition: AnythingToValueMap.h:34
pat::helper::AnythingToValueMap::Map
edm::ValueMap< value_type > Map
Definition: AnythingToValueMap.h:21
InputTag.h
ValueMap.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ValueMap
Definition: ValueMap.h:107
Exception
Definition: hltDiff.cc:246
edm::EDProducer
Definition: EDProducer.h:35
pat::helper::ManyThingsToValueMaps::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: AnythingToValueMap.h:91
edm::helper::Filler
Definition: ValueMap.h:22
genParticles_cff.map
map
Definition: genParticles_cff.py:11
View.h
ParameterSet.h
pat::helper::ManyThingsToValueMaps::~ManyThingsToValueMaps
~ManyThingsToValueMaps() override
Definition: AnythingToValueMap.h:79
pat::helper::ManyThingsToValueMaps::adaptors_
std::vector< Adaptor > adaptors_
Definition: AnythingToValueMap.h:87
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:153
pat::helper::ManyThingsToValueMaps::ManyThingsToValueMaps
ManyThingsToValueMaps(const edm::ParameterSet &iConfig)
Definition: AnythingToValueMap.h:70
edm::Event
Definition: Event.h:73