ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/AssociationMap.h
Revision: 1.5
Committed: Mon Aug 18 11:10:31 2008 UTC (16 years, 8 months ago) by sixie
Content type: text/plain
Branch: MAIN
Changes since 1.4: +15 -1 lines
Log Message:
Add HasMit function.

File Contents

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