CMS 3D CMS Logo

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