CMS 3D CMS Logo

Association.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_Association_h
2 #define DataFormats_Common_Association_h
3 /* \class Association<RefProd>
4  *
5  * \author Luca Lista, INFN
6  *
7  *
8  */
9 
14 
15 namespace edm {
16 
17  template <typename C>
18  class Association : private ValueMap<int> {
19  public:
20  typedef int index; // negative index == null reference
22  typedef typename base::offset offset;
23  typedef edm::RefProd<C> refprod_type; // could be specialized for View
25 
26  Association() : base() {}
27  template <typename H>
28  explicit Association(const H& h) : base(), ref_(h) {}
29 
30  // import this function from ValueMap<int>
31  using base::rawIndexOf;
32 
33  template <typename RefKey>
34  reference_type operator[](const RefKey& r) const {
35  return get(r.id(), r.key());
36  }
37 
39  reference_type get(size_t rawIdx) const {
40  index i = values_[rawIdx];
41  if (i < 0)
42  return reference_type();
43  size_t k = i;
44  if (k >= ref_->size())
46  return reference_type(ref_, k);
47  }
48 
49  reference_type get(ProductID id, size_t idx) const { return get(rawIndexOf(id, idx)); }
50 
52  add(o);
53  return *this;
54  }
55  void setRef(const refprod_type& ref) {
56  if (ref_.isNull()) {
57  ref_ = ref;
58  } else {
59  if (ref_.id() != ref.id())
60  throwRefSet();
61  }
62  }
63  bool contains(ProductID id) const { return base::contains(id); }
64  size_t size() const { return base::size(); }
65  bool empty() const { return base::empty(); }
66  void clear() { base::clear(); }
67  refprod_type ref() const { return ref_; }
69  this->ValueMap<int>::swap(other);
70  ref_.swap(other.ref_);
71  }
72 
73  class Filler : public helper::Filler<Association<C> > {
75 
76  public:
79  base::map_.setRef(association.ref());
81  }
82  };
83 
85  const id_offset_vector& ids() const { return ids_; }
88 
89  //Used by ROOT storage
91 
92  private:
94  void throwIndexMapBound() const {
95  Exception::throwThis(errors::InvalidReference, "Association: index in the map out of upper boundary\n");
96  }
97  void throwRefSet() const {
98  Exception::throwThis(errors::InvalidReference, "Association: reference to product already set\n");
99  }
100 
101  void add(const Association<C>& o) {
102  Filler filler(*this);
103  filler.add(o);
104  filler.fill();
105  }
106 
107  friend class helper::Filler<Association<C> >;
108  };
109 
110  // Free swap function
111  template <typename C>
112  inline void swap(Association<C>& lhs, Association<C>& rhs) {
113  lhs.swap(rhs);
114  }
115 
116  template <typename C>
118  Association<C> a = a1;
119  a += a2;
120  return a;
121  }
122 } // namespace edm
123 
124 #endif
refprod_type ref_
Definition: Association.h:93
reference_type operator[](const RefKey &r) const
Definition: Association.h:34
unsigned int offset
Definition: ValueMap.h:111
void clear()
Definition: ValueMap.h:153
void add(const Association< C > &association)
Definition: Association.h:78
refprod_type ref() const
Definition: Association.h:67
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:117
base::offset offset
Definition: Association.h:22
void setRef(const refprod_type &ref)
Definition: Association.h:55
void swap(ValueMap &other)
Definition: ValueMap.h:118
Association< C > & operator+=(const Association< C > &o)
Definition: Association.h:51
id_offset_vector ids_
Definition: ValueMap.h:236
#define CMS_CLASS_VERSION(_version_)
size_t rawIndexOf(ProductID id, size_t idx) const
Definition: ValueMap.h:128
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
Ref< typename refprod_type::product_type > reference_type
Definition: Association.h:24
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:86
const id_offset_vector & ids() const
meant to be used in AssociativeIterator, not by the ordinary user
Definition: Association.h:85
std::vector< std::pair< ProductID, offset > > id_offset_vector
Definition: ValueMap.h:112
void swap(Association &other)
Definition: Association.h:68
void add(const Association< C > &o)
Definition: Association.h:101
void add(const ValueMap< T > &o)
Definition: ValueMap.h:257
void swap(RefProd< C > &)
Definition: RefProd.h:175
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:124
ValueMap< index > base
Definition: Association.h:21
edm::RefProd< C > refprod_type
Definition: Association.h:23
Filler(Association< C > &association)
Definition: Association.h:77
bool contains(ProductID id) const
Definition: Association.h:63
Association(const H &h)
Definition: Association.h:28
size_t size() const
Definition: Association.h:64
void throwIndexMapBound() const
Definition: Association.h:94
bool empty() const
Definition: Association.h:65
size_t size() const
Definition: ValueMap.h:150
helper::Filler< Association< C > > base
Definition: Association.h:74
HLT enums.
bool isNull() const
Checks for null.
Definition: RefProd.h:115
double a
Definition: hdecay.h:121
void throwRefSet() const
Definition: Association.h:97
std::vector< std::pair< ProductID, offset > > id_offset_vector
meant to be used in AssociativeIterator, not by the ordinary user
Definition: ValueMap.h:112
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool empty() const
Definition: ValueMap.h:152
bool contains(ProductID id) const
Definition: ValueMap.h:149
container values_
Definition: ValueMap.h:235