ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/AssociationMap.h
Revision: 1.6
Committed: Wed Sep 10 03:30:22 2008 UTC (16 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre1, Mit_006b, Mit_006a, Mit_006, Mit_005, Mit_004
Changes since 1.5: +3 -5 lines
Log Message:
Cleanup

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: AssociationMap.h,v 1.5 2008/08/18 11:10:31 sixie Exp $
3 //
4 // Association Map
5 //
6 // Wrapper for std::map, used to resolve links during tree filling.
7 //
8 // Authors: J.Bendavid, C.Loizides
9 //--------------------------------------------------------------------------------------------------
10
11 #ifndef MITPROD_TREEFILLER_ASSOCIATIONMAP_H
12 #define MITPROD_TREEFILLER_ASSOCIATIONMAP_H
13
14 #include <map>
15 #include <TObject.h>
16 #include "FWCore/MessageLogger/interface/MessageLogger.h"
17
18 namespace mithep
19 {
20 template <class EdmClass, class MitClass> class AssociationMap : public TObject
21 {
22 typedef std::map<EdmClass, MitClass> fwdMapType;
23 typedef std::map<MitClass, EdmClass> revMapType;
24
25 public:
26 AssociationMap() : edmProductId_(0) {}
27 ~AssociationMap() {}
28
29 void Add(EdmClass edmObj, MitClass mitObj);
30 EdmClass GetEdm(MitClass mitObj) const;
31 Int_t GetEdmProductId() const { return edmProductId_; }
32 Int_t GetEntries() const { return fwdMap_.size(); }
33 MitClass GetMit(EdmClass edmObj) const;
34 bool HasMit(EdmClass edmObj) const;
35 void Reset() { fwdMap_.clear(); revMap_.clear(); }
36 void SetEdmProductId(Int_t id) { edmProductId_ = id; }
37
38 protected:
39 fwdMapType fwdMap_; //map between edm ref and mit ptr
40 revMapType revMap_; //map between mit ptr and edm ref
41 Int_t edmProductId_; //product id for consistency check
42 };
43 }
44
45 //--------------------------------------------------------------------------------------------------
46 template <class EdmClass, class MitClass>
47 inline void mithep::AssociationMap<EdmClass,MitClass>::Add(EdmClass edmObj, MitClass mitObj)
48 {
49 fwdMap_[edmObj]=mitObj;
50 revMap_.insert(std::pair<MitClass, EdmClass>(mitObj,edmObj));
51 }
52
53 //--------------------------------------------------------------------------------------------------
54 template <class EdmClass, class MitClass>
55 inline MitClass mithep::AssociationMap<EdmClass,MitClass>::GetMit(EdmClass edmObj) const
56 {
57 typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj);
58
59 if (iter != fwdMap_.end())
60 return iter->second;
61 else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetMit()\n")
62 << "Error! EDM Object (" << typeid(edmObj).name()
63 << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl;
64 }
65
66 //--------------------------------------------------------------------------------------------------
67 template <class EdmClass, class MitClass>
68 inline EdmClass mithep::AssociationMap<EdmClass,MitClass>::GetEdm(MitClass mitObj) const
69 {
70 typename revMapType::const_iterator iter = revMap_.find(mitObj);
71 if (iter != revMap_.end())
72 return iter->second;
73 else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetEdm()\n")
74 << "Error! MITHEP Object (" << typeid(mitObj).name()
75 << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl;
76 }
77
78 //--------------------------------------------------------------------------------------------------
79 template <class EdmClass, class MitClass>
80 inline bool mithep::AssociationMap<EdmClass,MitClass>::HasMit(EdmClass edmObj) const
81 {
82 typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj);
83
84 if (iter != fwdMap_.end())
85 return true;
86 else
87 return false;
88 }
89 #endif