ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/AssociationMap.h
Revision: 1.10
Committed: Sat May 5 16:49:58 2012 UTC (12 years, 11 months ago) by paus
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_028, Mit_027a, Mit_027, HEAD
Changes since 1.9: +25 -23 lines
Log Message:
Version 027 - complete version for ICHEP 2012.

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: AssociationMap.h,v 1.9 2009/03/15 11:20:40 loizides Exp $
3 //
4 // AssociationMap
5 //
6 // Wrapper for std::map, used to resolve links during tree filling.
7 //
8 // Authors: C.Paus, 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 public:
23 typedef std::map<EdmClass, MitClass> fwdMapType;
24 typedef std::map<MitClass, EdmClass> revMapType;
25
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 const fwdMapType &FwdMap() const { return fwdMap_; }
41 const revMapType &RevMap() const { return revMap_; }
42
43 protected:
44 fwdMapType fwdMap_; //map between edm ref and mit ptr
45 revMapType revMap_; //map between mit ptr and edm ref
46 Int_t edmProductId_; //product id for consistency check
47 std::string brname_; //branch name of MIT objects
48 };
49 }
50
51 //--------------------------------------------------------------------------------------------------
52 template <class EdmClass, class MitClass>
53 inline void mithep::AssociationMap<EdmClass,MitClass>::Add(EdmClass edmObj, MitClass mitObj)
54 {
55 fwdMap_[edmObj]=mitObj;
56 revMap_.insert(std::pair<MitClass, EdmClass>(mitObj,edmObj));
57 }
58
59 //--------------------------------------------------------------------------------------------------
60 template <class EdmClass, class MitClass>
61 inline MitClass mithep::AssociationMap<EdmClass,MitClass>::GetMit(EdmClass edmObj) const
62 {
63 typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj);
64
65 if (iter != fwdMap_.end())
66 return iter->second;
67 else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetMit()\n")
68 << "Error! EDM Object (" << typeid(edmObj).name()
69 << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl;
70 }
71
72 //--------------------------------------------------------------------------------------------------
73 template <class EdmClass, class MitClass>
74 inline EdmClass mithep::AssociationMap<EdmClass,MitClass>::GetEdm(MitClass mitObj) const
75 {
76 typename revMapType::const_iterator iter = revMap_.find(mitObj);
77 if (iter != revMap_.end())
78 return iter->second;
79 else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetEdm()\n")
80 << "Error! MITHEP Object (" << typeid(mitObj).name()
81 << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl;
82 }
83
84 //--------------------------------------------------------------------------------------------------
85 template <class EdmClass, class MitClass>
86 inline bool mithep::AssociationMap<EdmClass,MitClass>::HasMit(EdmClass edmObj) const
87 {
88 typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj);
89
90 if (iter != fwdMap_.end())
91 return true;
92 else
93 return false;
94 }
95 #endif