CMS 3D CMS Logo

ThinnedRefSet.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_ThinnedRefSet_h
2 #define DataFormats_Common_ThinnedRefSet_h
3 //
4 // Package: DataFormats/Common
5 // Class : ThinnedRefSet
6 //
48 
49 #include <unordered_set>
50 
51 namespace edm {
52  class EDProductGetter;
53 
55 
56  template <typename C>
57  class ThinnedRefSet {
58  public:
59  class Filler {
60  public:
61  explicit Filler(ThinnedRefSet<C>* set, RefProd<C> thinned, edm::EDProductGetter const& prodGetter)
62  : set_(set), thinnedRefProd_(thinned), prodGetter_(prodGetter) {}
63 
64  template <typename T, typename F>
65  void insert(Ref<C, T, F> const& ref) {
66  if (ref.isNonnull()) {
67  Ref<C, T, F> thinnedRef;
68  if (set_->invalidParentRefMode_ == ThinnedRefSetMode::ignoreInvalidParentRef) {
69  thinnedRef = tryThinnedRefFrom(ref, thinnedRefProd_, prodGetter_);
70  } else {
71  thinnedRef = thinnedRefFrom(ref, thinnedRefProd_, prodGetter_);
72  }
73  if (thinnedRef.isNonnull()) {
74  set_->keys_.insert(thinnedRef.key());
75  }
76  }
77  }
78 
79  private:
83  };
84 
87 
88  Filler fill(RefProd<C> thinned, edm::EDProductGetter const& prodGetter) {
89  return Filler(this, thinned, prodGetter);
90  }
91 
92  void clear() { keys_.clear(); }
93 
94  bool contains(unsigned int key) const { return keys_.find(key) != keys_.end(); }
95 
96  private:
97  std::unordered_set<unsigned int> keys_;
99  };
100 } // namespace edm
101 
102 #endif
edm::RefProd
Definition: EDProductfwd.h:25
edm::ThinnedRefSet::invalidParentRefMode_
ThinnedRefSetMode invalidParentRefMode_
Definition: ThinnedRefSet.h:98
edm::ThinnedRefSet::ThinnedRefSet
ThinnedRefSet(ThinnedRefSetMode mode=ThinnedRefSetMode::throwOnInvalidParentRef)
Definition: ThinnedRefSet.h:85
Handle.h
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::tryThinnedRefFrom
Ref< C, T, F > tryThinnedRefFrom(Ref< C, T, F > const &parent, RefProd< C > const &thinned, edm::EDProductGetter const &prodGetter)
Return a Ref to thinned collection corresponding to an element of the Ref to parent collection.
Definition: RefItemGet.h:157
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
edm::ThinnedRefSetMode::ignoreInvalidParentRef
edm::ThinnedRefSetMode::throwOnInvalidParentRef
edm::ThinnedRefSet::Filler::prodGetter_
edm::EDProductGetter const & prodGetter_
Definition: ThinnedRefSet.h:82
edm::ThinnedRefSet::contains
bool contains(unsigned int key) const
Definition: ThinnedRefSet.h:94
edm::ThinnedRefSet::clear
void clear()
Definition: ThinnedRefSet.h:92
edm::Ref
Definition: AssociativeIterator.h:58
edm::ThinnedRefSet::keys_
std::unordered_set< unsigned int > keys_
Definition: ThinnedRefSet.h:97
edm::EDProductGetter
Definition: EDProductGetter.h:41
edm::ThinnedRefSet::Filler
Definition: ThinnedRefSet.h:59
edm::ThinnedRefSet::Filler::thinnedRefProd_
RefProd< C > thinnedRefProd_
Definition: ThinnedRefSet.h:81
EDProductGetter
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
edm::ThinnedRefSet::Filler::insert
void insert(Ref< C, T, F > const &ref)
Definition: ThinnedRefSet.h:65
edm::ThinnedRefSet::Filler::Filler
Filler(ThinnedRefSet< C > *set, RefProd< C > thinned, edm::EDProductGetter const &prodGetter)
Definition: ThinnedRefSet.h:61
Ref.h
edm::ThinnedRefSet
Definition: ThinnedRefSet.h:57
edm::ThinnedRefSetMode
ThinnedRefSetMode
Definition: ThinnedRefSet.h:54
edm::thinnedRefFrom
Ref< C, T, F > thinnedRefFrom(Ref< C, T, F > const &parent, RefProd< C > const &thinned, edm::EDProductGetter const &prodGetter)
Return a Ref to thinned collection corresponding to an element of the Ref to parent collection.
Definition: RefItemGet.h:129
edm::ThinnedRefSet::Filler::set_
ThinnedRefSet< C > * set_
Definition: ThinnedRefSet.h:80
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
RefItemGet.h
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::ThinnedRefSet::fill
Filler fill(RefProd< C > thinned, edm::EDProductGetter const &prodGetter)
Definition: ThinnedRefSet.h:88