CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OneToValue.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_OneToValue_h
2 #define DataFormats_Common_OneToValue_h
3 
7 
8 #include <map>
9 
10 namespace edm {
11  template<typename CKey, typename Val, typename index = unsigned int>
12  class OneToValue {
16  typedef Val map_assoc;
17  public:
19  typedef Val val_type;
23  typedef Val data_type;
25  typedef index index_type;
27  typedef std::map<index_type, map_assoc> map_type;
31  typedef std::map<typename CKey::value_type const*, Val> transient_map_type;
33  typedef std::vector<typename CKey::value_type const*> transient_key_vector;
35  typedef std::vector<Val> transient_val_vector;
37  static void insert(ref_type& ref, map_type& m,
38  key_type const& k, data_type const& v) {
39  if(k.isNull()) {
41  "can't insert null references in AssociationMap");
42  }
43  if(ref.key.isNull()) {
44  ref.key = KeyRefProd(k);
45  }
46  helpers::checkRef(ref.key, k);
47  index_type ik = index_type(k.key());
48  m[ik] = v;
49  }
51  static val_type val(ref_type const&, map_assoc const& v) {
52  return v;
53  }
55  static typename map_type::size_type size(map_assoc const&) { return 1; }
57  static void sort(map_type&) { }
59  static transient_map_type transientMap(ref_type const& ref, map_type const& map) {
61  CKey const& ckey = *ref.key;
62  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
63  typename CKey::value_type const* k = &ckey[i->first];
64  m.insert(std::make_pair(k, i->second));
65  }
66  return m;
67  }
71  CKey const& ckey = *ref.key;
72  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
73  m.push_back(& ckey[i->first]);
74  }
75  return m;
76  }
80  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
81  m.push_back(i->second);
82  }
83  return m;
84  }
85  };
86 }
87 
88 #endif
Val map_assoc
internal map associated data
Definition: OneToValue.h:16
int i
Definition: DBlmapReader.cc:9
std::map< typename CKey::value_type const *, Val > transient_map_type
transient map type
Definition: OneToValue.h:31
helpers::Key< KeyRefProd > ref_type
reference set type
Definition: OneToValue.h:29
static transient_map_type transientMap(ref_type const &ref, map_type const &map)
fill transient map
Definition: OneToValue.h:59
static map_type::size_type size(map_assoc const &)
size of data_type
Definition: OneToValue.h:55
index index_type
index type
Definition: OneToValue.h:25
static void sort(map_type &)
sort
Definition: OneToValue.h:57
Val val_type
values reference collection type
Definition: OneToValue.h:19
static val_type val(ref_type const &, map_assoc const &v)
return values collection
Definition: OneToValue.h:51
uint16_t size_type
Ref< CKey > key_type
insert key type
Definition: OneToValue.h:21
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
std::vector< typename CKey::value_type const * > transient_key_vector
transient key vector
Definition: OneToValue.h:33
bool isNull() const
Checks for null.
Definition: Ref.h:247
Container::value_type value_type
int k[5][pyjets_maxn]
Val data_type
insert val type
Definition: OneToValue.h:23
std::map< index_type, map_assoc > map_type
map type
Definition: OneToValue.h:27
key_type key() const
Accessor for product key.
Definition: Ref.h:266
RefProd< CKey > KeyRefProd
reference to &quot;key&quot; collection
Definition: OneToValue.h:14
std::vector< Val > transient_val_vector
transient val vector
Definition: OneToValue.h:35
static transient_key_vector transientKeyVector(ref_type const &ref, map_type const &map)
fill transient key vector
Definition: OneToValue.h:69
void checkRef(const RP &rp, const R &r)
throw if r hasn&#39;t the same id as rp
static void insert(ref_type &ref, map_type &m, key_type const &k, data_type const &v)
insert in the map
Definition: OneToValue.h:37
static transient_val_vector transientValVector(ref_type const &ref, map_type const &map)
fill transient val vector
Definition: OneToValue.h:78