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  *
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) return reference_type();
42  size_t k = i;
43  if (k >= ref_->size()) throwIndexMapBound();
44  return reference_type(ref_,k);
45  }
46 
47  reference_type get(ProductID id, size_t idx) const {
48  return get(rawIndexOf(id,idx));
49  }
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()) throwRefSet();
60  }
61  }
62  bool contains(ProductID id) const { return base::contains(id); }
63  size_t size() const { return base::size(); }
64  bool empty() const { return base::empty(); }
65  void clear() { base::clear(); }
66  refprod_type ref() const { return ref_; }
67  void swap(Association& other) {
68  this->ValueMap<int>::swap(other);
69  ref_.swap(other.ref_);
70  }
72  Association temp(rhs);
73  this->swap(temp);
74  return *this;
75  }
76 
77  class Filler : public helper::Filler<Association<C> > {
79  public:
80  explicit Filler(Association<C> & association) :
81  base(association) { }
82  void add(const Association<C> & association) {
83  base::map_.setRef(association.ref());
84  base::add(association);
85  }
86  };
87 
89  const id_offset_vector & ids() const { return ids_; }
92 
93  //Used by ROOT storage
95 
96  private:
98  void throwIndexMapBound() const {
99  Exception::throwThis(errors::InvalidReference, "Association: index in the map out of upper boundary\n");
100  }
101  void throwRefSet() const {
102  Exception::throwThis(errors::InvalidReference, "Association: reference to product already set\n");
103  }
104 
105  void add( const Association<C> & o ) {
106  Filler filler(*this);
107  filler.add(o);
108  filler.fill();
109  }
110 
111  friend class helper::Filler<Association<C> >;
112  };
113 
114  // Free swap function
115  template <typename C>
116  inline void swap(Association<C>& lhs, Association<C>& rhs) {
117  lhs.swap(rhs);
118  }
119 
120  template<typename C>
122  const Association<C> & a2 ) {
123  Association<C> a = a1;
124  a += a2;
125  return a;
126  }
127 }
128 
129 #endif
bool empty() const
Definition: ValueMap.h:159
int i
Definition: DBlmapReader.cc:9
refprod_type ref() const
Definition: Association.h:66
refprod_type ref_
Definition: Association.h:97
unsigned int offset
Definition: ValueMap.h:108
void clear()
Definition: ValueMap.h:160
void add(const Association< C > &association)
Definition: Association.h:82
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:121
bool isNull() const
Checks for null.
Definition: RefProd.h:131
base::offset offset
Definition: Association.h:22
void setRef(const refprod_type &ref)
Definition: Association.h:55
void swap(ValueMap &other)
Definition: ValueMap.h:115
Association< C > & operator+=(const Association< C > &o)
Definition: Association.h:51
bool empty() const
Definition: Association.h:64
id_offset_vector ids_
Definition: ValueMap.h:222
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
const id_offset_vector & ids() const
meant to be used in AssociativeIterator, not by the ordinary user
Definition: Association.h:89
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
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="")
size_t rawIndexOf(ProductID id, size_t idx) const
Definition: ValueMap.h:131
bool contains(ProductID id) const
Definition: ValueMap.h:154
std::vector< std::pair< ProductID, offset > > id_offset_vector
Definition: ValueMap.h:109
void swap(Association &other)
Definition: Association.h:67
void add(const Association< C > &o)
Definition: Association.h:105
void add(const ValueMap< T > &o)
Definition: ValueMap.h:244
void swap(RefProd< C > &)
Definition: RefProd.h:212
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
reference_type operator[](const RefKey &r) const
Definition: Association.h:34
bool contains(ProductID id) const
Definition: Association.h:62
void throwIndexMapBound() const
Definition: Association.h:98
size_t size() const
Definition: Association.h:63
void throwRefSet() const
Definition: Association.h:101
ValueMap< index > base
Definition: Association.h:21
edm::RefProd< C > refprod_type
Definition: Association.h:23
Filler(Association< C > &association)
Definition: Association.h:80
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
Association(const H &h)
Definition: Association.h:28
#define private
Definition: FWFileEntry.h:17
helper::Filler< Association< C > > base
Definition: Association.h:78
size_t size() const
Definition: ValueMap.h:157
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:109
Association & operator=(Association const &rhs)
Definition: Association.h:71
void add(const Map &map)
Definition: ValueMap.h:33
container values_
Definition: ValueMap.h:221