CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
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>();
57  MapFiller filler(*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;
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
edm::ValueMap< value_type > Map
tuple ret
prodAgent to be discontinued
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< edm::InputTag > inputs_
int iEvent
Definition: GenABIO.cc:224
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
def move
Definition: eostools.py:511
tuple handle
Definition: patZpeak.py:23
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
bool failedToGet() const
Definition: HandleBase.h:72
AnythingToValueMap(const edm::ParameterSet &iConfig)
edm::EDGetTokenT< Collection > src_
edm::ValueMap< value_type > Map
edm::EDGetTokenT< Collection > src_
ManyThingsToValueMaps(const edm::ParameterSet &iConfig)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override