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
edm::StreamID
Definition: StreamID.h:30
MessageLogger.h
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
watchdog.const
const
Definition: watchdog.py:83
UniqueMerger::UniqueMerger
UniqueMerger(const edm::ParameterSet &)
constructor from parameter set
Definition: UniqueMerger.h:57
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CloneTrait.h
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::clonehelper::CloneTrait
Definition: CloneTrait.h:12
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
UniqueMerger::srcToken_
vtoken srcToken_
labels of the collections to be merged
Definition: UniqueMerger.h:49
edm::global::EDProducer
Definition: EDProducer.h:32
edm::vector_transform
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
UniqueMerger::skipNulls_
bool skipNulls_
choose whether to skip null/invalid pointers
Definition: UniqueMerger.h:51
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
UniqueMerger::set_type
std::set< typename OutputCollection::value_type > set_type
Definition: UniqueMerger.h:37
UniqueMerger::~UniqueMerger
~UniqueMerger() override
destructor
Definition: UniqueMerger.h:66
UniqueMerger::vtoken
std::vector< edm::EDGetTokenT< InputCollection > > vtoken
vector of strings
Definition: UniqueMerger.h:47
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
UniqueMerger
Definition: UniqueMerger.h:35
InputTag.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
transform.h
UniqueMerger::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
process an event
Definition: UniqueMerger.h:69
SimL1EmulatorRepack_GT2_cff.InputCollection
InputCollection
Definition: SimL1EmulatorRepack_GT2_cff.py:16
ParameterSet.h
EDProducer.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
P
std::pair< OmniClusterRef, TrackingParticleRef > P
Definition: BDHadronTrackMonitoringAnalyzer.cc:202
edm::Event
Definition: Event.h:73
HLTTauReferences_cfi.OutputCollection
OutputCollection
Definition: HLTTauReferences_cfi.py:92
edm::Event::get
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:342
UniqueMerger::warnOnSkip_
bool warnOnSkip_
choose whether to warn when skipping pointers
Definition: UniqueMerger.h:53