ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/AssociationMap.h
Revision: 1.3
Committed: Wed Jul 2 19:29:27 2008 UTC (16 years, 10 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.2: +6 -3 lines
Log Message:
Improved AssociationMap error handling

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: AssociationMap.h,v 1.2 2008/07/01 21:11:12 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 GetEdmRef(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 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 not found in AssociationMap." << std::endl;
63 }
64
65 //--------------------------------------------------------------------------------------------------
66 template <class EdmClass, class MitClass>
67 inline EdmClass mithep::AssociationMap<EdmClass,MitClass>::GetEdmRef(MitClass mitObj) const
68 {
69 typename revMapType::const_iterator iter = revMap_.find(mitObj);
70 if (iter != revMap_.end())
71 return iter->second;
72 else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetEdmRef()\n")
73 << "Error! mithep Object not found in AssociationMap." << std::endl;
74 }
75 #endif