test
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  if(k.isTransient()) {
46  "can't insert transient references in uninitialized AssociationMap");
47  }
48  //another thread might change the value of productGetter()
49  auto getter =ref.key.productGetter();
50  if(getter == nullptr) {
52  "Can't insert into AssociationMap unless it was properly initialized.\n"
53  "The most common fix for this is to add an argument to the call to the\n"
54  "AssociationMap constructor that is a valid Handle to the container.\n"
55  "If you don't have a valid handle or the template parameter to the\n"
56  "AssociationMap is a View, then see the comments in AssociationMap.h.\n"
57  "(note this was a new requirement added in the 7_5_X release series)\n");
58  }
59  ref.key = KeyRefProd(k.id(), getter);
60  }
61  helpers::checkRef(ref.key, k);
62  index_type ik = index_type(k.key());
63  m[ik] = v;
64  }
66  static val_type val(ref_type const&, map_assoc const& v) {
67  return v;
68  }
70  static typename map_type::size_type size(map_assoc const&) { return 1; }
72  static void sort(map_type&) { }
74  static transient_map_type transientMap(ref_type const& ref, map_type const& map) {
76  if(!map.empty()) {
77  CKey const& ckey = *ref.key;
78  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
79  typename CKey::value_type const* k = &ckey[i->first];
80  m.insert(std::make_pair(k, i->second));
81  }
82  }
83  return m;
84  }
86  static transient_key_vector transientKeyVector(ref_type const& ref, map_type const& map) {
88  if(!map.empty()) {
89  CKey const& 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  }
93  }
94  return m;
95  }
97  static transient_val_vector transientValVector(ref_type const& ref, map_type const& map) {
99  if(!map.empty()) {
100  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
101  m.push_back(i->second);
102  }
103  }
104  return m;
105  }
106  };
107 }
108 
109 #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:74
bool isTransient() const
Checks if this ref is transient (i.e. not persistable).
Definition: Ref.h:277
static map_type::size_type size(map_assoc const &)
size of data_type
Definition: OneToValue.h:70
index index_type
index type
Definition: OneToValue.h:25
static void sort(map_type &)
sort
Definition: OneToValue.h:72
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:66
key_type key() const
Accessor for product key.
Definition: Ref.h:264
uint16_t size_type
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
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:249
Val data_type
insert val type
Definition: OneToValue.h:23
std::map< index_type, map_assoc > map_type
map type
Definition: OneToValue.h:27
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:86
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:97