ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/AssociationMap.h
Revision: 1.2
Committed: Tue Jul 1 21:11:12 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.1: +43 -41 lines
Log Message:
Cleanup and added check if object is in map.

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: AssociationMap.h,v 1.1 2008/07/01 14:39:28 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
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 GetEdmRef(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 void Reset() { fwdMap_.clear(); revMap_.clear(); }
35 void SetEdmProductId(Int_t id) { edmProductId_ = id; }
36
37 protected:
38 fwdMapType fwdMap_; //map between edm ref and mit ptr
39 revMapType revMap_; //map between mit ptr and edm ref
40 Int_t edmProductId_; //product id for consistency check
41 };
42 }
43
44 //--------------------------------------------------------------------------------------------------
45 template <class EdmClass, class MitClass>
46 inline void mithep::AssociationMap<EdmClass,MitClass>::Add(EdmClass edmObj, MitClass mitObj)
47 {
48 fwdMap_[edmObj]=mitObj;
49 revMap_.insert(std::pair<MitClass, EdmClass>(mitObj,edmObj));
50 }
51
52 //--------------------------------------------------------------------------------------------------
53 template <class EdmClass, class MitClass>
54 inline MitClass mithep::AssociationMap<EdmClass,MitClass>::GetMit(EdmClass edmObj) const
55 {
56 typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj);
57
58 if (iter != fwdMap_.end())
59 return iter->second;
60 else return 0;
61 }
62
63 //--------------------------------------------------------------------------------------------------
64 template <class EdmClass, class MitClass>
65 inline EdmClass mithep::AssociationMap<EdmClass,MitClass>::GetEdmRef(MitClass mitObj) const
66 {
67 typename revMapType::const_iterator iter = revMap_.find(mitObj);
68 if (iter != revMap_.end())
69 return iter->second;
70 else return 0;
71 }
72 #endif