CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
ThinnedRefSet< C > * set_
Definition: ThinnedRefSet.h:80
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
void insert(Ref< C, T, F > const &ref)
Definition: ThinnedRefSet.h:65
key_type key() const
Accessor for product key.
Definition: Ref.h:250
bool contains(unsigned int key) const
Definition: ThinnedRefSet.h:94
std::unordered_set< unsigned int > keys_
Definition: ThinnedRefSet.h:97
tuple key
prepare the HTCondor submission files and eventually submit them
Filler(ThinnedRefSet< C > *set, RefProd< C > thinned, edm::EDProductGetter const &prodGetter)
Definition: ThinnedRefSet.h:61
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::EDProductGetter const & prodGetter_
Definition: ThinnedRefSet.h:82
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
ThinnedRefSetMode
Definition: ThinnedRefSet.h:54
ThinnedRefSetMode invalidParentRefMode_
Definition: ThinnedRefSet.h:98
ThinnedRefSet(ThinnedRefSetMode mode=ThinnedRefSetMode::throwOnInvalidParentRef)
Definition: ThinnedRefSet.h:85
Filler fill(RefProd< C > thinned, edm::EDProductGetter const &prodGetter)
Definition: ThinnedRefSet.h:88