CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OneToMany.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_OneToMany_h
2 #define DataFormats_Common_OneToMany_h
7 #include <map>
8 #include <vector>
9 
10 namespace edm {
11  template<typename CKey, typename CVal, typename index = unsigned int>
12  class OneToMany {
18  typedef std::vector<index> map_assoc;
19  public:
27  typedef index index_type;
29  typedef std::map<index_type, map_assoc > map_type;
33  typedef std::map<const typename CKey::value_type *,
34  std::vector<const typename CVal::value_type *>
37  typedef std::vector<const typename CKey::value_type *> transient_key_vector;
39  typedef std::vector<std::vector<const typename CVal::value_type *> > transient_val_vector;
41  static void insert(ref_type & ref, map_type & m,
42  const key_type & k, const data_type & v) {
43  if (k.isNull() || v.isNull())
45  "can't insert null references in AssociationMap");
46  if (ref.key.isNull()) {
47  ref.key = KeyRefProd(k);
48  ref.val = ValRefProd(v);
49  }
50  helpers::checkRef(ref.key, k); helpers::checkRef(ref.val, v);
51  index_type ik = index_type(k.key()), iv = index_type(v.key());
52  m[ ik ].push_back(iv);
53  }
54  static void insert(ref_type & ref, map_type & m, const key_type & k, const val_type & v) {
55  for(typename val_type::const_iterator i = v.begin(), iEnd = v.end(); i != iEnd; ++i)
56  insert(ref, m, k, *i);
57  }
59  static val_type val(const ref_type & ref, const map_assoc & iv) {
60  val_type v;
61  for(typename map_assoc::const_iterator idx = iv.begin(), idxEnd = iv.end(); idx != idxEnd; ++idx)
62  v.push_back(edm::Ref<CVal>(ref.val, *idx));
63  return v;
64  }
66  static typename map_type::size_type size(const map_assoc & v) { return v.size(); }
68  static void sort(map_type &) { }
70  static transient_map_type transientMap(const ref_type & ref, const map_type & map) {
72  const CKey & ckey = * ref.key;
73  const CVal & cval = * ref.val;
74  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++ i) {
75  const map_assoc & a = i->second;
76  const typename CKey::value_type * k = & ckey[ i->first ];
77  std::vector<const typename CVal::value_type *> v;
78  for(typename map_assoc::const_iterator j = a.begin(); j != a.end(); ++j) {
79  const typename CVal::value_type * val = & cval[ *j ];
80  v.push_back(val);
81  }
82  m.insert(std::make_pair(k, v));
83  }
84  return m;
85  }
89  const CKey & ckey = * ref.key;
90  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++ i)
91  m.push_back(& ckey[i->first]);
92  return m;
93  }
97  const CVal & cval = * ref.val;
98  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++ i) {
99  const map_assoc & a = i->second;
100  std::vector<const typename CVal::value_type *> v;
101  m.push_back(v);
102  for(typename map_assoc::const_iterator j = a.begin(); j != a.end(); ++j)
103  m.back().push_back(& cval[ *j ]);
104  }
105  return m;
106  }
107  };
108 }
109 
110 #endif
std::map< const typename CKey::value_type *, std::vector< const typename CVal::value_type * > > transient_map_type
transient map type
Definition: OneToMany.h:35
int i
Definition: DBlmapReader.cc:9
static void sort(map_type &)
sort
Definition: OneToMany.h:68
helpers::KeyVal< KeyRefProd, ValRefProd > ref_type
reference set type
Definition: OneToMany.h:31
static val_type val(const ref_type &ref, const map_assoc &iv)
return values collection
Definition: OneToMany.h:59
edm::Ref< CKey > key_type
insert key type
Definition: OneToMany.h:23
static void insert(ref_type &ref, map_type &m, const key_type &k, const data_type &v)
insert in the map
Definition: OneToMany.h:41
static void insert(ref_type &ref, map_type &m, const key_type &k, const val_type &v)
Definition: OneToMany.h:54
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
edm::Ref< CVal > data_type
insert val type
Definition: OneToMany.h:25
uint16_t size_type
static map_type::size_type size(const map_assoc &v)
size of data_type
Definition: OneToMany.h:66
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
dictionary map
Definition: Association.py:205
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
std::map< index_type, map_assoc > map_type
map type
Definition: OneToMany.h:29
index index_type
index type
Definition: OneToMany.h:27
edm::RefProd< CKey > KeyRefProd
reference to &quot;key&quot; collection
Definition: OneToMany.h:14
bool isNull() const
Checks for null.
Definition: Ref.h:247
int j
Definition: DBlmapReader.cc:9
edm::RefProd< CVal > ValRefProd
reference to &quot;value&quot; collection
Definition: OneToMany.h:16
static transient_map_type transientMap(const ref_type &ref, const map_type &map)
fill transient map
Definition: OneToMany.h:70
Container::value_type value_type
int k[5][pyjets_maxn]
std::vector< const typename CKey::value_type * > transient_key_vector
transient key vector
Definition: OneToMany.h:37
key_type key() const
Accessor for product key.
Definition: Ref.h:266
edm::RefVector< CVal > val_type
values reference collection type
Definition: OneToMany.h:21
double a
Definition: hdecay.h:121
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
static transient_val_vector transientValVector(const ref_type &ref, const map_type &map)
fill transient val vector
Definition: OneToMany.h:95
static transient_key_vector transientKeyVector(const ref_type &ref, const map_type &map)
fill transient key vector
Definition: OneToMany.h:87
void checkRef(const RP &rp, const R &r)
throw if r hasn&#39;t the same id as rp
mathSSE::Vec4< T > v
std::vector< std::vector< const typename CVal::value_type * > > transient_val_vector
transient val vector
Definition: OneToMany.h:39
std::vector< index > map_assoc
internal map associated data
Definition: OneToMany.h:18