CMS 3D CMS Logo

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 
18  public:
20  typedef Val val_type;
24  typedef Val data_type;
26  typedef index index_type;
28  typedef std::map<index_type, map_assoc> map_type;
32  typedef std::map<typename CKey::value_type const*, Val> transient_map_type;
34  typedef std::vector<typename CKey::value_type const*> transient_key_vector;
36  typedef std::vector<Val> transient_val_vector;
38  static void insert(ref_type& ref, map_type& m, key_type const& k, data_type const& v) {
39  if (k.isNull()) {
40  Exception::throwThis(errors::InvalidReference, "can't insert null references in AssociationMap");
41  }
42  if (ref.key.isNull()) {
43  if (k.isTransient()) {
45  "can't insert transient references in uninitialized AssociationMap");
46  }
47  //another thread might change the value of productGetter()
48  auto getter = ref.key.productGetter();
49  if (getter == nullptr) {
51  "Can't insert into AssociationMap unless it was properly initialized.\n"
52  "The most common fix for this is to add an argument to the call to the\n"
53  "AssociationMap constructor that is a valid Handle to the container.\n"
54  "If you don't have a valid handle or the template parameter to the\n"
55  "AssociationMap is a View, then see the comments in AssociationMap.h.\n"
56  "(note this was a new requirement added in the 7_5_X release series)\n");
57  }
58  ref.key = KeyRefProd(k.id(), getter);
59  }
60  helpers::checkRef(ref.key, k);
61  index_type ik = index_type(k.key());
62  m[ik] = v;
63  }
65  static val_type val(ref_type const&, map_assoc const& v) { return v; }
67  static typename map_type::size_type size(map_assoc const&) { return 1; }
69  static void sort(map_type&) {}
71  static transient_map_type transientMap(ref_type const& ref, map_type const& map) {
73  if (!map.empty()) {
74  CKey const& ckey = *ref.key;
75  for (typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
76  typename CKey::value_type const* k = &ckey[i->first];
77  m.insert(std::make_pair(k, i->second));
78  }
79  }
80  return m;
81  }
85  if (!map.empty()) {
86  CKey const& ckey = *ref.key;
87  for (typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
88  m.push_back(&ckey[i->first]);
89  }
90  }
91  return m;
92  }
96  if (!map.empty()) {
97  for (typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
98  m.push_back(i->second);
99  }
100  }
101  return m;
102  }
103  };
104 } // namespace edm
105 
106 #endif
Val map_assoc
internal map associated data
Definition: OneToValue.h:16
std::map< typename CKey::value_type const *, Val > transient_map_type
transient map type
Definition: OneToValue.h:32
helpers::Key< KeyRefProd > ref_type
reference set type
Definition: OneToValue.h:30
static transient_map_type transientMap(ref_type const &ref, map_type const &map)
fill transient map
Definition: OneToValue.h:71
static map_type::size_type size(map_assoc const &)
size of data_type
Definition: OneToValue.h:67
index index_type
index type
Definition: OneToValue.h:26
static void sort(map_type &)
sort
Definition: OneToValue.h:69
Val val_type
values reference collection type
Definition: OneToValue.h:20
static val_type val(ref_type const &, map_assoc const &v)
return values collection
Definition: OneToValue.h:65
uint16_t size_type
Ref< CKey > key_type
insert key type
Definition: OneToValue.h:22
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:85
std::vector< typename CKey::value_type const * > transient_key_vector
transient key vector
Definition: OneToValue.h:34
Val data_type
insert val type
Definition: OneToValue.h:24
std::map< index_type, map_assoc > map_type
map type
Definition: OneToValue.h:28
RefProd< CKey > KeyRefProd
reference to "key" collection
Definition: OneToValue.h:14
HLT enums.
std::vector< Val > transient_val_vector
transient val vector
Definition: OneToValue.h:36
static transient_key_vector transientKeyVector(ref_type const &ref, map_type const &map)
fill transient key vector
Definition: OneToValue.h:83
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:38
static transient_val_vector transientValVector(ref_type const &ref, map_type const &map)
fill transient val vector
Definition: OneToValue.h:94