CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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_; }
68  void swap(Association& other) {
69  this->ValueMap<int>::swap(other);
70  ref_.swap(other.ref_);
71  }
73  Association temp(rhs);
74  this->swap(temp);
75  return *this;
76  }
77 
78  class Filler : public helper::Filler<Association<C> > {
80 
81  public:
82  explicit Filler(Association<C>& association) : base(association) {}
84  base::map_.setRef(association.ref());
85  base::add(association);
86  }
87  };
88 
90  const id_offset_vector& ids() const { return ids_; }
93 
94  //Used by ROOT storage
96 
97  private:
99  void throwIndexMapBound() const {
100  Exception::throwThis(errors::InvalidReference, "Association: index in the map out of upper boundary\n");
101  }
102  void throwRefSet() const {
103  Exception::throwThis(errors::InvalidReference, "Association: reference to product already set\n");
104  }
105 
106  void add(const Association<C>& o) {
107  Filler filler(*this);
108  filler.add(o);
109  filler.fill();
110  }
111 
112  friend class helper::Filler<Association<C> >;
113  };
114 
115  // Free swap function
116  template <typename C>
117  inline void swap(Association<C>& lhs, Association<C>& rhs) {
118  lhs.swap(rhs);
119  }
120 
121  template <typename C>
123  Association<C> a = a1;
124  a += a2;
125  return a;
126  }
127 } // namespace edm
128 
129 #endif
bool empty() const
Definition: ValueMap.h:158
refprod_type ref() const
Definition: Association.h:67
refprod_type ref_
Definition: Association.h:98
unsigned int offset
Definition: ValueMap.h:111
void clear()
Definition: ValueMap.h:159
void add(const Association< C > &association)
Definition: Association.h:83
uint16_t *__restrict__ id
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:122
bool isNull() const
Checks for null.
Definition: RefProd.h:115
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
bool empty() const
Definition: Association.h:65
id_offset_vector ids_
Definition: ValueMap.h:242
#define CMS_CLASS_VERSION(_version_)
const id_offset_vector & ids() const
meant to be used in AssociativeIterator, not by the ordinary user
Definition: Association.h:90
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
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:83
size_t rawIndexOf(ProductID id, size_t idx) const
Definition: ValueMap.h:134
bool contains(ProductID id) const
Definition: ValueMap.h:155
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
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:106
void add(const ValueMap< T > &o)
Definition: ValueMap.h:263
void swap(RefProd< C > &)
Definition: RefProd.h:173
reference_type operator[](const RefKey &r) const
Definition: Association.h:34
bool contains(ProductID id) const
Definition: Association.h:63
void throwIndexMapBound() const
Definition: Association.h:99
size_t size() const
Definition: Association.h:64
void throwRefSet() const
Definition: Association.h:102
ValueMap< index > base
Definition: Association.h:21
edm::RefProd< C > refprod_type
Definition: Association.h:23
Filler(Association< C > &association)
Definition: Association.h:82
Association(const H &h)
Definition: Association.h:28
helper::Filler< Association< C > > base
Definition: Association.h:79
size_t size() const
Definition: ValueMap.h:156
double a
Definition: hdecay.h:119
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:124
std::vector< std::pair< ProductID, offset > > id_offset_vector
meant to be used in AssociativeIterator, not by the ordinary user
Definition: ValueMap.h:112
Association & operator=(Association const &rhs)
Definition: Association.h:72
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
container values_
Definition: ValueMap.h:241