CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OneToManyWithQualityGeneric.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_OneToManyWithQualityGeneric_h
2 #define DataFormats_Common_OneToManyWithQualityGeneric_h
6 #include <map>
7 #include <vector>
8 #include <algorithm>
9 #include <boost/bind.hpp>
10 
12 
13 namespace edm {
14  template<typename CKey, typename CVal, typename Q, typename index = unsigned int,
15  typename KeyRefProd = typename helper::MapRefViewTrait<CKey>::refprod_type,
16  typename ValRefProd = typename helper::MapRefViewTrait<CVal>::refprod_type,
17  typename KeyRef = typename helper::MapRefViewTrait<CKey>::ref_type,
18  typename ValRef = typename helper::MapRefViewTrait<CVal>::ref_type >
21  typedef KeyRefProd keyrefprod_type;
23  typedef ValRefProd valrefprod_type;
25  typedef std::vector<std::pair<index, Q> > map_assoc;
26 
27  public:
29  typedef std::vector<std::pair<ValRef, Q> > val_type;
31  typedef KeyRef key_type;
33  typedef std::pair<ValRef, Q> data_type;
35  typedef index index_type;
37  typedef std::map<index_type, map_assoc> map_type;
41  typedef std::map<const typename CKey::value_type *,
42  std::vector<std::pair<const typename CVal::value_type *, Q > >
45  typedef std::vector<const typename CKey::value_type *> transient_key_vector;
47  typedef std::vector<std::vector<std::pair<const typename CVal::value_type *, Q > >
50  static void insert(ref_type & ref, map_type & m,
51  const key_type & k, const data_type & v) {
52  const ValRef & vref = v.first;
53  if (k.isNull() || vref.isNull())
55  "can't insert null references in AssociationMap");
56  if (ref.key.isNull()) {
57  ref.key = keyrefprod_type(k);
58  ref.val = valrefprod_type(vref);
59  }
60  helpers::checkRef(ref.key, k); helpers::checkRef(ref.val, vref);
61  index_type ik = index_type(k.key()), iv = index_type(vref.key());
62  m[ik].push_back(std::make_pair(iv, v.second));
63  }
64  static void insert(ref_type & ref, map_type & m, const key_type & k, const val_type & v) {
65  for(typename val_type::const_iterator i = v.begin(), iEnd = v.end(); i != iEnd; ++i)
66  insert(ref, m, k, *i);
67  }
69  static val_type val(const ref_type & ref, const map_assoc & iv) {
70  val_type v;
71  for(typename map_assoc::const_iterator idx = iv.begin(), idxEnd = iv.end(); idx != idxEnd; ++idx)
72  v.push_back(std::make_pair(ValRef(ref.val, idx->first), idx->second));
73  return v;
74  }
76  static typename map_type::size_type size(const map_assoc & v) { return v.size(); }
78  static void sort(map_type & m) {
79  // using namespace boost::lambda;
80  for(typename map_type::iterator i = m.begin(), iEnd = m.end(); i != iEnd; ++i) {
81  map_assoc & v = i->second;
82  // Q std::pair<index, Q>::*quality = &std::pair<index, Q>::second;
83  // std::sort(v.begin(), v.end(),
84  // bind(quality, boost::lambda::_2) < bind(quality, boost::lambda::_1));
85  std::sort(v.begin(), v.end(),
86  boost::bind(std::less<Q>(),
87  boost::bind(&std::pair<index, Q>::second,_2), boost::bind( &std::pair<index, Q>::second,_1)
88  )
89  );
90 
91  }
92  }
94  static transient_map_type transientMap(const ref_type & ref, const map_type & map) {
96  const CKey & ckey = * ref.key;
97  const CVal & cval = * ref.val;
98  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++ i) {
99  const map_assoc & a = i->second;
100  const typename CKey::value_type * k = & ckey[i->first];
101  std::vector<std::pair<const typename CVal::value_type *, Q> > v;
102  for(typename map_assoc::const_iterator j = a.begin(); j != a.end(); ++j) {
103  const typename CVal::value_type * val = & cval[j->first];
104  v.push_back(std::make_pair(val, j->second));
105  }
106  m.insert(std::make_pair(k, v));
107  }
108  return m;
109  }
113  const CKey & ckey = * ref.key;
114  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++ i)
115  m.push_back(& ckey[i->first]);
116  return m;
117  }
121  const CVal & cval = * ref.val;
122  for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++ i) {
123  const map_assoc & a = i->second;
124  std::vector<std::pair<const typename CVal::value_type *, Q> > v;
125  m.push_back(v);
126  for(typename map_assoc::const_iterator j = a.begin(); j != a.end(); ++j)
127  m.back().push_back(std::make_pair(& cval[ j->first ], j->second));
128  }
129  return m;
130  }
131  };
132 }
133 
134 #endif
int i
Definition: DBlmapReader.cc:9
static map_type::size_type size(const map_assoc &v)
size of data_type
KeyRefProd keyrefprod_type
reference to &quot;key&quot; collection
uint16_t size_type
static transient_val_vector transientValVector(const ref_type &ref, const map_type &map)
fill transient val vector
static val_type val(const ref_type &ref, const map_assoc &iv)
return values collection
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
std::vector< std::pair< ValRef, Q > > val_type
values reference collection type
U second(std::pair< T, U > const &p)
static transient_key_vector transientKeyVector(const ref_type &ref, const map_type &map)
fill transient key vector
static void insert(ref_type &ref, map_type &m, const key_type &k, const val_type &v)
int j
Definition: DBlmapReader.cc:9
Container::value_type value_type
helpers::KeyVal< keyrefprod_type, valrefprod_type > ref_type
reference set type
int k[5][pyjets_maxn]
std::vector< std::pair< index, Q > > map_assoc
internal map associated data
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
static transient_map_type transientMap(const ref_type &ref, const map_type &map)
fill transient map
std::pair< ValRef, Q > data_type
insert val type
std::vector< std::vector< std::pair< const typename CVal::value_type *, Q > > > transient_val_vector
transient val vector
double a
Definition: hdecay.h:121
std::vector< const typename CKey::value_type * > transient_key_vector
transient key vector
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, const key_type &k, const data_type &v)
insert in the map
std::map< index_type, map_assoc > map_type
map type
ValRefProd valrefprod_type
reference to &quot;value&quot; collection
std::map< const typename CKey::value_type *, std::vector< std::pair< const typename CVal::value_type *, Q > > > transient_map_type
transient map type