CMS 3D CMS Logo

OneToValue.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_OneToValue_h
00002 #define DataFormats_Common_OneToValue_h
00003 #include "DataFormats/Common/interface/AssociationMapHelpers.h"
00004 #include "DataFormats/Common/interface/Ref.h"
00005 #include "DataFormats/Common/interface/RefProd.h"
00006 #include <map>
00007 
00008 namespace edm {
00009   template<typename CKey, typename Val, typename index = unsigned int>
00010   class OneToValue {
00012     typedef edm::RefProd<CKey> KeyRefProd;
00014     typedef Val map_assoc;
00015   public:
00017     typedef Val val_type;
00019     typedef edm::Ref<CKey> key_type;
00021     typedef Val data_type;
00023     typedef index index_type;
00025     typedef std::map<index_type, map_assoc> map_type;
00027     typedef helpers::Key<KeyRefProd> ref_type;
00029     typedef std::map<const typename CKey::value_type *, Val> transient_map_type;
00031     typedef std::vector<const typename CKey::value_type *> transient_key_vector;
00033     typedef std::vector<Val> transient_val_vector;
00035     static void insert(ref_type & ref, map_type & m,
00036                         const key_type & k, const data_type & v) {
00037       if (k.isNull())
00038         throw edm::Exception(edm::errors::InvalidReference)
00039           << "can't insert null references in AssociationMap";
00040       if (ref.key.isNull()) {
00041         ref.key = KeyRefProd(k);
00042       }
00043       helpers::checkRef(ref.key, k);
00044       index_type ik = index_type(k.key());
00045       m[ik] = v;
00046     }
00048     static val_type val(const ref_type & ref, const map_assoc & v) {
00049       return v;
00050     }
00052     static typename map_type::size_type size(const map_assoc &) { return 1; }
00054     static void sort(map_type &) { }
00056     static transient_map_type transientMap(const ref_type & ref, const map_type & map) {
00057       transient_map_type m;
00058       const CKey & ckey = * ref.key;
00059       for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++ i) {
00060         const typename CKey::value_type * k = & ckey[i->first];
00061         m.insert(std::make_pair(k, i->second));
00062       }
00063       return m;
00064     }
00066     static transient_key_vector transientKeyVector(const ref_type & ref, const map_type & map) {
00067       transient_key_vector m;
00068       const CKey & ckey = * ref.key;
00069       for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++ i)
00070         m.push_back(& ckey[i->first]);
00071       return m;
00072     }
00074     static transient_val_vector transientValVector(const ref_type & ref, const map_type & map) {
00075       transient_val_vector m;
00076       for(typename map_type::const_iterator i = map.begin(); i != map.end(); ++ i)
00077         m.push_back(i->second);
00078       return m;
00079     }
00080   };
00081 }
00082 
00083 #endif

Generated on Tue Jun 9 17:29:30 2009 for CMSSW by  doxygen 1.5.4