CMS 3D CMS Logo

UniqueMerger.h
Go to the documentation of this file.
1 #ifndef UtilAlgos_UniqueMerger_h
2 #define UtilAlgos_UniqueMerger_h
3 
30 #include <vector>
31 
32 template <typename InputCollection,
36 public:
37  typedef std::set<typename OutputCollection::value_type> set_type;
39  explicit UniqueMerger(const edm::ParameterSet&);
41  ~UniqueMerger() override;
42 
43 private:
45  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
47  typedef std::vector<edm::EDGetTokenT<InputCollection> > vtoken;
51  bool skipNulls_;
54 };
55 
56 template <typename InputCollection, typename OutputCollection, typename P>
58  : srcToken_(edm::vector_transform(par.template getParameter<std::vector<edm::InputTag> >("src"),
59  [this](edm::InputTag const& tag) { return consumes<InputCollection>(tag); })),
60  skipNulls_(par.getParameter<bool>("skipNulls")),
61  warnOnSkip_(par.getParameter<bool>("warnOnSkip")) {
62  produces<OutputCollection>();
63 }
64 
65 template <typename InputCollection, typename OutputCollection, typename P>
67 
68 template <typename InputCollection, typename OutputCollection, typename P>
70  edm::Event& evt,
71  const edm::EventSetup&) const {
72  set_type coll_set;
73  for (auto const& s : srcToken_) {
74  for (auto const& c : evt.get(s)) {
75  if (!skipNulls_ || (c.isNonnull() && c.isAvailable())) {
76  coll_set.emplace(P::clone(c));
77  } else if (warnOnSkip_) {
78  edm::LogWarning("InvalidPointer") << "Found an invalid pointer. Will not merge to collection.";
79  }
80  }
81  }
82  std::unique_ptr<OutputCollection> coll(new OutputCollection(coll_set.size()));
83  std::copy(coll_set.begin(), coll_set.end(), coll->begin());
84  evt.put(std::move(coll));
85 }
86 
87 #endif
UniqueMerger(const edm::ParameterSet &)
constructor from parameter set
Definition: UniqueMerger.h:57
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:347
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
bool skipNulls_
choose whether to skip null/invalid pointers
Definition: UniqueMerger.h:51
bool warnOnSkip_
choose whether to warn when skipping pointers
Definition: UniqueMerger.h:53
vtoken srcToken_
labels of the collections to be merged
Definition: UniqueMerger.h:49
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
process an event
Definition: UniqueMerger.h:69
std::set< typename OutputCollection::value_type > set_type
Definition: UniqueMerger.h:37
std::pair< OmniClusterRef, TrackingParticleRef > P
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
HLT enums.
~UniqueMerger() override
destructor
Definition: UniqueMerger.h:66
std::vector< edm::EDGetTokenT< InputCollection > > vtoken
vector of strings
Definition: UniqueMerger.h:47
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511