CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/FWCore/Framework/src/GenericObjectOwner.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Framework
00004 // Class  :     GenericObjectOwner
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Thu Feb  7 17:21:22 EST 2008
00011 //
00012 
00013 // system include files
00014 
00015 // user include files
00016 #include "FWCore/Framework/interface/GenericObjectOwner.h"
00017 #include "FWCore/Framework/interface/EventPrincipal.h"
00018 #include "FWCore/Utilities/interface/WrappedClassName.h"
00019 
00020 namespace edm {
00021 //
00022 // constants, enums and typedefs
00023 //
00024 
00025 //
00026 // static data member definitions
00027 //
00028 
00029 //
00030 // constructors and destructor
00031 //
00032 //GenericObjectOwner::GenericObjectOwner()
00033 //{
00034 //}
00035 
00036 // GenericObjectOwner::GenericObjectOwner(const GenericObjectOwner& rhs)
00037 // {
00038 //    // do actual copying here;
00039 // }
00040 
00041 GenericObjectOwner::~GenericObjectOwner()
00042 {
00043    if(m_ownData) {
00044       m_object.Destruct();
00045    }
00046 }
00047 
00048 //
00049 // assignment operators
00050 //
00051 // const GenericObjectOwner& GenericObjectOwner::operator=(const GenericObjectOwner& rhs)
00052 // {
00053 //   //An exception safe implementation is
00054 //   GenericObjectOwner temp(rhs);
00055 //   swap(rhs);
00056 //
00057 //   return *this;
00058 // }
00059 
00060 //
00061 // member functions
00062 //
00063 void 
00064 GenericObjectOwner::swap(GenericObjectOwner& iOther) {
00065    Reflex::Object old(m_object);
00066    m_object = iOther.m_object;
00067    iOther.m_object = m_object;
00068 }
00069 
00070 //
00071 // const member functions
00072 //
00073 Reflex::Object 
00074 GenericObjectOwner::object() const {
00075    return m_object;
00076 }
00077 
00078 //
00079 // static member functions
00080 //
00081 
00082 template <>
00083 OrphanHandle<GenericObjectOwner> 
00084 Event::put<GenericObjectOwner>(std::auto_ptr<GenericObjectOwner> product, std::string const& productInstanceName)
00085 {
00086    if(product.get() == 0) {                // null pointer is illegal
00087       throw edm::Exception(edm::errors::NullPointerError)
00088       << "Event::put: A null auto_ptr was passed to 'put'.\n"
00089       << "The pointer is of type " << "GenericObjectOwner" << ".\n"
00090       << "The specified productInstanceName was '" << productInstanceName << "'.\n";
00091    }
00092    
00093    // The following will call post_insert if T has such a function,
00094    // and do nothing if T has no such function.
00095    /*
00096    typename boost::mpl::if_c<detail::has_postinsert<PROD>::value, 
00097    DoPostInsert<PROD>, 
00098    DoNotPostInsert<PROD> >::type maybe_inserter;
00099    maybe_inserter(product.get());
00100    */
00101    ConstBranchDescription const& desc =
00102    provRecorder_.getBranchDescription(TypeID(product->object().TypeOf().TypeInfo()), productInstanceName);
00103    
00104    Reflex::Type const wrapperType = Reflex::Type::ByName(wrappedClassName(desc.fullClassName()));
00105    if(wrapperType == Reflex::Type()) {
00106       throw edm::Exception(errors::DictionaryNotFound, "NoWrapperDictionary")
00107       << "Event::put: the class type '" << desc.fullClassName()
00108       << "' was passed to put but the Reflex dictionary for the required class '"
00109       << wrappedClassName(desc.fullClassName()) << "' could not be found./n"
00110       << "Please change the C++ package which contains the description of '" << desc.fullClassName()
00111       << "' so that the required class also has a dictionary autogenerated.";
00112    }
00113    std::vector<void*> args;
00114    args.reserve(1);
00115    args.push_back(product->object().Address());
00116    //generate the signature of the function we want to call
00117    std::string s("void(");
00118    s += desc.fullClassName();
00119    s += "*)";
00120    Reflex::Type ptrT = Reflex::Type::ByName(s);
00121    Reflex::Object oWrapper(wrapperType.Construct(ptrT,args));
00122    //ownership was transfered to the wrapper
00123    product.release();
00124 
00125    //static Reflex::Type s_edproductType(Reflex::Type::ByTypeInfo(typeid(EDProduct)));
00126    WrapperOwningHolder wp(oWrapper.Address(), desc.getInterface());
00127    putProducts().push_back(std::make_pair(wp, &desc));
00128    
00129    // product.release(); // The object has been copied into the Wrapper.
00130    // The old copy must be deleted, so we cannot release ownership.
00131    
00132    return(OrphanHandle<GenericObjectOwner>(oWrapper.Get("obj"), eventPrincipal().branchIDToProductID(desc.branchID())));
00133 }
00134 }
00135