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
edm::RefProd
Definition: EDProductfwd.h:25
edm::OneToValue::ref_type
helpers::Key< KeyRefProd > ref_type
reference set type
Definition: OneToValue.h:30
RefProd.h
mps_fire.i
i
Definition: mps_fire.py:355
edm::errors::InvalidReference
Definition: EDMException.h:39
edm::errors::LogicError
Definition: EDMException.h:37
edm::OneToValue::transientMap
static transient_map_type transientMap(ref_type const &ref, map_type const &map)
fill transient map
Definition: OneToValue.h:71
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::OneToValue::val_type
Val val_type
values reference collection type
Definition: OneToValue.h:20
edm::OneToValue::size
static map_type::size_type size(map_assoc const &)
size of data_type
Definition: OneToValue.h:67
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::OneToValue::key_type
Ref< CKey > key_type
insert key type
Definition: OneToValue.h:22
edm::helpers::Key
Definition: AssociationMapHelpers.h:37
edm::Ref
Definition: AssociativeIterator.h:58
edm::OneToValue::val
static val_type val(ref_type const &, map_assoc const &v)
return values collection
Definition: OneToValue.h:65
edm::OneToValue::transient_key_vector
std::vector< typename CKey::value_type const * > transient_key_vector
transient key vector
Definition: OneToValue.h:34
edm::OneToValue::index_type
index index_type
index type
Definition: OneToValue.h:26
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::OneToValue::sort
static void sort(map_type &)
sort
Definition: OneToValue.h:69
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
edm::helpers::checkRef
void checkRef(const RP &rp, const R &r)
throw if r hasn't the same id as rp
Definition: AssociationMapHelpers.h:51
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::OneToValue::map_type
std::map< index_type, map_assoc > map_type
map type
Definition: OneToValue.h:28
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::OneToValue::KeyRefProd
RefProd< CKey > KeyRefProd
reference to "key" collection
Definition: OneToValue.h:14
edm::OneToValue::transientKeyVector
static transient_key_vector transientKeyVector(ref_type const &ref, map_type const &map)
fill transient key vector
Definition: OneToValue.h:83
AssociationMapHelpers.h
edm::OneToValue::transient_val_vector
std::vector< Val > transient_val_vector
transient val vector
Definition: OneToValue.h:36
Ref.h
edm::OneToValue::insert
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
edm::OneToValue::data_type
Val data_type
insert val type
Definition: OneToValue.h:24
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
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edm::OneToValue::transientValVector
static transient_val_vector transientValVector(ref_type const &ref, map_type const &map)
fill transient val vector
Definition: OneToValue.h:94
edm::OneToValue
Definition: OneToValue.h:12
edm::OneToValue::map_assoc
Val map_assoc
internal map associated data
Definition: OneToValue.h:16
edm::helpers::Key::key
K key
Definition: AssociationMapHelpers.h:46
edm::OneToValue::transient_map_type
std::map< typename CKey::value_type const *, Val > transient_map_type
transient map type
Definition: OneToValue.h:32