CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/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.1 2010/07/23 16:02:54 eulisse Exp $
00032 //
00033 
00034 // system include files
00035 #include <string>
00036 
00037 // user include files
00038 #include "Reflex/Object.h"
00039 #include "FWCore/Common/interface/EventBase.h"
00040 #include "FWCore/Utilities/interface/UseReflex.h"
00041 #include "DataFormats/Common/interface/Handle.h"
00042 #include "DataFormats/Common/interface/ConvertHandle.h"
00043 
00044 // forward declarations
00045 namespace edm {
00047 struct FWGenericObject
00048 {
00049 };
00050 
00051 template<>
00052 class Handle<FWGenericObject> {
00053 public:
00055       Handle(std::string const& iName) : 
00056         type_(Reflex::Type::ByName(iName)), prod_(), prov_(0) {
00057            if(type_ == Reflex::Type()) {
00058               Exception::throwThis(errors::NotFound,
00059                 "Handle<FWGenericObject> told to use uknown type '",
00060                 iName.c_str(),
00061                 "'.\n Please check spelling or that a module uses this type in the job.");
00062            }
00063            if(type_.IsTypedef()){
00064               //For a 'Reflex::Typedef' the 'toType' method returns the actual type
00065               // this is needed since you are now allowed to 'invoke' methods of a 'Typedef'
00066               // only for a 'real' class
00067               type_ = type_.ToType();
00068            }
00069         }
00070    
00072    Handle(Reflex::Type const& iType):
00073       type_(iType), prod_(), prov_(0) {
00074          if(iType == Reflex::Type()) {
00075             Exception::throwThis(errors::NotFound, "Handle<FWGenericObject> given an invalid Reflex::Type");
00076          }
00077          if(type_.IsTypedef()){
00078             //For a 'Reflex::Typedef' the 'toType' method returns the actual type
00079             // this is needed since you are now allowed to 'invoke' methods of a 'Typedef'
00080             // only for a 'real' class
00081             type_ = type_.ToType();
00082          }
00083       }
00084    
00085    Handle(Handle<FWGenericObject> const& h):
00086    type_(h.type_),
00087    prod_(h.prod_),
00088    prov_(h.prov_),
00089    whyFailed_(h.whyFailed_)
00090    { }
00091    
00092    Handle(Reflex::Object const& prod, Provenance const* prov, ProductID const& pid):
00093    type_(prod.TypeOf()),
00094    prod_(prod),
00095    prov_(prov) { 
00096       assert(prod_);
00097       assert(prov_);
00098       // assert(prov_->productID() != ProductID());
00099    }
00100    
00101       //~Handle();
00102       
00103    void swap(Handle<FWGenericObject>& other)
00104    {
00105       // use unqualified swap for user defined classes
00106       using std::swap;
00107       swap(type_, other.type_);
00108       std::swap(prod_, other.prod_);
00109       swap(prov_, other.prov_);
00110       swap(whyFailed_, other.whyFailed_);
00111    }
00112    
00113    
00114    Handle<FWGenericObject>& operator=(Handle<FWGenericObject> const& rhs)
00115    {
00116       Handle<FWGenericObject> temp(rhs);
00117       this->swap(temp);
00118       return *this;
00119    }
00120    
00121    bool isValid() const {
00122       return prod_ && 0!= prov_;
00123    }
00124 
00125    bool failedToGet() const {
00126      return 0 != whyFailed_.get();
00127    }
00128    Reflex::Object const* product() const { 
00129      if(this->failedToGet()) { 
00130        whyFailed_->raise();
00131      } 
00132      return &prod_;
00133    }
00134    Reflex::Object const* operator->() const {return this->product();}
00135    Reflex::Object const& operator*() const {return *(this->product());}
00136    
00137    Reflex::Type const& type() const {return type_;}
00138    Provenance const* provenance() const {return prov_;}
00139    
00140    ProductID id() const {return prov_->productID();}
00141 
00142    void clear() { prov_ = 0; whyFailed_.reset();}
00143       
00144    void setWhyFailed(boost::shared_ptr<cms::Exception> const& iWhyFailed) {
00145     whyFailed_=iWhyFailed;
00146   }
00147 private:
00148    Reflex::Type type_;
00149    Reflex::Object prod_;
00150    Provenance const* prov_;    
00151    boost::shared_ptr<cms::Exception> whyFailed_;
00152 };
00153 
00154 typedef Handle<FWGenericObject> FWGenericHandle;
00155 
00157 void convert_handle(BasicHandle const& orig,
00158                     Handle<FWGenericObject>& result);
00159 
00160 
00162 template <>
00163 bool
00164 edm::EventBase::getByLabel(edm::InputTag const& tag, Handle<FWGenericObject>& result) const;   
00165 
00166 }
00167 #endif