CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/Fireworks/Core/src/FWGenericHandle.h

Go to the documentation of this file.
00001 #ifndef Fireworks_FWGenericHandle_h
00002 #define Fireworks_FWGenericHandle_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Framework
00006 // Class  :     FWGenericHandle
00007 // 
00028 //
00029 // Original Author:  Chris Jones
00030 //         Created:  Sat Jan  7 15:40:43 EST 2006
00031 // $Id: FWGenericHandle.h,v 1.3 2012/08/03 18:20:28 wmtan Exp $
00032 //
00033 
00034 // system include files
00035 #include <string>
00036 
00037 // user include files
00038 #include "FWCore/Utilities/interface/ObjectWithDict.h"
00039 #include "FWCore/Common/interface/EventBase.h"
00040 #include "DataFormats/Common/interface/Handle.h"
00041 #include "DataFormats/Common/interface/ConvertHandle.h"
00042 
00043 // forward declarations
00044 namespace edm {
00046 struct FWGenericObject
00047 {
00048 };
00049 
00050 template<>
00051 class Handle<FWGenericObject> {
00052 public:
00054       Handle(std::string const& iName) : 
00055         type_(edm::TypeWithDict::byName(iName)), prod_(), prov_(0) {
00056            if(type_ == edm::TypeWithDict()) {
00057               Exception::throwThis(errors::NotFound,
00058                 "Handle<FWGenericObject> told to use uknown type '",
00059                 iName.c_str(),
00060                 "'.\n Please check spelling or that a module uses this type in the job.");
00061            }
00062            if(type_.isTypedef()){
00063               //For a 'edm::TypeWithDictdef' the 'toType' method returns the actual type
00064               // this is needed since you are now allowed to 'invoke' methods of a 'Typedef'
00065               // only for a 'real' class
00066               type_ = type_.toType();
00067            }
00068         }
00069    
00071    Handle(edm::TypeWithDict const& iType):
00072       type_(iType), prod_(), prov_(0) {
00073          if(iType == edm::TypeWithDict()) {
00074             Exception::throwThis(errors::NotFound, "Handle<FWGenericObject> given an invalid edm::TypeWithDict");
00075          }
00076          if(type_.isTypedef()){
00077             //For a 'edm::TypeWithDictdef' the 'toType' method returns the actual type
00078             // this is needed since you are now allowed to 'invoke' methods of a 'Typedef'
00079             // only for a 'real' class
00080             type_ = type_.toType();
00081          }
00082       }
00083    
00084    Handle(Handle<FWGenericObject> const& h):
00085    type_(h.type_),
00086    prod_(h.prod_),
00087    prov_(h.prov_),
00088    whyFailed_(h.whyFailed_)
00089    { }
00090    
00091    Handle(edm::ObjectWithDict const& prod, Provenance const* prov, ProductID const& pid):
00092    type_(prod.typeOf()),
00093    prod_(prod),
00094    prov_(prov) { 
00095       assert(prod_);
00096       assert(prov_);
00097       // assert(prov_->productID() != ProductID());
00098    }
00099    
00100       //~Handle();
00101       
00102    void swap(Handle<FWGenericObject>& other)
00103    {
00104       // use unqualified swap for user defined classes
00105       using std::swap;
00106       swap(type_, other.type_);
00107       std::swap(prod_, other.prod_);
00108       swap(prov_, other.prov_);
00109       swap(whyFailed_, other.whyFailed_);
00110    }
00111    
00112    
00113    Handle<FWGenericObject>& operator=(Handle<FWGenericObject> const& rhs)
00114    {
00115       Handle<FWGenericObject> temp(rhs);
00116       this->swap(temp);
00117       return *this;
00118    }
00119    
00120    bool isValid() const {
00121       return prod_ && 0!= prov_;
00122    }
00123 
00124    bool failedToGet() const {
00125      return 0 != whyFailed_.get();
00126    }
00127    edm::ObjectWithDict const* product() const { 
00128      if(this->failedToGet()) { 
00129        whyFailed_->raise();
00130      } 
00131      return &prod_;
00132    }
00133    edm::ObjectWithDict const* operator->() const {return this->product();}
00134    edm::ObjectWithDict const& operator*() const {return *(this->product());}
00135    
00136    edm::TypeWithDict const& type() const {return type_;}
00137    Provenance const* provenance() const {return prov_;}
00138    
00139    ProductID id() const {return prov_->productID();}
00140 
00141    void clear() { prov_ = 0; whyFailed_.reset();}
00142       
00143    void setWhyFailed(boost::shared_ptr<cms::Exception> const& iWhyFailed) {
00144     whyFailed_=iWhyFailed;
00145   }
00146 private:
00147    edm::TypeWithDict type_;
00148    edm::ObjectWithDict prod_;
00149    Provenance const* prov_;    
00150    boost::shared_ptr<cms::Exception> whyFailed_;
00151 };
00152 
00153 typedef Handle<FWGenericObject> FWGenericHandle;
00154 
00156 void convert_handle(BasicHandle const& orig,
00157                     Handle<FWGenericObject>& result);
00158 
00159 
00161 template <>
00162 bool
00163 edm::EventBase::getByLabel(edm::InputTag const& tag, Handle<FWGenericObject>& result) const;   
00164 
00165 }
00166 #endif