CMS 3D CMS Logo

OneToOneGeneric.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_OneToOneGeneric_h
2 #define DataFormats_Common_OneToOneGeneric_h
3 
6 
7 #include <map>
8 
9 namespace edm {
10  template <typename CKey,
11  typename CVal,
12  typename index = unsigned int,
13  typename KeyRefProd = typename helper::MapRefViewTrait<CKey>::refprod_type,
14  typename ValRefProd = typename helper::MapRefViewTrait<CVal>::refprod_type,
15  typename KeyRef = typename helper::MapRefViewTrait<CKey>::ref_type,
16  typename ValRef = typename helper::MapRefViewTrait<CVal>::ref_type>
19  typedef KeyRefProd keyrefprod_type;
21  typedef ValRefProd valrefprod_type;
23  typedef index map_assoc;
24 
25  public:
27  typedef ValRef val_type;
29  typedef KeyRef key_type;
31  typedef ValRef data_type;
33  typedef index index_type;
35  typedef std::map<index_type, map_assoc> map_type;
39  typedef std::map<typename CKey::value_type const*, typename CVal::value_type const*> transient_map_type;
41  typedef std::vector<typename CKey::value_type const*> transient_key_vector;
43  typedef std::vector<typename CVal::value_type const*> transient_val_vector;
45  static void insert(ref_type& ref, map_type& m, key_type const& k, data_type const& v) {
46  if (k.isNull() || v.isNull()) {
47  Exception::throwThis(errors::InvalidReference, "can't insert null references in AssociationMap");
48  }
49  if (ref.key.isNull()) {
50  if (k.isTransient() || v.isTransient()) {
52  "can't insert transient references in uninitialized AssociationMap");
53  }
54  //another thread might change the value of productGetter()
55  auto getter = ref.key.productGetter();
56  if (getter == nullptr) {
58  "Can't insert into AssociationMap unless it was properly initialized.\n"
59  "The most common fix for this is to add arguments to the call to the\n"
60  "AssociationMap constructor that are valid Handle's to the containers.\n"
61  "If you don't have valid handles or either template parameter to the\n"
62  "AssociationMap is a View, then see the comments in AssociationMap.h.\n"
63  "(note this was a new requirement added in the 7_5_X release series)\n");
64  }
65  ref.key = KeyRefProd(k.id(), getter);
66  ref.val = ValRefProd(v.id(), ref.val.productGetter());
67  }
68  helpers::checkRef(ref.key, k);
69  helpers::checkRef(ref.val, v);
70  index_type ik = index_type(k.key()), iv = index_type(v.key());
71  m[ik] = iv;
72  }
74  static val_type val(ref_type const& ref, map_assoc iv) { return val_type(ref.val, iv); }
76  static typename map_type::size_type size(map_assoc const&) { return 1; }
78  static void sort(map_type&) {}
80  static transient_map_type transientMap(ref_type const& ref, map_type const& map) {
82  if (!map.empty()) {
83  CKey const& ckey = *ref.key;
84  CVal const& cval = *ref.val;
85  for (typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
86  typename CKey::value_type const* k = &ckey[i->first];
87  typename CVal::value_type const* v = &cval[i->second];
88  m.insert(std::make_pair(k, v));
89  }
90  }
91  return m;
92  }
96  if (!map.empty()) {
97  CKey const& ckey = *ref.key;
98  for (typename map_type::const_iterator i = map.begin(); i != map.end(); ++i)
99  m.push_back(&ckey[i->first]);
100  }
101  return m;
102  }
106  if (!map.empty()) {
107  CVal const& cval = *ref.val;
108  for (typename map_type::const_iterator i = map.begin(); i != map.end(); ++i) {
109  m.push_back(&cval[i->second]);
110  }
111  }
112  return m;
113  }
114  };
115 } // namespace edm
116 
117 #endif
edm::OneToOneGeneric::transientMap
static transient_map_type transientMap(ref_type const &ref, map_type const &map)
fill transient map
Definition: OneToOneGeneric.h:80
edm::OneToOneGeneric::map_type
std::map< index_type, map_assoc > map_type
map type
Definition: OneToOneGeneric.h:35
mps_fire.i
i
Definition: mps_fire.py:428
edm::OneToOneGeneric::valrefprod_type
ValRefProd valrefprod_type
reference to "value" collection
Definition: OneToOneGeneric.h:21
edm::errors::InvalidReference
Definition: EDMException.h:39
edm::errors::LogicError
Definition: EDMException.h:37
edm::helper::MapRefViewTrait::refprod_type
RefProd< C > refprod_type
Definition: MapRefViewTrait.h:14
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::OneToOneGeneric::map_assoc
index map_assoc
internal map associated data
Definition: OneToOneGeneric.h:23
gpuVertexFinder::iv
int32_t *__restrict__ iv
Definition: gpuClusterTracksDBSCAN.h:42
edm::OneToOneGeneric::transient_val_vector
std::vector< typename CVal::value_type const * > transient_val_vector
transient val vector
Definition: OneToOneGeneric.h:43
edm::helpers::KeyVal
Definition: AssociationMapHelpers.h:22
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::OneToOneGeneric::sort
static void sort(map_type &)
sort
Definition: OneToOneGeneric.h:78
edm::OneToOneGeneric::transientKeyVector
static transient_key_vector transientKeyVector(ref_type const &ref, map_type const &map)
fill transient key vector
Definition: OneToOneGeneric.h:94
edm::OneToOneGeneric
Definition: OneToOneGeneric.h:17
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::OneToOneGeneric::transient_key_vector
std::vector< typename CKey::value_type const * > transient_key_vector
transient key vector
Definition: OneToOneGeneric.h:41
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
edm::OneToOneGeneric::data_type
ValRef data_type
insert val type
Definition: OneToOneGeneric.h:31
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
edm::OneToOneGeneric::transientValVector
static transient_val_vector transientValVector(ref_type const &ref, map_type const &map)
fill transient val vector
Definition: OneToOneGeneric.h:104
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::OneToOneGeneric::val_type
ValRef val_type
values reference collection type
Definition: OneToOneGeneric.h:27
edm::OneToOneGeneric::insert
static void insert(ref_type &ref, map_type &m, key_type const &k, data_type const &v)
insert in the map
Definition: OneToOneGeneric.h:45
edm::helpers::KeyVal::val
V val
Definition: AssociationMapHelpers.h:33
edm::OneToOneGeneric::ref_type
helpers::KeyVal< keyrefprod_type, valrefprod_type > ref_type
reference set type
Definition: OneToOneGeneric.h:37
edm::helper::MapRefViewTrait::ref_type
Ref< C > ref_type
Definition: MapRefViewTrait.h:13
edm::OneToOneGeneric::val
static val_type val(ref_type const &ref, map_assoc iv)
return values collection
Definition: OneToOneGeneric.h:74
createfilelist.int
int
Definition: createfilelist.py:10
MapRefViewTrait.h
edm::OneToOneGeneric::key_type
KeyRef key_type
insert key type
Definition: OneToOneGeneric.h:29
edm::OneToOneGeneric::size
static map_type::size_type size(map_assoc const &)
size of data_type
Definition: OneToOneGeneric.h:76
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::OneToOneGeneric::index_type
index index_type
index type
Definition: OneToOneGeneric.h:33
edm::helpers::KeyVal::key
K key
Definition: AssociationMapHelpers.h:32
AssociationMapHelpers.h
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
edm::OneToOneGeneric::transient_map_type
std::map< typename CKey::value_type const *, typename CVal::value_type const * > transient_map_type
transient map type
Definition: OneToOneGeneric.h:39
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edm::OneToOneGeneric::keyrefprod_type
KeyRefProd keyrefprod_type
reference to "key" collection
Definition: OneToOneGeneric.h:19