ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/AssociationMap.h
Revision: 1.9
Committed: Sun Mar 15 11:20:40 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, Mit_009c, Mit_009b, Mit_009a, Mit_009, Mit_008, Mit_008pre2
Branch point for: Mit_025c_branch
Changes since 1.8: +3 -2 lines
Log Message:
Introduced BranchTable plus general cleanup.

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: AssociationMap.h,v 1.8 2009/03/14 06:04:59 loizides Exp $
3 //
4 // AssociationMap
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 const char *GetBrName() const { return brname_.c_str(); }
35 bool HasMit(EdmClass edmObj) const;
36 void Reset() { fwdMap_.clear(); revMap_.clear(); }
37 void SetEdmProductId(Int_t id) { edmProductId_ = id; }
38 void SetBrName(const std::string &n) { brname_ = n; }
39 void SetBrName(const char *n) { brname_ = n; }
40
41 protected:
42 fwdMapType fwdMap_; //map between edm ref and mit ptr
43 revMapType revMap_; //map between mit ptr and edm ref
44 Int_t edmProductId_; //product id for consistency check
45 std::string brname_; //branch name of MIT objects
46 };
47 }
48
49 //--------------------------------------------------------------------------------------------------
50 template <class EdmClass, class MitClass>
51 inline void mithep::AssociationMap<EdmClass,MitClass>::Add(EdmClass edmObj, MitClass mitObj)
52 {
53 fwdMap_[edmObj]=mitObj;
54 revMap_.insert(std::pair<MitClass, EdmClass>(mitObj,edmObj));
55 }
56
57 //--------------------------------------------------------------------------------------------------
58 template <class EdmClass, class MitClass>
59 inline MitClass mithep::AssociationMap<EdmClass,MitClass>::GetMit(EdmClass edmObj) const
60 {
61 typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj);
62
63 if (iter != fwdMap_.end())
64 return iter->second;
65 else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetMit()\n")
66 << "Error! EDM Object (" << typeid(edmObj).name()
67 << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl;
68 }
69
70 //--------------------------------------------------------------------------------------------------
71 template <class EdmClass, class MitClass>
72 inline EdmClass mithep::AssociationMap<EdmClass,MitClass>::GetEdm(MitClass mitObj) const
73 {
74 typename revMapType::const_iterator iter = revMap_.find(mitObj);
75 if (iter != revMap_.end())
76 return iter->second;
77 else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetEdm()\n")
78 << "Error! MITHEP Object (" << typeid(mitObj).name()
79 << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl;
80 }
81
82 //--------------------------------------------------------------------------------------------------
83 template <class EdmClass, class MitClass>
84 inline bool mithep::AssociationMap<EdmClass,MitClass>::HasMit(EdmClass edmObj) const
85 {
86 typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj);
87
88 if (iter != fwdMap_.end())
89 return true;
90 else
91 return false;
92 }
93 #endif