--- UserCode/MitProd/TreeFiller/interface/AssociationMap.h 2008/07/02 19:29:27 1.3 +++ UserCode/MitProd/TreeFiller/interface/AssociationMap.h 2009/03/13 09:35:19 1.7 @@ -1,16 +1,15 @@ //-------------------------------------------------------------------------------------------------- -// $Id: AssociationMap.h,v 1.3 2008/07/02 19:29:27 bendavid Exp $ +// $Id: AssociationMap.h,v 1.7 2009/03/13 09:35:19 loizides Exp $ // // Association Map // // Wrapper for std::map, used to resolve links during tree filling. -// This class needs work! CL. // // Authors: J.Bendavid, C.Loizides //-------------------------------------------------------------------------------------------------- -#ifndef TREEFILLER_ASSOCIATIONMAP_H -#define TREEFILLER_ASSOCIATIONMAP_H +#ifndef MITPROD_TREEFILLER_ASSOCIATIONMAP_H +#define MITPROD_TREEFILLER_ASSOCIATIONMAP_H #include #include @@ -24,21 +23,25 @@ namespace mithep typedef std::map revMapType; public: - AssociationMap() : edmProductId_(0) {} + AssociationMap(const char *n=0) : edmProductId_(0), brname_(n) {} ~AssociationMap() {} - void Add(EdmClass edmObj, MitClass mitObj); - EdmClass GetEdmRef(MitClass mitObj) const; - Int_t GetEdmProductId() const { return edmProductId_; } - Int_t GetEntries() const { return fwdMap_.size(); } - MitClass GetMit(EdmClass edmObj) const; - void Reset() { fwdMap_.clear(); revMap_.clear(); } - void SetEdmProductId(Int_t id) { edmProductId_ = id; } + void Add(EdmClass edmObj, MitClass mitObj); + EdmClass GetEdm(MitClass mitObj) const; + Int_t GetEdmProductId() const { return edmProductId_; } + Int_t GetEntries() const { return fwdMap_.size(); } + MitClass GetMit(EdmClass edmObj) const; + const char *GetName() const { return brname_.c_str(); } + bool HasMit(EdmClass edmObj) const; + void Reset() { fwdMap_.clear(); revMap_.clear(); } + void SetEdmProductId(Int_t id) { edmProductId_ = id; } + void SetName(const char *n) { brname_ = n; } protected: - fwdMapType fwdMap_; //map between edm ref and mit ptr - revMapType revMap_; //map between mit ptr and edm ref - Int_t edmProductId_; //product id for consistency check + fwdMapType fwdMap_; //map between edm ref and mit ptr + revMapType revMap_; //map between mit ptr and edm ref + Int_t edmProductId_; //product id for consistency check + std::string brname_; //branch name of MIT objects }; } @@ -59,17 +62,31 @@ inline MitClass mithep::AssociationMapsecond; else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetMit()\n") - << "Error! Edm Object not found in AssociationMap." << std::endl; + << "Error! EDM Object (" << typeid(edmObj).name() + << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl; } //-------------------------------------------------------------------------------------------------- template -inline EdmClass mithep::AssociationMap::GetEdmRef(MitClass mitObj) const +inline EdmClass mithep::AssociationMap::GetEdm(MitClass mitObj) const { typename revMapType::const_iterator iter = revMap_.find(mitObj); if (iter != revMap_.end()) return iter->second; - else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetEdmRef()\n") - << "Error! mithep Object not found in AssociationMap." << std::endl; + else throw edm::Exception(edm::errors::Configuration, "AssociationMap::GetEdm()\n") + << "Error! MITHEP Object (" << typeid(mitObj).name() + << ") not found in AssociationMap (" << typeid(*this).name() << ")." << std::endl; +} + +//-------------------------------------------------------------------------------------------------- +template +inline bool mithep::AssociationMap::HasMit(EdmClass edmObj) const +{ + typename fwdMapType::const_iterator iter = fwdMap_.find(edmObj); + + if (iter != fwdMap_.end()) + return true; + else + return false; } #endif