CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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  * \version $Id: Association.h,v 1.9 2011/03/08 18:47:15 chrjones Exp $
8  *
9  */
10 
15 
16 namespace edm {
17 
18  template<typename C>
19  class Association : private ValueMap<int> {
20  public:
21  typedef int index; // negative index == null reference
23  typedef typename base::offset offset;
24  typedef edm::RefProd<C> refprod_type; // could be specialized for View
26 
27  Association() : base() { }
28  template<typename H>
29  explicit Association(const H & h) : base(), ref_(h) { }
30 
31  // import this function from ValueMap<int>
32  using base::rawIndexOf;
33 
34  template<typename RefKey>
35  reference_type operator[](const RefKey & r) const {
36  return get(r.id(), r.key());
37  }
38 
40  reference_type get(size_t rawIdx) const {
41  index i = values_[rawIdx];
42  if(i < 0) return reference_type();
43  size_t k = i;
44  if (k >= ref_->size()) throwIndexMapBound();
45  return reference_type(ref_,k);
46  }
47 
48  reference_type get(ProductID id, size_t idx) const {
49  return get(rawIndexOf(id,idx));
50  }
51 
53  add(o);
54  return *this;
55  }
56  void setRef(const refprod_type & ref) {
57  if(ref_.isNull() ) {
58  ref_ = ref;
59  } else {
60  if(ref_.id() != ref.id()) 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  public:
81  explicit Filler(Association<C> & association) :
82  base(association) { }
83  void add(const Association<C> & 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  const Association<C> & a2 ) {
124  Association<C> a = a1;
125  a += a2;
126  return a;
127  }
128 }
129 
130 #endif
bool empty() const
Definition: ValueMap.h:154
int i
Definition: DBlmapReader.cc:9
refprod_type ref() const
Definition: Association.h:67
refprod_type ref_
Definition: Association.h:98
unsigned int offset
Definition: ValueMap.h:103
void clear()
Definition: ValueMap.h:155
void add(const Association< C > &association)
Definition: Association.h:83
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:122
bool isNull() const
Checks for null.
Definition: RefProd.h:131
base::offset offset
Definition: Association.h:23
void setRef(const refprod_type &ref)
Definition: Association.h:56
void swap(ValueMap &other)
Definition: ValueMap.h:110
Association< C > & operator+=(const Association< C > &o)
Definition: Association.h:52
bool empty() const
Definition: Association.h:65
id_offset_vector ids_
Definition: ValueMap.h:209
#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:25
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
size_t rawIndexOf(ProductID id, size_t idx) const
Definition: ValueMap.h:126
bool contains(ProductID id) const
Definition: ValueMap.h:149
std::vector< std::pair< ProductID, offset > > id_offset_vector
Definition: ValueMap.h:104
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:231
void swap(RefProd< C > &)
Definition: RefProd.h:212
reference_type operator[](const RefKey &r) const
Definition: Association.h:35
bool contains(ProductID id) const
Definition: Association.h:63
int k[5][pyjets_maxn]
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:22
edm::RefProd< C > refprod_type
Definition: Association.h:24
Filler(Association< C > &association)
Definition: Association.h:81
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
Association(const H &h)
Definition: Association.h:29
#define private
Definition: FWFileEntry.h:18
helper::Filler< Association< C > > base
Definition: Association.h:79
size_t size() const
Definition: ValueMap.h:152
double a
Definition: hdecay.h:121
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:140
std::vector< std::pair< ProductID, offset > > id_offset_vector
meant to be used in AssociativeIterator, not by the ordinary user
Definition: ValueMap.h:104
Association & operator=(Association const &rhs)
Definition: Association.h:72
container values_
Definition: ValueMap.h:208