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.8 by loizides, Sat Mar 14 06:04:59 2009 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   //
8 < // Authors: J.Bendavid
8 > // Authors: J.Bendavid, C.Loizides
9   //--------------------------------------------------------------------------------------------------
10  
11 < #ifndef TREEFILLER_ASSOCIATIONMAP_H
12 < #define TREEFILLER_ASSOCIATIONMAP_H
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   {
# Line 25 | Line 26 | namespace mithep
26        AssociationMap() : edmProductId_(0) {}
27        ~AssociationMap() {}
28        
29 <      void Add(EdmClass edmObj, MitClass mitObj) {
30 <        fwdMap[edmObj]=mitObj;
31 <        //revMap[mitObj]=edmObj;
32 <        revMap.insert(std::pair<MitClass, EdmClass>(mitObj,edmObj));
33 <      }
34 <      
35 <      MitClass GetMit(EdmClass edmObj) const {
36 <        //MitClass iter = fwdMap.find(edmObj);
37 <        //fwdMapType::iterator iter;
38 <        //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; }
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 char *n)         { brname_ = n;                      }
39  
40      protected:
41 <        fwdMapType fwdMap;
42 <        revMapType revMap;
43 <        Int_t edmProductId_;
44 <      
41 >      fwdMapType   fwdMap_;       //map between edm ref and mit ptr
42 >      revMapType   revMap_;       //map between mit ptr and edm ref
43 >      Int_t        edmProductId_; //product id for consistency check
44 >      std::string  brname_;       //branch name of MIT objects
45    };
46   }
47 +
48 + //--------------------------------------------------------------------------------------------------
49 + template <class EdmClass, class MitClass>
50 + inline void mithep::AssociationMap<EdmClass,MitClass>::Add(EdmClass edmObj, MitClass mitObj)
51 + {
52 +  fwdMap_[edmObj]=mitObj;
53 +  revMap_.insert(std::pair<MitClass, EdmClass>(mitObj,edmObj));
54 + }
55 +
56 + //--------------------------------------------------------------------------------------------------
57 + template <class EdmClass, class MitClass>
58 + inline MitClass mithep::AssociationMap<EdmClass,MitClass>::GetMit(EdmClass edmObj) const
59 + {
60 +  typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj);
61 +
62 +  if (iter != fwdMap_.end())
63 +    return iter->second;
64 +  else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetMit()\n")
65 +         << "Error! EDM Object (" << typeid(edmObj).name()
66 +         << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl;
67 + }
68 +      
69 + //--------------------------------------------------------------------------------------------------
70 + template <class EdmClass, class MitClass>
71 + inline EdmClass mithep::AssociationMap<EdmClass,MitClass>::GetEdm(MitClass mitObj) const
72 + {
73 +  typename revMapType::const_iterator iter = revMap_.find(mitObj);
74 +  if (iter != revMap_.end())
75 +    return iter->second;
76 +  else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetEdm()\n")
77 +         << "Error! MITHEP Object (" << typeid(mitObj).name()
78 +         << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl;
79 + }
80 +
81 + //--------------------------------------------------------------------------------------------------
82 + template <class EdmClass, class MitClass>
83 + inline bool mithep::AssociationMap<EdmClass,MitClass>::HasMit(EdmClass edmObj) const
84 + {
85 +  typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj);
86 +
87 +  if (iter != fwdMap_.end())
88 +    return true;
89 +  else
90 +    return false;
91 + }
92   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines