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  }
73  Association temp(rhs);
74  this->swap(temp);
75  return *this;
76  }
77 
78  class Filler : public helper::Filler<Association<C> > {
80 
81  public:
84  base::map_.setRef(association.ref());
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
edm::ValueMap::offset
unsigned int offset
Definition: ValueMap.h:111
edm::RefProd
Definition: EDProductfwd.h:25
class-composition.H
H
Definition: class-composition.py:31
RefProd.h
mps_fire.i
i
Definition: mps_fire.py:355
edm::ValueMap::clear
void clear()
Definition: ValueMap.h:159
edm::Association::Filler
Definition: Association.h:78
edm::RefProd::id
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:124
edm::errors::InvalidReference
Definition: EDMException.h:39
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
edm::Association::operator[]
reference_type operator[](const RefKey &r) const
Definition: Association.h:34
edm::Association::base
ValueMap< index > base
Definition: Association.h:21
edm::Association::throwRefSet
void throwRefSet() const
Definition: Association.h:102
edm::Association::contains
bool contains(ProductID id) const
Definition: Association.h:63
edm::ValueMap< int >::ids_
id_offset_vector ids_
Definition: ValueMap.h:242
edm::Association::refprod_type
edm::RefProd< C > refprod_type
Definition: Association.h:23
edm::Association::Association
Association(const H &h)
Definition: Association.h:28
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
training_settings.idx
idx
Definition: training_settings.py:16
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
edm::Ref
Definition: AssociativeIterator.h:58
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition: testProducerWithPsetDescEmpty_cfi.py:35
edm::Association::clear
void clear()
Definition: Association.h:66
edm::Association::Filler::Filler
Filler(Association< C > &association)
Definition: Association.h:82
edm::Association::get
reference_type get(ProductID id, size_t idx) const
Definition: Association.h:49
edm::Association::operator+=
Association< C > & operator+=(const Association< C > &o)
Definition: Association.h:51
edm::ValueMap::empty
bool empty() const
Definition: ValueMap.h:158
edm::RefProd::isNull
bool isNull() const
Checks for null.
Definition: RefProd.h:115
edm::Association::operator=
Association & operator=(Association const &rhs)
Definition: Association.h:72
trackingPlots.other
other
Definition: trackingPlots.py:1465
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
edm::Association::Filler::add
void add(const Association< C > &association)
Definition: Association.h:83
h
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::ValueMap< int >::values_
container values_
Definition: ValueMap.h:241
edm::RefProd::swap
void swap(RefProd< C > &)
Definition: RefProd.h:173
a
double a
Definition: hdecay.h:119
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
edm::ValueMap::swap
void swap(ValueMap &other)
Definition: ValueMap.h:118
edm::Association::add
void add(const Association< C > &o)
Definition: Association.h:106
edm::Association::ref
refprod_type ref() const
Definition: Association.h:67
edm::Association::ref_
refprod_type ref_
Definition: Association.h:98
edm::Association::Association
Association()
Definition: Association.h:26
edm::Association
Definition: Association.h:18
edm::Association::size
size_t size() const
Definition: Association.h:64
edm::Association::offset
base::offset offset
Definition: Association.h:22
TrackValidation_cff.association
association
Definition: TrackValidation_cff.py:286
alignCSCRings.r
r
Definition: alignCSCRings.py:93
ValueMap.h
Ref.h
CMS_CLASS_VERSION.h
edm::Association::setRef
void setRef(const refprod_type &ref)
Definition: Association.h:55
edm::ValueMap::id_offset_vector
std::vector< std::pair< ProductID, offset > > id_offset_vector
Definition: ValueMap.h:112
edm::Association::reference_type
Ref< typename refprod_type::product_type > reference_type
Definition: Association.h:24
gen::C
C
Definition: PomwigHadronizer.cc:76
edm::Association::get
reference_type get(size_t rawIdx) const
meant to be used internally or in AssociativeIterator, not by the ordinary user
Definition: Association.h:39
edm::ValueMap
Definition: ValueMap.h:107
edm::Exception::throwThis
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
edm::ValueMap::rawIndexOf
size_t rawIndexOf(ProductID id, size_t idx) const
Definition: ValueMap.h:134
edm::Association::throwIndexMapBound
void throwIndexMapBound() const
Definition: Association.h:99
edm::Association::empty
bool empty() const
Definition: Association.h:65
edm::ValueMap::add
void add(const ValueMap< T > &o)
Definition: ValueMap.h:263
edm::ValueMap::contains
bool contains(ProductID id) const
Definition: ValueMap.h:155
edm::operator+
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:122
edm::helper::Filler
Definition: ValueMap.h:22
edm::Association::index
int index
Definition: Association.h:20
edm::Association::ids
const id_offset_vector & ids() const
meant to be used in AssociativeIterator, not by the ordinary user
Definition: Association.h:90
edm::Association::Filler::base
helper::Filler< Association< C > > base
Definition: Association.h:79
edm::Association::id_offset_vector
std::vector< std::pair< ProductID, offset > > id_offset_vector
meant to be used in AssociativeIterator, not by the ordinary user
Definition: ValueMap.h:112
edm::Association::swap
void swap(Association &other)
Definition: Association.h:68
edm::ProductID
Definition: ProductID.h:27
edm::ValueMap::size
size_t size() const
Definition: ValueMap.h:156