ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/AssociationMap.h
(Generate patch)

Comparing UserCode/MitProd/TreeFiller/interface/AssociationMap.h (file contents):
Revision 1.1 by loizides, Tue Jul 1 14:39:28 2008 UTC vs.
Revision 1.5 by sixie, Mon Aug 18 11:10:31 2008 UTC

# Line 3 | Line 3
3   //
4   // Association Map
5   //
6 < // wrapper for std::map, used to resolve links during tree filling
6 > // Wrapper for std::map, used to resolve links during tree filling.
7 > // This class needs work! CL.
8   //
9 < // Authors: J.Bendavid
9 > // Authors: J.Bendavid, C.Loizides
10   //--------------------------------------------------------------------------------------------------
11  
12   #ifndef TREEFILLER_ASSOCIATIONMAP_H
# Line 13 | Line 14
14  
15   #include <map>
16   #include <TObject.h>
17 + #include "FWCore/MessageLogger/interface/MessageLogger.h"
18  
19   namespace mithep
20   {
# Line 25 | Line 27 | namespace mithep
27        AssociationMap() : edmProductId_(0) {}
28        ~AssociationMap() {}
29        
30 <      void Add(EdmClass edmObj, MitClass mitObj) {
31 <        fwdMap[edmObj]=mitObj;
32 <        //revMap[mitObj]=edmObj;
33 <        revMap.insert(std::pair<MitClass, EdmClass>(mitObj,edmObj));
34 <      }
35 <      
36 <      MitClass GetMit(EdmClass edmObj) const {
37 <        //MitClass iter = fwdMap.find(edmObj);
36 <        //fwdMapType::iterator iter;
37 <        //fwdIter = fwdMap.find(edmObj);
38 <        //if ( iter != fwdMap.end() )
39 <        //      return iter->second;
40 <        //else return 0;
41 <        return fwdMap.find(edmObj)->second;
42 <      }
43 <      
44 <       EdmClass GetEdmRef(MitClass mitObj) const {
45 < //         //EdmClass iter = revMap.find(mitObj);
46 < // //   revMapType::iterator iter = revMap.find(mitObj);
47 < // //   if ( iter != revMap.end() )
48 < // //           return iter->second;
49 < // //   else return 0;
50 <        return revMap.find(mitObj)->second;
51 <       }
52 <      
53 <      Int_t GetEntries() { return fwdMap.size(); }
54 <      
55 <      void Reset() {
56 <        fwdMap.clear();
57 <        revMap.clear();
58 <      }
59 <      
60 <        Int_t GetEdmProductId() const { return edmProductId_; }
61 <        void  SetEdmProductId(Int_t id) { edmProductId_ = id; }
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;
41 <        revMapType revMap;
42 <        Int_t edmProductId_;
67 <      
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines